This repository was archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathcli.js
More file actions
102 lines (82 loc) · 2.7 KB
/
cli.js
File metadata and controls
102 lines (82 loc) · 2.7 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
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
#!/usr/bin/env node
import path from 'path';
import mkdirp from 'mkdirp';
import {createCompilerHostFromProjectRoot} from './config-parser';
import {forAllFiles} from './for-all-files';
process.on('unhandledRejection', (e) => {
d(e.message || e);
d(e.stack || '');
});
process.on('uncaughtException', (e) => {
d(e.message || e);
d(e.stack || '');
});
export async function main(appDir, sourceDirs, cacheDir, sourceMapDir) {
let compilerHost = null;
if (!cacheDir || cacheDir.length < 1) {
cacheDir = '.cache';
}
let rootCacheDir = path.join(appDir, cacheDir);
mkdirp.sync(rootCacheDir);
let mapDir = rootCacheDir;
if (sourceMapDir) {
mapDir = path.join(appDir, sourceMapDir);
d(`specifed separate source map dir at ${mapDir}, creating it`);
mkdirp.sync(mapDir);
}
if (process.env.NODE_ENV !== 'production') {
console.log(`Using NODE_ENV = ${process.env.NODE_ENV || 'development'}`);
}
d(`main: ${appDir}, ${JSON.stringify(sourceDirs)}`);
try {
compilerHost = await createCompilerHostFromProjectRoot(appDir, rootCacheDir, sourceMapDir);
} catch (e) {
console.error(`Couldn't set up compilers: ${e.message}`);
d(e.stack);
throw e;
}
await Promise.all(sourceDirs.map((dir) => forAllFiles(dir, async (f) => {
try {
d(`Starting compilation for ${f}`);
await compilerHost.compile(f);
} catch (e) {
console.error(`Failed to compile file: ${f}`);
console.error(e.message);
d(e.stack);
}
})));
d('Saving out configuration');
await compilerHost.saveConfiguration();
}
const d = require('debug')('electron-compile');
const yargs = require('yargs')
.usage('Usage: electron-compile --appdir [root-app-dir] paths...')
.alias('a', 'appdir')
.describe('a', 'The top-level application directory (i.e. where your package.json is)')
.default('a', process.cwd())
.alias('c', 'cachedir')
.describe('c', 'The directory to put the cache')
.alias('s', 'sourcemapdir')
.describe('s', 'The directory to store sourcemap if compiler configured to have sourcemap file. Default to cachedir if not specified.')
.help('h')
.alias('h', 'help')
.epilog('Copyright 2015');
if (process.mainModule === module) {
const argv = yargs.argv;
if (!argv._ || argv._.length < 1) {
yargs.showHelp();
process.exit(-1);
}
const sourceDirs = argv._;
const appDir = argv.a;
const cacheDir = argv.c;
const sourceMapDir = argv.s;
main(appDir, sourceDirs, cacheDir, sourceMapDir)
.then(() => process.exit(0))
.catch((e) => {
console.error(e.message || e);
d(e.stack);
console.error("Compilation failed!\nFor extra information, set the DEBUG environment variable to '*'");
process.exit(-1);
});
}