@realtimex/pp-cli 2.0.20 → 2.0.21
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/bin/realtimex-pp-cli.js +106 -0
- package/package.json +7 -7
package/bin/realtimex-pp-cli.js
CHANGED
|
@@ -3,9 +3,115 @@ const { spawnSync } = require('child_process');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
|
|
6
|
+
const MAIN_PACKAGE_NAME = '@realtimex/pp-cli';
|
|
7
|
+
const MODERATOR_PLUGIN_ID = 'com.realtimex.moderator-sdk';
|
|
8
|
+
const SDK_PACKAGE_NAME = '@realtimex/sdk';
|
|
9
|
+
const SDK_PACKAGE_PATH_PARTS = [
|
|
10
|
+
'plugin-data',
|
|
11
|
+
MODERATOR_PLUGIN_ID,
|
|
12
|
+
'node_modules',
|
|
13
|
+
'@realtimex',
|
|
14
|
+
'sdk',
|
|
15
|
+
'package.json',
|
|
16
|
+
];
|
|
6
17
|
const packageName = '@realtimex/pp-cli-' + process.platform + '-' + process.arch;
|
|
7
18
|
const binaryName = process.platform === 'win32' ? 'realtimex-pp-cli.exe' : 'realtimex-pp-cli';
|
|
8
19
|
|
|
20
|
+
function readPackageVersion(packageJsonPath) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version || null;
|
|
23
|
+
} catch (_) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function installedCliVersion() {
|
|
29
|
+
try {
|
|
30
|
+
const packageJsonPath = path.resolve(__dirname, '..', 'package.json');
|
|
31
|
+
return readPackageVersion(packageJsonPath);
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function moderatorSdkPackageJsonPath() {
|
|
38
|
+
const storageDir = String(process.env.STORAGE_DIR || '').trim();
|
|
39
|
+
if (!storageDir) return null;
|
|
40
|
+
return path.join(storageDir, ...SDK_PACKAGE_PATH_PARTS);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function installCliVersion(version) {
|
|
44
|
+
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
45
|
+
const result = spawnSync(
|
|
46
|
+
npmCommand,
|
|
47
|
+
['install', '-g', MAIN_PACKAGE_NAME + '@' + version],
|
|
48
|
+
{ stdio: 'inherit' }
|
|
49
|
+
);
|
|
50
|
+
if (result.error) {
|
|
51
|
+
console.error('warning: failed to update ' + MAIN_PACKAGE_NAME + ': ' + result.error.message);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (result.status !== 0) {
|
|
55
|
+
console.error(
|
|
56
|
+
'warning: failed to update ' +
|
|
57
|
+
MAIN_PACKAGE_NAME +
|
|
58
|
+
' to ' +
|
|
59
|
+
version +
|
|
60
|
+
' (npm exited ' +
|
|
61
|
+
(result.status == null ? 'unknown' : result.status) +
|
|
62
|
+
'); continuing with the current CLI.'
|
|
63
|
+
);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
const updatedVersion = installedCliVersion();
|
|
67
|
+
if (updatedVersion !== version) {
|
|
68
|
+
console.error(
|
|
69
|
+
'warning: updated ' +
|
|
70
|
+
MAIN_PACKAGE_NAME +
|
|
71
|
+
', but installed version is still ' +
|
|
72
|
+
(updatedVersion || 'unknown') +
|
|
73
|
+
' instead of ' +
|
|
74
|
+
version +
|
|
75
|
+
'; continuing with the current CLI.'
|
|
76
|
+
);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ensureCliVersionMatchesModeratorSdk() {
|
|
83
|
+
if (process.env.REALTIMEX_PP_CLI_PLUGIN_UPDATE_CHECK === '0') return;
|
|
84
|
+
const sdkPackageJsonPath = moderatorSdkPackageJsonPath();
|
|
85
|
+
if (!sdkPackageJsonPath || !fs.existsSync(sdkPackageJsonPath)) return;
|
|
86
|
+
|
|
87
|
+
const sdkVersion = readPackageVersion(sdkPackageJsonPath);
|
|
88
|
+
const cliVersion = installedCliVersion();
|
|
89
|
+
if (!sdkVersion || !cliVersion || sdkVersion === cliVersion) return;
|
|
90
|
+
|
|
91
|
+
console.error(
|
|
92
|
+
'Updating ' +
|
|
93
|
+
MAIN_PACKAGE_NAME +
|
|
94
|
+
' from ' +
|
|
95
|
+
cliVersion +
|
|
96
|
+
' to ' +
|
|
97
|
+
sdkVersion +
|
|
98
|
+
' to match ' +
|
|
99
|
+
SDK_PACKAGE_NAME +
|
|
100
|
+
' in plugin data.'
|
|
101
|
+
);
|
|
102
|
+
if (!installCliVersion(sdkVersion)) return;
|
|
103
|
+
const rerun = spawnSync(process.execPath, [process.argv[1], ...process.argv.slice(2)], {
|
|
104
|
+
stdio: 'inherit',
|
|
105
|
+
});
|
|
106
|
+
if (rerun.error) {
|
|
107
|
+
console.error(rerun.error.message);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
process.exit(rerun.status == null ? 1 : rerun.status);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
ensureCliVersionMatchesModeratorSdk();
|
|
114
|
+
|
|
9
115
|
let binaryPath;
|
|
10
116
|
try {
|
|
11
117
|
binaryPath = path.join(path.dirname(require.resolve(packageName + '/package.json')), 'bin', binaryName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realtimex/pp-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
4
4
|
"description": "RealtimeX Printing Press CLI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"optionalDependencies": {
|
|
14
|
-
"@realtimex/pp-cli-darwin-x64": "2.0.
|
|
15
|
-
"@realtimex/pp-cli-darwin-arm64": "2.0.
|
|
16
|
-
"@realtimex/pp-cli-linux-x64": "2.0.
|
|
17
|
-
"@realtimex/pp-cli-linux-arm64": "2.0.
|
|
18
|
-
"@realtimex/pp-cli-win32-x64": "2.0.
|
|
19
|
-
"@realtimex/pp-cli-win32-arm64": "2.0.
|
|
14
|
+
"@realtimex/pp-cli-darwin-x64": "2.0.21",
|
|
15
|
+
"@realtimex/pp-cli-darwin-arm64": "2.0.21",
|
|
16
|
+
"@realtimex/pp-cli-linux-x64": "2.0.21",
|
|
17
|
+
"@realtimex/pp-cli-linux-arm64": "2.0.21",
|
|
18
|
+
"@realtimex/pp-cli-win32-x64": "2.0.21",
|
|
19
|
+
"@realtimex/pp-cli-win32-arm64": "2.0.21"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|