| 18 | } |
| 19 | let entryPoints: {sPath: string; newPath: string}[] = []; |
| 20 | async function bundleFiles() { |
| 21 | const filter = new Set<string>(); |
| 22 | entryPoints = entryPoints.filter((_) => { |
| 23 | if (filter.has(_.sPath)) return false; |
| 24 | filter.add(_.sPath); |
| 25 | return true; |
| 26 | }); |
| 27 | let mod = await swc.bundle( |
| 28 | entryPoints.map(({sPath}) => { |
| 29 | return { |
| 30 | entry: sPath, |
| 31 | output: { |
| 32 | path: path.parse(sPath).dir, |
| 33 | name: path.parse(sPath).base, |
| 34 | }, |
| 35 | env: { |
| 36 | targets: "Chrome > 120", |
| 37 | }, |
| 38 | module: { |
| 39 | minify: true, |
| 40 | sourceMaps: true, |
| 41 | isModule: true, |
| 42 | jsc: { |
| 43 | minify: { |
| 44 | mangle: false, |
| 45 | }, |
| 46 | }, |
| 47 | }, |
| 48 | externalModules: ["/translations/langs.js"], |
| 49 | options: { |
| 50 | minify: !process.argv.includes("watch"), |
| 51 | jsc: { |
| 52 | minify: { |
| 53 | mangle: false, |
| 54 | }, |
| 55 | }, |
| 56 | }, |
| 57 | }; |
| 58 | }), |
| 59 | ); |
| 60 | |
| 61 | await Promise.all( |
| 62 | entryPoints.map(async ({sPath, newPath}) => { |
| 63 | const code = mod[path.parse(sPath).base] || mod; |
| 64 | const newfileDir = path.join(newPath, path.parse(sPath).name); |
| 65 | |
| 66 | await Promise.all([ |
| 67 | fs.writeFile( |
| 68 | newfileDir + ".js", |
| 69 | code.code + "\n" + `//# sourceMappingURL=${path.parse(sPath).name}.js.map`, |
| 70 | ), |
| 71 | code.map ? fs.writeFile(newfileDir + ".js.map", code.map as string) : null, |
| 72 | ]); |
| 73 | }), |
| 74 | ); |
| 75 | } |
| 76 | async function moveFiles(curPath: string, newPath: string, first = true) { |
| 77 | async function processFile(file: string) { |