creative-upload-extension-updater 0.1.3 → 0.1.4

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.
@@ -4,6 +4,11 @@ const path = require('node:path');
4
4
  const { diagnose, install, requestChromeReload, rollback, uninstall, update, TRANSITION_HTTP_REGISTRY_ORIGIN } = require('../lib/updater');
5
5
 
6
6
  const packageVersion = require('../package.json').version;
7
+ const printJson = (value) => process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
8
+ const printResult = (args, value, lines) => {
9
+ if (args.json === true) return printJson(value);
10
+ process.stdout.write(`${lines.join('\n')}\n`);
11
+ };
7
12
  const printInstallGuide = (extensionDirectory) => {
8
13
  process.stdout.write('\n安装完成。请在 Chrome 完成一次加载:\n\n');
9
14
  process.stdout.write(' 1. 打开 chrome://extensions\n');
@@ -23,7 +28,8 @@ const usage = `用法:creative-upload-updater <命令> [选项]
23
28
 
24
29
  选项:
25
30
  --help, -h 显示帮助
26
- --version, -v 显示版本`;
31
+ --version, -v 显示版本
32
+ --json 以 JSON 输出命令结果`;
27
33
 
28
34
  const parseArguments = (values) =>
29
35
  values.reduce((result, value, index) => {
@@ -57,21 +63,44 @@ const main = async () => {
57
63
  allowInsecure: args['allow-insecure'] === true,
58
64
  hostPath: path.resolve(__dirname, 'native-host.js'),
59
65
  });
60
- process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
66
+ printResult(args, result, [
67
+ '插件更新器安装完成。',
68
+ `已安装插件版本:${result.targetVersion ?? result.currentVersion}`,
69
+ `扩展目录:${result.extensionDirectory}`,
70
+ ]);
61
71
  printInstallGuide(result.extensionDirectory);
62
72
  return;
63
73
  }
64
- if (command === 'diagnose') return process.stdout.write(`${JSON.stringify(diagnose(), null, 2)}\n`);
74
+ if (command === 'diagnose') {
75
+ const result = diagnose();
76
+ return printResult(args, result, [
77
+ '更新器诊断结果:',
78
+ `扩展目录:${result.extensionDirectory}`,
79
+ `扩展文件:${result.extensionLoaded ? '已找到' : '未找到'}`,
80
+ `Native Messaging:${result.nativeHostRegistered ? '已注册' : '未注册'}`,
81
+ `更新源:${result.registryUrl}`,
82
+ `扩展 ID:${result.extensionId}`,
83
+ ]);
84
+ }
65
85
  if (command === 'update') {
66
86
  const result = await update();
67
87
  if (result.status === 'updated' && args['no-reload'] !== true) {
68
88
  const diagnostic = diagnose();
69
89
  Object.assign(result, { chromeReload: requestChromeReload(diagnostic.extensionId) });
70
90
  }
71
- return process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
91
+ const changed = result.status === 'updated';
92
+ return printResult(args, result, changed
93
+ ? [`更新完成:${result.currentVersion} → ${result.targetVersion}`, 'Chrome 将自动重新加载扩展;如未生效,请在 chrome://extensions 手动重新加载。']
94
+ : [`已是最新版本:${result.currentVersion}`]);
95
+ }
96
+ if (command === 'rollback') {
97
+ const result = rollback();
98
+ return printResult(args, result, ['已回滚到上一插件版本。', `扩展目录:${result.extensionDirectory}`, '请在 chrome://extensions 手动重新加载扩展。']);
99
+ }
100
+ if (command === 'uninstall') {
101
+ const result = uninstall();
102
+ return printResult(args, result, ['卸载完成。', '已删除更新器注册、插件文件与历史版本。', '请在 chrome://extensions 手动移除已加载的扩展。']);
72
103
  }
73
- if (command === 'rollback') return process.stdout.write(`${JSON.stringify(rollback(), null, 2)}\n`);
74
- if (command === 'uninstall') return process.stdout.write(`${JSON.stringify(uninstall(), null, 2)}\n`);
75
104
  throw new Error(`未知命令:${command}\n\n${usage}`);
76
105
  };
77
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creative-upload-extension-updater",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "Native Messaging updater for the Creative Upload unpacked Chrome extension.",
6
6
  "scripts": {