-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·117 lines (96 loc) · 3.31 KB
/
index.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
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
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
import cp from 'child_process';
import chalk from 'chalk';
import { selphBG } from 'selph-bg';
import fs from 'fs-extra'
import open from 'open';
const arg = process.argv.slice(2)[0];
const commands = [
{
title: 'dev',
log: '🟥 Selph - Starting Dev Server...',
selph: true,
mainCommand: 'cd ../frontend && npm start',
execCommand: ' npm run dev',
functions: [selphBG.genEnv, selphBG.genAppJs, selphBG.genModels, selphBG.genCg, selphBG.genRg, selphBG.genSg]
},
{
title: 'build',
log: '🟥 Selph - Starting Build Process...',
selph: false,
mainCommand: "",
execCommand: 'npm run build'
},
{
title: 'start',
selph: true,
log: '🟥 Selph - Starting Frontend Application & Backend Server...',
mainCommand: "(cd ../frontend && npm start)",
execCommand: 'npm start',
functions: [selphBG.genEnv, selphBG.genAppJs, selphBG.genModels, selphBG.genCg, selphBG.genRg, selphBG.genSg]
},
{
title: 'start-frontend',
selph: false,
log: '🟥 Selph - Starting Frontend...',
mainCommand: "",
execCommand: 'cd frontend && npm start'
},
{
title: 'start-backend',
selph: true,
log: '🟥 Selph - Starting Backend Server...',
mainCommand: "npm start",
execCommand: '',
functions: [selphBG.genEnv, selphBG.genAppJs, selphBG.genModels, selphBG.genCg, selphBG.genRg, selphBG.genSg]
},
{
title: 'create-admin',
selph: false,
log: '🟥 Selph - Creating admin/superuser',
mainCommand: "",
execCommand: 'cd backend && npm run createsuperuser',
functions: null
},
]
let sh;
const main = async () => {
let config = await JSON.parse(fs.readFileSync('selph.config.json'));
if(config){
if(commands.map(itm => itm.title).includes(arg)){
let command = commands.find(itm => itm.title == arg);
if(command.selph){
try {
console.log(command.log)
await command.functions?.map(async mdl => {
let log = await mdl(config, 'backend/')
if(log){
console.log(log)
}
})
sh = cp.exec(command.mainCommand + ' &' +command.execCommand, {
cwd: 'backend'
},(error, stdout, stderr) => {
if (error) {
console.error(`An error occurred: `, error);
} else {
console.log(`stdout:`, stdout);
console.log(`stderr:`, stderr);
}
})
open(`${config?.https ? 'https' : 'http'}://localhost:${config.apiPort}/swagger`)
} catch (error) {
throw error
}
}else{
cp.execSync(command.execCommand, {stdio: 'inherit', stdin: "inherit"});
}
}else{
console.log(chalk.red(`🚫 Sorry, This command (${arg}) is not supported by Selph...`))
}
}else{
console.log(chalk.red(`🚫 There is no selph config in this directory...`))
}
}
await main()
// process.exit()