-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml.mjs
More file actions
executable file
·30 lines (26 loc) · 1 KB
/
Copy pathhtml.mjs
File metadata and controls
executable file
·30 lines (26 loc) · 1 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
#!/usr/bin/env node
import { program } from 'commander';
import { updateImportmap } from './index.js';
import { readFile } from 'node:fs/promises';
import pkg from './package.json' with { type: 'json' };
async function init() {
program
.name(Object.keys(pkg.bin)[1])
.version(pkg.version)
.argument('<html-file>')
.description('CLI utility for updating `<script type="importmap">` in HTML files')
.option('-a, --algo [algo]', 'Hashing algorigthm to use for `integrity`', 'SHA-384')
.option('-s, --spaces [spaces]', 'Spaces to indent with', (spaces) => parseInt(spaces) || 0)
.option('-i, --importmap [importmap]', 'Source importmap.json file.', file => readFile(file, { encoding: 'utf8' }).then(data => JSON.parse(data)))
.parse(process.argv);
return {
args: program.args,
opts: program.opts(),
};
}
init().then(async ({
args: [file],
opts: { algo = 'SHA-384', importmap = Promise.resolve(), spaces } = {}
} = {}) => {
await updateImportmap(file, { algo, spaces, importmap: await importmap });
});