@fullstackunicorn/root 1.0.2 → 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.cmd.js +7 -8
- package/index.dep.js +5 -2
- package/index.js +3 -3
- package/modules/generate.gen.js +34 -0
- package/modules/generate.js +71 -0
- package/modules/generate.tools.js +20 -0
- package/package.json +1 -1
- package/modules/root.generate.js +0 -54
- /package/modules/{root.upgrade.js → upgrade.js} +0 -0
- /package/modules/{root.verify.js → verify.js} +0 -0
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 {
|
|
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 <
|
|
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 === '
|
|
17
|
-
|
|
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 === '
|
|
23
|
-
await
|
|
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
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// NODE BUILT IN
|
|
2
|
-
|
|
3
|
-
|
|
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/
|
|
4
|
-
export { verify } from '#@/modules/
|
|
5
|
-
export { upgrade } from '#@/modules/
|
|
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
package/modules/root.generate.js
DELETED
|
@@ -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
|