-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathboilergen_old.js
More file actions
105 lines (90 loc) · 3.02 KB
/
boilergen_old.js
File metadata and controls
105 lines (90 loc) · 3.02 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import {models} from './models.js'
var exec = require('child_process').exec
var stdin = process.openStdin()
var model = '';
let readLineAux = false;
let chalk = false;
let name ='my-app';
let seelogs = true;
const execbash = function(command){
return new Promise(resolve => {
exec(command, (error, stdout, stderr) => {
if(seelogs)
console.log(stdout)
resolve(stdout)
})
})
}
console.log(model.toUpperCase()+' CLI v0.2')
console.log('')
const phases = {
'PrepareWorkspace': async function(){
console.log('Preparing workspace...')
const resp = await execbash('npm install readline-sync chalk')
readLineAux = require('readline-sync')
chalk = require('chalk');
const global = await execbash('sudo npm i --global react-scripts')
return new Promise(resolve => {
resolve()
})
},
'GetProjectData': async function(){
process.stdin.isTTY = process.stdout.isTTY = true;
modelOption = readLineAux.question(chalk.green(`What model whould you like to use?
\n
`));
model = process.env.NODE_ENV ? process.env.NODE_ENV : 'boilergen_model'
name = readLineAux.question(chalk.green('What is your app name? '));
return new Promise(resolve => {
resolve()
})
},
'CreateProject': async function(){
console.log(model);
console.log("Creating app... \033[0;32m (it can take a while, time to grab a coffee) \033[0m ")
await execbash('npx create-react-app '+name)
console.log('Ejecting app... \033[0;32m (it can take a while too, time to grab some tea) \033[0m ')
await execbash('cd '+name+' && echo "y" | sudo react-scripts eject ')
console.log(`Copying ${model}... (this one is blazing fast, i swear) `)
await execbash('cd '+name+' && rm -rf ./src')
console.log(model);
await execbash('cp -r ./'+model+'/* ./'+name+'/')
await execbash('cd '+name+' && touch .env && npm install')
console.log('Getting some libs with yarn... \033[0;32m (Almost there, trust me) \033[0m ')
await execbash('yarn')
await execbash('npm start')
return new Promise(resolve => {
resolve()
})
},
'FinalInformative': async function(){
console.log('')
console.log('Awesome, project ready!')
console.log('')
console.info('To start use -> npm start or yarn start')
console.info('To test use -> npm test or yarn test')
console.info('To build use -> npm run build or yarn build')
console.log('')
console.log("(tip: sometimes it's to run with sudo prefix)")
console.log('')
return new Promise(resolve => {
resolve()
})
},
'CleanWorkspace': async function(){
const resp3 = await execbash('rm -rf node_modules')
return new Promise(resolve => {
resolve()
})
}
}
const createNewApp = async function(){
console.log('models', models)
// await phases.PrepareWorkspace()
// await phases.GetProjectData()
// await phases.CreateProject()
// await phases.FinalInformative()
// await phases.CleanWorkspace()
process.exit()
}
createNewApp()