-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
47 lines (38 loc) · 1.25 KB
/
install.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
const { execSync } = require('child_process');
const templateTypes = ['babel', 'ts'];
const project = process.argv[2];
const templateType = process.argv[3];
if (!project) {
console.log('프로젝트 이름을 넣어주세요.');
console.log('node install.js <프로젝트 이름> <템플릿 유형>');
return;
}
if (!templateTypes.includes(templateType)) {
console.log('템플릿 유형을 넣어주세요.(babel 또는 ts)');
console.log('node install.js <프로젝트 이름> <템플릿 유형>');
}
try {
const fs = require('fs');
const projectRoot = `project/${project}`;
const ready = () => {
execSync(`rm -rf ${project}`);
if (!fs.existsSync('project')) {
execSync(`mkdir project`);
}
execSync(`cp -r template/${templateType} ${projectRoot}`);
};
const editPackangeJSON = () => {
const packageJSON = require(`./${projectRoot}/package.json`);
packageJSON.name = project;
fs.writeFileSync(`./${projectRoot}/package.json`, JSON.stringify(packageJSON, null, "\t"));
};
const createNvmrc = () => {
const nodeVersion = execSync(`node -v`).toString();
fs.writeFileSync(`./${projectRoot}/.nvmrc`, nodeVersion);
};
ready();
editPackangeJSON();
createNvmrc();
} catch (error) {
console.log(error);
}