-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
79 lines (67 loc) · 1.76 KB
/
setup.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
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
/* eslint-disable import/no-dynamic-require */
const path = require('path');
const fs = require('fs');
function copy(from, to, overwrite = true) {
if (!fs.existsSync(to) || overwrite) {
fs.copyFileSync(from, to);
return true;
}
return false;
}
function createFolder(p) {
if (!fs.existsSync(p)) {
fs.mkdirSync(p);
}
}
const setupRoot = __dirname;
const projectRoot = process.cwd();
const DEFAULT_PKG_JSON = `{
"name": "${path.basename(projectRoot)}"
}`;
if (!fs.existsSync(`${projectRoot}/package.json`)) {
fs.writeFileSync(`${projectRoot}/package.json`, DEFAULT_PKG_JSON);
}
if (!fs.existsSync(`${projectRoot}/.gitignore`)) {
fs.writeFileSync(`${projectRoot}/.gitignore`, 'node_modules');
}
const setupPkg = require(path.resolve(__dirname, 'package.json'));
const projectPkg = require(`${projectRoot}/package.json`);
projectPkg.devDependencies = {
...projectPkg.devDependencies,
...setupPkg.devDependencies,
};
projectPkg.dependencies = {
...projectPkg.dependencies,
...setupPkg.dependencies,
};
projectPkg.scripts = {
...projectPkg.scripts,
...setupPkg.scripts,
};
// saving changes in package.json
fs.writeFileSync(
`${projectRoot}/package.json`,
JSON.stringify(projectPkg, null, 2)
);
// copying files
createFolder(`${projectRoot}/src`);
createFolder(`${projectRoot}/src/components`);
createFolder(`${projectRoot}/public`);
[
'.babelrc',
'.eslintrc',
'tsconfig.json',
'webpack.config.js',
'webpack.prod.js',
'src/index.tsx',
'src/components/App.tsx',
'public/index.html',
].forEach(f => {
copy(`${setupRoot}/${f}`, `${projectRoot}/${f}`);
});
console.log(`
ᐅ Files copied successfully. Next steps:
1. Run "npm install" (or "yarn install")
2. Run "npm run dev" and open "http://localhost:9000"
`);