|
1 | | -import { build } from "esbuild"; |
2 | | -import { |
3 | | - rmSync, |
4 | | - mkdirSync, |
5 | | - cpSync, |
6 | | - writeFileSync, |
7 | | - createWriteStream, |
8 | | -} from "fs"; |
9 | | -import { join } from "path"; |
10 | | -import process from "process"; |
11 | | -import archiver from "archiver"; |
| 1 | +import { build } from 'esbuild'; |
| 2 | +import { rmSync, mkdirSync, cpSync, writeFileSync, createWriteStream } from 'fs'; |
| 3 | +import { join } from 'path'; |
| 4 | +import process from 'process'; |
| 5 | +import archiver from 'archiver'; |
12 | 6 |
|
13 | 7 | const args = process.argv.slice(2); |
14 | | -const isProduction = args.includes("--production"); |
15 | | -const browserFlag = args.find((arg) => arg.startsWith("--browser=")); |
16 | | -const browser = browserFlag ? browserFlag.split("=")[1] : "chrome"; |
| 8 | +const isProduction = args.includes('--production'); |
| 9 | +const browserFlag = args.find((arg) => arg.startsWith('--browser=')); |
| 10 | +const browser = browserFlag ? browserFlag.split('=')[1] : 'chrome'; |
17 | 11 |
|
18 | 12 | const outdir = `build/${browser}`; |
19 | 13 | rmSync(outdir, { recursive: true, force: true }); |
20 | 14 | mkdirSync(outdir, { recursive: true }); |
21 | 15 |
|
22 | 16 | const staticDirs = [ |
23 | | - "assets", |
24 | | - "dashboard", |
25 | | - "editor", |
26 | | - "offscreen", |
27 | | - "popup", |
28 | | - "GM", |
29 | | - "utils", |
30 | | - "ai_dom_editor", |
31 | | - "_locales", |
| 17 | + 'assets', |
| 18 | + 'dashboard', |
| 19 | + 'editor', |
| 20 | + 'offscreen', |
| 21 | + 'popup', |
| 22 | + 'GM', |
| 23 | + 'utils', |
| 24 | + 'ai_dom_editor', |
| 25 | + '_locales', |
32 | 26 | ]; |
33 | 27 | for (const dir of staticDirs) { |
34 | 28 | cpSync(`src/${dir}`, join(outdir, dir), { recursive: true }); |
35 | 29 | } |
36 | 30 |
|
37 | 31 | const manifest = { |
38 | 32 | manifest_version: 3, |
39 | | - name: "__MSG_appName__", |
40 | | - version: "1.0.0", |
41 | | - description: "__MSG_appDescription__", |
42 | | - default_locale: "en", |
| 33 | + name: '__MSG_appName__', |
| 34 | + version: '1.0.0', |
| 35 | + description: '__MSG_appDescription__', |
| 36 | + default_locale: 'en', |
43 | 37 | permissions: [ |
44 | | - "storage", |
45 | | - "tabs", |
46 | | - "scripting", |
47 | | - "webNavigation", |
48 | | - "contextMenus", |
49 | | - "notifications", |
50 | | - "offscreen", |
51 | | - "clipboardWrite", |
52 | | - "downloads", |
| 38 | + 'storage', |
| 39 | + 'tabs', |
| 40 | + 'scripting', |
| 41 | + 'webNavigation', |
| 42 | + 'contextMenus', |
| 43 | + 'notifications', |
| 44 | + 'offscreen', |
| 45 | + 'clipboardWrite', |
| 46 | + 'downloads', |
53 | 47 | ], |
54 | | - host_permissions: ["http://*/*", "https://*/*"], |
| 48 | + host_permissions: ['http://*/*', 'https://*/*'], |
55 | 49 | background: { |
56 | | - service_worker: "background/background.js", |
57 | | - type: "module", |
| 50 | + service_worker: 'background/background.js', |
| 51 | + type: 'module', |
58 | 52 | }, |
59 | 53 | action: { |
60 | | - default_popup: "popup/popup.html", |
| 54 | + default_popup: 'popup/popup.html', |
61 | 55 | default_icon: { |
62 | | - 16: "assets/icons/icon16.png", |
63 | | - 48: "assets/icons/icon48.png", |
64 | | - 128: "assets/icons/icon128.png", |
| 56 | + 16: 'assets/icons/icon16.png', |
| 57 | + 48: 'assets/icons/icon48.png', |
| 58 | + 128: 'assets/icons/icon128.png', |
65 | 59 | }, |
66 | 60 | }, |
67 | 61 | icons: { |
68 | | - 16: "assets/icons/icon16.png", |
69 | | - 48: "assets/icons/icon48.png", |
70 | | - 128: "assets/icons/icon128.png", |
| 62 | + 16: 'assets/icons/icon16.png', |
| 63 | + 48: 'assets/icons/icon48.png', |
| 64 | + 128: 'assets/icons/icon128.png', |
71 | 65 | }, |
72 | 66 | content_scripts: [ |
73 | 67 | { |
74 | | - matches: ["http://*/*", "https://*/*"], |
75 | | - js: ["elementSelector/main.js"], |
76 | | - css: ["assets/styles/elementSelector.css"], |
77 | | - run_at: "document_start", |
| 68 | + matches: ['http://*/*', 'https://*/*'], |
| 69 | + js: ['elementSelector/main.js'], |
| 70 | + css: ['assets/styles/elementSelector.css'], |
| 71 | + run_at: 'document_start', |
78 | 72 | }, |
79 | 73 | { |
80 | | - matches: ["http://*/*", "https://*/*"], |
81 | | - js: ["utils/content_bridge.js"], |
82 | | - run_at: "document_start", |
83 | | - world: "ISOLATED", |
| 74 | + matches: ['http://*/*', 'https://*/*'], |
| 75 | + js: ['utils/content_bridge.js'], |
| 76 | + run_at: 'document_start', |
| 77 | + world: 'ISOLATED', |
84 | 78 | }, |
85 | 79 | { |
86 | | - matches: ["http://*/*", "https://*/*"], |
87 | | - js: ["ai_dom_editor/editor/ai_dom_content.js", "ai_dom_editor/sidebar/ai_dom_sidebar.js"], |
88 | | - run_at: "document_idle", |
| 80 | + matches: ['http://*/*', 'https://*/*'], |
| 81 | + js: ['ai_dom_editor/editor/ai_dom_content.js', 'ai_dom_editor/sidebar/ai_dom_sidebar.js'], |
| 82 | + run_at: 'document_idle', |
89 | 83 | }, |
90 | 84 | { |
91 | | - matches: ["https://greasyfork.org/*"], |
92 | | - js: ["utils/greasyfork_interceptor.js"], |
93 | | - run_at: "document_start", |
| 85 | + matches: ['https://greasyfork.org/*'], |
| 86 | + js: ['utils/greasyfork_interceptor.js'], |
| 87 | + run_at: 'document_start', |
94 | 88 | }, |
95 | 89 | ], |
96 | 90 | web_accessible_resources: [ |
97 | 91 | { |
98 | | - resources: ["utils/*", "GM/*", "ai_dom_editor/*"], |
99 | | - matches: ["<all_urls>"], |
| 92 | + resources: ['utils/*', 'GM/*', 'ai_dom_editor/*'], |
| 93 | + matches: ['<all_urls>'], |
100 | 94 | }, |
101 | 95 | ], |
102 | 96 | }; |
103 | 97 |
|
104 | | -writeFileSync(join(outdir, "manifest.json"), JSON.stringify(manifest, null, 2)); |
| 98 | +writeFileSync(join(outdir, 'manifest.json'), JSON.stringify(manifest, null, 2)); |
105 | 99 | await build({ |
106 | 100 | entryPoints: [ |
107 | | - "src/background/background.js", |
108 | | - "src/utils/content_bridge.js", |
109 | | - "src/elementSelector/main.js", |
110 | | - "src/GM/gm_core.js", |
111 | | - "src/utils/greasyfork_interceptor.js", |
112 | | - "src/utils/inject.js", |
113 | | - "src/utils/urls.js", |
114 | | - "src/popup/popup.js", |
115 | | - "src/editor/editor.js", |
116 | | - "src/dashboard/dashboard.js", |
117 | | - "src/ai_dom_editor/editor/ai_dom_content.js", |
118 | | - "src/ai_dom_editor/sidebar/ai_dom_sidebar.js", |
119 | | - "src/ai_dom_editor/editor/ai_dom_editor.js", |
120 | | - "src/ai_dom_editor/settings/ai_settings.js", |
| 101 | + 'src/background/background.js', |
| 102 | + 'src/utils/content_bridge.js', |
| 103 | + 'src/elementSelector/main.js', |
| 104 | + 'src/GM/gm_core.js', |
| 105 | + 'src/utils/greasyfork_interceptor.js', |
| 106 | + 'src/utils/inject.js', |
| 107 | + 'src/utils/urls.js', |
| 108 | + 'src/popup/popup.js', |
| 109 | + 'src/editor/editor.js', |
| 110 | + 'src/dashboard/dashboard.js', |
| 111 | + 'src/ai_dom_editor/editor/ai_dom_content.js', |
| 112 | + 'src/ai_dom_editor/sidebar/ai_dom_sidebar.js', |
| 113 | + 'src/ai_dom_editor/editor/ai_dom_editor.js', |
| 114 | + 'src/ai_dom_editor/settings/ai_settings.js', |
121 | 115 | ], |
122 | 116 | bundle: true, |
123 | 117 | outdir, |
124 | | - logLevel: "info", |
125 | | - platform: "browser", |
| 118 | + logLevel: 'info', |
| 119 | + platform: 'browser', |
126 | 120 | define: { |
127 | | - "process.env.BROWSER": JSON.stringify(browser), |
| 121 | + 'process.env.BROWSER': JSON.stringify(browser), |
128 | 122 | }, |
129 | 123 | }); |
130 | 124 | if (isProduction) { |
131 | 125 | const archiveName = `codetweak-${browser}.zip`; |
132 | | - const output = createWriteStream(join("build", archiveName)); |
133 | | - const archive = archiver("zip", { zlib: { level: 9 } }); |
| 126 | + const output = createWriteStream(join('build', archiveName)); |
| 127 | + const archive = archiver('zip', { zlib: { level: 9 } }); |
134 | 128 |
|
135 | | - output.on("close", () => { |
136 | | - console.log( |
137 | | - `Successfully created ${archiveName} (${archive.pointer()} bytes)` |
138 | | - ); |
| 129 | + output.on('close', () => { |
| 130 | + console.log(`Successfully created ${archiveName} (${archive.pointer()} bytes)`); |
139 | 131 | }); |
140 | 132 |
|
141 | | - archive.on("error", (err) => { |
| 133 | + archive.on('error', (err) => { |
142 | 134 | throw err; |
143 | 135 | }); |
144 | 136 |
|
|
0 commit comments