@fullstackunicorn/root 1.0.0 → 1.0.3

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.cmd.js CHANGED
@@ -1,26 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  import '@fullstackunicorn/initialize'
3
3
  F3.service = '@fullstackunicorn/root'
4
- import { init, generate, upgrade } from '#@/index.js'
4
+ import { generate, verify, upgrade } from '#@/index.js'
5
5
 
6
6
  const [nodePath, nodeScriptPath, command, ...args] = process.argv
7
7
 
8
8
  if (!command) {
9
9
  console.error('Error: invalid arguments. See documentation.')
10
- console.error('Usage: yarn root <init|generate|upgrade> [args...]')
10
+ console.error('Usage: yarn root <generate|verify|upgrade> [args...]')
11
11
  process.exit(1)
12
12
  }
13
13
 
14
14
  try {
15
15
 
16
- if (command === 'init') {
17
- const [foldername] = args
18
- await init.run(foldername ?? null)
16
+ if (command === 'generate') {
17
+ await generate.run(...args)
19
18
  process.exit(0)
20
19
  }
21
20
 
22
- if (command === 'generate') {
23
- await generate.run(...args)
21
+ if (command === 'verify') {
22
+ await verify.run(...args)
24
23
  process.exit(0)
25
24
  }
26
25
 
@@ -31,8 +30,8 @@ try {
31
30
 
32
31
  console.error(`Error: command "${command}" not found.`)
33
32
  console.error('Available commands:')
34
- console.error(' - init [foldername]')
35
33
  console.error(' - generate')
34
+ console.error(' - verify')
36
35
  console.error(' - upgrade')
37
36
  process.exit(1)
38
37
 
package/index.dep.js CHANGED
@@ -3,4 +3,4 @@ export { default as path } from 'path'
3
3
  export { fileURLToPath } from 'url'
4
4
 
5
5
  // FULLSTACKUNICORN
6
- import { fsa } from '@fullstackunicorn/filesystem'
6
+ export { fss, fsa } from '@fullstackunicorn/filesystem'
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import '#@/initialize.js'
2
1
 
3
- export { init } from '#@/modules/root.init.js'
2
+
4
3
  export { generate } from '#@/modules/root.generate.js'
4
+ export { verify } from '#@/modules/root.verify.js'
5
5
  export { upgrade } from '#@/modules/root.upgrade.js'
@@ -1,7 +1,53 @@
1
+ import { fss, path } from '#@/index.dep.js'
2
+
1
3
  class Generate {
2
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
+
3
26
  async run() {
4
- console.log('root generate (TODO)')
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
+ }
5
51
  }
6
52
  }
7
53
 
@@ -0,0 +1,8 @@
1
+ class Verify {
2
+
3
+ async run() {
4
+ console.log('root verify (TODO)')
5
+ }
6
+ }
7
+
8
+ export const verify = new Verify()
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0",
2
+ "version": "1.0.3",
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,29 +0,0 @@
1
- import { path } from '#@/index.dep.js'
2
- import { fsa } from '#@/fsa.js'
3
-
4
- class Init {
5
-
6
- async run(foldername = null) {
7
-
8
- const base = process.cwd()
9
-
10
- const targetDir = foldername
11
- ? path.resolve(base, foldername)
12
- : base
13
-
14
- await fsa.ensureDir(targetDir)
15
-
16
- const configPath = path.join(targetDir, 'root.config.json')
17
- const readmePath = path.join(targetDir, 'root.readme.md')
18
-
19
- // per ora vuoti
20
- if (!await fsa.exists(configPath)) await fsa.writeText(configPath, '')
21
- if (!await fsa.exists(readmePath)) await fsa.writeText(readmePath, '')
22
-
23
- console.log(`✅ root init: ${targetDir}`)
24
- console.log(` - ${configPath}`)
25
- console.log(` - ${readmePath}`)
26
- }
27
- }
28
-
29
- export const init = new Init()