(cssEntries)
| 73 | * @returns {ReturnType<typeof createTask>} |
| 74 | */ |
| 75 | export function createBundleCSSTask(cssEntries) { |
| 76 | /** @type {string[]} */ |
| 77 | let currentWatchFiles; |
| 78 | |
| 79 | const getWatchFiles = () => { |
| 80 | const watchFiles = new Set(); |
| 81 | cssEntries.forEach((entry) => { |
| 82 | entry.watchFiles?.forEach((file) => watchFiles.add(file)); |
| 83 | const entryFile = getEntryFile(entry); |
| 84 | if (!watchFiles.has(entryFile)) { |
| 85 | watchFiles.add(entryFile); |
| 86 | } |
| 87 | }); |
| 88 | currentWatchFiles = Array.from(watchFiles); |
| 89 | return currentWatchFiles; |
| 90 | }; |
| 91 | |
| 92 | const bundleCSS = async ({platforms, debug}) => { |
| 93 | for (const entry of cssEntries) { |
| 94 | for (const platform in platforms) { |
| 95 | if (!platforms[platform]) { |
| 96 | continue; |
| 97 | } |
| 98 | const css = await bundleCSSEntry(entry, platform === PLATFORM.CHROMIUM_MV2_PLUS); |
| 99 | await writeFiles(entry.dest, {[platform]: true}, debug, css); |
| 100 | } |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | /** @type {(changedFiles: string[], watcher: FSWatcher, platforms: any) => Promise<void>} */ |
| 105 | const onChange = async (changedFiles, watcher, platforms) => { |
| 106 | const entries = cssEntries.filter((entry) => { |
| 107 | const entryFile = getEntryFile(entry); |
| 108 | return changedFiles.some((changed) => { |
| 109 | return entry.watchFiles?.includes(changed) || changed === entryFile; |
| 110 | }); |
| 111 | }); |
| 112 | for (const entry of entries) { |
| 113 | const css = await bundleCSSEntry(entry, true); |
| 114 | await writeFiles(entry.dest, platforms, true, css); |
| 115 | } |
| 116 | |
| 117 | const newWatchFiles = getWatchFiles(); |
| 118 | watcher.unwatch( |
| 119 | currentWatchFiles.filter((oldFile) => !newWatchFiles.includes(oldFile)) |
| 120 | ); |
| 121 | watcher.add( |
| 122 | newWatchFiles.filter((newFile) => currentWatchFiles.includes(newFile)) |
| 123 | ); |
| 124 | |
| 125 | reload.reload({type: reload.CSS}); |
| 126 | }; |
| 127 | |
| 128 | return createTask( |
| 129 | 'bundle-css', |
| 130 | bundleCSS, |
| 131 | ).addWatcher( |
| 132 | () => { |
no test coverage detected