@fullstackunicorn/root 1.0.15 → 1.0.16

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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import '@fullstackunicorn/initialize'
3
3
  F3.service = '@fullstackunicorn/root'
4
- import { generate, verify, upgrade } from '#@/index.js'
4
+ import { generate, verify, upgrade, initialize } from '#@/index.js'
5
5
 
6
6
  const [nodePath, nodeScriptPath, command, ...args] = process.argv
7
7
 
@@ -28,8 +28,14 @@ try {
28
28
  process.exit(0)
29
29
  }
30
30
 
31
+ if (command === 'initialize') {
32
+ await initialize.run(...args)
33
+ process.exit(0)
34
+ }
35
+
31
36
  console.error(`Error: command "${command}" not found.`)
32
37
  console.error('Available commands:')
38
+ console.error(' - initialize')
33
39
  console.error(' - generate')
34
40
  console.error(' - verify')
35
41
  console.error(' - upgrade')
package/index.def.js CHANGED
@@ -1,15 +1,70 @@
1
+ import { basePath } from '#@/index.dep.js'
2
+
1
3
  export class Def {
2
4
 
3
5
  constructor() {
4
6
 
5
7
  this.cwd = process.cwd()
8
+ this.basePath = basePath
6
9
 
7
- this.files = {}
8
- this.files.rootConfigApp = `${this.cwd}/root.config.app.js`
10
+ this.templates = `${this.basePath}/assets/templates`
11
+ this.rootConfigApp = `${this.cwd}/root.config.app.js`
9
12
 
10
13
  this.urls = {}
11
- this.urls.basePath = 'https://api.websites.minderable.com'
12
- this.urls.generate = `${this.urls.basePath}/root/generate`
14
+ this.urls.auth = 'https://auth.minderable.com'
15
+ this.urls.account = 'https://account.minderable.com'
16
+ this.urls.authApi = 'https://api.auth.minderable.com'
17
+
18
+ this.files = {}
19
+ this.folders = {}
20
+ // devtools
21
+ this.files.devtools = {}
22
+ this.files.devtools.git = `.devtools/git.sh`
23
+ this.files.devtools.gitlab = `.devtools/gitlab.sh` // da capire a cosa serviva
24
+ // frontend
25
+ this.files.frontend = {}
26
+ this.files.frontend.env = `frontend/.env`
27
+ this.files.frontend.envDev = 'frontend/configure/env.json'
28
+ this.files.frontend.envProd = 'frontend/configure/env.prod.json'
29
+ this.files.frontend.package = 'frontend/package.json'
30
+ this.files.frontend.webmanifest = 'frontend/assets/index.webmanifest'
31
+ this.files.frontend.trademark = 'frontend/configure/trademark.json'
32
+ this.files.frontend.cache = 'frontend/configure/cache.json'
33
+ this.files.frontend.logo = 'frontend/configure/logo.json'
34
+ this.files.frontend.layout = 'frontend/configure/layout.json'
35
+ this.files.frontend.services = 'frontend/configure/services.json'
36
+ // backend
37
+ this.files.backend = {}
38
+ this.files.backend.env = `backend/.env`
39
+ this.files.backend.package = 'backend/package.json'
40
+ this.files.backend.auth = 'backend/server/middleware.auth.js'
41
+ // manager
42
+ this.files.manager = {}
43
+ this.files.manager.env = `manager/.env`
44
+ this.files.manager.package = 'manager/package.json'
45
+ this.files.manager.auth = 'manager/server/middleware.auth.js'
46
+ // assets
47
+ this.files.assets = {}
48
+ this.files.assets.env = `assets/.env`
49
+ this.files.assets.package = 'assets/package.json'
50
+ this.files.assets.auth = 'assets/modules/sync.auth.js'
51
+
52
+ // initialize lists
53
+ this.lists = {}
54
+ this.lists.initializePackages = [
55
+ `${this.cwd}/package.json`,
56
+ `${this.cwd}/assets/package.json`,
57
+ `${this.cwd}/backend/package.json`,
58
+ `${this.cwd}/frontend/package.json`,
59
+ `${this.cwd}/manager/package.json`,
60
+ ]
61
+ this.lists.initializeFolders = [
62
+ `${this.cwd}`,
63
+ `${this.cwd}/assets`,
64
+ `${this.cwd}/backend`,
65
+ `${this.cwd}/frontend`,
66
+ `${this.cwd}/manager`,
67
+ ]
13
68
 
14
69
  }
15
- }
70
+ }
package/index.dep.js CHANGED
@@ -1,9 +1,16 @@
1
1
  // @FULLSTACKUNICORN
