-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (78 loc) · 2.8 KB
/
index.js
File metadata and controls
87 lines (78 loc) · 2.8 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
const fs = require('fs');
const readline = require('readline');
const execSync = require('child_process').execSync;
const path = require('path');
const exec = require('child_process').exec;
const chalk = require('chalk');
let child;
var ininstalling = { "angular": false, "express" : false, "nodemon": false};
const r1 = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function brogfinisch(finishname) {
ininstalling[finishname] = true;
var stop = false;
var notfinisch = [];
for(var key in ininstalling) {
if (ininstalling[key] == false) {
notfinisch.push(key);
stop = true;
}
}
if (stop) {
console.log(chalk.blue("Waiting that " + notfinisch.toString().replace(',', ', ') + " is installed"));
return;
}
process.exit(1);
}
r1.question('Please specify the App-Name: ', appname =>{
console.log(chalk.blue("Creating Angular App..."));
process.chdir(process.cwd());
execSync('ng new ' + appname+ " --skip-install");
console.log(chalk.green("Angular Struktur Created"));
process.chdir(path.basename(process.cwd()+"\\"+appname));
console.log(chalk.blue("Now installing Express and Body Parser"))
child = exec("yarn install", function (error, stdout, stderr) {
if (error !== null) {
return console.log(chalk.red('exec error: ' + error));
}
console.log(chalk.green("Angular Modules Installed"));
brogfinisch("angular")
});
child = exec("yarn add express body-parser", function (error, stdout, stderr) {
if (error !== null) {
console.log(chalk.red('Express and body-parser cann\'t be installed: ' + error));
return;
}
console.log(chalk.green('Express and body-parser installed'));
brogfinisch("express")
});
child = exec("yarn add nodemon --dev", function (error, stdout, stderr) {
if (error !== null) {
console.log(chalk.red('nodemon cannt be installed ' + error));
return;
}
console.log(chalk.green('Nodemon installed'));
brogfinisch("nodemon")
});
console.log(chalk.blue('Creating Server.js'));
var target = __dirname+"\\"+"server.js";
var source = process.cwd()+"\\"+"server.js";
fs.writeFileSync(source, fs.readFileSync(target));
console.log(chalk.green('Created Server.js'));
console.log(chalk.blue('Creating api.js'));
target = __dirname+"\\"+"api.js";
source = process.cwd()+"\\server\\routes\\"+"api.js";
var dir = path.basename(process.cwd()+"\\server")
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
process.chdir(path.basename(process.cwd()+"\\server"))
var dir = path.basename(process.cwd()+"\\routes")
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
fs.writeFileSync(source, fs.readFileSync(target));
console.log(chalk.green('Created api.js'));
})