@nocobase/cli 2.1.9 → 2.1.11-test.1
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/dist/commands/app/restart.js +38 -0
- package/dist/commands/app/start.js +92 -0
- package/dist/commands/app/upgrade.js +11 -0
- package/dist/commands/init.js +15 -1
- package/dist/commands/install.js +135 -4
- package/dist/commands/self/update.js +1 -1
- package/dist/commands/source/dev.js +9 -5
- package/dist/commands/source/download.js +66 -0
- package/dist/lib/app-managed-resources.js +101 -1
- package/dist/lib/auth-store.js +7 -1
- package/dist/lib/cli-config.js +19 -0
- package/dist/lib/env-config.js +1 -0
- package/dist/lib/hook-script.js +160 -0
- package/dist/lib/run-npm.js +4 -0
- package/dist/lib/self-manager.js +64 -11
- package/dist/lib/source-publish.js +2 -2
- package/dist/lib/startup-update.js +1 -1
- package/package.json +2 -3
package/dist/lib/self-manager.js
CHANGED
|
@@ -108,19 +108,34 @@ function readCurrentVersion(packageRoot) {
|
|
|
108
108
|
const pkg = JSON.parse(content);
|
|
109
109
|
return String(pkg.version ?? '').trim();
|
|
110
110
|
}
|
|
111
|
-
function detectInstallMethod(packageRoot,
|
|
111
|
+
function detectInstallMethod(packageRoot, options = {}) {
|
|
112
112
|
if (fs.existsSync(path.join(packageRoot, 'src'))
|
|
113
113
|
&& fs.existsSync(path.join(packageRoot, 'tsconfig.json'))) {
|
|
114
114
|
return 'source';
|
|
115
115
|
}
|
|
116
|
-
if (globalPrefix && isSubPath(globalPrefix, packageRoot)) {
|
|
116
|
+
if (options.globalPrefix && isSubPath(options.globalPrefix, packageRoot)) {
|
|
117
117
|
return 'npm-global';
|
|
118
118
|
}
|
|
119
|
+
if (options.yarnGlobalDir && isSubPath(options.yarnGlobalDir, packageRoot)) {
|
|
120
|
+
return 'yarn-global';
|
|
121
|
+
}
|
|
122
|
+
if (isPnpmGlobalPath(packageRoot)) {
|
|
123
|
+
return 'pnpm-global';
|
|
124
|
+
}
|
|
119
125
|
if (packageRoot.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
120
126
|
return 'package-local';
|
|
121
127
|
}
|
|
122
128
|
return 'unknown';
|
|
123
129
|
}
|
|
130
|
+
function isPnpmGlobalPath(packageRoot) {
|
|
131
|
+
const normalized = normalizePath(packageRoot);
|
|
132
|
+
const segments = normalized.split(path.sep).filter(Boolean);
|
|
133
|
+
const globalIndex = segments.findIndex((segment, index) => segment === 'global' && segments[index - 1] === 'pnpm');
|
|
134
|
+
if (globalIndex === -1) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return segments.slice(globalIndex + 2).includes('node_modules');
|
|
138
|
+
}
|
|
124
139
|
function getInstallMethodCacheFile() {
|
|
125
140
|
return path.join(resolveCliHomeDir('global'), INSTALL_METHOD_CACHE_FILE);
|
|
126
141
|
}
|
|
@@ -163,6 +178,16 @@ async function readGlobalPrefix(commandOutputFn) {
|
|
|
163
178
|
return undefined;
|
|
164
179
|
}
|
|
165
180
|
}
|
|
181
|
+
async function readYarnGlobalDir(commandOutputFn) {
|
|
182
|
+
try {
|
|
183
|
+
return (await commandOutputFn('yarn', ['global', 'dir'], {
|
|
184
|
+
errorName: 'yarn global dir',
|
|
185
|
+
})).trim();
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
166
191
|
async function readDistTags(packageName, commandOutputFn) {
|
|
167
192
|
const output = await commandOutputFn('npm', ['view', packageName, 'dist-tags', '--json'], {
|
|
168
193
|
errorName: 'npm view',
|
|
@@ -174,21 +199,21 @@ function getUnsupportedSelfUpdateReason(installMethod) {
|
|
|
174
199
|
if (installMethod === 'source') {
|
|
175
200
|
return [
|
|
176
201
|
'This CLI is running from source in a repository checkout.',
|
|
177
|
-
'Automatic self-update is only supported for standard global npm installs.',
|
|
202
|
+
'Automatic self-update is only supported for standard global npm, pnpm, or yarn installs.',
|
|
178
203
|
'Upgrade this checkout through your repo workflow instead.',
|
|
179
204
|
].join(' ');
|
|
180
205
|
}
|
|
181
206
|
if (installMethod === 'package-local') {
|
|
182
207
|
return [
|
|
183
208
|
'This CLI is installed from a local project dependency tree.',
|
|
184
|
-
'Automatic self-update is only supported for standard global npm installs.',
|
|
209
|
+
'Automatic self-update is only supported for standard global npm, pnpm, or yarn installs.',
|
|
185
210
|
'Upgrade the parent project dependency that provides this CLI instead.',
|
|
186
211
|
].join(' ');
|
|
187
212
|
}
|
|
188
213
|
if (installMethod === 'unknown') {
|
|
189
214
|
return [
|
|
190
|
-
'This CLI install could not be recognized as a standard global npm install.',
|
|
191
|
-
'Automatic self-update is only supported for standard global npm installs.',
|
|
215
|
+
'This CLI install could not be recognized as a standard global npm, pnpm, or yarn install.',
|
|
216
|
+
'Automatic self-update is only supported for standard global npm, pnpm, or yarn installs.',
|
|
192
217
|
].join(' ');
|
|
193
218
|
}
|
|
194
219
|
return undefined;
|
|
@@ -220,11 +245,17 @@ export async function inspectSelfInstall(options = {}) {
|
|
|
220
245
|
const commandOutputFn = options.commandOutputFn ?? commandOutput;
|
|
221
246
|
const cachedInstallMethod = await readCachedInstallMethod(packageRoot);
|
|
222
247
|
const globalPrefix = cachedInstallMethod?.globalPrefix ?? await readGlobalPrefix(commandOutputFn);
|
|
223
|
-
const
|
|
248
|
+
const yarnGlobalDir = cachedInstallMethod?.yarnGlobalDir ?? await readYarnGlobalDir(commandOutputFn);
|
|
249
|
+
const installMethod = cachedInstallMethod?.installMethod
|
|
250
|
+
?? detectInstallMethod(packageRoot, {
|
|
251
|
+
globalPrefix,
|
|
252
|
+
yarnGlobalDir,
|
|
253
|
+
});
|
|
224
254
|
if (!cachedInstallMethod) {
|
|
225
255
|
await writeCachedInstallMethod(packageRoot, {
|
|
226
256
|
installMethod,
|
|
227
257
|
globalPrefix,
|
|
258
|
+
yarnGlobalDir,
|
|
228
259
|
});
|
|
229
260
|
}
|
|
230
261
|
return {
|
|
@@ -261,7 +292,7 @@ export async function inspectSelfStatus(options = {}) {
|
|
|
261
292
|
latestVersion,
|
|
262
293
|
updateAvailable,
|
|
263
294
|
installMethod,
|
|
264
|
-
updatable: installMethod === 'npm-global',
|
|
295
|
+
updatable: installMethod === 'npm-global' || installMethod === 'pnpm-global' || installMethod === 'yarn-global',
|
|
265
296
|
updateBlockedReason: getUnsupportedSelfUpdateReason(installMethod),
|
|
266
297
|
globalPrefix,
|
|
267
298
|
registryError,
|
|
@@ -270,9 +301,30 @@ export async function inspectSelfStatus(options = {}) {
|
|
|
270
301
|
export function formatUnsupportedSelfUpdateMessage(status) {
|
|
271
302
|
return status.updateBlockedReason
|
|
272
303
|
?? [
|
|
273
|
-
'Automatic self-update is only supported for standard global npm installs.',
|
|
304
|
+
'Automatic self-update is only supported for standard global npm, pnpm, or yarn installs.',
|
|
274
305
|
].join('\n');
|
|
275
306
|
}
|
|
307
|
+
function resolveSelfUpdateInstallCommand(installMethod, packageSpec) {
|
|
308
|
+
if (installMethod === 'pnpm-global') {
|
|
309
|
+
return {
|
|
310
|
+
command: 'pnpm',
|
|
311
|
+
args: ['add', '-g', packageSpec],
|
|
312
|
+
errorName: 'pnpm add',
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (installMethod === 'yarn-global') {
|
|
316
|
+
return {
|
|
317
|
+
command: 'yarn',
|
|
318
|
+
args: ['global', 'add', packageSpec],
|
|
319
|
+
errorName: 'yarn global add',
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
command: 'npm',
|
|
324
|
+
args: ['install', '-g', packageSpec],
|
|
325
|
+
errorName: 'npm install',
|
|
326
|
+
};
|
|
327
|
+
}
|
|
276
328
|
export async function updateSelf(options = {}) {
|
|
277
329
|
const status = await inspectSelfStatus(options);
|
|
278
330
|
if (!status.updatable) {
|
|
@@ -291,9 +343,10 @@ export async function updateSelf(options = {}) {
|
|
|
291
343
|
};
|
|
292
344
|
}
|
|
293
345
|
const packageSpec = getSelfUpdatePackageSpec(status);
|
|
294
|
-
|
|
346
|
+
const installCommand = resolveSelfUpdateInstallCommand(status.installMethod, packageSpec);
|
|
347
|
+
await (options.runFn ?? run)(installCommand.command, installCommand.args, {
|
|
295
348
|
stdio: options.verbose ? 'inherit' : 'ignore',
|
|
296
|
-
errorName:
|
|
349
|
+
errorName: installCommand.errorName,
|
|
297
350
|
});
|
|
298
351
|
return {
|
|
299
352
|
action: 'updated',
|
|
@@ -232,7 +232,7 @@ export async function publishSourceSnapshot(params) {
|
|
|
232
232
|
version,
|
|
233
233
|
stdio,
|
|
234
234
|
});
|
|
235
|
-
await run('yarn', ['lerna', 'publish', 'from-package', '--registry', npmRegistry, '--dist-tag', 'local', '--yes', '--no-verify-access', '--git-head', gitSha], {
|
|
235
|
+
await run('yarn', ['lerna', 'publish', 'from-package', '--registry', npmRegistry, '--dist-tag', 'local', '--yes', '--no-verify-access', '--no-git-reset', '--git-head', gitSha], {
|
|
236
236
|
cwd: projectRoot,
|
|
237
237
|
errorName: 'lerna publish',
|
|
238
238
|
stdio,
|
|
@@ -319,7 +319,7 @@ export function buildSuggestedInitCommand(result) {
|
|
|
319
319
|
const normalizedRegistry = result.npmRegistry || `http://${host}:${port || DEFAULT_SOURCE_REGISTRY_PORT}`;
|
|
320
320
|
const suggestedEnv = ['snapshot', sanitizeEnvSegment(result.gitSha)].filter(Boolean).join('');
|
|
321
321
|
return [
|
|
322
|
-
`nb init --
|
|
322
|
+
`nb init --env ${suggestedEnv} --yes --source npm`,
|
|
323
323
|
`--version ${result.version}`,
|
|
324
324
|
`--npm-registry=${normalizedRegistry}`,
|
|
325
325
|
].join(' ');
|
|
@@ -151,7 +151,7 @@ export async function shouldRunStartupUpdateCheck(argv, now = new Date()) {
|
|
|
151
151
|
return readCurrentInstallLastCheckedDate(state) !== todayStamp(now);
|
|
152
152
|
}
|
|
153
153
|
export function shouldEnableStartupUpdateForInstallMethod(installMethod) {
|
|
154
|
-
return installMethod === 'npm-global';
|
|
154
|
+
return installMethod === 'npm-global' || installMethod === 'pnpm-global' || installMethod === 'yarn-global';
|
|
155
155
|
}
|
|
156
156
|
function hasPendingUpdates(selfStatus, skillsStatus) {
|
|
157
157
|
return Boolean(selfStatus.updateAvailable || skillsStatus.updateAvailable === true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.11-test.1",
|
|
4
4
|
"description": "NocoBase Command Line Tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/generated/command-registry.js",
|
|
@@ -142,6 +142,5 @@
|
|
|
142
142
|
"repository": {
|
|
143
143
|
"type": "git",
|
|
144
144
|
"url": "git+https://github.com/nocobase/nocobase.git"
|
|
145
|
-
}
|
|
146
|
-
"gitHead": "2b612d81c6f6115af75ea7b279384751af869510"
|
|
145
|
+
}
|
|
147
146
|
}
|