@fullstackunicorn/root 1.0.7 → 1.0.8
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 +6 -8
- package/modules/generate.js +48 -43
- package/package.json +3 -3
- package/assets/template/backend/.env +0 -3
- package/assets/template/frontend/.env +0 -3
- package/assets/template/frontend/assets/index.webmanifest +0 -21
- package/assets/template/frontend/package.json +0 -0
- package/assets/template/server/.env +0 -3
- package/modules/generate.gen.js +0 -34
- package/modules/generate.tools.js +0 -20
package/index.dep.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
// NODE
|
|
2
|
-
|
|
3
|
-
import { fileURLToPath } from 'url'
|
|
4
|
-
// BASEPATH
|
|
5
|
-
const getBasepath = () => path.dirname(fileURLToPath(import.meta.url))
|
|
6
|
-
export const basePath = getBasepath()
|
|
7
|
-
export { path }
|
|
1
|
+
// NODE BUILD IN
|
|
2
|
+
export { default as path } from 'path'
|
|
8
3
|
|
|
9
4
|
// FULLSTACKUNICORN
|
|
10
|
-
export { fss, fsa } from '@fullstackunicorn/filesystem'
|
|
5
|
+
export { fss, fsa } from '@fullstackunicorn/filesystem'
|
|
6
|
+
|
|
7
|
+
// NPM
|
|
8
|
+
export { default as JSZip } from 'jszip'
|
package/modules/generate.js
CHANGED
|
@@ -1,70 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { tools } from '#@/modules/generate.tools.js'
|
|
3
|
-
import { gen } from '#@/modules/generate.gen.js'
|
|
1
|
+
import { path, JSZip } from '#@/index.dep.js'
|
|
4
2
|
|
|
5
3
|
class Generate {
|
|
6
4
|
|
|
7
5
|
constructor() {
|
|
8
6
|
|
|
7
|
+
this.basePath = 'https://api.websites.minderable.com'
|
|
8
|
+
this.cwd = process.cwd()
|
|
9
|
+
|
|
9
10
|
this.filename = {}
|
|
10
11
|
this.filename.app = 'root.config.app.js'
|
|
11
|
-
this.filename.frontend = 'root.config.frontend.js'
|
|
12
|
-
this.filename.backend = 'root.config.backend.js'
|
|
13
|
-
this.filename.server = 'root.config.server.js'
|
|
14
12
|
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.paths.output = process.cwd()
|
|
13
|
+
this.url = {}
|
|
14
|
+
this.url.generate = `${this.basePath}/root/generate`
|
|
18
15
|
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
async
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// await this.handleServer()
|
|
27
|
-
|
|
18
|
+
post = async ({ endpoint, data, config }) => {
|
|
19
|
+
try {
|
|
20
|
+
const response = await axios.post(endpoint, data, config)
|
|
21
|
+
return response.data
|
|
22
|
+
} catch (error) { return F3.err.handle(error) }
|
|
28
23
|
}
|
|
29
24
|
|
|
30
|
-
async
|
|
31
|
-
|
|
32
|
-
const config = await tools.loadConfig(this.filename.app)
|
|
33
|
-
F3.log.obj({ config })
|
|
34
|
-
|
|
35
|
-
await gen.env(this.paths, config.env)
|
|
36
|
-
await gen.manifest(this.paths, config.manifest)
|
|
37
|
-
// await gen.package(this.paths, config.package)
|
|
25
|
+
ensureFileDir = async filepath => await fsa.ensureDir(path.dirname(filepath))
|
|
38
26
|
|
|
27
|
+
safePath = (name) => {
|
|
28
|
+
const clean = String(name).replace(/^([/\\])+/, '')
|
|
29
|
+
const resolved = path.resolve(this.cwd, clean)
|
|
30
|
+
const cwdResolved = path.resolve(this.cwd) + path.sep
|
|
31
|
+
if (!resolved.startsWith(cwdResolved)) F3.throw('zip-slip', { name })
|
|
32
|
+
return resolved
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
async
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
async getConfig(filename) {
|
|
36
|
+
const cwd = process.cwd()
|
|
37
|
+
const filePath = path.join(cwd, filename)
|
|
38
|
+
if (!fss.exists(filePath)) F3.throw('file-missing', { filePath })
|
|
39
|
+
try { return await import(filePath) }
|
|
40
|
+
catch (err) { F3.catch.throw(err) }
|
|
47
41
|
}
|
|
48
42
|
|
|
49
|
-
async
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
async unzip(zipBuffer) {
|
|
44
|
+
try {
|
|
45
|
+
const zip = await JSZip.loadAsync(zipBuffer)
|
|
46
|
+
const tasks = Object.entries(zip.files).map(async ([name, file]) => {
|
|
47
|
+
const filePath = this.safePath(name)
|
|
48
|
+
if (file.dir) return await fsa.ensureDir(filePath)
|
|
49
|
+
await this.ensureFileDir(filePath)
|
|
50
|
+
const content = await file.async('nodebuffer')
|
|
51
|
+
await fsa.writeFile(filePath, content)
|
|
52
|
+
})
|
|
53
|
+
await Promise.all(tasks)
|
|
54
|
+
return true
|
|
55
|
+
} catch (error) { F3.catch.throw(error) }
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
async
|
|
58
|
+
async run() {
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
const config = await tools.loadConfig(this.filename.server)
|
|
62
|
-
F3.log.obj({ config, templatePath })
|
|
63
|
-
|
|
64
|
-
}
|
|
60
|
+
const { app } = await this.getConfig(this.filename.app)
|
|
65
61
|
|
|
62
|
+
const payload = {}
|
|
63
|
+
payload.endpoint = this.url.generate
|
|
64
|
+
payload.data = { app }
|
|
65
|
+
payload.config = { responseType: 'arraybuffer' }
|
|
66
|
+
const zipBuffer = await this.post(payload)
|
|
66
67
|
|
|
68
|
+
if (zipBuffer.isOffline) return F3.logs('error-offline')
|
|
69
|
+
if (zipBuffer.isError) return F3.logs('error-failed-axios-post')
|
|
67
70
|
|
|
71
|
+
await this.unzip(zipBuffer)
|
|
72
|
+
}
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
export const generate = new Generate()
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.8",
|
|
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",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"index.cmd.js",
|
|
12
12
|
"index.js",
|
|
13
13
|
"index.dep.js",
|
|
14
|
-
"assets/",
|
|
15
14
|
"modules/"
|
|
16
15
|
],
|
|
17
16
|
"bin": {
|
|
@@ -36,7 +35,8 @@
|
|
|
36
35
|
"scripts": {},
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"@fullstackunicorn/filesystem": "^1.0.4",
|
|
39
|
-
"@fullstackunicorn/initialize": "^1.0.
|
|
38
|
+
"@fullstackunicorn/initialize": "^1.0.9",
|
|
39
|
+
"jszip": "^3.10.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@fullstackunicorn/cli": "^1.0.3",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Root",
|
|
3
|
-
"short_name": "Root",
|
|
4
|
-
"theme_color": "#ffffff",
|
|
5
|
-
"background_color": "#ffffff",
|
|
6
|
-
"display": "fullscreen",
|
|
7
|
-
"icons": [
|
|
8
|
-
{
|
|
9
|
-
"src": "/icons/icon-192.png",
|
|
10
|
-
"sizes": "192x192",
|
|
11
|
-
"type": "image/png",
|
|
12
|
-
"purpose": "maskable"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"src": "/icons/icon-512.png",
|
|
16
|
-
"sizes": "512x512",
|
|
17
|
-
"type": "image/png",
|
|
18
|
-
"purpose": "maskable"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
|
File without changes
|
package/modules/generate.gen.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { fsa } from '#@/index.dep.js'
|
|
2
|
-
|
|
3
|
-
class Gen {
|
|
4
|
-
|
|
5
|
-
constructor () {
|
|
6
|
-
|
|
7
|
-
this.frontend = {}
|
|
8
|
-
this.frontend.env = 'frontend/.env'
|
|
9
|
-
this.frontend.package = 'frontend/package.json'
|
|
10
|
-
this.frontend.webmanifest = 'frontend/assets/index.webmanifest'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async env (paths, variables) {
|
|
14
|
-
const template = await fsa.readText(`${paths.template}/${this.frontend.env}`)
|
|
15
|
-
const file = F3.replacer(template, variables)
|
|
16
|
-
await fsa.writeText(`${paths.output}/${this.frontend.env}`, file)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async webmanifest (paths, variables) {
|
|
20
|
-
const template = await fsa.readJSON(`${paths.template}/${this.frontend.webmanifest}`)
|
|
21
|
-
const file = {...template}
|
|
22
|
-
for (const [key, val] of Object.entries(variables)) file[key] = val
|
|
23
|
-
await fsa.writeText(`${paths.output}/${this.frontend.webmanifest}`, file)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// async package (paths, variables) {
|
|
27
|
-
// const template = await fsa.readText(`${paths.template}/${this.frontend.package}`)
|
|
28
|
-
// const file = F3.replacer(template, variables)
|
|
29
|
-
// await fsa.writeText(`${paths.output}/${this.frontend.env}`, file)
|
|
30
|
-
// }
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const gen = new Gen ()
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { fss, path } from '#@/index.dep.js'
|
|
2
|
-
|
|
3
|
-
class Tools {
|
|
4
|
-
|
|
5
|
-
async loadConfig(filename) {
|
|
6
|
-
|
|
7
|
-
const cwd = process.cwd()
|
|
8
|
-
const filePath = path.join(cwd, filename)
|
|
9
|
-
|
|
10
|
-
if (!fss.exists(filePath)) F3.throw('file-missing', {filePath})
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
const { config } = await import(filePath)
|
|
14
|
-
return config
|
|
15
|
-
} catch (err) {F3.catch.throw(err)}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const tools = new Tools ()
|