-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
66 lines (59 loc) · 1.76 KB
/
Copy pathbuild.mjs
File metadata and controls
66 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import * as esbuild from 'esbuild';
import fs from 'fs';
const isWatch = process.argv.includes( '--watch' );
const builds = [
{
entryPoints: [ 'assets/js/clink-checkout.js' ],
bundle: true,
minify: true,
outfile: 'assets/js/clink-checkout.min.js',
target: [ 'es2020' ],
format: 'iife',
globalName: 'ClinkCheckout',
loader: { '.wasm': 'empty' },
},
{
entryPoints: [ 'assets/js/clink-blocks.js' ],
bundle: false,
minify: true,
outfile: 'assets/js/clink-blocks.min.js',
target: [ 'es2020' ],
format: 'iife',
},
{
entryPoints: [ 'assets/js/clink-price-converter.js' ],
bundle: false,
minify: true,
outfile: 'assets/js/clink-price-converter.min.js',
target: [ 'es2020' ],
format: 'iife',
},
];
function stripGistUrl( file ) {
let content = fs.readFileSync( file, 'utf8' );
const gistRe = /`https:\/\/gist\.github\.com\/\$\{[^}]+\}\/\$\{[^}]+\}\/raw`/;
const verifyRe = /`Verifying that I control the following Nostr public key: \$\{[^}]+\}`/;
if ( gistRe.test( content ) || verifyRe.test( content ) ) {
content = content.replace( gistRe, '`/dev/null/gist/${e}/${n}/raw`' );
content = content.replace( verifyRe, '`gist-verify:${t}`' );
fs.writeFileSync( file, content, 'utf8' );
console.log( ' Stripped remote URLs from:', file );
}
}
if ( isWatch ) {
for ( const cfg of builds ) {
const ctx = await esbuild.context( cfg );
await ctx.watch();
}
console.log( 'Watching for changes...' );
} else {
for ( const cfg of builds ) {
await esbuild.build( cfg );
console.log( 'Build complete:', cfg.outfile );
}
for ( const cfg of builds ) {
if ( cfg.outfile && cfg.outfile.includes( 'clink-checkout' ) ) {
stripGistUrl( cfg.outfile );
}
}
}