-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
124 lines (107 loc) · 2.98 KB
/
Copy pathindex.js
File metadata and controls
124 lines (107 loc) · 2.98 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env node
const inquirer = require("inquirer");
const chalk = require("chalk");
const figlet = require("figlet");
const shell = require("shelljs");
const child_process = require("child_process");
const fs = require('fs');
const dependency = [
"@babel/polyfill",
"@babel/register",
"cookie-parser",
"debug",
"express",
"http-errors",
"morgan",
"node-sass",
"pug",
"react",
"react-dom",
"react-redux",
"react-router-dom",
"redux",
"redux-thunk"
];
const devDependency = [
"@babel/cli",
"@babel/core",
"@babel/node",
"@babel/preset-env",
"@babel/preset-react",
"babel-loader",
"babel-plugin-transform-class-properties",
"clean-webpack-plugin",
"concurrently",
"css-loader",
"eslint",
"eslint-config-airbnb",
"eslint-plugin-import",
"eslint-plugin-jsx-a11y",
"eslint-plugin-react",
"html-loader",
"html-webpack-plugin",
"nodemon",
"sass-loader",
"style-loader",
"url-loader",
"webpack",
"webpack-cli",
"webpack-dev-server"
];
const welcome = () => {
console.log(
chalk.green(
figlet.textSync("AD React Init", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default"
})
)
);
};
const init = () => {
child_process.execSync('npm init', {stdio: 'inherit'});
};
const readPackageJson = () => {
this.package = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
};
const configurePackageJson = () => {
this.package.scripts = {
...this.package.scripts,
"prestart": "npm run build:prod",
"start": "node src/server/bin/www",
"start:dev": "npm run build:dev && nodemon src/server/bin/www",
"build:dev": "webpack --mode development",
"build:prod": "webpack --mode production",
"client": "webpack-dev-server --mode development",
"server": "nodemon src/server/bin/www",
"dev": "concurrently \"npm run server\" \"npm run client\""
};
fs.writeFileSync("package.json", JSON.stringify(this.package), {encoding:'utf8',flag:'w'});
};
const copyPackage = () => {
shell.cp('-Rf', [`${__dirname}/lib/*`], `./`);
shell.cp('-Rf', [`${__dirname}/lib/.babelrc`], `./`);
shell.cp('-Rf', [`${__dirname}/lib/.eslintrc.json`], `./`);
shell.cp('-Rf', [`${__dirname}/lib/.gitignore`], `./`);
};
const installDependency = () => {
console.log("Installing Dependency....");
child_process.execSync(`npm i --save ${dependency.join(' ')}`, {stdio: 'inherit'});
child_process.execSync(`npm i --save-dev ${devDependency.join(' ')}`, {stdio: 'inherit'});
};
const success = (projectName) => {
console.log(
chalk.white.bgGreen.bold(`${projectName} Created! Happy Coding!`)
);
};
const run = async () => {
welcome();
init();
readPackageJson();
configurePackageJson();
copyPackage();
installDependency();
success(this.package.name);
};
run();