@nocobase/cli 2.1.0-alpha.45 → 2.1.0-alpha.46

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.
@@ -10,6 +10,7 @@ import fs from 'node:fs/promises';
10
10
  import path from 'node:path';
11
11
  import { fileURLToPath } from 'node:url';
12
12
  import { confirm } from "./inquirer.js";
13
+ import { DEFAULT_UPDATE_POLICY, getExplicitCliConfigValue, loadCliConfig, } from './cli-config.js';
13
14
  import { inspectSelfInstall, inspectSelfStatus, } from './self-manager.js';
14
15
  import { inspectSkillsStatus } from './skills-manager.js';
15
16
  import { resolveCliHomeDir } from './cli-home.js';
@@ -83,39 +84,53 @@ async function writeCurrentInstallEntry(updater) {
83
84
  const state = await readState();
84
85
  const installBinPath = getCurrentInstallBinPath();
85
86
  const nextEntry = updater(getCurrentInstallEntry(state), state);
87
+ const entries = {
88
+ ...(state.entries ?? {}),
89
+ };
90
+ if (nextEntry?.policy || nextEntry?.lastCheckedDate) {
91
+ entries[installBinPath] = nextEntry;
92
+ }
93
+ else {
94
+ delete entries[installBinPath];
95
+ }
86
96
  await writeState({
87
97
  ...state,
88
- entries: {
89
- ...(state.entries ?? {}),
90
- [installBinPath]: nextEntry,
91
- },
98
+ entries: Object.keys(entries).length ? entries : undefined,
92
99
  });
93
100
  }
