-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCompiler.js
More file actions
76 lines (63 loc) · 2.62 KB
/
Compiler.js
File metadata and controls
76 lines (63 loc) · 2.62 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
// import npm modules
var fs = require('fs');
var os = require('os');
var fsPath = require('fs-path');
var ncp = require('ncp').ncp;
// import generator modules from utils folder
const webpackGenerator = require('./utils/WebpackGenerator.js');
const pageGenerator = require('./utils/PageGenerator.js');
const nodeGenerator = require('./utils/NodeGenerator.js');
// get arguments
process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});
// read in json file first
fs.readFile(process.argv[2], 'utf8', function(err,data){
// error detection
if(err) {
console.log('Filename has error')
throw err;
}
// Step 1, read .json file and parse it
config = JSON.parse(data)
// Step 2, generate a wepack.config.js file inside of the application folder the user wants to write to
webpackGenerator(config.path)
// Step 3, generate pages based on user's page definition
pageGenerator(config.pages, config.path)
// Step 4, create index.html boilerplate for React application
fsPath.writeFile(config.path+'/index.html', __StaticHTML__, function (err, data) {
if (err) throw err;
})
// Step 5, Generate a node service file that will serve up Socket.io and React files
// nodeGenerator.socketSetup(config.path, 1);
nodeGenerator.expressSetup(config.path, config.port,config.maxMemorySize);
// Step 6, Copy lib folder into the app project
fsPath.mkdir(config.path+'/lib', function(err){
console.log('ok');
ncp('./lib', config.path+'/lib', function (err){
if (err) throw err;
console.log ('Copied Library into App Folder');
})
})
// Step 7, Generate a package.json file based on user's definition
fs.readFile('./utils/Default.json', 'utf8', function (err, data) {
var outputPackage = JSON.parse(data); //loads in default package
if (config.package.name) outputPackage.name = config.package.name
if (config.package.version) outputPackage.version = config.package.version
if (config.package.description) outputPackage.description = config.package.description
if (config.package.author) outputPackage.author = config.package.author
fsPath.writeFile(config.path+'/package.json', JSON.stringify(outputPackage, null, 2), function (err) {
if (err) throw err;
});
});
})
// boring biolerplate
const __StaticHTML__ = "<html>\
<head>\
<link href=\"https://fonts.googleapis.com/css?family=Slabo+27px\" rel=\"stylesheet\">\
</head>\
<body>\
<div id=\"app\"></div>\
<script src=\"/main.min.js\"></script>\
</body>\
</html>";