@litingwei621/test-deveco-cli 0.0.0-stage → 1.3.7

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.
Files changed (3) hide show
  1. package/cli.js +100 -0
  2. package/package.json +26 -6
  3. package/README.md +0 -3
package/cli.js ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ // Shell entry: map process.platform to an implementation package, resolve its
3
+ // absolute cli.js path, and spawn it with all argv forwarded.
4
+ // Command parsing, error handling, and exit code are all owned by the impl pkg.
5
+ import { spawn } from 'node:child_process';
6
+ import { createRequire } from 'node:module';
7
+ import { readFileSync } from 'node:fs';
8
+ import { constants } from 'node:os';
9
+ import process from 'node:process';
10
+
11
+ // Pass wrapper identity to the impl process so `devecocli update` installs
12
+ // THIS package (the one the user installed), not the nested impl dependency.
13
+ // These env names are NOT in tsup's `env` map, so they survive as runtime
14
+ // process.env reads in the built impl bundle.
15
+ const wrapperPkg = JSON.parse(
16
+ readFileSync(new URL('./package.json', import.meta.url), 'utf8')
17
+ );
18
+ process.env.DEVECO_CLI_WRAPPER_NAME = wrapperPkg.name;
19
+ process.env.DEVECO_CLI_WRAPPER_VERSION = wrapperPkg.version;
20
+
21
+ // Auto-adapt: read implementation package names from optionalDependencies so
22
+ // scope/name changes in package.json propagate without editing cli.js.
23
+ const IMPL_PKG = (() => {
24
+ const deps = Object.keys(wrapperPkg.optionalDependencies ?? {});
25
+ const needle = process.platform === 'openharmony' ? 'openharmony' : 'common';
26
+ const match = deps.find((name) => name.includes(needle));
27
+ if (!match) {
28
+ process.stderr.write(
29
+ `devecocli: no implementation package found for platform "${process.platform}".\n` +
30
+ ` available: ${deps.length ? deps.join(', ') : '(none)'}\n` +
31
+ ` expected a package containing "${needle}"\n`
32
+ );
33
+ process.exit(1);
34
+ }
35
+ return match;
36
+ })();
37
+
38
+ let cliPath;
39
+ try {
40
+ cliPath = createRequire(import.meta.url).resolve(IMPL_PKG + '/dist/cli.js');
41
+ } catch (err) {
42
+ process.stderr.write(
43
+ `devecocli: implementation package "${IMPL_PKG}" is not installed for this platform.\n` +
44
+ ` platform: ${process.platform}\n` +
45
+ ` expected: ${IMPL_PKG}\n` +
46
+ ` cause: ${err && err.message ? err.message : err}\n`
47
+ );
48
+ process.exit(1);
49
+ }
50
+
51
+ const args = [cliPath, ...process.argv.slice(2)];
52
+ if (process.env.DEVECO_CLI_DEBUG) {
53
+ process.stderr.write(
54
+ `[DEBUG] Executing: ${process.execPath} ${args.join(' ')}\n`
55
+ );
56
+ }
57
+ const child = spawn(process.execPath, args, {
58
+ stdio: 'inherit',
59
+ windowsHide: true,
60
+ });
61
+
62
+ let interrupted = false;
63
+ const handlers = new Map();
64
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
65
+ const handler = () => {
66
+ if (child.exitCode !== null || child.signalCode !== null) {
67
+ return;
68
+ }
69
+ if (interrupted) {
70
+ child.kill('SIGKILL');
71
+ return;
72
+ }
73
+ interrupted = true;
74
+ // Windows console Ctrl+C reaches the child; kill('SIGINT') would force it to exit.
75
+ if (process.platform !== 'win32' || signal !== 'SIGINT') {
76
+ child.kill(signal);
77
+ }
78
+ };
79
+ handlers.set(signal, handler);
80
+ process.on(signal, handler);
81
+ }
82
+
83
+ function cleanup() {
84
+ for (const [signal, handler] of handlers) {
85
+ process.off(signal, handler);
86
+ }
87
+ }
88
+
89
+ child.once('error', (error) => {
90
+ cleanup();
91
+ process.stderr.write(
92
+ `devecocli: failed to spawn implementation: ${error.message}\n`
93
+ );
94
+ process.exitCode = 1;
95
+ });
96
+ child.once('close', (code, signal) => {
97
+ cleanup();
98
+ process.exitCode ??=
99
+ code ?? (signal ? 128 + (constants.signals[signal] || 1) : 1);
100
+ });
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
- {
2
- "name": "@litingwei621/test-deveco-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@litingwei621/test-deveco-cli",
3
+ "version": "1.3.7",
4
+ "description": "HarmonyOS application development command line tool",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "devecocli": "cli.js"
9
+ },
10
+ "files": [
11
+ "cli.js"
12
+ ],
13
+ "engines": {
14
+ "node": ">=22"
15
+ },
16
+ "keywords": [
17
+ "harmonyos",
18
+ "deveco",
19
+ "cli",
20
+ "openharmony"
21
+ ],
22
+ "optionalDependencies": {
23
+ "@deveco/deveco-cli-openharmony-arm64": "1.3.7",
24
+ "@litingwei621/test-deveco-cli-common": "1.3.7"
25
+ }
26
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.