2
2
  export { fss, fsa } from '@fullstackunicorn/filesystem'
3
3
 
4
- // NODE BUILD IN
5
- export { default as path } from 'path'
4
+ // BASEPATH
5
+ import { default as path } from 'path'
6
+ import { fileURLToPath } from 'url'
7
+ export const basePath = path.dirname(fileURLToPath(import.meta.url))
8
+ export { path, fileURLToPath }
9
+
10
+ // NODE
11
+ export { execSync } from 'node:child_process'
6
12
 
7
13
  // PACKAGES
8
14
  export { default as JSZip } from 'jszip'
9
15
  export { default as axios } from 'axios'
16
+ export { v4 as makeId } from 'uuid'
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { initialize } from '#@/modules/initialize.js'
1
2
  export { generate } from '#@/modules/generate.js'
2
3
  export { verify } from '#@/modules/verify.js'
3
4
  export { upgrade } from '#@/modules/upgrade.js'
@@ -0,0 +1,60 @@
1
+ import { execSync, fsa } from '#@/index.dep.js'
2
+ import { Def } from '#@/index.def.js'
3
+ import { upgrade } from '#@/modules/upgrade.js'
4
+
5
+ class Initialize {
6
+
7
+ constructor() {
8
+ this.def = new Def()
9
+ }
10
+
11
+ resetPackage = async filePath => {
12
+
13
+ const exists = await fsa.exists(filePath)
14
+ if (!exists) return false
15
+
16
+ const json = await fsa.readJSON(filePath)
17
+ if (!F3.isObj(json)) F3.throw('invalid-package-json', { filePath })
18
+
19
+ json.dependencies = {}
20
+ json.devDependencies = {}
21
+
22
+ await fsa.writeJSON(filePath, json)
23
+ return true
24
+ }
25
+
26
+ resetPackages = async () => {
27
+ for (const filePath of this.def.lists.initializePackages) {
28
+ await this.resetPackage(filePath)
29
+ }
30
+ }
31
+
32
+ runYarnInitialize = folderPath => {
33
+ execSync('yarn initialize', {
34
+ cwd: folderPath,
35
+ stdio: 'inherit',
36
+ })
37
+ }
38
+
39
+ runInitializers = async () => {
40
+ for (const folderPath of this.def.lists.initializeFolders) {
41
+ this.runYarnInitialize(folderPath)
42
+ }
43
+ }
44
+
45
+ run = async () => {
46
+ try {
47
+
48
+ await this.resetPackages()
49
+ await this.runInitializers()
50
+ await upgrade.run()
51
+
52
+ F3.logs('✅ initialize-done')
53
+ return true
54
+
55
+ } catch (error) { F3.catch.throw(error, 'Initialize.run')}
56
+ }
57
+
58
+ }
59
+
60
+ export const initialize = new Initialize()
@@ -0,0 +1,170 @@
1
+ import { fsa } from '#@/index.dep.js'
2
+
3
+ export class Tools {
4
+
5
+ constructor() { }
6
+
7
+ toStr = value => F3.isNil(value) ? '' : String(value)
8
+
9
+ patchLine = (content = '', key, value) => {
10
+
11
+ const safeValue = this.toStr(value)
12
+
13
+ const patterns = [
14
+ new RegExp(`^(${key}=)"[^"]*"$`, 'm'),
15
+ new RegExp(`^(${key}=)'[^']*'$`, 'm'),
16
+ new RegExp(`^(${key}=).*$`, 'm'),
17
+ ]
18
+
19
+ for (const pattern of patterns) {
20
+ if (pattern.test(content)) {
21
+ return content.replace(pattern, `$1"${safeValue}"`)
22
+ }
23
+ }
24
+
25
+ if (F3.str.isGood(content) && !content.endsWith('\n')) content += '\n'
26
+ return `${content}${key}="${safeValue}"`
27
+ }
28
+
29
+ patchEnvContent = (content = '', values = {}) => {
30
+ let output = F3.isStr(content) ? content : ''
31
+
32
+ for (const key of Object.keys(F3.obj.safe(values))) {
33
+ output = this.patchLine(output, key, values[key])
34
+ }
35
+
36
+ return output
37
+ }
38
+
39
+ patchTemplateContent = (content = '', values = {}) => {
40
+ return F3.replacer(content, F3.obj.safe(values))
41
+ }
42
+
43
+ patchEnv = async ({ templatePath, outputPath, values }) => {
44
+
45
+ const template = await fsa.readText(templatePath)
46
+ if (!F3.str.isGood(template)) F3.throw('missing-template', { templatePath })
47
+
48
+ const exists = await fsa.exists(outputPath)
49
+
50
+ if (!exists) {
51
+ const file = this.patchTemplateContent(template, values)
52
+ await fsa.ensureFileDir(outputPath)
53
+ await fsa.writeText(outputPath, file)
54
+ return true
55
+ }
56
+
57
+ const current = await fsa.readText(outputPath)
58
+ const file = this.patchEnvContent(current, values)
59
+
60
+ await fsa.ensureFileDir(outputPath)
61
+ await fsa.writeText(outputPath, file)
62
+
63
+ return true
64
+ }
65
+
66
+ patchJSAuth = async ({ templatePath, outputPath, values }) => {
67
+
68
+ const template = await fsa.readText(templatePath)
69
+ if (!F3.str.isGood(template)) F3.throw('missing-template', { templatePath })
70
+
71
+ const safeValues = F3.obj.safe(values)
72
+ const exists = await fsa.exists(outputPath)
73
+
74
+ if (!exists) {
75
+ const file = F3.replacer(template, safeValues)
76
+ await fsa.ensureFileDir(outputPath)
77
+ await fsa.writeText(outputPath, file)
78
+ return true
79
+ }
80
+
81
+ let file = await fsa.readText(outputPath)
82
+ if (!F3.str.isGood(file)) file = template
83
+
84
+ if (file.includes('{{')) {
85
+ file = F3.replacer(file, safeValues)
86
+ }
87
+
88
+ const map = [
89
+ { key: 'token', fn: 'getToken' },
90
+ { key: 'user', fn: 'getUserId' },
91
+ ]
92
+
93
+ for (const item of map) {
94
+
95
+ const value = safeValues[item.key]
96
+ if (F3.isNil(value)) continue
97
+
98
+ const pattern = new RegExp(
99
+ `(auth\\.${item.fn}\\s*=\\s*(?:async\\s+)?\\s*=>\\s*['"])([^'"]*)(['"])`
100
+ )
101
+
102
+ if (pattern.test(file)) {
103
+ file = file.replace(pattern, `$1${String(value)}$3`)
104
+ }
105
+ }
106
+
107
+ await fsa.ensureFileDir(outputPath)
108
+ await fsa.writeText(outputPath, file)
109
+
110
+ return true
111
+ }
112
+
113
+ patchJSON = async ({ templatePath, outputPath, values }) => {
114
+
115
+ const template = await fsa.readJSON(templatePath)
116
+ if (!F3.isObj(template)) F3.throw('missing-template', { templatePath })
117
+
118
+ const exists = await fsa.exists(outputPath)
119
+
120
+ const base = exists
121
+ ? await fsa.readJSON(outputPath)
122
+ : template
123
+
124
+ const file = { ...F3.obj.safe(base) }
125
+
126
+ for (const [key, val] of Object.entries(F3.obj.safe(values))) {
127
+ file[key] = val
128
+ }
129
+
130
+ await fsa.ensureFileDir(outputPath)
131
+ await fsa.writeJSON(outputPath, file)
132
+
133
+ return true
134
+ }
135
+
136
+ patchPackage = async ({ templatePath, outputPath, values, dependencies, devDependencies }) => {
137
+
138
+ const template = await fsa.readJSON(templatePath)
139
+ if (!F3.isObj(template)) F3.throw('missing-template', { templatePath })
140
+
141
+ const exists = await fsa.exists(outputPath)
142
+ const base = exists ? await fsa.readJSON(outputPath) : template
143
+
144
+ const file = { ...F3.obj.safe(base) }
145
+
146
+ for (const [key, val] of Object.entries(F3.obj.safe(values))) {
147
+ file[key] = val
148
+ }
149
+
150
+ if (!exists) {
151
+ file.dependencies = { ...F3.obj.safe(dependencies) }
152
+ file.devDependencies = { ...F3.obj.safe(devDependencies) }
153
+ } else {
154
+ file.dependencies = {
155
+ ...F3.obj.safe(file.dependencies),
156
+ ...F3.obj.safe(dependencies),
157
+ }
158
+ file.devDependencies = {
159
+ ...F3.obj.safe(file.devDependencies),
160
+ ...F3.obj.safe(devDependencies),
161
+ }
162
+ }
163
+
164
+ await fsa.ensureFileDir(outputPath)
165
+ await fsa.writeJSON(outputPath, file)
166
+
167
+ return true
168
+ }
169
+
170
+ }
@@ -0,0 +1,38 @@
1
+ export class Assets {
2
+
3
+ constructor(init) {
4
+ this.def = init.def
5
+ this.ctx = init.ctx
6
+ this.tools = init.tools
7
+ }
8
+
9
+ async env() {
10
+ // CLIENT_NAME, CLIENT_ID
11
+ const objPath = 'app.assets.env'
12
+ const templatePath = `${this.def.templates}/${this.def.files.assets.env}`
13
+ const outputPath = `${this.def.cwd}/${this.def.files.assets.env}`
14
+ const values = F3.obj.get(this.ctx, objPath)
15
+ await this.tools.patchEnv({ templatePath, outputPath, values})
16
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.assets.env}`)
17
+ }
18
+
19
+ async auth() {
20
+ // token
21
+ const objPath = 'app.assets.auth'
22
+ const templatePath = `${this.def.templates}/${this.def.files.assets.auth}`
23
+ const outputPath = `${this.def.cwd}/${this.def.files.assets.auth}`
24
+ const values = F3.obj.get(this.ctx, objPath)
25
+ await this.tools.patchJSAuth({ templatePath, outputPath, values })
26
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.assets.auth}`)
27
+ }
28
+
29
+ async package() {
30
+ // name, author
31
+ const objPath = 'app.assets.package'
32
+ const templatePath = `${this.def.templates}/${this.def.files.assets.package}`
33
+ const outputPath = `${this.def.cwd}/${this.def.files.assets.package}`
34
+ const values = F3.obj.get(this.ctx, objPath)
35
+ await this.tools.patchJSON({ templatePath, outputPath, values })
36
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.assets.package}`)
37
+ }
38
+ }
@@ -0,0 +1,38 @@
1
+ export class Backend {
2
+
3
+ constructor(init) {
4
+ this.def = init.def
5
+ this.ctx = init.ctx
6
+ this.tools = init.tools
7
+ }
8
+
9
+ async env() {
10
+ // SERVER_NAME, SERVER_PORT, AUTH_CLIENT, CLIENT_ID
11
+ const objPath = 'app.backend.env'
12
+ const templatePath = `${this.def.templates}/${this.def.files.backend.env}`
13
+ const outputPath = `${this.def.cwd}/${this.def.files.backend.env}`
14
+ const values = F3.obj.get(this.ctx, 'app.backend.env')
15
+ await this.tools.patchEnv({ templatePath, outputPath, values})
16
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.backend.env}`)
17
+ }
18
+
19
+ async auth() {
20
+ // token
21
+ const objPath = 'app.backend.auth'
22
+ const templatePath = `${this.def.templates}/${this.def.files.backend.auth}`
23
+ const outputPath = `${this.def.cwd}/${this.def.files.backend.auth}`
24
+ const values = F3.obj.get(this.ctx, 'app.backend.auth')
25
+ await this.tools.patchJSAuth({ templatePath, outputPath, values })
26
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.backend.auth}`)
27
+ }
28
+
29
+ async package() {
30
+ // name, author
31
+ const objPath = 'app.backend.package'
32
+ const templatePath = `${this.def.templates}/${this.def.files.backend.package}`
33
+ const outputPath = `${this.def.cwd}/${this.def.files.backend.package}`
34
+ const values = F3.obj.get(this.ctx, 'app.backend.package')
35
+ await this.tools.patchJSON({ templatePath, outputPath, values })
36
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.backend.package}`)
37
+ }
38
+ }
@@ -0,0 +1,25 @@
1
+ export class Devtools {
2
+
3
+ constructor(init) {
4
+ this.def = init.def
5
+ this.ctx = init.ctx
6
+ this.tools = init.tools
7
+ }
8
+
9
+ async git() {
10
+ // GIT_USER_NAME, GIT_USER_EMAIL, REPO_NAMESPACE, REPO_NAME
11
+ const templatePath = `${this.def.templates}/${this.def.files.devtools.git}`
12
+ const outputPath = `${this.def.cwd}/${this.def.files.devtools.git}`
13
+ const values = F3.obj.get(this.ctx, 'app.devops.git')
14
+ await this.tools.patchEnv({ templatePath, outputPath, values})
15
+ }
16
+
17
+ async gitlab() {
18
+ // GITLAB_TOKEN, GITLAB_NAMESPACE_ID, GITLAB_PROJECT_NAME
19
+ const templatePath = `${this.def.templates}/${this.def.files.devtools.gitlab}`
20
+ const outputPath = `${this.def.cwd}/${this.def.files.devtools.gitlab}`
21
+ const values = F3.obj.get(this.ctx, 'app.devops.gitlab')
22
+ await this.tools.patchEnv({ templatePath, outputPath, values})
23
+ }
24
+
25
+ }
@@ -0,0 +1,111 @@
1
+ export class Frontend {
2
+
3
+ constructor(init) {
4
+ this.def = init.def
5
+ this.ctx = init.ctx
6
+ this.tools = init.tools
7
+ }
8
+
9
+ async env() {
10
+ // VITE_NAME, VITE_PORT
11
+ const objPath = 'app.frontend.env'
12
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.env}`
13
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.env}`
14
+ const values = F3.obj.get(this.ctx, 'app.frontend.env')
15
+ await this.tools.patchEnv({ templatePath, outputPath, values })
16
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.env}`)
17
+ }
18
+
19
+ async envDev() {
20
+ const objPath = 'app.frontend.configure.env'
21
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.envDev}`
22
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.envDev}`
23
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.env')
24
+ await this.tools.patchJSON({ templatePath, outputPath, values })
25
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.envDev}`)
26
+ }
27
+
28
+ async envProd() {
29
+ const objPath = 'app.frontend.configure.env'
30
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.envProd}`
31
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.envProd}`
32
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.env')
33
+ await this.tools.patchJSON({ templatePath, outputPath, values })
34
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.envProd}`)
35
+ }
36
+
37
+ async package() {
38
+ // name, homepage, author
39
+ const objPath = 'app.frontend.package'
40
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.package}`
41
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.package}`
42
+ const values = F3.obj.get(this.ctx, 'app.frontend.package')
43
+ await this.tools.patchJSON({ templatePath, outputPath, values })
44
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.package}`)
45
+ }
46
+
47
+ async webmanifest() {
48
+ // name, short_name, theme_color, background_color
49
+ const objPath = 'app.frontend.webmanifest'
50
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.webmanifest}`
51
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.webmanifest}`
52
+ const values = F3.obj.get(this.ctx, 'app.frontend.webmanifest')
53
+ await this.tools.patchJSON({ templatePath, outputPath, values })
54
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.webmanifest}`)
55
+ }
56
+
57
+ async configureCache() {
58
+ // stale
59
+ const objPath = 'app.frontend.configure.cache'
60
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.cache}`
61
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.cache}`
62
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.cache')
63
+ await this.tools.patchJSON({ templatePath, outputPath, values })
64
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.cache}`)
65
+ }
66
+
67
+ async configureLogo() {
68
+ // XY, canonical, inverse
69
+ const objPath = 'app.frontend.configure.logo'
70
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.logo}`
71
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.logo}`
72
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.logo')
73
+ await this.tools.patchJSON({ templatePath, outputPath, values })
74
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.logo}`)
75
+ }
76
+
77
+ async configureTrademark() {
78
+ // Xmax, Y, canonical, inverse
79
+ const objPath = 'app.frontend.configure.trademark'
80
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.trademark}`
81
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.trademark}`
82
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.trademark')
83
+ await this.tools.patchJSON({ templatePath, outputPath, values })
84
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.trademark}`)
85
+ }
86
+
87
+ async configureLayout() {
88
+ // column_1, column_2, column_3
89
+ // IS_SIDEBAR_ONE_INTERNAL_OFF, IS_SIDEBAR_ONE_EXTERNAL_OFF
90
+ // IS_SIDEBAR_TWO_INTERNAL_OFF, IS_SIDEBAR_TWO_EXTERNAL_OFF
91
+ const objPath = 'app.frontend.configure.layout'
92
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.layout}`
93
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.layout}`
94
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.layout')
95
+ await this.tools.patchJSON({ templatePath, outputPath, values })
96
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.layout}`)
97
+ }
98
+
99
+ async configureServices() {
100
+ // IS_DEFAULT_THEME_DARK
101
+ // IS_BUTTON_USER_OFF
102
+ // IS_CARD_ACCOUNT_OFF, IS_CARD_LANGUAGE_OFF, IS_CARD_THEME_OFF, IS_CARD_COOKIES_OFF, IS_CARD_LEGALS_OFF
103
+ // IS_BAND_CALLOUT_ON
104
+ const objPath = 'app.frontend.configure.services'
105
+ const templatePath = `${this.def.templates}/${this.def.files.frontend.services}`
106
+ const outputPath = `${this.def.cwd}/${this.def.files.frontend.services}`
107
+ const values = F3.obj.get(this.ctx, 'app.frontend.configure.services')
108
+ await this.tools.patchJSON({ templatePath, outputPath, values })
109
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.frontend.services}`)
110
+ }
111
+ }
@@ -0,0 +1,38 @@
1
+ export class Manager {
2
+
3
+ constructor(init) {
4
+ this.def = init.def
5
+ this.ctx = init.ctx
6
+ this.tools = init.tools
7
+ }
8
+
9
+ async env() {
10
+ // SERVER_NAME, SERVER_PORT, AUTH_CLIENT, CLIENT_ID
11
+ const objPath = 'app.manager.env'
12
+ const templatePath = `${this.def.templates}/${this.def.files.manager.env}`
13
+ const outputPath = `${this.def.cwd}/${this.def.files.manager.env}`
14
+ const values = F3.obj.get(this.ctx, objPath)
15
+ await this.tools.patchEnv({ templatePath, outputPath, values })
16
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.manager.env}`)
17
+ }
18
+
19
+ async auth() {
20
+ // token
21
+ const objPath = 'app.manager.auth'
22
+ const templatePath = `${this.def.templates}/${this.def.files.manager.auth}`
23
+ const outputPath = `${this.def.cwd}/${this.def.files.manager.auth}`
24
+ const values = F3.obj.get(this.ctx, objPath)
25
+ await this.tools.patchJSAuth({ templatePath, outputPath, values })
26
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.manager.auth}`)
27
+ }
28
+
29
+ async package() {
30
+ // name, author
31
+ const objPath = 'app.manager.package'
32
+ const templatePath = `${this.def.templates}/${this.def.files.manager.package}`
33
+ const outputPath = `${this.def.cwd}/${this.def.files.manager.package}`
34
+ const values = F3.obj.get(this.ctx, objPath)
35
+ await this.tools.patchJSON({ templatePath, outputPath, values })
36
+ F3.logs(`✅ ${objPath} ➡️ ${this.def.files.manager.package}`)
37
+ }
38
+ }
@@ -1,6 +1,186 @@
1
+ import { path, fss, fsa } from '#@/index.dep.js'
2
+ import { Devtools } from '#@/modules/targets/devtools.js'
3
+ import { Assets } from '#@/modules/targets/assets.js'
4
+ import { Frontend } from '#@/modules/targets/frontend.js'
5
+ import { Backend } from '#@/modules/targets/backend.js'
6
+ import { Manager } from '#@/modules/targets/manager.js'
7
+ import { Def } from '#@/index.def.js'
8
+ import { Tools } from '#@/modules/targets/@tools.js'
9
+
1
10
  class Upgrade {
2
11
 
3
- async run() { console.log('root upgrade (TODO)')}
12
+ constructor() {
13
+
14
+ this.def = new Def()
15
+ this.ctx = {}
16
+ this.ctx.app = {}
17
+
18
+ this.tools = new Tools()
19
+
20
+ const init = { def: this.def, ctx: this.ctx, tools: this.tools }
21
+
22
+ this.assets = new Assets(init)
23
+ this.backend = new Backend(init)
24
+ this.devtools = new Devtools(init)
25
+ this.frontend = new Frontend(init)
26
+ this.manager = new Manager(init)
27
+
28
+ }
29
+
30
+ run = async () => {
31
+
32
+ try {
33
+
34
+ this.ctx.app = await this.getApp()
35
+
36
+ // devtools
37
+ await this.devtools.git()
38
+ await this.devtools.gitlab()
39
+
40
+ // frontend
41
+ await this.frontend.env()
42
+ await this.frontend.envDev()
43
+ await this.frontend.envProd()
44
+ await this.frontend.package()
45
+ await this.frontend.webmanifest()
46
+ await this.frontend.configureLogo()
47
+ await this.frontend.configureTrademark()
48
+ await this.frontend.configureLayout()
49
+ await this.frontend.configureServices()
50
+
51
+ // backend
52
+ await this.backend.env()
53
+ await this.backend.package()
54
+ await this.backend.auth()
55
+
56
+ // // manager
57
+ await this.manager.env()
58
+ await this.manager.package()
59
+ await this.manager.auth()
60
+
61
+ // assets
62
+ await this.assets.env()
63
+ await this.assets.package()
64
+ await this.assets.auth()
65
+
66
+
67
+ } catch (error) { console.error(error) }
68
+
69
+ }
70
+
71
+ getApp = async () => {
72
+
73
+ const { app: a } = await import(this.def.rootConfigApp)
74
+ if (!F3.obj.isGood(a)) F3.throw('missing-configuration')
75
+
76
+ const app = {}
77
+
78
+
79
+ app.languages = a.languages
80
+ app.index = a.index
81
+ app.devops = a.devops
82
+
83
+
84
+ // modules
85
+ app.assets = {}
86
+ app.backend = {}
87
+ app.manager = {}
88
+ app.frontend = {}
89
+
90
+
91
+ // assets.auth
92
+ app.assets.auth = {}
93
+ app.assets.auth.token = a.dev.token
94
+ // backend.auth
95
+ app.backend.auth = {}
96
+ app.backend.auth.user = a.dev.user
97
+ app.backend.auth.token = a.dev.token
98
+ // manager.auth
99
+ app.manager.auth = {}
100
+ app.manager.auth.user = a.dev.user
101
+ app.manager.auth.token = a.dev.token
102
+
103
+
104
+ // assets.env
105
+ app.assets.env = {}
106
+ app.assets.env.CLIENT_NAME = a.domain.name
107
+ app.assets.env.CLIENT_ID = a.domain.client
108
+ // backend.env
109
+ app.backend.env = {}
110
+ app.backend.env.SERVER_NAME = a.domain.name
111
+ app.backend.env.SERVER_PORT = Number(a.dev.port) + 1
112
+ app.backend.env.AUTH_CLIENT = a.domain.name
113
+ app.backend.env.CLIENT_ID = a.domain.client
114
+ // manager.env
115
+ app.manager.env = {}
116
+ app.manager.env.SERVER_NAME = `cms.${a.domain.name}`
117
+ app.manager.env.SERVER_PORT = Number(a.dev.port) + 2
118
+ app.manager.env.AUTH_CLIENT = a.domain.name
119
+ app.manager.env.CLIENT_ID = a.domain.client
120
+ // frontend.env
121
+ app.frontend.env = {}
122
+ app.frontend.env.VITE_NAME = a.domain.name
123
+ app.frontend.env.VITE_PORT = Number(a.dev.port)
124
+ // frontend.configure.env
125
+ app.frontend.configure = {}
126
+ app.frontend.configure.env = {}
127
+ app.frontend.configure.env.PLATFORM = a.configure.PLATFORM
128
+ app.frontend.configure.env.CLIENT_ID = a.domain.client
129
+ app.frontend.configure.env.PROTOCOL_AUTH = 'https'
130
+ app.frontend.configure.env.CLIENT_URL_AUTH = this.def.urls.auth
131
+ app.frontend.configure.env.CLIENT_URL_ACCOUNT = this.def.urls.account
132
+ app.frontend.configure.env.SERVER_URL_AUTH = this.def.urls.authApi
133
+
134
+ // assets.package
135
+ app.assets.package = {}
136
+ app.assets.package.name = `@${a.domain.name}/assets`
137
+ app.assets.package.author = a.package.author
138
+ // backend.package
139
+ app.backend.package = {}
140
+ app.backend.package.name = `@${a.domain.name}/backend`
141
+ app.backend.package.author = a.package.author
142
+ // manager.package
143
+ app.manager.package = {}
144
+ app.manager.package.name = `@${a.domain.name}/manager`
145
+ app.manager.package.author = a.package.author
146
+ // frontend.package
147
+ app.frontend.package = {}
148
+ app.frontend.package.name = `@${a.domain.name}/frontend`
149
+ app.frontend.package.homepage = `https://${a.domain.name}`
150
+ app.frontend.package.author = a.package.author
151
+
152
+
153
+ // frontend.manifest
154
+ app.frontend.webmanifest = {}
155
+ app.frontend.webmanifest.name = a.index.name
156
+ app.frontend.webmanifest.short_name = a.index.short_name
157
+ app.frontend.webmanifest.theme_color = a.index.theme_color
158
+ app.frontend.webmanifest.background_color = a.index.background_color
159
+
160
+ // frontend.configure
161
+ app.frontend.configure = app.frontend.configure || {}
162
+ // frontend.configure.cache
163
+ app.frontend.configure.cache = {}
164
+ app.frontend.configure.cache.stale = a.configure.cache.stale
165
+ // frontend.configure.logo
166
+ app.frontend.configure.logo = {}
167
+ app.frontend.configure.logo.XY = a.configure.logo.XY
168
+ app.frontend.configure.logo.canonical = `logo.${a.configure.logo.ext}`
169
+ app.frontend.configure.logo.inverse = `logo.inverse.${a.configure.logo.ext}`
170
+ // frontend.configure.trademark
171
+ app.frontend.configure.trademark = {}
172
+ app.frontend.configure.trademark.ratio = [a.configure.trademark.X, a.configure.trademark.Y]
173
+ app.frontend.configure.trademark.Y = a.configure.trademark.Y
174
+ app.frontend.configure.trademark.canonical = `trademark.${a.configure.trademark.ext}`
175
+ app.frontend.configure.trademark.inverse = `trademark.inverse.${a.configure.trademark.ext}`
176
+ // frontend.configure.layout
177
+ app.frontend.configure.layout = a.configure.layout
178
+ // frontend.configure.services
179
+ app.frontend.configure.services = a.configure.services
180
+
181
+ return app
182
+
183
+ }
4
184
  }
5
185
 
6
- export const upgrade = new Upgrade()
186
+ export const upgrade = new Upgrade()
package/modules/verify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  class Verify {
2
2
 
3
- async run() { console.log('root verify (TODO)')}
3
+ async run() { console.log('root verify')}
4
4
  }
5
5
 
6
6
  export const verify = new Verify()
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
- "version": "1.0.15",
2
+ "version": "1.0.16",
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",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "private": false,
9
- "readme": "package.readme.md",
9
+ "readme": "package.md",
10
10
  "files": [
11
11
  "index.cmd.js",
12
12
  "index.def.js",
@@ -41,7 +41,8 @@
41
41
  "@fullstackunicorn/filesystem": "^1.0.11",
42
42
  "@fullstackunicorn/initialize": "^1.0.13",
43
43
  "axios": "^1.13.6",
44
- "jszip": "^3.10.1"
44
+ "jszip": "^3.10.1",
45
+ "uuid": "^13.0.0"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@fullstackunicorn/cli": "^1.0.8",