creative-upload-extension-updater 0.1.1 → 0.1.3
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/README.md +6 -7
- package/bin/creative-upload-extension-updater.js +34 -4
- package/lib/updater.js +24 -5
- package/package.json +5 -3
- package/scripts/postinstall.js +7 -0
package/README.md
CHANGED
|
@@ -5,14 +5,13 @@ macOS Native Messaging updater for the unpacked Creative Upload Chrome extension
|
|
|
5
5
|
## First installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install -g creative-upload-extension-updater
|
|
8
|
+
npm install -g @ttam/creative-upload-extension-updater
|
|
9
9
|
creative-upload-extension-updater install
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
The command downloads and verifies the first release, then prints the fixed extension directory. In Chrome, enable Developer mode once and choose **Load unpacked** for that directory.
|
|
12
|
+
`npm install` 完成后会提示运行 `creative-upload-updater install`;安装 npm 包本身不会自动下载插件或修改 Chrome。
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
安装成功后,CLI 会输出扩展目录,并引导依次打开 `chrome://extensions`、开启开发者模式、点击「加载已解压的扩展程序」。在 macOS 文件选择器中按 `Command + Shift + G`,粘贴输出的目录即可直接打开。
|
|
16
15
|
|
|
17
16
|
## Operations
|
|
18
17
|
|
|
@@ -20,13 +19,13 @@ The extension ID is fixed to `amfhocfbdlbooohhoinhhhgobfdmaljc`. Do not change t
|
|
|
20
19
|
creative-upload-extension-updater diagnose
|
|
21
20
|
creative-upload-extension-updater update
|
|
22
21
|
creative-upload-extension-updater rollback
|
|
22
|
+
creative-upload-updater uninstall
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
`creative-upload-updater` is kept as a shorter command alias. Both commands
|
|
26
|
-
run the same updater and are supported for backward compatibility.
|
|
27
|
-
|
|
28
25
|
`update` immediately checks the Registry and applies a newer verified release when available. On macOS it then opens a controlled extension URL so the running extension calls `chrome.runtime.reload()` automatically; pass `--no-reload` to only replace files. `rollback` restores the previous verified extension directory. Chrome must then reload the extension once.
|
|
29
26
|
|
|
27
|
+
`uninstall` removes the Native Messaging registration, updater configuration, downloaded extension, and rollback files. It still requires manually removing the loaded extension in `chrome://extensions`; uninstall the CLI itself with `npm uninstall -g creative-upload-extension-updater`.
|
|
28
|
+
|
|
30
29
|
## Security
|
|
31
30
|
|
|
32
31
|
The updater accepts only the configured Registry URL, checks the release SHA256, verifies the detached Ed25519 signature, and verifies the manifest version and fixed Extension ID before replacing files. HTTP is a temporary internal-network transport exception; the signing private key is never stored in this package or in the Registry.
|
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const fs = require('node:fs');
|
|
3
3
|
const path = require('node:path');
|
|
4
|
-
const { diagnose, install, requestChromeReload, rollback, update, TRANSITION_HTTP_REGISTRY_ORIGIN } = require('../lib/updater');
|
|
4
|
+
const { diagnose, install, requestChromeReload, rollback, uninstall, update, TRANSITION_HTTP_REGISTRY_ORIGIN } = require('../lib/updater');
|
|
5
|
+
|
|
6
|
+
const packageVersion = require('../package.json').version;
|
|
7
|
+
const printInstallGuide = (extensionDirectory) => {
|
|
8
|
+
process.stdout.write('\n安装完成。请在 Chrome 完成一次加载:\n\n');
|
|
9
|
+
process.stdout.write(' 1. 打开 chrome://extensions\n');
|
|
10
|
+
process.stdout.write(' 2. 开启右上角「开发者模式」\n');
|
|
11
|
+
process.stdout.write(' 3. 点击「加载已解压的扩展程序」\n');
|
|
12
|
+
process.stdout.write(` 4. 在文件选择器中按 Command + Shift + G,粘贴并打开:${extensionDirectory}\n\n`);
|
|
13
|
+
process.stdout.write('后续发布新版本后,扩展会定时检查更新;也可手动运行 creative-upload-updater update。\n');
|
|
14
|
+
};
|
|
15
|
+
const usage = `用法:creative-upload-updater <命令> [选项]
|
|
16
|
+
|
|
17
|
+
命令:
|
|
18
|
+
install [--registry <url>] [--allow-insecure] 安装更新器与首次插件版本
|
|
19
|
+
update [--no-reload] 下载并应用最新插件版本
|
|
20
|
+
diagnose 输出本机安装诊断
|
|
21
|
+
rollback 回滚到上一插件版本
|
|
22
|
+
uninstall 移除更新器注册、插件文件与历史版本
|
|
23
|
+
|
|
24
|
+
选项:
|
|
25
|
+
--help, -h 显示帮助
|
|
26
|
+
--version, -v 显示版本`;
|
|
5
27
|
|
|
6
28
|
const parseArguments = (values) =>
|
|
7
29
|
values.reduce((result, value, index) => {
|
|
@@ -15,6 +37,14 @@ const parseArguments = (values) =>
|
|
|
15
37
|
const main = async () => {
|
|
16
38
|
const [command] = process.argv.slice(2);
|
|
17
39
|
const args = parseArguments(process.argv.slice(3));
|
|
40
|
+
if (!command || command === '--help' || command === '-h' || args.help === true) {
|
|
41
|
+
process.stdout.write(`${usage}\n`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (command === '--version' || command === '-v' || args.version === true) {
|
|
45
|
+
process.stdout.write(`${packageVersion}\n`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
18
48
|
if (command === 'install') {
|
|
19
49
|
const publicKey =
|
|
20
50
|
typeof args['public-key'] === 'string'
|
|
@@ -28,6 +58,7 @@ const main = async () => {
|
|
|
28
58
|
hostPath: path.resolve(__dirname, 'native-host.js'),
|
|
29
59
|
});
|
|
30
60
|
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
61
|
+
printInstallGuide(result.extensionDirectory);
|
|
31
62
|
return;
|
|
32
63
|
}
|
|
33
64
|
if (command === 'diagnose') return process.stdout.write(`${JSON.stringify(diagnose(), null, 2)}\n`);
|
|
@@ -40,9 +71,8 @@ const main = async () => {
|
|
|
40
71
|
return process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
41
72
|
}
|
|
42
73
|
if (command === 'rollback') return process.stdout.write(`${JSON.stringify(rollback(), null, 2)}\n`);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
);
|
|
74
|
+
if (command === 'uninstall') return process.stdout.write(`${JSON.stringify(uninstall(), null, 2)}\n`);
|
|
75
|
+
throw new Error(`未知命令:${command}\n\n${usage}`);
|
|
46
76
|
};
|
|
47
77
|
|
|
48
78
|
main().catch((error) => {
|
package/lib/updater.js
CHANGED
|
@@ -16,6 +16,15 @@ const configPath = path.join(baseDirectory, 'updater.json');
|
|
|
16
16
|
const extensionDirectory = path.join(baseDirectory, 'extension');
|
|
17
17
|
const previousDirectory = path.join(baseDirectory, 'previous');
|
|
18
18
|
const nativeHostLauncherPath = path.join(baseDirectory, 'native-host');
|
|
19
|
+
const nativeHostManifestPath = path.join(
|
|
20
|
+
os.homedir(),
|
|
21
|
+
'Library',
|
|
22
|
+
'Application Support',
|
|
23
|
+
'Google',
|
|
24
|
+
'Chrome',
|
|
25
|
+
'NativeMessagingHosts',
|
|
26
|
+
`${HOST_NAME}.json`,
|
|
27
|
+
);
|
|
19
28
|
|
|
20
29
|
const readConfig = () => {
|
|
21
30
|
if (!fs.existsSync(configPath)) throw new Error('更新器尚未安装。请运行 creative-upload-extension-updater install。');
|
|
@@ -148,12 +157,23 @@ const install = async ({ registryUrl = TRANSITION_HTTP_REGISTRY_ORIGIN, extensio
|
|
|
148
157
|
const config = { registryUrl: registryUrl.replace(/\/$/, ''), extensionId, signingPublicKey: publicKey, allowInsecure };
|
|
149
158
|
writeConfig(config);
|
|
150
159
|
const update = await checkAndUpdate({ extensionId, currentVersion: '0.0.0' });
|
|
151
|
-
const manifestDirectory = path.
|
|
160
|
+
const manifestDirectory = path.dirname(nativeHostManifestPath);
|
|
152
161
|
fs.mkdirSync(manifestDirectory, { recursive: true, mode: 0o700 });
|
|
153
162
|
const launcherPath = installNativeHostLauncher(hostPath);
|
|
154
|
-
fs.writeFileSync(
|
|
163
|
+
fs.writeFileSync(nativeHostManifestPath, `${JSON.stringify({ name: HOST_NAME, description: 'Creative Upload Extension Updater', path: launcherPath, type: 'stdio', allowed_origins: [`chrome-extension://${extensionId}/`] }, null, 2)}\n`, { mode: 0o600 });
|
|
155
164
|
return { ...update, extensionDirectory, extensionId };
|
|
156
165
|
};
|
|
166
|
+
const uninstall = () => {
|
|
167
|
+
const nativeHostRegistered = fs.existsSync(nativeHostManifestPath);
|
|
168
|
+
fs.rmSync(nativeHostManifestPath, { force: true });
|
|
169
|
+
fs.rmSync(baseDirectory, { recursive: true, force: true });
|
|
170
|
+
return {
|
|
171
|
+
nativeHostRemoved: nativeHostRegistered,
|
|
172
|
+
extensionDirectory,
|
|
173
|
+
extensionRemoved: !fs.existsSync(extensionDirectory),
|
|
174
|
+
chromeAction: '请在 chrome://extensions 手动移除已加载的扩展。',
|
|
175
|
+
};
|
|
176
|
+
};
|
|
157
177
|
const rollback = () => {
|
|
158
178
|
if (!fs.existsSync(previousDirectory)) throw new Error('没有可回滚的上一版本。');
|
|
159
179
|
const currentDirectory = `${extensionDirectory}.rollback-${Date.now()}`;
|
|
@@ -164,8 +184,7 @@ const rollback = () => {
|
|
|
164
184
|
};
|
|
165
185
|
const diagnose = () => {
|
|
166
186
|
const config = readConfig();
|
|
167
|
-
|
|
168
|
-
return { extensionDirectory, extensionLoaded: fs.existsSync(path.join(extensionDirectory, 'manifest.json')), nativeHostRegistered: fs.existsSync(manifestPath), registryUrl: config.registryUrl, extensionId: config.extensionId };
|
|
187
|
+
return { extensionDirectory, extensionLoaded: fs.existsSync(path.join(extensionDirectory, 'manifest.json')), nativeHostRegistered: fs.existsSync(nativeHostManifestPath), registryUrl: config.registryUrl, extensionId: config.extensionId };
|
|
169
188
|
};
|
|
170
189
|
|
|
171
|
-
module.exports = { DEFAULT_EXTENSION_ID, HOST_NAME, TRANSITION_HTTP_REGISTRY_ORIGIN, checkAndUpdate, diagnose, install, requestChromeReload, rollback, update };
|
|
190
|
+
module.exports = { DEFAULT_EXTENSION_ID, HOST_NAME, TRANSITION_HTTP_REGISTRY_ORIGIN, checkAndUpdate, diagnose, install, requestChromeReload, rollback, uninstall, update };
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "creative-upload-extension-updater",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Native Messaging updater for the Creative Upload unpacked Chrome extension.",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"postinstall": "node scripts/postinstall.js"
|
|
8
|
+
},
|
|
6
9
|
"bin": {
|
|
7
|
-
"creative-upload-updater": "bin/creative-upload-extension-updater.js"
|
|
8
|
-
"creative-upload-extension-updater": "bin/creative-upload-extension-updater.js"
|
|
10
|
+
"creative-upload-updater": "bin/creative-upload-extension-updater.js"
|
|
9
11
|
},
|
|
10
12
|
"engines": {
|
|
11
13
|
"node": ">=18"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const packageInfo = require('../package.json');
|
|
4
|
+
|
|
5
|
+
process.stdout.write(`\nCreative Upload Extension Updater v${packageInfo.version} 已安装。\n`);
|
|
6
|
+
process.stdout.write('下一步运行:creative-upload-updater install\n');
|
|
7
|
+
process.stdout.write('该命令会下载已验证的插件版本,并引导你在 Chrome 中加载扩展。\n\n');
|