-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacksfc.js
71 lines (51 loc) · 1.75 KB
/
packsfc.js
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
67
68
69
70
71
#!/usr/bin/env node
// packsfc.js
// copy all files for the full featured web server into the dist folder
// ready to be published on http://homeding.github.io/vxx
// ===== Packages used =====
import { readFile, writeFile } from 'node:fs/promises';
import console from 'node:console';
import yargs from 'yargs';
import * as HTMLMinifier from 'html-minifier-terser';
const sfcFolder = "sfc";
const sfcExt = ".vue";
const outFile = sfcFolder + "\\bundle" + sfcExt;
// ===== Command line support =====
const options = yargs(process.argv.slice(2))
.usage('Usage: $0 [options] <sfc-names> ...')
.option('v', { alias: 'verbose', describe: 'Verbose logging', type: 'boolean', demandOption: false, default: false })
.option('p', { alias: 'pack', describe: 'pack resulting file', type: 'boolean', demandOption: false, default: true })
.demandCommand(1)
.argv;
// ===== initializing modules =====
// wrap component
async function wrapSFC(sfcName, pack = false) {
let txt;
console.log(`reading ${sfcName} ...`);
txt = await readFile(sfcFolder + '/' + sfcName + sfcExt, 'utf8')
// console.log(txt);
if (pack) {
txt = await HTMLMinifier.minify(txt, {
collapseWhitespace: true,
removeComments: true,
removeTagWhitespace: true,
minifyCSS: true,
minifyJS: true,
verbose: true,
quoteCharacter: "'"
});
}
txt = `<sfc tag='${sfcName}'>\n${txt}\n</sfc>\n`;
return (txt);
}
console.log(`Start bundling SFCs...`);
let txt = '';
for (const c of options._) {
txt += await wrapSFC(c, options.pack);
}
console.log(`writing ${outFile} ...`);
await writeFile(outFile, txt, 'utf-8');
if (options.verbose) {
console.log(txt);
}
console.log(`done.`);