@bitfun-test/deveco-code 0.1.0-test
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/deveco.cjs +42 -0
- package/package.json +24 -0
package/bin/deveco.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('node:child_process');
|
|
4
|
+
const { chmodSync, existsSync } = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
|
|
7
|
+
const packageRoot = path.resolve(__dirname, '..');
|
|
8
|
+
const manifest = require(path.join(packageRoot, 'package.json'));
|
|
9
|
+
const platforms = {
|
|
10
|
+
'linux:x64': ['linux-x64', 'x86_64-unknown-linux-gnu', 'deveco'],
|
|
11
|
+
'darwin:arm64': ['darwin-arm64', 'aarch64-apple-darwin', 'deveco'],
|
|
12
|
+
'win32:x64': ['win32-x64', 'x86_64-pc-windows-msvc', 'deveco.exe'],
|
|
13
|
+
'openharmony:arm64': ['ohos-arm64', 'aarch64-unknown-linux-ohos', 'deveco'],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const selected = platforms[`${process.platform}:${process.arch}`];
|
|
17
|
+
if (!selected) throw new Error(`Unsupported platform: ${process.platform} (${process.arch})`);
|
|
18
|
+
|
|
19
|
+
const dependency = `${manifest.name}-${selected[0]}`;
|
|
20
|
+
let vendorRoot;
|
|
21
|
+
try {
|
|
22
|
+
vendorRoot = path.join(path.dirname(require.resolve(`${dependency}/package.json`)), 'vendor');
|
|
23
|
+
} catch {
|
|
24
|
+
vendorRoot = path.join(packageRoot, 'vendor');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const executable = path.join(vendorRoot, selected[1], 'bin', selected[2]);
|
|
28
|
+
if (!existsSync(executable)) throw new Error(`Missing optional dependency ${dependency}`);
|
|
29
|
+
if (process.platform !== 'win32') chmodSync(executable, 0o755);
|
|
30
|
+
|
|
31
|
+
const child = spawn(executable, process.argv.slice(2), {
|
|
32
|
+
stdio: 'inherit',
|
|
33
|
+
env: { ...process.env, DEVECO_MANAGED_BY_NPM: '1' },
|
|
34
|
+
});
|
|
35
|
+
child.on('error', (error) => {
|
|
36
|
+
console.error(error);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
});
|
|
39
|
+
child.on('exit', (code, signal) => {
|
|
40
|
+
if (signal) process.kill(process.pid, signal);
|
|
41
|
+
else process.exit(code ?? 1);
|
|
42
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitfun-test/deveco-code",
|
|
3
|
+
"version": "0.1.0-test",
|
|
4
|
+
"description": "DevEco Code native CLI",
|
|
5
|
+
"bin": {
|
|
6
|
+
"deveco": "bin/deveco.cjs"
|
|
7
|
+
},
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"bin",
|
|
13
|
+
"package.json"
|
|
14
|
+
],
|
|
15
|
+
"optionalDependencies": {
|
|
16
|
+
"@bitfun-test/deveco-code-linux-x64": "npm:@bitfun-test/deveco-code@0.1.0-test.linux-x64",
|
|
17
|
+
"@bitfun-test/deveco-code-win32-x64": "npm:@bitfun-test/deveco-code@0.1.0-test.win32-x64",
|
|
18
|
+
"@bitfun-test/deveco-code-darwin-arm64": "npm:@bitfun-test/deveco-code@0.1.0-test.darwin-arm64",
|
|
19
|
+
"@bitfun-test/deveco-code-ohos-arm64": "npm:@bitfun-test/deveco-code@0.1.0-test.ohos-arm64"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
}
|
|
24
|
+
}
|