94
101
  async function markChecked(now = new Date()) {
95
- await writeCurrentInstallEntry((current, state) => {
102
+ await writeCurrentInstallEntry((current) => {
96
103
  return {
97
- policy: current?.policy ?? 'daily',
104
+ ...current,
98
105
  lastCheckedDate: todayStamp(now),
99
106
  };
100
107
  });
101
108
  }
102
- async function disableStartupUpdateForCurrentInstall() {
103
- await writeCurrentInstallEntry((current, state) => {
104
- return {
105
- policy: 'disabled',
106
- lastCheckedDate: current?.lastCheckedDate
107
- ?? state.lastCheckedDate,
108
- };
109
- });
109
+ function resolveLegacyStartupUpdatePolicy(state) {
110
+ const policy = getCurrentInstallEntry(state)?.policy;
111
+ if (policy === 'disabled') {
112
+ return 'off';
113
+ }
114
+ if (policy === 'daily') {
115
+ return 'prompt';
116
+ }
117
+ return undefined;
110
118
  }
111
- async function enableDailyStartupUpdateForCurrentInstall() {
112
- await writeCurrentInstallEntry((current, state) => {
113
- return {
114
- policy: 'daily',
115
- lastCheckedDate: current?.lastCheckedDate
116
- ?? state.lastCheckedDate,
117
- };
118
- });
119
+ async function resolveStartupUpdatePolicy(state) {
120
+ const config = await loadCliConfig({ scope: 'global' });
121
+ const explicit = getExplicitCliConfigValue(config, 'update.policy');
122
+ return explicit ?? resolveLegacyStartupUpdatePolicy(state) ?? DEFAULT_UPDATE_POLICY;
123
+ }
124
+ export async function clearLegacyStartupUpdatePolicyForCurrentInstall() {
125
+ const state = await readState();
126
+ const current = getCurrentInstallEntry(state);
127
+ if (!current?.policy) {
128
+ return false;
129
+ }
130
+ await writeCurrentInstallEntry(() => ({
131
+ lastCheckedDate: current.lastCheckedDate,
132
+ }));
133
+ return true;
119
134
  }
120
135
  export async function shouldRunStartupUpdateCheck(argv, now = new Date()) {
121
136
  if (process.env[NB_SKIP_STARTUP_UPDATE_ENV] === '1') {
@@ -125,19 +140,14 @@ export async function shouldRunStartupUpdateCheck(argv, now = new Date()) {
125
140
  return false;
126
141
  }
127
142
  const state = await readState();
128
- const currentEntry = getCurrentInstallEntry(state);
129
- if (currentEntry?.policy === 'disabled') {
143
+ const policy = await resolveStartupUpdatePolicy(state);
144
+ if (policy === 'off') {
130
145
  return false;
131
146
  }
132
- if (currentEntry?.policy === 'daily') {
133
- return readCurrentInstallLastCheckedDate(state) !== todayStamp(now);
134
- }
135
147
  const selfInstall = await inspectSelfInstall();
136
148
  if (!shouldEnableStartupUpdateForInstallMethod(selfInstall.installMethod)) {
137
- await disableStartupUpdateForCurrentInstall();
138
149
  return false;
139
150
  }
140
- await enableDailyStartupUpdateForCurrentInstall();
141
151
  return readCurrentInstallLastCheckedDate(state) !== todayStamp(now);
142
152
  }
143
153
  export function shouldEnableStartupUpdateForInstallMethod(installMethod) {
@@ -189,14 +199,13 @@ function buildPromptMessage(selfStatus, skillsStatus) {
189
199
  return lines.join('\n');
190
200
  }
191
201
  function buildUpdateCommands(selfStatus, skillsStatus) {
192
- const commands = [];
193
202
  if (selfStatus.updateAvailable && selfStatus.updatable) {
194
- commands.push('nb self update --yes');
203
+ return [skillsStatus.updateAvailable === true ? 'nb self update --yes --skills' : 'nb self update --yes'];
195
204
  }
196
205
  if (skillsStatus.updateAvailable === true) {
197
- commands.push('nb skills update --yes');
206
+ return ['nb skills update --yes'];
198
207
  }
199
- return commands;
208
+ return [];
200
209
  }
201
210
  function buildNonInteractiveWarning(selfStatus, skillsStatus) {
202
211
  const commands = buildUpdateCommands(selfStatus, skillsStatus);
@@ -233,26 +242,36 @@ function buildDeclinedWarning(selfStatus, skillsStatus) {
233
242
  'You may run into compatibility issues until you update.',
234
243
  ].join(' ');
235
244
  }
236
- async function runStartupUpdates() {
237
- await run('nb', ['self', 'update', '--yes'], {
238
- stdio: 'inherit',
239
- env: {
240
- [NB_SKIP_STARTUP_UPDATE_ENV]: '1',
241
- },
242
- errorName: 'nb self update',
243
- });
244
- await run('nb', ['skills', 'update', '--yes'], {
245
- stdio: 'inherit',
246
- env: {
247
- [NB_SKIP_STARTUP_UPDATE_ENV]: '1',
248
- },
249
- errorName: 'nb skills update',
250
- });
245
+ async function runStartupUpdates(selfStatus, skillsStatus) {
246
+ if (selfStatus.updateAvailable && selfStatus.updatable) {
247
+ const args = ['self', 'update', '--yes'];
248
+ if (skillsStatus.updateAvailable === true) {
249
+ args.push('--skills');
250
+ }
251
+ await run('nb', args, {
252
+ stdio: 'inherit',
253
+ env: {
254
+ [NB_SKIP_STARTUP_UPDATE_ENV]: '1',
255
+ },
256
+ errorName: 'nb self update',
257
+ });
258
+ return;
259
+ }
260
+ if (skillsStatus.updateAvailable === true) {
261
+ await run('nb', ['skills', 'update', '--yes'], {
262
+ stdio: 'inherit',
263
+ env: {
264
+ [NB_SKIP_STARTUP_UPDATE_ENV]: '1',
265
+ },
266
+ errorName: 'nb skills update',
267
+ });
268
+ }
251
269
  }
252
- export async function maybeRunStartupUpdatePrompt(argv) {
270
+ export async function maybeRunStartupUpdate(argv) {
253
271
  if (!(await shouldRunStartupUpdateCheck(argv))) {
254
272
  return { kind: 'skipped' };
255
273
  }
274
+ const policy = await resolveStartupUpdatePolicy(await readState());
256
275
  const selfStatus = await inspectSelfStatus();
257
276
  const skillsStatus = await inspectSkillsStatus();
258
277
  if (!hasPendingUpdates(selfStatus, skillsStatus)) {
@@ -264,6 +283,11 @@ export async function maybeRunStartupUpdatePrompt(argv) {
264
283
  await markChecked();
265
284
  return { kind: 'warned' };
266
285
  }
286
+ if (policy === 'auto') {
287
+ await runStartupUpdates(selfStatus, skillsStatus);
288
+ await markChecked();
289
+ return { kind: 'updated' };
290
+ }
267
291
  let answer = false;
268
292
  try {
269
293
  answer = await confirm({
@@ -279,7 +303,7 @@ export async function maybeRunStartupUpdatePrompt(argv) {
279
303
  await markChecked();
280
304
  return { kind: 'declined' };
281
305
  }
282
- await runStartupUpdates();
306
+ await runStartupUpdates(selfStatus, skillsStatus);
283
307
  await markChecked();
284
308
  return { kind: 'updated' };
285
309
  }
@@ -370,6 +370,12 @@
370
370
  "description": "Set up the first admin."
371
371
  }
372
372
  }
373
+ },
374
+ "env": {
375
+ "messages": {
376
+ "noEnvsConfigured": "No envs configured.",
377
+ "noEnvsConfiguredHelp": "Run `nb init --ui` to create one first."
378
+ }
373
379
  }
374
380
  },
375
381
  "apiCommandCompat": {
@@ -370,6 +370,12 @@
370
370
  "description": "设置第一个管理员账号。"
371
371
  }
372
372
  }
373
+ },
374
+ "env": {
375
+ "messages": {
376
+ "noEnvsConfigured": "尚未配置任何 env。",
377
+ "noEnvsConfiguredHelp": "请先运行 `nb init --ui` 创建一个。"
378
+ }
373
379
  }
374
380
  },
375
381
  "apiCommandCompat": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "2.1.0-alpha.45",
3
+ "version": "2.1.0-alpha.46",
4
4
  "description": "NocoBase Command Line Tool",
5
5
  "type": "module",
6
6
  "main": "dist/generated/command-registry.js",
@@ -140,5 +140,5 @@
140
140
  "type": "git",
141
141
  "url": "git+https://github.com/nocobase/nocobase.git"
142
142
  },
143
- "gitHead": "e9e24987e12d0ad10a5db8815b1e1b7b447f1938"
143
+ "gitHead": "42b269944cdd1908d7a848c0af4936fe94c03bb7"
144
144
  }