-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
78 lines (74 loc) · 1.82 KB
/
index.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
72
73
74
75
76
77
78
'use strict';
var argv = require('yargs')
.usage('Usage: usemin [input.html] [--dest|-d dir] [--output|-o output.html] [options]')
.example('usemin src/index.html -d dist -o dist/index.html', '')
.example('usemin src/index.html -d dist > dist/index.html', '')
.options({
'd': {
alias: 'dest',
demand: 'Please specify the output directory',
describe: 'Output directory for compressed output files',
type: 'string',
},
'o': {
alias: 'output',
describe: 'HTML output file',
type: 'string',
},
'htmlmin': {
default: false,
describe: 'Also minifies the input HTML file',
type: 'boolean',
},
'rmlr': {
alias: 'removeLivereload',
default: false,
describe: 'Remove livereload script',
type: 'boolean',
},
'noprocess': {
default: false,
describe: 'Do not process files, just replace references',
type: 'boolean',
},
'c': {
alias: 'config',
describe: 'Config file for UglifyJS, CleanCSS and htmlmin',
type: 'string',
},
'listblocks': {
default: 'false',
describe: ('Write blocks to stdout or filename.json.\n' +
'E.g., --listblocks\n.' +
' --listblocks blocks.json'),
type: 'string',
},
})
.demand(1)
.argv;
var fs = require('fs');
var usemin = require('usemin');
var html = usemin(argv._[0], argv.dest, {
output: argv.o,
configFile: argv.c,
htmlmin: argv.htmlmin,
noprocess: argv.noprocess,
removeLivereload: argv.removeLivereload,
});
if (argv.listblocks !== 'false') {
var content = fs.readFileSync(argv._[0]).toString();
var blocks = JSON.stringify(usemin.getBlocks(argv._[0], content, argv.removeLivereload),
null, ' ');
if (argv.listblocks === '') {
console.log(blocks);
} else {
fs.writeFile(argv.listblocks, blocks, function (err) {
if (err) {
return console.error(err);
}
});
}
}
if (!argv.o) {
console.log(html);
}