UNPKG

816 BPlain TextView Raw
1#!/usr/bin/env node
2
3var fs = require('fs');
4var path = require('path');
5
6var compile = require('../index').compile;
7
8var getPackage = () => {
9 let content = fs.readFileSync('package.json', 'utf8');
10 return JSON.parse(content) || null;
11};
12
13let pack = getPackage();
14if (pack || !pack.gccmin) {
15 let conf = pack.gccmin;
16 let source = conf.source;
17 if (!path.extname(source)) {
18 source += '/main.js';
19 }
20 if (!fs.existsSync(source)) {
21 throw new Error(`${source} could not be found.`);
22 }
23
24 let {
25 repository,
26 author,
27 license,
28 name,
29 description,
30 version
31 } = pack;
32
33 Object.assign(conf, {
34 repository,
35 author,
36 license,
37 name,
38 description,
39 version
40 });
41
42 conf.code = fs.readFileSync(source, 'utf8');
43
44 let output = compile(conf);
45 console.log(output);
46}