@fullstackunicorn/root 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.dep.js +1 -1
- package/modules/generate.js +45 -45
- package/modules/upgrade.js +1 -3
- package/modules/verify.js +1 -3
- package/package.json +6 -6
package/index.dep.js
CHANGED
package/modules/generate.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
1
|
import { axios, path, fss, fsa, JSZip } from '#@/index.dep.js'
|
|
2
|
+
import { Def } from '#@/index.def.js'
|
|
2
3
|
|
|
3
4
|
class Generate {
|
|
4
5
|
|
|
5
6
|
constructor() {
|
|
7
|
+
this.def = new Def()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
verifyPath = filePath => {
|
|
11
|
+
const cwd = path.resolve(this.def.cwd)
|
|
12
|
+
if (!filePath.startsWith(cwd)) F3.throw('zip-slip', { filePath })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
unzip = async zipBuffer => {
|
|
6
16
|
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
try {
|
|
18
|
+
|
|
19
|
+
const zip = await JSZip.loadAsync(zipBuffer)
|
|
9
20
|
|
|
10
|
-
|
|
11
|
-
this.filename.app = 'root.config.app.js'
|
|
21
|
+
for (const [name, file] of Object.entries(zip.files)) {
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
|
|
23
|
+
if (file.dir) continue
|
|
24
|
+
this.verifyPath(name)
|
|
25
|
+
const content = await file.async('nodebuffer')
|
|
26
|
+
const filePath = path.join(this.def.cwd, name)
|
|
27
|
+
await fsa.ensureFileDir(filePath)
|
|
28
|
+
await fsa.writeFile(filePath, content)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return true
|
|
32
|
+
|
|
33
|
+
} catch (error) { F3.catch.throw(error) }
|
|
15
34
|
}
|
|
16
35
|
|
|
17
36
|
post = async ({ endpoint, data, config }) => {
|
|
18
37
|
try {
|
|
19
38
|
const response = await axios.post(endpoint, data, config)
|
|
20
39
|
return response.data
|
|
21
|
-
} catch (error) {
|
|
40
|
+
} catch (error) {
|
|
22
41
|
F3.log.arr(error)
|
|
23
|
-
return F3.err.handle(error)
|
|
42
|
+
return F3.err.handle(error)
|
|
43
|
+
}
|
|
24
44
|
}
|
|
25
45
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
safePath = (name) => {
|
|
29
|
-
const clean = String(name).replace(/^([/\\])+/, '')
|
|
30
|
-
const resolved = path.resolve(this.cwd, clean)
|
|
31
|
-
const cwdResolved = path.resolve(this.cwd) + path.sep
|
|
32
|
-
if (!resolved.startsWith(cwdResolved)) F3.throw('zip-slip', { name })
|
|
33
|
-
return resolved
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getConfig(filename) {
|
|
37
|
-
const cwd = process.cwd()
|
|
38
|
-
const filePath = path.join(cwd, filename)
|
|
46
|
+
async getConfig() {
|
|
47
|
+
const filePath = this.def.files.rootConfigApp
|
|
39
48
|
if (!fss.exists(filePath)) F3.throw('file-missing', { filePath })
|
|
40
49
|
try { return await import(filePath) }
|
|
41
|
-
catch (
|
|
50
|
+
catch (e) { F3.catch.throw(e) }
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
async
|
|
53
|
+
async run() {
|
|
54
|
+
|
|
45
55
|
try {
|
|
46
|
-
const zip = await JSZip.loadAsync(zipBuffer)
|
|
47
|
-
const tasks = Object.entries(zip.files).map(async ([name, file]) => {
|
|
48
|
-
const filePath = this.safePath(name)
|
|
49
|
-
if (file.dir) return await fsa.ensureDir(filePath)
|
|
50
|
-
await this.ensureFileDir(filePath)
|
|
51
|
-
const content = await file.async('nodebuffer')
|
|
52
|
-
await fsa.writeFile(filePath, content)
|
|
53
|
-
})
|
|
54
|
-
await Promise.all(tasks)
|
|
55
|
-
return true
|
|
56
|
-
} catch (error) { F3.catch.throw(error) }
|
|
57
|
-
}
|
|
58
56
|
|
|
59
|
-
|
|
57
|
+
const { app } = await this.getConfig()
|
|
58
|
+
|
|
59
|
+
const payload = {}
|
|
60
|
+
payload.endpoint = this.def.urls.generate
|
|
61
|
+
payload.data = { app }
|
|
62
|
+
payload.config = { responseType: 'arraybuffer' }
|
|
63
|
+
const response = await this.post(payload)
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
if (response.isOffline) return F3.logs('error-offline')
|
|
66
|
+
if (response.isError) return F3.logs('error-failed-axios-post')
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
payload.endpoint = this.url.generate
|
|
65
|
-
payload.data = { app }
|
|
66
|
-
payload.config = { responseType: 'arraybuffer' }
|
|
67
|
-
const zipBuffer = await this.post(payload)
|
|
68
|
+
F3.log.obj({ response })
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
if (zipBuffer.isError) return F3.logs('error-failed-axios-post')
|
|
70
|
+
await this.unzip(response)
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
} catch (e) { F3.catch.throw(e)}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
package/modules/upgrade.js
CHANGED
package/modules/verify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.12",
|
|
3
3
|
"name": "@fullstackunicorn/root",
|
|
4
4
|
"author": "lucanigido (https://fullstackunicorn.dev/author/lucanigido)",
|
|
5
5
|
"description": "Root CLI: init config, generate project, upgrade project",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"test": "exit 1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@fullstackunicorn/filesystem": "^1.0.
|
|
41
|
-
"@fullstackunicorn/initialize": "^1.0.
|
|
42
|
-
"axios": "^1.13.
|
|
40
|
+
"@fullstackunicorn/filesystem": "^1.0.11",
|
|
41
|
+
"@fullstackunicorn/initialize": "^1.0.13",
|
|
42
|
+
"axios": "^1.13.6",
|
|
43
43
|
"jszip": "^3.10.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@fullstackunicorn/cli": "^1.0.
|
|
47
|
-
"@fullstackunicorn/reduce": "^1.0.
|
|
46
|
+
"@fullstackunicorn/cli": "^1.0.8",
|
|
47
|
+
"@fullstackunicorn/reduce": "^1.0.22"
|
|
48
48
|
}
|
|
49
49
|
}
|