Skip to content

Commit 0e4c83d

Browse files
committed
chore: npx generate script 추가
1 parent f1db63c commit 0e4c83d

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#! /usr/bin/env node
2+
3+
const { execSync } = require('child_process');
4+
const path = require('path');
5+
const fs = require('fs');
6+
7+
if (process.argv.length < 3) {
8+
console.log('You have to provide a name to your app.');
9+
console.log('For example :');
10+
console.log(' npx create-my-boilerplate my-app');
11+
process.exit(1);
12+
}
13+
14+
const projectName = process.argv[2];
15+
const currentPath = process.cwd();
16+
const projectPath = path.join(currentPath, projectName);
17+
const GIT_REPO = 'https://github.com/vvs-kim/react-webpack-ts-boilerplate';
18+
19+
if (projectName !== '.') {
20+
try {
21+
fs.mkdirSync(projectPath);
22+
} catch (error) {
23+
if (error.code === 'EEXIST') {
24+
console.log(projectName);
25+
console.log(
26+
`The file ${projectName} already exist in the current directory, please give it another name.`
27+
);
28+
} else {
29+
console.log(error);
30+
}
31+
process.exit(1);
32+
}
33+
}
34+
35+
async function main() {
36+
try {
37+
console.log('Downloading files...');
38+
execSync(`git clone --depth 1 ${GIT_REPO} ${projectPath}`);
39+
40+
if (projectName !== '.') {
41+
process.chdir(projectPath);
42+
}
43+
44+
console.log('Installing dependencies');
45+
execSync('npm install');
46+
47+
console.log('Removing useless files');
48+
execSync('npx rimraf ./git');
49+
execSync('npx rimraf ./bin');
50+
51+
console.log('The installation is done, this is ready to use !');
52+
} catch (error) {
53+
console.log(error);
54+
}
55+
}
56+
57+
main();

package.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
{
22
"name": "create-react-webpack-ts-app",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "It automatically builds a react, webpack, and ts working environment",
55
"main": "index.tsx",
66
"scripts": {
77
"dev": "webpack-dev-server --config config/webpack.dev.js",
88
"build": "webpack --config config/webpack.prod.js"
99
},
1010
"license": "ISC",
11+
"bin": {
12+
"create-react-webpack-ts-app": "./bin/generate-app.js"
13+
},
14+
"homepage": "https://github.com/vvs-kim/react_webpack_ts_boilerplate",
15+
"author": {
16+
"name": "Wooseok Kim"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/vvs-kim/react-webpack-ts-boilerplate"
21+
},
22+
"keywords": [
23+
"react",
24+
"typescript",
25+
"webpack",
26+
"yarn-berry",
27+
"prettier",
28+
"airbnb",
29+
"eslint"
30+
],
1131
"dependencies": {
1232
"react": "^18.0.0",
1333
"react-dom": "^18.0.0",

0 commit comments

Comments
 (0)