|
| 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-react-ts-webpack-app 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-ts-webpack-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 | + console.log('Remove git version file'); |
| 44 | + execSync('npx rimraf ./.git'); |
| 45 | + |
| 46 | + console.log('💾 Yarn install...'); |
| 47 | + execSync('yarn'); |
| 48 | + |
| 49 | + console.log('🗑 Removing useless files'); |
| 50 | + execSync('npx rimraf ./.bin'); |
| 51 | + |
| 52 | + console.log('The installation is done, this is ready to use !'); |
| 53 | + } catch (error) { |
| 54 | + console.log(error); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +main(); |
0 commit comments