@fullstackunicorn/root 1.0.10 → 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 CHANGED
@@ -1,8 +1,9 @@
1
+ // @FULLSTACKUNICORN
2
+ export { fss, fsa } from '@fullstackunicorn/filesystem'
3
+
1
4
  // NODE BUILD IN
2
5
  export { default as path } from 'path'
3
6
 
4
- // FULLSTACKUNICORN
5
- export { fss, fsa } from '@fullstackunicorn/filesystem'
6
-
7
- // NPM
8
- export { default as JSZip } from 'jszip'
7
+ // PACKAGES
8
+ export { default as JSZip } from 'jszip'
9
+ export { default as axios } from 'axios'
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  export { generate } from '#@/modules/generate.js'
4
2
  export { verify } from '#@/modules/verify.js'
5
3
  export { upgrade } from '#@/modules/upgrade.js'
@@ -1,74 +1,75 @@
1
- import { path, JSZip } from '#@/index.dep.js'
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
+ }
6
9
 
7
- this.basePath = 'https://api.websites.minderable.com'
8
- this.cwd = process.cwd()
10
+ verifyPath = filePath => {
11
+ const cwd = path.resolve(this.def.cwd)
12
+ if (!filePath.startsWith(cwd)) F3.throw('zip-slip', { filePath })
13
+ }
9
14
 
10
- this.filename = {}
11
- this.filename.app = 'root.config.app.js'
15
+ unzip = async zipBuffer => {
12
16
 
13
- this.url = {}
14
- this.url.generate = `${this.basePath}/root/generate`
17
+ try {
15
18
 
19
+ const zip = await JSZip.loadAsync(zipBuffer)
20
+
21
+ for (const [name, file] of Object.entries(zip.files)) {
22
+
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) }
16
34
  }
17
35
 
18
36
  post = async ({ endpoint, data, config }) => {
19
37
  try {
20
38
  const response = await axios.post(endpoint, data, config)
21
39
  return response.data
22
- } catch (error) { return F3.err.handle(error) }
40
+ } catch (error) {
41
+ F3.log.arr(error)
42
+ return F3.err.handle(error)
43
+ }
23
44
  }
24
45
 
25
- ensureFileDir = async filepath => await fsa.ensureDir(path.dirname(filepath))
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
33
- }
34
-
35
- async getConfig(filename) {
36
- const cwd = process.cwd()
37
- const filePath = path.join(cwd, filename)
46
+ async getConfig() {
47
+ const filePath = this.def.files.rootConfigApp
38
48
  if (!fss.exists(filePath)) F3.throw('file-missing', { filePath })
39
49
  try { return await import(filePath) }
40
- catch (err) { F3.catch.throw(err) }
50
+ catch (e) { F3.catch.throw(e) }
41
51
  }
42
52
 
43
- async unzip(zipBuffer) {
53
+ async run() {
54
+
44
55
  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
- }
57
56
 
58
- async run() {
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)
59
64
 
60
- const { app } = await this.getConfig(this.filename.app)
65
+ if (response.isOffline) return F3.logs('error-offline')
66
+ if (response.isError) return F3.logs('error-failed-axios-post')
61
67
 
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)
68
+ F3.log.obj({ response })
67
69
 
68
- if (zipBuffer.isOffline) return F3.logs('error-offline')
69
- if (zipBuffer.isError) return F3.logs('error-failed-axios-post')
70
+ await this.unzip(response)
70
71
 
71
- await this.unzip(zipBuffer)
72
+ } catch (e) { F3.catch.throw(e)}
72
73
  }
73
74
  }
74
75
 
@@ -1,8 +1,6 @@
1
1
  class Upgrade {
2
2
 
3
- async run() {
4
- console.log('root upgrade (TODO)')
5
- }
3
+ async run() { console.log('root upgrade (TODO)')}
6
4
  }
7
5
 
8
6
  export const upgrade = new Upgrade()
package/modules/verify.js CHANGED
@@ -1,8 +1,6 @@
1
1
  class Verify {
2
2
 
3
- async run() {
4
- console.log('root verify (TODO)')
5
- }
3
+ async run() { console.log('root verify (TODO)')}
6
4
  }
7
5
 
8
6
  export const verify = new Verify()
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.10",
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",
@@ -32,14 +32,18 @@
32
32
  "#@": "./",
33
33
  "#@/*": "./*"
34
34
  },
35
- "scripts": {},
35
+ "scripts": {
36
+ "cmd": "chmod +x ./config.cmd.sh && ./config.cmd.sh",
37
+ "test": "exit 1"
38
+ },
36
39
  "dependencies": {
37
- "@fullstackunicorn/filesystem": "^1.0.4",
38
- "@fullstackunicorn/initialize": "^1.0.9",
40
+ "@fullstackunicorn/filesystem": "^1.0.11",
41
+ "@fullstackunicorn/initialize": "^1.0.13",
42
+ "axios": "^1.13.6",
39
43
  "jszip": "^3.10.1"
40
44
  },
41
45
  "devDependencies": {
42
- "@fullstackunicorn/cli": "^1.0.3",
43
- "@fullstackunicorn/reduce": "^1.0.20"
46
+ "@fullstackunicorn/cli": "^1.0.8",
47
+ "@fullstackunicorn/reduce": "^1.0.22"
44
48
  }
45
49
  }