Tools for Deno-Powered Web Extensions
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Expose paths as script args (#9)

Allows for passing custom build target locations

authored by

Moritz Tim W. and committed by
GitHub
ad13d104 03be6e36

+44 -15
+7 -1
README.md
··· 23 23 > bext chrome # only chrome 24 24 > bext firefox # only ff 25 25 26 - > bext --watch # build again on change 26 + # Watch mode 27 + > bext --watch # or -w: build again on change 27 28 > bext chrome -w # variations can be used for single-platform 28 29 > bext firefox --watch 30 + 31 + # Custom directories 32 + > bext --source=src # --source or -s: specify source directory (default: "source") 33 + > bext --source=src --static=assets # --static or -t: specify static assets directory (default: "static") 34 + > bext --source=src --static=assets --output=build # --output or -o: specify output directory (default: "dist") 29 35 ``` 30 36 31 37 ## Types and Utilities
+37 -14
source/main.ts
··· 14 14 * bext --watch # build again on change 15 15 * bext chrome -w # variations can be used for single-platform 16 16 * bext firefox --watch 17 + * bext --source=src --static=public --output=builds # custom paths 17 18 * ``` 18 19 */ 19 20 ··· 35 36 [id: string]: BrowserManifestSettings 36 37 } 37 38 38 - const args = parseArgs(Deno.args) 39 - const isWatching = args.watch || args.w 39 + const args = parseArgs(Deno.args, { 40 + string: ['source', 'static', 'output'], 41 + boolean: ['watch'], 42 + alias: { 43 + w: 'watch', 44 + s: 'source', 45 + t: 'static', 46 + o: 'output', 47 + }, 48 + default: { 49 + source: 'source', 50 + static: 'static', 51 + output: 'dist', 52 + }, 53 + }) 54 + 55 + const isWatching = args.watch 40 56 41 57 const browsers: BrowserManifests = { 42 58 chrome: { ··· 58 74 if (args._[0] === 'chrome') delete browsers.firefox 59 75 if (args._[0] === 'firefox') delete browsers.chrome 60 76 77 + const entryPoints = [ 78 + 'options.tsx', 79 + 'content_script.ts', 80 + 'background.ts', 81 + 'popup.tsx', 82 + ].map((file) => `${args.source}/${file}`) 83 + 61 84 console.log('\x1b[37mPackager\n========\x1b[0m') 85 + console.log(`Using paths: 86 + Source: "${resolve(args.source)}" 87 + Static: "${resolve(args.static)}" 88 + output: "${resolve(args.output)}" 89 + `) 62 90 63 91 const builds = Object.keys(browsers).map(async (browserId) => { 64 - const distDir = `dist/${browserId}` 92 + /** Browser-Specific Build Path */ 93 + const outdir = `${args.output}/${browserId}` 65 94 66 95 // Copy JS/HTML/CSS/ICONS 67 - ensureDir(`${distDir}/static`) 96 + ensureDir(`${outdir}/static`) 68 97 69 98 const options = { overwrite: true } 70 - copySync('static', distDir, options) 99 + copySync(args.static, outdir, options) 71 100 72 101 const browserManifestSettings = browsers[browserId] 73 102 74 103 // Transform Manifest 75 104 const manifest = { 76 - ...JSON.parse(Deno.readTextFileSync('source/manifest.json')), 105 + ...JSON.parse(Deno.readTextFileSync(`${args.source}/manifest.json`)), 77 106 ...browserManifestSettings.overrides, 78 107 } 79 108 browserManifestSettings.omits.forEach((omit) => delete manifest[omit]) 80 109 81 110 Deno.writeTextFileSync( 82 - distDir + '/manifest.json', 111 + outdir + '/manifest.json', 83 112 JSON.stringify(manifest, null, 2), 84 113 ) 85 114 86 115 const color = browserManifestSettings.color || '' 87 116 const browserName = browserId.toUpperCase() 88 117 const colorizedBrowserName = `\x1b[1m${color}${browserName}\x1b[0m` 89 - const outdir = `dist/${browserId}/` 90 118 91 119 console.log(`Initializing ${colorizedBrowserName} build...`) 92 120 const esBuildOptions: esbuild.BuildOptions = { 93 - entryPoints: [ 94 - 'source/options.tsx', 95 - 'source/content_script.ts', 96 - 'source/background.ts', 97 - 'source/popup.tsx', 98 - ], 121 + entryPoints, 99 122 outdir, 100 123 bundle: true, 101 124 format: 'esm',