@fullstackunicorn/root 1.0.3 → 1.0.4

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,6 +1,9 @@
1
1
  // NODE BUILT IN
2
- export { default as path } from 'path'
3
- export { fileURLToPath } from 'url'
2
+ import { default as path } from 'path'
3
+ import { fileURLToPath } from 'url'
4
+ // BASEPATH
5
+ const getBasepath = () => path.dirname(fileURLToPath(import.meta.url))
6
+ export const basePath = getBasepath()
4
7
 
5
8
  // FULLSTACKUNICORN
6
9
  export { fss, fsa } from '@fullstackunicorn/filesystem'
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
 
3
- export { generate } from '#@/modules/root.generate.js'
4
- export { verify } from '#@/modules/root.verify.js'
5
- export { upgrade } from '#@/modules/root.upgrade.js'
3
+ export { generate } from '#@/modules/generate.js'
4
+ export { verify } from '#@/modules/verify.js'
5
+ export { upgrade } from '#@/modules/upgrade.js'
@@ -0,0 +1,34 @@
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 ()
@@ -0,0 +1,71 @@
1
+ import { basePath } from '#@/index.dep.js'
2
+ import { tools } from '#@/modules/generate.tools.js'
3
+ import { gen } from '#@/modules/generate.gen.js'
4
+
5
+ class Generate {
6
+
7
+ constructor() {
8
+
9
+ this.filename = {}
10
+ 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
+
15
+ this.paths = {}
16
+ this.paths.template = `${basePath}/assets/template/{{item}}`
17
+ this.paths.output = process.cwd()
18
+
19
+ }
20
+
21
+ async run () {
22
+
23
+ await this.handleApp()
24
+ await this.handleFrontend()
25
+ await this.handleBackend()
26
+ await this.handleServer()
27
+
28
+ }
29
+
30
+ async handleApp () {
31
+
32
+ const config = await tools.loadConfig(this.filename.app)
33
+ F3.log.obj({ config, templatePath })
34
+
35
+ const templateFrontend = F3.replacer(this.templatePath, {item:'frontend'})
36
+ await gen.env(this.paths, config.env)
37
+ await gen.manifest(templateFrontend, config.manifest)
38
+ // await gen.package(templateFrontend, config.package)
39
+
40
+ }
41
+
42
+ async handleFrontend () {
43
+
44
+ const templatePath = F3.replacer(this.templatePath, {item:'frontend'})
45
+ const config = await tools.loadConfig(this.filename.frontend)
46
+ F3.log.obj({ config, templatePath })
47
+
48
+ }
49
+
50
+ async handleBackend () {
51
+
52
+ const templatePath = F3.replacer(this.templatePath, {item:'backend'})
53
+ const config = await tools.loadConfig(this.filename.backend)
54
+ F3.log.obj({ config, templatePath })
55
+
56
+
57
+ }
58
+
59
+ async handleServer () {
60
+
61
+ const templatePath = F3.replacer(this.templatePath, {item:'server'})
62
+ const config = await tools.loadConfig(this.filename.server)
63
+ F3.log.obj({ config, templatePath })
64
+
65
+ }
66
+
67
+
68
+
69
+ }
70
+
71
+ export const generate = new Generate()
@@ -0,0 +1,20 @@
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 ()
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.3",
2
+ "version": "1.0.4",
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",
@@ -1,54 +0,0 @@
1
- import { fss, path } from '#@/index.dep.js'
2
-
3
- class Generate {
4
-
5
- async loadConfig(cwd, filename) {
6
-
7
- const filePath = path.join(cwd, filename)
8
-
9
- // check exists (like reduce)
10
- if (!fss.exists(filePath)) {
11
- console.log(`❌ Missing ${filename} in: ${cwd}`)
12
- return null
13
- }
14
-
15
- // import + cache-bust (optional but nice during dev)
16
- try {
17
- const mod = await import(`${filePath}?t=${Date.now()}`)
18
- return mod?.default ?? null
19
- } catch (err) {
20
- console.log(`❌ Failed to load ${filename}`)
21
- console.log(err)
22
- return null
23
- }
24
- }
25
-
26
- async run() {
27
-
28
- const cwd = process.cwd()
29
-
30
- const files = [
31
- 'root.config.app.js',
32
- 'root.config.frontend.js',
33
- 'root.config.backend.js',
34
- 'root.config.server.js',
35
- ]
36
-
37
- const out = {}
38
-
39
- for (const file of files) {
40
- const cfg = await this.loadConfig(cwd, file)
41
- out[file] = cfg
42
- }
43
-
44
- // console log results
45
- console.log('\n✅ root generate: loaded configs\n')
46
- for (const [file, cfg] of Object.entries(out)) {
47
- console.log(`=== ${file} ===`)
48
- console.log(cfg)
49
- console.log('')
50
- }
51
- }
52
- }
53
-
54
- export const generate = new Generate()
File without changes
File without changes