@newlogic-digital/cli 1.5.0-next.7 → 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/package.json +4 -3
- package/src/commands/init/ui.mjs +30 -3
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
|
}
|
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)
|