-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbin.js
More file actions
executable file
·39 lines (35 loc) · 1.01 KB
/
Copy pathbin.js
File metadata and controls
executable file
·39 lines (35 loc) · 1.01 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
#!/usr/bin/env node
const asbundle = require('./index.js');
const argv = process.argv.filter(arg => !/^-/.test(arg));
let source = argv[2];
if (!source) {
const info = require('./package.json');
console.log(`
\x1B[1masbundle\x1B[0m v${info.version}
${'-'.repeat(info.description.length)}
${info.description}
${'-'.repeat(info.description.length)}
asbundle sourceFile
asbundle sourceFile destFile
${'-'.repeat(info.description.length)}
${' '.repeat(info.description.length)
.slice(0, -(3 + info.author.length))}by ${info.author}
`);
} else {
const fs = require('fs');
const path = require('path');
let dest = argv.filter(arg => !/^-/.test(arg))[3];
source = path.resolve(process.cwd(), source);
if (dest) {
dest = path.resolve(process.cwd(), dest)
}
fs.stat(source, (err, stat) => {
if (err) throw err;
if (!stat.isFile()) throw `unknown file ${source}`;
const result = asbundle(source);
if (dest) {
fs.writeFileSync(dest, result);
}
else process.stdout.write(result);
});
}