-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbin.js
More file actions
59 lines (40 loc) · 1.53 KB
/
bin.js
File metadata and controls
59 lines (40 loc) · 1.53 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
#!/usr/bin/env node
const fs = require('fs')
const { execSync } = require('child_process')
const runCommand = (command) => {
try {
execSync(`${command}`, { stdio: 'inherit' })
} catch (error) {
console.error(`Failed executing ${command} `, error)
return false
}
return true
}
const authorName = process.argv[3]
const repoName = process.argv[2]
const gitCheckoutCommand = `git clone --depth 1 https://github.com/rubemfsv/clean-react-app ${repoName}`
const installDependenciesCommand = `cd ${repoName} && npm install`
console.log(`Cloning the repository with the name ${repoName}`)
const checkedOut = runCommand(gitCheckoutCommand)
if (!checkedOut) process.exit(-1)
console.log(`Installing dependencies for ${repoName}`)
const installedDependencies = runCommand(installDependenciesCommand)
if (!installedDependencies) process.exit(-1)
console.log(
'Congratulations! You are ready. Follow the following commands to start'
)
console.log(`cd ${repoName} && npm run dev`)
// Dynamically update package.json
const packageJsonPath = `${repoName}/package.json`
try {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
// Update package.json fields
packageJson.name = repoName
packageJson.author = authorName
packageJson.version = '0.0.1'
// Write the updated package.json back to the file
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
console.log('Updated package.json with dynamic values.')
} catch (error) {
console.error('Failed to update package.json: ', error)
}