@talknote/create-talknote-h5 0.0.8 → 0.0.9
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/package.json +1 -1
- package/template/package.json +2 -2
- package/template/scripts/dev.js +45 -0
package/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
"private": true,
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "alita build",
|
|
6
|
-
"dev": "
|
|
6
|
+
"dev": "node scripts/dev.js",
|
|
7
7
|
"format": "prettier --write .",
|
|
8
8
|
"lint-staged": "lint-staged",
|
|
9
9
|
"lint-staged:js": "eslint --ext .ts,.tsx",
|
|
10
10
|
"plugin": "alita plugin list",
|
|
11
|
-
"start": "
|
|
11
|
+
"start": "node scripts/dev.js",
|
|
12
12
|
"test": "jest"
|
|
13
13
|
},
|
|
14
14
|
"lint-staged": {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 开发启动脚本
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* yarn dev # 使用 proxy.ts 中的默认代理地址
|
|
7
|
+
* yarn dev http://1.2.3.4:10000 # 把 process.env.BASE_URL 注入为该地址,代理过去
|
|
8
|
+
* yarn dev http://1.2.3.4:10000 --port 8081 # 额外参数透传给 alita dev
|
|
9
|
+
*
|
|
10
|
+
* 说明:
|
|
11
|
+
* 第一个以 http:// 或 https:// 开头的参数会被当作代理地址,
|
|
12
|
+
* 注入 process.env.BASE_URL(proxy.ts 会读取它)。
|
|
13
|
+
* 其余参数原样透传给 alita dev。
|
|
14
|
+
*/
|
|
15
|
+
const { spawn } = require('child_process');
|
|
16
|
+
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
|
|
19
|
+
// 找出第一个 http/https 开头的参数作为代理地址
|
|
20
|
+
const proxyIndex = args.findIndex((a) => /^https?:\/\//i.test(a));
|
|
21
|
+
const proxyUrl = proxyIndex >= 0 ? args.splice(proxyIndex, 1)[0] : undefined;
|
|
22
|
+
|
|
23
|
+
if (proxyUrl) {
|
|
24
|
+
process.env.BASE_URL = proxyUrl;
|
|
25
|
+
console.log(`\n[dev] 代理地址已注入 BASE_URL = ${proxyUrl}\n`);
|
|
26
|
+
} else {
|
|
27
|
+
console.log('\n[dev] 未指定代理地址,使用 proxy.ts 中的默认值\n');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 启动 alita dev,剩余参数透传
|
|
31
|
+
// shell: true 仅为兼容 Windows 下的 .cmd 可执行文件
|
|
32
|
+
const child = spawn('alita', ['dev', ...args], {
|
|
33
|
+
stdio: 'inherit',
|
|
34
|
+
env: process.env,
|
|
35
|
+
shell: process.platform === 'win32',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
child.on('error', (err) => {
|
|
39
|
+
console.error('[dev] 启动 alita 失败:', err.message);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
child.on('close', (code) => {
|
|
44
|
+
process.exit(code ?? 0);
|
|
45
|
+
});
|