@airiot/cli 1.0.11 → 1.0.12

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/config/envs.js CHANGED
@@ -1,16 +1,43 @@
1
1
  import paths from './paths.js';
2
2
  import { URL } from 'url';
3
+ import { resolve, dirname, basename } from 'path';
3
4
 
4
5
  let developConfig = {};
5
6
 
7
+ // attempt to load the developConfig file, if not found try parent directories up to root
6
8
  try {
7
- const module = await import(new URL(`file://${paths.developConfig}`));
8
- developConfig = module.default;
9
+ let filePath = resolve(paths.developConfig);
10
+ const fileName = basename(filePath);
11
+ let dir = dirname(filePath);
12
+
13
+ while (true) {
14
+ const candidate = resolve(dir, fileName);
15
+ // build a file:// URL compatible with Windows and POSIX
16
+ const fileUrl = new URL(`file://${process.platform === 'win32' ? '/' : ''}${candidate.replace(/\\/g, '/')}`).href;
17
+
18
+ try {
19
+ const module = await import(fileUrl);
20
+ developConfig = module.default;
21
+ break;
22
+ } catch (err) {
23
+ if (err && err.code !== 'ERR_MODULE_NOT_FOUND') {
24
+ throw err;
25
+ }
26
+ const parent = dirname(dir);
27
+ if (parent === dir) {
28
+ // reached filesystem root, stop searching
29
+ break;
30
+ }
31
+ dir = parent;
32
+ }
33
+ }
9
34
  } catch (err) {
10
- if (err.code !== 'ERR_MODULE_NOT_FOUND') {
35
+ // preserve original behavior: only rethrow unexpected errors
36
+ if (err && err.code !== 'ERR_MODULE_NOT_FOUND') {
11
37
  throw err;
12
38
  }
13
39
  }
40
+
14
41
  const getHost = () => {
15
42
  if (developConfig.host) {
16
43
  return developConfig.host;
@@ -65,6 +92,16 @@ const getBaseUrl = () => {
65
92
  return baseUrl;
66
93
  };
67
94
 
95
+ const getOpsInfo = () => {
96
+ if (developConfig.ops) {
97
+ return {
98
+ ...developConfig.ops,
99
+ ophost: developConfig.ops.host
100
+ };
101
+ }
102
+ return null;
103
+ }
104
+
68
105
  const getModule = () => {
69
106
  const envs = process.env;
70
107
  const args = process.argv;
@@ -102,4 +139,4 @@ const translateKeys = () => {
102
139
  return { appid, secret };
103
140
  }
104
141
 
105
- export { getHost, getBaseUrl, getModule, developConfig, translateKeys };
142
+ export { getHost, getBaseUrl, getModule, getOpsInfo, developConfig, translateKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@airiot/cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "AIRIOT平台前端包管理工具",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -7,6 +7,7 @@ import fs from "fs";
7
7
  import fetch from "node-fetch";
8
8
  import FormData from "form-data";
9
9
  import paths from "../config/paths.js";
10
+ import { getOpsInfo } from '../config/envs.js';
10
11
 
11
12
  const jsonData = fs.readFileSync(paths.appPackageJson, 'utf-8');
12
13
  const packageJson = JSON.parse(jsonData);
@@ -14,12 +15,15 @@ const packageJson = JSON.parse(jsonData);
14
15
  const envs = process.env;
15
16
  const args = process.argv;
16
17
  let packageName = packageJson.name;
18
+ const developOpsConfig = getOpsInfo();
17
19
 
18
20
  const getOption = (name, envName) => {
19
21
  let value;
20
22
  const optionArgs = args.filter((arg) => arg.startsWith(`--${name}=`));
21
23
  if (optionArgs.length != 0) {
22
24
  value = optionArgs[0].replace(`--${name}=`, "");
25
+ } else if (developOpsConfig && developOpsConfig[name]) {
26
+ value = developOpsConfig[name];
23
27
  } else if (envs[envName]) {
24
28
  value = envs[envName];
25
29
  }
@@ -34,7 +38,7 @@ const getOption = (name, envName) => {
34
38
  const questions = [];
35
39
  const forceQuestion = args.filter((arg) => arg.startsWith("-f")).length != 0;
36
40
  const options = {
37
- host: getOption("ophost", "IOT_OPURL"),
41
+ host: getOption("ophost", "IOT_OPHOST"),
38
42
  username: getOption("username", "IOT_OP_USER"),
39
43
  password: getOption("password", "IOT_OP_PASSWORD"),
40
44
  branch: getOption("branch", "IOT_BRANCH"),
@@ -61,6 +65,27 @@ inquirer
61
65
  let password = answers.password || options.password;
62
66
  let branch = answers.branch || options.branch;
63
67
 
68
+ console.log(chalk.yellow("[iot:install] 请确认以下参数:"));
69
+ console.log(chalk.yellow(` host: ${host || "(未提供)"}`));
70
+ console.log(chalk.yellow(` username: ${username || "(未提供)"}`));
71
+ console.log(chalk.yellow(` password: ${password ? "********" : "(未提供)"}`));
72
+ console.log(chalk.yellow(` branch: ${branch || "(未提供)"}`));
73
+ console.log(chalk.yellow(` package: ${packageName}\n`));
74
+
75
+ const { confirmProceed } = await inquirer.prompt([
76
+ {
77
+ name: "confirmProceed",
78
+ type: "confirm",
79
+ message: "确认以上参数并继续安装吗?",
80
+ default: true,
81
+ },
82
+ ]);
83
+
84
+ if (!confirmProceed) {
85
+ console.log(chalk.red("[iot:install] 操作已取消"));
86
+ return;
87
+ }
88
+
64
89
  host = host.endsWith("/") ? host : host + "/";
65
90
 
66
91
  try {
@@ -9,7 +9,7 @@ const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3030;
9
9
  const host = getHost();
10
10
  const baseUrl = getBaseUrl();
11
11
 
12
- console.log(chalk.green('[iot:envs] 请求 IOT_URL 为: ' + host));
12
+ console.log(chalk.green('[iot:envs] 请求 IOT_URL 为: ' + host + ', 基础路径为: ' + baseUrl));
13
13
 
14
14
  (async () => {
15
15
  const proxy = {
package/scripts/start.js CHANGED
@@ -9,7 +9,7 @@ const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
9
9
  const host = getHost();
10
10
  const baseUrl = getBaseUrl();
11
11
 
12
- console.log(chalk.green('[iot:envs] 请求 IOT_URL 为: ' + host));
12
+ console.log(chalk.green('[iot:envs] 请求 IOT_URL 为: ' + host + ', 基础路径为: ' + baseUrl));
13
13
 
14
14
  (async () => {
15
15
  const proxy = {