@newlogic-digital/cli 1.5.0-next.6 → 1.5.0-next.8
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.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newlogic-digital/cli",
|
|
3
|
-
"version": "1.5.0-next.
|
|
3
|
+
"version": "1.5.0-next.8",
|
|
4
4
|
"main": "index.mjs",
|
|
5
5
|
"bin": {
|
|
6
6
|
"newlogic-cli": "index.mjs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@clack/prompts": "^1.1.0",
|
|
17
|
-
"ajv": "^8.
|
|
17
|
+
"ajv": "^8.18.0",
|
|
18
18
|
"dedent": "^1.7.2",
|
|
19
19
|
"es-toolkit": "^1.45.1",
|
|
20
20
|
"fast-glob": "^3.3.3",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@stylistic/eslint-plugin": "^5.10",
|
|
34
|
-
"
|
|
34
|
+
"@types/fs-extra": "^11.0.4",
|
|
35
|
+
"oxlint": "^1.57.0"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spinner as createSpinner } from '@clack/prompts'
|
|
1
2
|
import { styleText } from 'node:util'
|
|
2
3
|
import { createBlocksService } from './service.mjs'
|
|
3
4
|
|
|
@@ -39,6 +40,7 @@ function formatErrorMessage(message) {
|
|
|
39
40
|
function createSilentLogger() {
|
|
40
41
|
return {
|
|
41
42
|
info() {},
|
|
43
|
+
progress() {},
|
|
42
44
|
warn() {},
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -100,14 +102,45 @@ function formatInfoMessage(message) {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
function createCliLogger() {
|
|
105
|
+
const progress = createSpinner()
|
|
106
|
+
let hasActiveProgress = false
|
|
107
|
+
|
|
108
|
+
function clearProgress() {
|
|
109
|
+
if (!hasActiveProgress) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
progress.clear()
|
|
114
|
+
hasActiveProgress = false
|
|
115
|
+
}
|
|
116
|
+
|
|
103
117
|
return {
|
|
118
|
+
progress(message) {
|
|
119
|
+
if (!message) {
|
|
120
|
+
clearProgress()
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!hasActiveProgress) {
|
|
125
|
+
progress.start(message)
|
|
126
|
+
hasActiveProgress = true
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
progress.message(message)
|
|
131
|
+
},
|
|
132
|
+
|
|
104
133
|
info(message) {
|
|
134
|
+
clearProgress()
|
|
105
135
|
console.log(formatInfoMessage(message))
|
|
106
136
|
},
|
|
107
137
|
|
|
108
138
|
warn(message) {
|
|
139
|
+
clearProgress()
|
|
109
140
|
console.log(`${label('yellow', 'warn')} ${styleText('yellow', highlightTokens(message))}`)
|
|
110
141
|
},
|
|
142
|
+
|
|
143
|
+
clearProgress,
|
|
111
144
|
}
|
|
112
145
|
}
|
|
113
146
|
|
|
@@ -148,6 +181,8 @@ function printBlocksUsage() {
|
|
|
148
181
|
}
|
|
149
182
|
|
|
150
183
|
export default async function blocks(action, names = [], options = {}) {
|
|
184
|
+
let activeLogger
|
|
185
|
+
|
|
151
186
|
if (!action || action === 'help' || action === '--help') {
|
|
152
187
|
printBlocksUsage()
|
|
153
188
|
return
|
|
@@ -167,7 +202,8 @@ export default async function blocks(action, names = [], options = {}) {
|
|
|
167
202
|
throw new Error('Missing block name for "newlogic blocks add"')
|
|
168
203
|
}
|
|
169
204
|
|
|
170
|
-
|
|
205
|
+
activeLogger = createCliLogger()
|
|
206
|
+
const service = createBlocksService({ logger: activeLogger })
|
|
171
207
|
await service.addBlocks(names, {
|
|
172
208
|
target: options.target,
|
|
173
209
|
})
|
|
@@ -179,13 +215,15 @@ export default async function blocks(action, names = [], options = {}) {
|
|
|
179
215
|
throw new Error('Missing block name for "newlogic blocks remove"')
|
|
180
216
|
}
|
|
181
217
|
|
|
182
|
-
|
|
218
|
+
activeLogger = createCliLogger()
|
|
219
|
+
const service = createBlocksService({ logger: activeLogger })
|
|
183
220
|
await service.removeBlocks(names)
|
|
184
221
|
return
|
|
185
222
|
}
|
|
186
223
|
|
|
187
224
|
if (action === 'update') {
|
|
188
|
-
|
|
225
|
+
activeLogger = createCliLogger()
|
|
226
|
+
const service = createBlocksService({ logger: activeLogger })
|
|
189
227
|
await service.updateBlocks()
|
|
190
228
|
return
|
|
191
229
|
}
|
|
@@ -193,6 +231,7 @@ export default async function blocks(action, names = [], options = {}) {
|
|
|
193
231
|
throw new Error(`Unknown blocks action "${action}"`)
|
|
194
232
|
}
|
|
195
233
|
catch (error) {
|
|
234
|
+
activeLogger?.clearProgress?.()
|
|
196
235
|
console.log(`${label('red', 'error')} ${formatErrorMessage(error.message)}`)
|
|
197
236
|
process.exit(1)
|
|
198
237
|
}
|
|
@@ -13,6 +13,7 @@ const BLOCK_TARGETS = new Set(['ui', 'cms'])
|
|
|
13
13
|
function defaultLogger() {
|
|
14
14
|
return {
|
|
15
15
|
info: message => console.log(message),
|
|
16
|
+
progress() {},
|
|
16
17
|
warn: message => console.warn(message),
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -264,7 +265,7 @@ function saveProjectConfig(configPath, config, blocks) {
|
|
|
264
265
|
blocks: Object.fromEntries(
|
|
265
266
|
blocks.map(block => [
|
|
266
267
|
block.name,
|
|
267
|
-
{ ...
|
|
268
|
+
{ ...block.config },
|
|
268
269
|
]),
|
|
269
270
|
),
|
|
270
271
|
}
|
|
@@ -396,6 +397,8 @@ export function createBlocksService({
|
|
|
396
397
|
assertBlockName(normalizedName)
|
|
397
398
|
|
|
398
399
|
if (!metaCache.has(normalizedName)) {
|
|
400
|
+
validatorPromise ||= createMetaValidator(repository)
|
|
401
|
+
logger.progress?.(`Downloading block metadata: ${normalizedName}`)
|
|
399
402
|
const meta = await repository.getMeta(normalizedName)
|
|
400
403
|
await validateMeta(meta, `block "${normalizedName}"`)
|
|
401
404
|
metaCache.set(normalizedName, meta)
|
|
@@ -546,6 +549,7 @@ export function createBlocksService({
|
|
|
546
549
|
}
|
|
547
550
|
}
|
|
548
551
|
|
|
552
|
+
logger.progress?.(`Downloading ${relativeTargetPath}`)
|
|
549
553
|
const contents = await repository.getFileBuffer(blockName, rule.source)
|
|
550
554
|
|
|
551
555
|
fse.ensureDirSync(path.dirname(targetPath))
|
package/src/commands/init/ui.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { cancel, confirm, isCancel, select, text } from '@clack/prompts'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import { styleText } from 'node:util'
|
|
2
4
|
import { execSync } from '../../utils.mjs'
|
|
3
5
|
import fse from 'fs-extra'
|
|
4
6
|
import { join, resolve } from 'path'
|
|
@@ -71,6 +73,23 @@ function prepareBlankInstall(projectPath) {
|
|
|
71
73
|
fse.outputFileSync(join(pagesPath, 'index.json'), '{\n "title": "Hello world"\n}\n')
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
function cloneExec(path, { branch, url }) {
|
|
77
|
+
execSync(`git clone -b ${branch} --single-branch --depth 1 ${url}/newlogic-ui.git ${path}`)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function scaffoldIntoExistingDirectory(projectPath, { branch, url }) {
|
|
81
|
+
const tempDir = fse.mkdtempSync(join(os.tmpdir(), 'newlogic-ui-'))
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
cloneExec(tempDir, { branch, url })
|
|
85
|
+
fse.removeSync(join(tempDir, '.git'))
|
|
86
|
+
fse.copySync(tempDir, projectPath, { overwrite: false, errorOnExist: false })
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
fse.removeSync(tempDir)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
74
93
|
export default async function ui(name, { branch, ...options } = {}) {
|
|
75
94
|
const autoYes = isAutoYes(options)
|
|
76
95
|
let clone = normalizeEnum(options.clone, ['ssh', 'https'])
|
|
@@ -125,12 +144,20 @@ export default async function ui(name, { branch, ...options } = {}) {
|
|
|
125
144
|
url = 'https://git.newlogic.cz/newlogic-digital'
|
|
126
145
|
}
|
|
127
146
|
|
|
128
|
-
execSync(`git clone -b ${branch} --single-branch --depth 1 ${url}/newlogic-ui.git ${name || '.'}`)
|
|
129
|
-
|
|
130
147
|
const projectPath = name ? resolve(process.cwd(), name) : resolve(process.cwd())
|
|
148
|
+
const packageJsonPath = join(projectPath, 'package.json')
|
|
131
149
|
const gitPath = join(projectPath, '.git')
|
|
132
150
|
|
|
133
|
-
fse.
|
|
151
|
+
if (!fse.existsSync(projectPath)) {
|
|
152
|
+
cloneExec(name || '.', { branch, url })
|
|
153
|
+
fse.removeSync(gitPath)
|
|
154
|
+
}
|
|
155
|
+
else if (!fse.existsSync(packageJsonPath)) {
|
|
156
|
+
scaffoldIntoExistingDirectory(projectPath, { branch, url })
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
console.log(styleText('yellow', 'Project files already exist in the directory, skipping copy step (delete package.json to force)'))
|
|
160
|
+
}
|
|
134
161
|
|
|
135
162
|
if (scope === 'blank') {
|
|
136
163
|
prepareBlankInstall(projectPath)
|