-
Notifications
You must be signed in to change notification settings - Fork 0
/
ez-compiler.js
66 lines (48 loc) · 1.59 KB
/
ez-compiler.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
#!/usr/bin/env node
'use strict'
const FS = require('fs'),
fsExtra = require('fs-extra'),
exec = require('child_process').exec,
createDir = require('./lib/createDir'),
options = process.argv;
// Declare command
let command = 'concurrently ';
// argv = ['node', 'ez-compiler', task]
let task = process.argv[2];
// Create project template
if(task === 'create'){
let projectType = process.argv[3];
if (projectType === "default") createDir.default();
if (projectType === "angular1") createDir.angular1();
}
// Wants to lint the file with Jshint
else if (task === "lint"){
let fileNameOrPath = process.argv[3]
command += ("jshint " + fileNameOrPath);
}
// Wants to test files with Mocha/Chai
else if (task === "test"){
let fileNameOrPath = process.argv[3]
command += ("mocha " + fileNameOrPath);
}
else if (task === 'compile'){
FS.readFile('ezconfig.json', 'utf8', (error, data) => {
error ? console.log(error) : true;
let config = JSON.parse(data);
const reqMods = config.preprocessors; // Required modules to use while creating a compile command
// const source = config.source; // Where the file is
// const destination = config.destination; // Where it's going
// Adds npm run command to each preprocessor
let commandCreator = reqMods.forEach((val) => {
command = command.concat("\"npm run " + val + "\" ")
})
// What executes the command
const child = exec(command, (error, stdout, stderr) => {
console.log("stdout: ", stdout);
console.log("stderr: ", stderr);
if (error !== null) {
console.log("execution error: ", error);
}
});
}); // readFile()
}