This repository was archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrape.js
194 lines (156 loc) · 5.04 KB
/
grape.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const uri = 'https://github.com/codebenderhq/backpack/releases/latest/download/grape.js'
const cmdRun = async(command,msg) => {
const cmd = command.split(' ')
const p = Deno.run({
cmd,
stderr: "piped",
})
const {code} = await p.status
// const rawOutput = await p.output();
const rawError = await p.stderrOutput();
// console.log(msg)
console.log(msg)
if (code === 0) {
// await Deno.stdout.write(rawOutput);
} else {
// const errorString = new TextDecoder().decode(rawError);
// console.log(errorString);
}
}
const upgrade = async () => {
const code = await commands(['deno','cache','--reload', uri])
if(code === 0 ){
console.log('backpack upgraded')
}
}
const tailwindInit = async () => {
try{
await Deno.readTextFile("tailwind.config.js");
}catch{
const styleInitCmd = './tailwindcss init'.split(' ')
const styleInitProcess = Deno.run(
{
cmd:styleInitCmd,
})
await styleInitProcess.status()
}
}
const tailwindRun = async (isBuild) => {
console.log('generating styles')
const styleCMD = `./tailwindcss -i ./src/input.css -o ./src/public/output.css ${isBuild ? '--minify': '--watch' }`.split(' ')
const styleProcess = Deno.run({
cmd:styleCMD,
stdout: "piped",
stderr: "piped",
})
const {code} =await styleProcess.status
const rawError = await styleProcess.stderrOutput();
if (code === 0) {
console.log('styles generated')
} else {
const errorString = new TextDecoder().decode(rawError);
console.log(errorString);
}
}
const devServe = async () => {
try{
await tailwindInit()
tailwindRun()
console.log('Happy Developing')
}catch(err){
console.log('err',err)
}
}
const prodServe = async () => {
try{
await tailwindInit()
tailwindRun(true)
console.log('Happy Hunting')
}catch(err){
console.log('err',err)
}
}
const new_project = async (name) => {
const frame_installer = 'curl -sLO https://github.com/codebenderhq/backpack-frame/archive/refs/heads/main.zip'
const unzip_installer = `unzip -q main.zip`
const rename_zip = `mv backpack-frame-main ${name}`
await cmdRun(frame_installer,'FRAME installed')
await cmdRun(unzip_installer,'FRAME ready to be used')
await cmdRun(rename_zip,'FRAME ready to be used')
// const srd_installer = 'curl -sLO https://github.com/codebenderhq/backpack-std/archive/refs/heads/main.zip'
// const unzip_std = `unzip -q main.zip`
// const rename_std = `mv backpack-frame-main ${name}`
}
const deno_task = async (arg) => {
const deno_option = `deno task ${arg}`
await cmdRun(deno_option,'grape executed')
}
// generate templates for quicker development
// will then edit the templates before generation to speed up development
const generate = async (args) => {
let path;
let template_path = `${Deno.cwd()}/std/.frame/templates`
const type = args[1]
const name = args[2]
const instance = args[4]
const other = args[5]
// create page and service together
if(type ==='page'){
console.log(`generating ${name} page for ${instance} instance`)
path = `${Deno.cwd()}/src/_app/${instance}/pages`
Deno.mkdir(path,{ recursive: true })
await Deno.copyFile(`${template_path}/index.html`, `${path}/${name}.html`);
}
if(type === 'service'){
path = `${Deno.cwd()}/src/_app/${instance}/services`
Deno.mkdir(path,{ recursive: true })
console.log(`generating ${name} service for the ${instance} instance`)
await Deno.copyFile(`${template_path}/service.js`, `${path}/${name}.js`);
}
const nameArray = name.split('/')
let subPath = '';
let _name = name;
if(nameArray.length > 1){
subPath = `/${nameArray[0]}`
_name = nameArray[1]
}
if(type === 'api'){
path = `${Deno.cwd()}/src/_app/${instance}/api${subPath}`
console.log(path)
Deno.mkdir(path,{ recursive: true })
console.log(`generating ${name} api for the ${instance} instance`)
await Deno.copyFile(`${template_path}/api.js`, `${path}/${_name}.js`);
}
}
if (import.meta.main) {
const args = Deno.args
if(args.length > 0)
{
switch (args[0]) {
case "new":
await new_project(args[1])
break;
case "create":
await generate(args)
break;
case "tw":
await devServe()
break;
case "build":
await prodServe()
break;
case "help":
console.log('Setup your enviroment here --> https://codebenderhq.notion.site/4806ddc648e644d38e2223793a6a815e');
break;
case "upgrade":
upgrade()
break;
default:
deno_task(args[0])
break;
}
}else{
console.log('Welcome to grape');
// console.log(instances)
}
}