@deveco-test/hmos-deveco-cli 0.3.0-TD.2-alpha1 → 0.3.0-TD.2-alpha2

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 (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +785 -1548
  3. package/SKILL.md +172 -224
  4. package/THIRD-PARTY-LICENSES +1088 -47
  5. package/dist/cli.js +132 -118
  6. package/dist/internal/doc-init-background.js +65 -1
  7. package/index.zip +0 -0
  8. package/package.json +102 -96
  9. package/scripts/install-better-sqlite3.mjs +51 -0
  10. package/scripts/install-jieba-wasm.mjs +47 -0
  11. package/scripts/lib/better-sqlite3-vendor.mjs +128 -0
  12. package/scripts/lib/cli-data-dir.mjs +44 -0
  13. package/scripts/lib/doc-init-log-path.mjs +15 -0
  14. package/scripts/lib/jieba-wasm-vendor.mjs +102 -0
  15. package/scripts/postinstall.mjs +54 -33
  16. package/src/resources/aclPermission/aclPermissionsInfo.json +310 -310
  17. package/templates/application/AppScope/app.json5 +10 -10
  18. package/templates/application/AppScope/resources/base/element/string.json +8 -8
  19. package/templates/application/AppScope/resources/base/media/layered_image.json +6 -6
  20. package/templates/application/build-profile.json5 +41 -41
  21. package/templates/application/code-linter.json5 +31 -31
  22. package/templates/application/entry/build-profile.json5 +32 -32
  23. package/templates/application/entry/gitignore.txt +5 -5
  24. package/templates/application/entry/hvigorfile.ts +7 -7
  25. package/templates/application/entry/obfuscation-rules.txt +19 -19
  26. package/templates/application/entry/oh-package.json5 +10 -10
  27. package/templates/application/entry/src/main/ets/entryability/EntryAbility.ets +62 -62
  28. package/templates/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +30 -30
  29. package/templates/application/entry/src/main/ets/pages/Index.ets +37 -37
  30. package/templates/application/entry/src/main/module.json5 +49 -49
  31. package/templates/application/entry/src/main/resources/base/element/color.json +7 -7
  32. package/templates/application/entry/src/main/resources/base/element/float.json +8 -8
  33. package/templates/application/entry/src/main/resources/base/element/string.json +15 -15
  34. package/templates/application/entry/src/main/resources/base/media/layered_image.json +6 -6
  35. package/templates/application/entry/src/main/resources/base/profile/backup_config.json +2 -2
  36. package/templates/application/entry/src/main/resources/base/profile/main_pages.json +5 -5
  37. package/templates/application/entry/src/main/resources/dark/element/color.json +7 -7
  38. package/templates/application/gitignore.txt +11 -11
  39. package/templates/application/hvigor/hvigor-config.json5 +23 -23
  40. package/templates/application/hvigorfile.ts +7 -7
  41. package/templates/application/oh-package.json5 +10 -10
  42. package/dist/internal/telemetry-upload-background.js +0 -9
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * SPDX-License-Identifier: MIT
4
+ *
5
+ * Keep in sync with src/utils/cli-data-dir.ts
6
+ */
7
+
8
+ import { homedir } from 'os';
9
+ import { join, resolve } from 'path';
10
+
11
+ const APP_NAME = 'deveco-cli';
12
+
13
+ /** Strip quotes from cmd.exe `set VAR="path"` (quotes become part of the value). */
14
+ function normalizeEnvDataDir(value) {
15
+ let normalized = value.trim();
16
+ if (
17
+ (normalized.startsWith('"') && normalized.endsWith('"')) ||
18
+ (normalized.startsWith("'") && normalized.endsWith("'"))
19
+ ) {
20
+ normalized = normalized.slice(1, -1).trim();
21
+ }
22
+ return normalized;
23
+ }
24
+
25
+ export function isCliDataDirConfigured() {
26
+ const raw = process.env.DEVECO_CLI_DATA_DIR;
27
+ return raw !== undefined && normalizeEnvDataDir(raw) !== '';
28
+ }
29
+
30
+ function getDefaultCliDataDir() {
31
+ return join(homedir(), '.local', 'share', APP_NAME);
32
+ }
33
+
34
+ export function getCliDataDir() {
35
+ const raw = process.env.DEVECO_CLI_DATA_DIR;
36
+ if (raw === undefined || raw === '') {
37
+ return getDefaultCliDataDir();
38
+ }
39
+ const envDir = normalizeEnvDataDir(raw);
40
+ if (!envDir) {
41
+ return getDefaultCliDataDir();
42
+ }
43
+ return resolve(envDir);
44
+ }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { join } from 'path';
7
+ import { getCliDataDir } from './cli-data-dir.mjs';
8
+
9
+ export function getDocInitLogDir() {
10
+ return join(getCliDataDir(), 'logs');
11
+ }
12
+
13
+ export function getDocInitLogPath() {
14
+ return join(getDocInitLogDir(), 'doc-init.log');
15
+ }
@@ -0,0 +1,102 @@
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { dirname, join } from 'path';
7
+ import { existsSync } from 'fs';
8
+ import { spawnSync } from 'child_process';
9
+ import { fileURLToPath } from 'url';
10
+ import { packageRoot } from './better-sqlite3-vendor.mjs';
11
+
12
+ const JIEBA_WASM_VERSION = '2.0.1';
13
+
14
+ function resolveNpmCliPath() {
15
+ const nodeDir = dirname(process.execPath);
16
+ const candidates = [
17
+ join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
18
+ join(nodeDir, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'),
19
+ ];
20
+ return candidates.find((candidate) => existsSync(candidate)) ?? null;
21
+ }
22
+
23
+ function quoteWindowsCmdArg(arg) {
24
+ return /\s/.test(arg) ? `"${arg.replace(/"/g, '\\"')}"` : arg;
25
+ }
26
+
27
+ function spawnDetail(result) {
28
+ return [result.stderr, result.stdout, result.error?.message]
29
+ .filter(Boolean)
30
+ .join('\n')
31
+ .trim();
32
+ }
33
+
34
+ function runNpmInstallJiebaWasm(targetVersion) {
35
+ const args = [
36
+ 'install',
37
+ `@node-rs/jieba-wasm32-wasi@${targetVersion}`,
38
+ '--no-save',
39
+ '--cpu=wasm32',
40
+ ];
41
+ const npmCli = resolveNpmCliPath();
42
+ if (npmCli) {
43
+ return spawnSync(process.execPath, [npmCli, ...args], {
44
+ cwd: packageRoot,
45
+ stdio: 'pipe',
46
+ encoding: 'utf-8',
47
+ });
48
+ }
49
+ if (process.platform === 'win32') {
50
+ const command = ['npm', ...args].map(quoteWindowsCmdArg).join(' ');
51
+ return spawnSync(command, {
52
+ cwd: packageRoot,
53
+ stdio: 'pipe',
54
+ encoding: 'utf-8',
55
+ shell: true,
56
+ });
57
+ }
58
+ return spawnSync('npm', args, {
59
+ cwd: packageRoot,
60
+ stdio: 'pipe',
61
+ encoding: 'utf-8',
62
+ });
63
+ }
64
+
65
+ export async function installJiebaWasmViaNpm(targetVersion = JIEBA_WASM_VERSION) {
66
+ try {
67
+ await import('@node-rs/jieba-wasm32-wasi');
68
+ return { ok: true, skipped: true, reason: 'already-installed' };
69
+ } catch {
70
+ // continue — try native or install wasm
71
+ }
72
+
73
+ try {
74
+ await import('@node-rs/jieba');
75
+ return { ok: true, skipped: true, reason: 'native-available' };
76
+ } catch {
77
+ // continue — install wasm fallback
78
+ }
79
+
80
+ const result = runNpmInstallJiebaWasm(targetVersion);
81
+ if (result.status !== 0) {
82
+ return {
83
+ ok: false,
84
+ reason: 'npm-install-failed',
85
+ version: targetVersion,
86
+ error: spawnDetail(result) || `exit ${result.status ?? 'null'}`,
87
+ };
88
+ }
89
+
90
+ try {
91
+ await import('@node-rs/jieba-wasm32-wasi');
92
+ } catch {
93
+ return {
94
+ ok: false,
95
+ reason: 'load-failed',
96
+ version: targetVersion,
97
+ error:
98
+ 'npm install finished but @node-rs/jieba-wasm32-wasi still cannot be imported',
99
+ };
100
+ }
101
+ return { ok: true, version: targetVersion, method: 'npm' };
102
+ }
@@ -1,33 +1,54 @@
1
- /*
2
- * Copyright (c) 2026 Huawei Device Co., Ltd.
3
- * SPDX-License-Identifier: MIT
4
- */
5
-
6
- import { spawn } from 'child_process';
7
- import { existsSync } from 'fs';
8
- import { dirname, join } from 'path';
9
- import { fileURLToPath } from 'url';
10
-
11
- const root = join(dirname(fileURLToPath(import.meta.url)), '..');
12
- const initScript = join(root, 'dist', 'internal', 'doc-init-background.js');
13
-
14
- if (!existsSync(initScript)) {
15
- process.exit(0);
16
- }
17
-
18
- const child = spawn(
19
- process.execPath,
20
- [initScript],
21
- {
22
- detached: true,
23
- stdio: ['ignore', 'ignore', 'ignore'],
24
- env: {
25
- ...process.env,
26
- DEVECO_CLI_SKIP_VERSION_CHECK: '1',
27
- DEVECO_CLI_POSTINSTALL: '1',
28
- },
29
- }
30
- );
31
-
32
- child.unref();
33
- process.exit(0);
1
+ /*
2
+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { spawn } from 'child_process';
7
+ import { existsSync, mkdirSync } from 'fs';
8
+ import { dirname, join } from 'path';
9
+ import { fileURLToPath } from 'url';
10
+ import { ensureBetterSqlite3ForDocs } from './install-better-sqlite3.mjs';
11
+ import { ensureJiebaWasmForDocs } from './install-jieba-wasm.mjs';
12
+ import { getDocInitLogPath } from './lib/doc-init-log-path.mjs';
13
+
14
+ const root = join(dirname(fileURLToPath(import.meta.url)), '..');
15
+ const logPath = getDocInitLogPath();
16
+ mkdirSync(dirname(logPath), { recursive: true });
17
+
18
+ const nativeResult = await ensureBetterSqlite3ForDocs();
19
+ if (!nativeResult.ok && !nativeResult.skipped) {
20
+ console.warn(
21
+ `[deveco-cli] better-sqlite3 install via npm failed; docs search will use sqlite-wasm fallback.\n` +
22
+ `${nativeResult.error ?? ''}\n`
23
+ );
24
+ }
25
+
26
+ const jiebaResult = await ensureJiebaWasmForDocs();
27
+ if (!jiebaResult.ok && !jiebaResult.skipped) {
28
+ console.warn(
29
+ `[deveco-cli] jieba wasm install via npm failed; docs search may fail on this machine.\n` +
30
+ `${jiebaResult.error ?? ''}\n`
31
+ );
32
+ }
33
+ const initScript = join(root, 'dist', 'internal', 'doc-init-background.js');
34
+
35
+ if (!existsSync(initScript)) {
36
+ process.exit(0);
37
+ }
38
+
39
+ const child = spawn(
40
+ process.execPath,
41
+ [initScript],
42
+ {
43
+ detached: true,
44
+ stdio: ['ignore', 'ignore', 'ignore'],
45
+ env: {
46
+ ...process.env,
47
+ DEVECO_CLI_SKIP_VERSION_CHECK: '1',
48
+ DEVECO_CLI_POSTINSTALL: '1',
49
+ },
50
+ }
51
+ );
52
+
53
+ child.unref();
54
+ process.exit(0);