-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathmincer.js
executable file
·130 lines (86 loc) · 2.48 KB
/
mincer.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env node
'use strict';
// stdlib
var fs = require('fs');
var path = require('path');
// 3rd-party
var ArgumentParser = require('argparse').ArgumentParser;
var shellwords = require('shellwords').split;
// internal
var Mincer = require('..');
////////////////////////////////////////////////////////////////////////////////
var cli = new ArgumentParser({
prog: 'mincer',
version: require('../package.json').version,
addHelp: true
});
cli.addArgument([ '--noenv' ], {
help: 'Disables .mincerrc file',
action: 'storeTrue'
});
cli.addArgument([ '-I', '--include' ], {
help: 'Adds the directory to the Mincer load path',
metavar: 'DIRECTORY',
action: 'append',
required: true
});
cli.addArgument([ '-o', '--output' ], {
help: 'Copy provided assets into DIRECTORY',
metavar: 'DIRECTORY'
});
cli.addArgument([ 'filenames' ], {
help: 'File(s) to process',
metavar: 'FILE',
nargs: '+'
});
////////////////////////////////////////////////////////////////////////////////
if (process.argv.indexOf('--noenv') === -1) {
if (fs.existsSync('.mincerrc')) {
var rcflags = fs.readFileSync('.mincerrc', 'utf8').replace(/^#.*/gm, '');
[].splice.apply(process.argv, [ 2, 0 ].concat(shellwords(rcflags)));
}
}
var args = cli.parseArgs();
var environment = new Mincer.Environment(process.cwd());
var filenames = [];
(process.env.MINCER_PATH || '').split(':').forEach(function (path) {
if (path) {
environment.appendPath(path);
}
});
args.include.forEach(function (path) {
environment.appendPath(path);
});
args.filenames.forEach(function (file) {
filenames.push(path.normalize(file));
});
////////////////////////////////////////////////////////////////////////////////
//
// Configure Mincer logger
//
Mincer.logger.use(console);
//
// Compiling manifest with bunch of files
//
/*eslint-disable no-console*/
if (args.output) {
var manifest = new Mincer.Manifest(environment, args.output);
try {
manifest.compile(filenames);
} catch (err) {
console.error(err);
process.exit(1);
}
process.exit(0);
}
if (filenames.length === 1) {
var asset = environment.findAsset(filenames[0]);
if (!asset) {
console.error('Cannot find logical path: ' + filenames[0]);
process.exit(1);
}
process.stdout.write(asset.toString());
process.exit(0);
}
console.error('Only one file can be compiled to stdout at a time');
process.exit(1);