@easyv/screen-cli 0.1.1 → 0.1.3
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/README.md +16 -6
- package/bin/postinstall.js +9 -0
- package/dist/commands/component.js +37 -8
- package/dist/commands/skills.js +10 -41
- package/dist/commands/update.js +17 -0
- package/dist/config.js +5 -0
- package/dist/index.js +11 -2
- package/dist/package-info.js +17 -0
- package/dist/postinstall.js +15 -0
- package/dist/skills-install.js +68 -0
- package/dist/update-check.js +167 -0
- package/package.json +2 -1
- package/skills/easyv-component-dev/SKILL.md +7 -9
- package/skills/easyv-component-dev/references/assets.md +81 -0
- package/skills/easyv-component-dev/references/component-spec.md +23 -17
- package/skills/easyv-component-dev/references/configuration.md +655 -0
- package/skills/easyv-screen-build/SKILL.md +23 -9
- package/skills/easyv-screen-build/references/component-selection.md +182 -0
- package/skills/easyv-screen-edit/SKILL.md +4 -1
- package/skills/easyv-screen-shared/SKILL.md +1 -0
- package/spec/openapi.v1.yaml +151 -8
package/README.md
CHANGED
|
@@ -20,13 +20,19 @@
|
|
|
20
20
|
npm install -g @easyv/screen-cli
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
全局安装结束时,会把附带技能链接到 `~/.agents/skills`,再链接到 `~/.cursor/skills`、`~/.claude/skills` 和 `~/.codex/skills`。链接指向 CLI 安装包里的技能,升级包之后技能内容跟着变。需要重做链接时再执行:
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
easyv-screen skills install
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
## 升级
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
easyv-screen update
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
有新版本时,终端里每次执行命令都会在错误输出里提示一行。管道或 Agent 调用最多每天提示一次,命令结果仍写在标准输出。设置 `EASYV_SCREEN_NO_UPDATE_CHECK=1` 后不再检查。
|
|
30
36
|
|
|
31
37
|
## 配置工作台
|
|
32
38
|
|
|
@@ -97,17 +103,21 @@ easyv-screen screen document get <id> -o doc.json
|
|
|
97
103
|
|
|
98
104
|
`document get` 拿到当前文档和 `revision`。之后的写入带上这个版本号,避免盖掉别人刚保存的内容。
|
|
99
105
|
|
|
100
|
-
|
|
106
|
+
组件目录和配置字段从平台实时读取。选型先查官方组件;官方组件没有合适的,再查当前空间自己开发的组件。两个列表都只含已发布组件,官方列表不含定制组件。
|
|
101
107
|
|
|
102
108
|
```bash
|
|
103
109
|
easyv-screen component list --keyword 折线
|
|
110
|
+
easyv-screen component list --source space --keyword 指标卡
|
|
104
111
|
easyv-screen component schema basicLineV2
|
|
112
|
+
easyv-screen component children basicPlaneMap
|
|
105
113
|
easyv-screen component fields basicLineV2 --keyword "图例 宽度"
|
|
114
|
+
easyv-screen component fields basicPlaneMap --child VectorScatterLayer --keyword "尺寸"
|
|
106
115
|
```
|
|
107
116
|
|
|
108
|
-
- `list`
|
|
117
|
+
- `list` 默认列出已发布的官方组件,含中文名、分类和版本。`--source space` 只查当前空间已发布的自定义组件,两个来源不会一起返回
|
|
109
118
|
- `schema` 给出数据字段、事件、动作、默认尺寸和全部配置字段
|
|
110
|
-
- `fields`
|
|
119
|
+
- `children` 列出父组件包里的子组件。返回的 `module` 传给 `schema` 和 `fields` 的 `--child`;`id` 用来对齐这一层的数据。没有子组件时 `children` 为空数组
|
|
120
|
+
- `fields` 按意图查少量配置字段。返回的 `path` 用于新增或修改组件;多个词用空格分隔,需要同时命中。不传关键词时只看分组。`--child` 只查父组件包里的一个子组件,不传则只查父组件自己的字段
|
|
111
121
|
|
|
112
122
|
新增组件时,服务端以组件包的默认配置为底,只叠加传入的字段。
|
|
113
123
|
|
|
@@ -249,7 +259,7 @@ easyv config set secretkey <Secret Key>
|
|
|
249
259
|
|
|
250
260
|
## 给 AI 用的技能
|
|
251
261
|
|
|
252
|
-
`easyv-screen skills install`
|
|
262
|
+
全局安装或 `easyv-screen skills install` 会装上下面这些技能。Agent 接到对应任务时按技能里的步骤调用命令。升级 CLI 后技能一起更新。
|
|
253
263
|
|
|
254
264
|
| 技能 | 什么时候用 |
|
|
255
265
|
| --- | --- |
|
|
@@ -11,15 +11,16 @@ const PROJECT_DIR = 'easyv-components';
|
|
|
11
11
|
function registerComponent(program) {
|
|
12
12
|
const component = program.command('component').description('组件:目录、schema,以及从零开发');
|
|
13
13
|
component.command('list')
|
|
14
|
-
.description('
|
|
14
|
+
.description('列出已发布组件。默认是官方组件,用于选型')
|
|
15
15
|
.option('--keyword <keyword>', '按名称或 module 过滤')
|
|
16
|
-
.option('--source <source>', 'platform
|
|
16
|
+
.option('--source <source>', 'platform 查官方组件(默认);space 查当前空间自己开发的组件')
|
|
17
17
|
.action(async function (options) {
|
|
18
18
|
try {
|
|
19
|
-
const
|
|
19
|
+
const source = resolveListSource(options.source);
|
|
20
|
+
const result = await (0, client_1.createClient)().request('GET', catalogPath(source), {
|
|
20
21
|
query: { keyword: options.keyword },
|
|
21
22
|
});
|
|
22
|
-
const items =
|
|
23
|
+
const items = result.components ?? [];
|
|
23
24
|
(0, output_1.emit)((0, auth_1.globalJson)(this), { components: items }, () => {
|
|
24
25
|
for (const item of items)
|
|
25
26
|
console.log(`${item.source}\t${item.status}\t${item.module}@${item.version}\t${item.name}`);
|
|
@@ -29,14 +30,30 @@ function registerComponent(program) {
|
|
|
29
30
|
(0, client_1.exitOnError)(error);
|
|
30
31
|
}
|
|
31
32
|
});
|
|
33
|
+
component.command('children')
|
|
34
|
+
.description('列出父组件包里的子组件。返回的 module 用于 schema 和 fields 的 --child')
|
|
35
|
+
.argument('<module>')
|
|
36
|
+
.option('--version <version>')
|
|
37
|
+
.action(async function (moduleName, options) {
|
|
38
|
+
try {
|
|
39
|
+
const result = await (0, client_1.createClient)().request('GET', `/components/${moduleName}/children`, {
|
|
40
|
+
query: { version: options.version },
|
|
41
|
+
});
|
|
42
|
+
(0, output_1.emit)((0, auth_1.globalJson)(this), result, () => console.log(JSON.stringify(result, null, 2)));
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
(0, client_1.exitOnError)(error);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
32
48
|
component.command('schema')
|
|
33
49
|
.description('查看组件的配置结构')
|
|
34
50
|
.argument('<module>')
|
|
35
51
|
.option('--version <version>')
|
|
52
|
+
.option('--child <module>', '只看这个子组件,不传则只看父组件自己的配置')
|
|
36
53
|
.action(async function (moduleName, options) {
|
|
37
54
|
try {
|
|
38
55
|
const result = await (0, client_1.createClient)().request('GET', `/components/${moduleName}/schema`, {
|
|
39
|
-
query: { version: options.version },
|
|
56
|
+
query: { version: options.version, child: options.child },
|
|
40
57
|
});
|
|
41
58
|
(0, output_1.emit)((0, auth_1.globalJson)(this), result, () => console.log(JSON.stringify(result, null, 2)));
|
|
42
59
|
}
|
|
@@ -48,12 +65,13 @@ function registerComponent(program) {
|
|
|
48
65
|
.description('按意图查组件配置字段,如 --keyword "图例 宽度";不传关键词只看分组')
|
|
49
66
|
.argument('<module>')
|
|
50
67
|
.option('--keyword <keyword>', '中文标签或路径,空格分隔的多个词需要同时命中')
|
|
68
|
+
.option('--child <module>', '只查这个子组件的配置,不传则只查父组件自己的字段')
|
|
51
69
|
.option('--version <version>')
|
|
52
70
|
.option('--limit <limit>', '最多返回多少条,默认 30')
|
|
53
71
|
.action(async function (moduleName, options) {
|
|
54
72
|
try {
|
|
55
73
|
const result = await (0, client_1.createClient)().request('GET', `/components/${moduleName}/config-fields`, {
|
|
56
|
-
query: { keyword: options.keyword, version: options.version, limit: options.limit },
|
|
74
|
+
query: { keyword: options.keyword, child: options.child, version: options.version, limit: options.limit },
|
|
57
75
|
});
|
|
58
76
|
(0, output_1.emit)((0, auth_1.globalJson)(this), result, () => console.log(JSON.stringify(result, null, 2)));
|
|
59
77
|
}
|
|
@@ -158,11 +176,22 @@ async function publishComponent(name) {
|
|
|
158
176
|
});
|
|
159
177
|
console.log(`已上传 ${uploaded.module}@${uploaded.version}(${uploaded.status})`);
|
|
160
178
|
}
|
|
179
|
+
function resolveListSource(source) {
|
|
180
|
+
if (source == null || source === 'platform')
|
|
181
|
+
return 'platform';
|
|
182
|
+
if (source === 'space')
|
|
183
|
+
return 'space';
|
|
184
|
+
console.error('--source 只能是 platform 或 space');
|
|
185
|
+
process.exit(2);
|
|
186
|
+
}
|
|
187
|
+
function catalogPath(source) {
|
|
188
|
+
return source === 'space' ? '/components/space' : '/components/official';
|
|
189
|
+
}
|
|
161
190
|
async function remoteVersion(moduleName) {
|
|
162
|
-
const result = await (0, client_1.createClient)().request('GET', '/components', {
|
|
191
|
+
const result = await (0, client_1.createClient)().request('GET', '/components/space', {
|
|
163
192
|
query: { keyword: moduleName },
|
|
164
193
|
});
|
|
165
|
-
const matched = (result.components ?? []).find(item => item.module === moduleName
|
|
194
|
+
const matched = (result.components ?? []).find(item => item.module === moduleName);
|
|
166
195
|
return matched?.version;
|
|
167
196
|
}
|
|
168
197
|
function compareVersion(left, right) {
|
package/dist/commands/skills.js
CHANGED
|
@@ -1,53 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerSkills = registerSkills;
|
|
4
|
-
const
|
|
5
|
-
const node_os_1 = require("node:os");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
/** 技能随 CLI 发布,安装到各 AI 工具的技能目录 */
|
|
8
|
-
const SKILL_TARGETS = [
|
|
9
|
-
(0, node_path_1.join)((0, node_os_1.homedir)(), '.agents', 'skills'),
|
|
10
|
-
(0, node_path_1.join)((0, node_os_1.homedir)(), '.claude', 'skills'),
|
|
11
|
-
(0, node_path_1.join)((0, node_os_1.homedir)(), '.cursor', 'skills'),
|
|
12
|
-
(0, node_path_1.join)((0, node_os_1.homedir)(), '.codex', 'skills'),
|
|
13
|
-
];
|
|
4
|
+
const skills_install_1 = require("../skills-install");
|
|
14
5
|
function registerSkills(program) {
|
|
15
6
|
program.command('skills')
|
|
16
7
|
.description('安装随 CLI 附带的技能')
|
|
17
8
|
.command('install')
|
|
18
|
-
.description('
|
|
9
|
+
.description('链接到 Claude、Cursor、Codex 的技能目录,升级 CLI 后技能一起更新')
|
|
19
10
|
.action(() => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const names = (0, node_fs_1.readdirSync)(source).filter(name => (0, node_fs_1.existsSync)((0, node_path_1.join)(source, name, 'SKILL.md')));
|
|
26
|
-
const canonical = SKILL_TARGETS[0];
|
|
27
|
-
(0, node_fs_1.mkdirSync)(canonical, { recursive: true });
|
|
28
|
-
for (const name of names) {
|
|
29
|
-
const target = (0, node_path_1.join)(canonical, name);
|
|
30
|
-
(0, node_fs_1.rmSync)(target, { recursive: true, force: true });
|
|
31
|
-
(0, node_fs_1.cpSync)((0, node_path_1.join)(source, name), target, { recursive: true });
|
|
11
|
+
try {
|
|
12
|
+
const result = (0, skills_install_1.installSkills)();
|
|
13
|
+
console.log(`已安装 ${result.names.length} 个技能:${result.names.join('、')}`);
|
|
14
|
+
if (result.copied.length > 0)
|
|
15
|
+
console.error(`有 ${result.copied.length} 处无法创建链接,已改为复制`);
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
(
|
|
35
|
-
|
|
36
|
-
linkSkill((0, node_path_1.join)(canonical, name), (0, node_path_1.join)(linkRoot, name));
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
19
|
+
process.exit(1);
|
|
37
20
|
}
|
|
38
|
-
console.log(`已安装 ${names.length} 个技能:${names.join('、')}`);
|
|
39
21
|
});
|
|
40
22
|
}
|
|
41
|
-
function linkSkill(from, to) {
|
|
42
|
-
if ((0, node_fs_1.existsSync)(to)) {
|
|
43
|
-
if ((0, node_fs_1.lstatSync)(to).isSymbolicLink())
|
|
44
|
-
return;
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
(0, node_fs_1.symlinkSync)(from, to);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
(0, node_fs_1.cpSync)(from, to, { recursive: true });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerUpdate = registerUpdate;
|
|
4
|
+
const update_check_1 = require("../update-check");
|
|
5
|
+
function registerUpdate(program) {
|
|
6
|
+
program.command('update')
|
|
7
|
+
.description('安装最新版本,并同步附带的技能')
|
|
8
|
+
.action(async () => {
|
|
9
|
+
try {
|
|
10
|
+
await (0, update_check_1.updateCli)();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MISSING_WORKSPACE = void 0;
|
|
4
|
+
exports.screenHome = screenHome;
|
|
4
5
|
exports.isSession = isSession;
|
|
5
6
|
exports.listEnvironments = listEnvironments;
|
|
6
7
|
exports.hasMultipleWorkspaces = hasMultipleWorkspaces;
|
|
@@ -23,6 +24,10 @@ const node_fs_1 = require("node:fs");
|
|
|
23
24
|
const node_os_1 = require("node:os");
|
|
24
25
|
const node_path_1 = require("node:path");
|
|
25
26
|
const HOME = process.env['EASYV_SCREEN_HOME'] ?? (0, node_path_1.join)((0, node_os_1.homedir)(), '.easyv-screen');
|
|
27
|
+
/** 配置、登录和版本检查缓存所在的目录 */
|
|
28
|
+
function screenHome() {
|
|
29
|
+
return HOME;
|
|
30
|
+
}
|
|
26
31
|
const CONFIG_FILE = (0, node_path_1.join)(HOME, 'config.json');
|
|
27
32
|
const SECRET_FILE = (0, node_path_1.join)(HOME, 'credentials.json');
|
|
28
33
|
const KEYCHAIN_SERVICE = 'easyv-screen';
|
package/dist/index.js
CHANGED
|
@@ -7,11 +7,15 @@ const data_1 = require("./commands/data");
|
|
|
7
7
|
const debug_1 = require("./commands/debug");
|
|
8
8
|
const screen_1 = require("./commands/screen");
|
|
9
9
|
const skills_1 = require("./commands/skills");
|
|
10
|
+
const update_1 = require("./commands/update");
|
|
11
|
+
const package_info_1 = require("./package-info");
|
|
12
|
+
const update_check_1 = require("./update-check");
|
|
13
|
+
const { version } = (0, package_info_1.packageInfo)();
|
|
10
14
|
const program = new commander_1.Command();
|
|
11
15
|
program
|
|
12
16
|
.name('easyv-screen')
|
|
13
17
|
.description('用命令驱动 EasyV 大屏:搭建、修改、排查,以及从零开发组件')
|
|
14
|
-
.version(
|
|
18
|
+
.version(version)
|
|
15
19
|
.option('--json', '输出 JSON。现在默认就是 JSON,这个参数可以不写');
|
|
16
20
|
(0, auth_1.registerAuth)(program);
|
|
17
21
|
(0, screen_1.registerScreen)(program);
|
|
@@ -19,7 +23,12 @@ program
|
|
|
19
23
|
(0, data_1.registerData)(program);
|
|
20
24
|
(0, debug_1.registerDebug)(program);
|
|
21
25
|
(0, skills_1.registerSkills)(program);
|
|
22
|
-
|
|
26
|
+
(0, update_1.registerUpdate)(program);
|
|
27
|
+
async function main() {
|
|
28
|
+
await (0, update_check_1.maybeNotifyUpdate)(process.argv);
|
|
29
|
+
await program.parseAsync(process.argv);
|
|
30
|
+
}
|
|
31
|
+
main().catch((error) => {
|
|
23
32
|
console.error(error.message);
|
|
24
33
|
process.exit(1);
|
|
25
34
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.packageInfo = packageInfo;
|
|
4
|
+
exports.registryBase = registryBase;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
let cached;
|
|
8
|
+
function packageInfo() {
|
|
9
|
+
if (cached == null)
|
|
10
|
+
cached = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'package.json'), 'utf8'));
|
|
11
|
+
return cached;
|
|
12
|
+
}
|
|
13
|
+
/** 发布用的注册表,去掉末尾斜杠 */
|
|
14
|
+
function registryBase() {
|
|
15
|
+
const registry = packageInfo().publishConfig?.registry ?? 'https://registry.npmjs.org/';
|
|
16
|
+
return registry.replace(/\/$/, '');
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const skills_install_1 = require("./skills-install");
|
|
4
|
+
/** 只有全局安装会改用户主目录里的技能链接。仓库里 npm install 不触发 */
|
|
5
|
+
if (process.env['npm_config_global'] === 'true') {
|
|
6
|
+
try {
|
|
7
|
+
const result = (0, skills_install_1.installSkills)();
|
|
8
|
+
console.log(`已同步 ${result.names.length} 个技能:${result.names.join('、')}`);
|
|
9
|
+
if (result.copied.length > 0)
|
|
10
|
+
console.error(`有 ${result.copied.length} 处无法创建链接,已改为复制`);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
console.error(`技能未同步:${error instanceof Error ? error.message : String(error)}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skillsDirectory = skillsDirectory;
|
|
4
|
+
exports.installSkills = installSkills;
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const node_os_1 = require("node:os");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
/** 规范副本放在第一项,其余目录链接到它 */
|
|
9
|
+
const TOOL_DIRS = ['.agents', '.claude', '.cursor', '.codex'];
|
|
10
|
+
/** 安装包里的技能目录。文件随包升级后,链接到这里的技能会一起换成新内容 */
|
|
11
|
+
function skillsDirectory() {
|
|
12
|
+
return (0, node_path_1.join)(__dirname, '..', 'skills');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 把技能链接进各 AI 工具的技能目录。
|
|
16
|
+
* 传入 home 时写到该目录下,默认是用户主目录。
|
|
17
|
+
*/
|
|
18
|
+
function installSkills(home = (0, node_os_1.homedir)()) {
|
|
19
|
+
const source = skillsDirectory();
|
|
20
|
+
if (!(0, node_fs_1.existsSync)(source))
|
|
21
|
+
throw new Error('没有找到技能目录,确认 CLI 安装完整');
|
|
22
|
+
const names = (0, node_fs_1.readdirSync)(source).filter((name) => {
|
|
23
|
+
const dir = (0, node_path_1.join)(source, name);
|
|
24
|
+
return (0, node_fs_1.lstatSync)(dir).isDirectory() && (0, node_fs_1.existsSync)((0, node_path_1.join)(dir, 'SKILL.md'));
|
|
25
|
+
});
|
|
26
|
+
if (names.length === 0)
|
|
27
|
+
throw new Error('技能目录里没有可安装的技能');
|
|
28
|
+
const roots = TOOL_DIRS.map(dir => (0, node_path_1.join)(home, dir, 'skills'));
|
|
29
|
+
const canonical = roots[0];
|
|
30
|
+
const copied = [];
|
|
31
|
+
(0, node_fs_1.mkdirSync)(canonical, { recursive: true });
|
|
32
|
+
for (const name of names) {
|
|
33
|
+
const from = (0, node_path_1.join)(source, name);
|
|
34
|
+
if (ensureLink((0, node_path_1.join)(canonical, name), from, from))
|
|
35
|
+
copied.push((0, node_path_1.join)(canonical, name));
|
|
36
|
+
}
|
|
37
|
+
for (const root of roots.slice(1)) {
|
|
38
|
+
(0, node_fs_1.mkdirSync)(root, { recursive: true });
|
|
39
|
+
for (const name of names) {
|
|
40
|
+
const target = (0, node_path_1.join)(root, name);
|
|
41
|
+
if (ensureLink(target, (0, node_path_1.join)(canonical, name), (0, node_path_1.join)(source, name)))
|
|
42
|
+
copied.push(target);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { names, copied };
|
|
46
|
+
}
|
|
47
|
+
/** 已经指向同一目录时保留。返回 true 表示退回了复制 */
|
|
48
|
+
function ensureLink(linkPath, linkTarget, copyFrom) {
|
|
49
|
+
if (samePlace(linkPath, linkTarget))
|
|
50
|
+
return false;
|
|
51
|
+
(0, node_fs_1.rmSync)(linkPath, { recursive: true, force: true });
|
|
52
|
+
try {
|
|
53
|
+
(0, node_fs_1.symlinkSync)(linkTarget, linkPath, process.platform === 'win32' ? 'junction' : 'dir');
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
(0, node_fs_1.cpSync)(copyFrom, linkPath, { recursive: true });
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function samePlace(linkPath, linkTarget) {
|
|
62
|
+
try {
|
|
63
|
+
return (0, node_fs_1.realpathSync)(linkPath) === (0, node_fs_1.realpathSync)(linkTarget);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compareVersion = compareVersion;
|
|
4
|
+
exports.fetchLatestVersion = fetchLatestVersion;
|
|
5
|
+
exports.maybeNotifyUpdate = maybeNotifyUpdate;
|
|
6
|
+
exports.updateCli = updateCli;
|
|
7
|
+
const node_child_process_1 = require("node:child_process");
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_https_1 = require("node:https");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const config_1 = require("./config");
|
|
12
|
+
const package_info_1 = require("./package-info");
|
|
13
|
+
const skills_install_1 = require("./skills-install");
|
|
14
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
15
|
+
const NOTICE_TIMEOUT_MS = 2000;
|
|
16
|
+
const UPDATE_TIMEOUT_MS = 15000;
|
|
17
|
+
/** 设为 1 或 true 时,日常命令不再访问注册表 */
|
|
18
|
+
function updateCheckDisabled() {
|
|
19
|
+
const value = process.env['EASYV_SCREEN_NO_UPDATE_CHECK'];
|
|
20
|
+
return value === '1' || value === 'true';
|
|
21
|
+
}
|
|
22
|
+
function cacheFile() {
|
|
23
|
+
return (0, node_path_1.join)((0, config_1.screenHome)(), 'update-check.json');
|
|
24
|
+
}
|
|
25
|
+
function compareVersion(left, right) {
|
|
26
|
+
const a = left.split('.').map(part => Number.parseInt(part, 10));
|
|
27
|
+
const b = right.split('.').map(part => Number.parseInt(part, 10));
|
|
28
|
+
const length = Math.max(a.length, b.length);
|
|
29
|
+
for (let index = 0; index < length; index++) {
|
|
30
|
+
const diff = (Number.isFinite(a[index]) ? a[index] : 0) - (Number.isFinite(b[index]) ? b[index] : 0);
|
|
31
|
+
if (diff !== 0)
|
|
32
|
+
return diff;
|
|
33
|
+
}
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
function fetchLatestVersion(timeoutMs) {
|
|
37
|
+
const name = (0, package_info_1.packageInfo)().name.replace('/', '%2f');
|
|
38
|
+
return readLatest(`${(0, package_info_1.registryBase)()}/${name}/latest`, timeoutMs, 0);
|
|
39
|
+
}
|
|
40
|
+
function readLatest(url, timeoutMs, redirects) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const req = (0, node_https_1.request)(url, { method: 'GET', headers: { accept: 'application/json' } }, (res) => {
|
|
43
|
+
const location = res.headers.location;
|
|
44
|
+
if (res.statusCode != null && res.statusCode >= 300 && res.statusCode < 400 && location) {
|
|
45
|
+
res.resume();
|
|
46
|
+
if (redirects >= 3) {
|
|
47
|
+
reject(new Error('版本检查重定向过多'));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(readLatest(new URL(location, url).href, timeoutMs, redirects + 1));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (res.statusCode !== 200) {
|
|
54
|
+
res.resume();
|
|
55
|
+
reject(new Error(`查询版本失败(${res.statusCode ?? '无状态码'})`));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
collectBody(res).then((body) => {
|
|
59
|
+
const parsed = JSON.parse(body);
|
|
60
|
+
if (typeof parsed.version !== 'string' || parsed.version === '')
|
|
61
|
+
reject(new Error('注册表没有返回版本号'));
|
|
62
|
+
else
|
|
63
|
+
resolve(parsed.version);
|
|
64
|
+
}).catch(() => {
|
|
65
|
+
reject(new Error('注册表返回的内容无法解析'));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
req.setTimeout(timeoutMs, () => {
|
|
69
|
+
req.destroy();
|
|
70
|
+
reject(new Error('查询版本超时'));
|
|
71
|
+
});
|
|
72
|
+
req.on('error', reject);
|
|
73
|
+
req.end();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function collectBody(res) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const chunks = [];
|
|
79
|
+
res.on('data', (chunk) => chunks.push(chunk));
|
|
80
|
+
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
81
|
+
res.on('error', reject);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function readCache() {
|
|
85
|
+
try {
|
|
86
|
+
const parsed = JSON.parse((0, node_fs_1.readFileSync)(cacheFile(), 'utf8'));
|
|
87
|
+
if (typeof parsed.checkedAt !== 'number' || typeof parsed.latest !== 'string')
|
|
88
|
+
return undefined;
|
|
89
|
+
return parsed;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function writeCache(cache) {
|
|
96
|
+
try {
|
|
97
|
+
(0, node_fs_1.mkdirSync)((0, config_1.screenHome)(), { recursive: true });
|
|
98
|
+
(0, node_fs_1.writeFileSync)(cacheFile(), JSON.stringify(cache, null, 2));
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// 缓存写不进去不影响当前命令
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function isUpdateCommand(argv) {
|
|
105
|
+
const args = argv.slice(2).filter(arg => arg !== '--' && !arg.startsWith('-'));
|
|
106
|
+
return args[0] === 'update';
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 最多每天查一次注册表。有新版本时写到 stderr,避免打进 JSON 结果。
|
|
110
|
+
* 终端里每次命令都提示;管道或 Agent 调用只在真正发起检查的那次提示。
|
|
111
|
+
*/
|
|
112
|
+
async function maybeNotifyUpdate(argv) {
|
|
113
|
+
if (updateCheckDisabled() || isUpdateCommand(argv))
|
|
114
|
+
return;
|
|
115
|
+
try {
|
|
116
|
+
const current = (0, package_info_1.packageInfo)().version;
|
|
117
|
+
const cached = readCache();
|
|
118
|
+
const fresh = cached != null && Date.now() - cached.checkedAt < CHECK_INTERVAL_MS;
|
|
119
|
+
let latest = cached?.latest;
|
|
120
|
+
let fetched = false;
|
|
121
|
+
if (!fresh) {
|
|
122
|
+
try {
|
|
123
|
+
latest = await fetchLatestVersion(NOTICE_TIMEOUT_MS);
|
|
124
|
+
fetched = true;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
latest = cached?.latest;
|
|
128
|
+
}
|
|
129
|
+
// 失败也记下时间,离线时不要每次命令都等超时
|
|
130
|
+
writeCache({ checkedAt: Date.now(), latest: latest ?? current });
|
|
131
|
+
}
|
|
132
|
+
if (latest == null || compareVersion(latest, current) <= 0)
|
|
133
|
+
return;
|
|
134
|
+
if (!process.stderr.isTTY && !fetched)
|
|
135
|
+
return;
|
|
136
|
+
console.error(`新版本 ${latest} 可用(当前 ${current}),运行 easyv-screen update`);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// 离线或超时保持静默,当前命令照常执行
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** 安装注册表上的最新版本,并把技能链接对齐到安装包 */
|
|
143
|
+
async function updateCli() {
|
|
144
|
+
const { name, version } = (0, package_info_1.packageInfo)();
|
|
145
|
+
const latest = await fetchLatestVersion(UPDATE_TIMEOUT_MS);
|
|
146
|
+
writeCache({ checkedAt: Date.now(), latest });
|
|
147
|
+
if (compareVersion(latest, version) <= 0) {
|
|
148
|
+
const result = (0, skills_install_1.installSkills)();
|
|
149
|
+
console.log(`已是最新版本 ${version}`);
|
|
150
|
+
console.log(`已同步 ${result.names.length} 个技能:${result.names.join('、')}`);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
console.log(`正在安装 ${latest}(当前 ${version})`);
|
|
154
|
+
installGlobal(`${name}@${latest}`);
|
|
155
|
+
const result = (0, skills_install_1.installSkills)();
|
|
156
|
+
console.log(`已更新到 ${latest},已同步 ${result.names.length} 个技能:${result.names.join('、')}`);
|
|
157
|
+
}
|
|
158
|
+
function installGlobal(spec) {
|
|
159
|
+
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
160
|
+
const result = (0, node_child_process_1.spawnSync)(npm, ['install', '-g', spec], { stdio: 'inherit' });
|
|
161
|
+
if (result.error) {
|
|
162
|
+
console.error(`无法执行 npm:${result.error.message}`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
if (result.status !== 0)
|
|
166
|
+
process.exit(result.status ?? 1);
|
|
167
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easyv/screen-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "用自然语言驱动 EasyV 大屏的命令行工具:搭建、修改、排查,以及从零开发组件",
|
|
5
5
|
"bin": {
|
|
6
6
|
"easyv-screen": "bin/easyv-screen.js"
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"build": "tsc -p tsconfig.json",
|
|
16
16
|
"sync-spec": "node scripts/sync-spec.js",
|
|
17
17
|
"prepack": "npm run sync-spec && npm run build",
|
|
18
|
+
"postinstall": "node bin/postinstall.js",
|
|
18
19
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
19
20
|
},
|
|
20
21
|
"engines": {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: easyv-component-dev
|
|
3
|
-
description: 从零开发一个 EasyV
|
|
3
|
+
description: 从零开发一个 EasyV 组件并上传到平台。按组件规范定义配置项、静态数据、触发事件和接收的动作,打包签名后发布,然后在大屏里使用。当官方组件和当前空间已发布的自定义组件都不合适、或需要定制可视化时使用。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# 从零开发 EasyV 组件
|
|
7
7
|
|
|
8
8
|
组件是 React 组件。配置项、事件和动作都声明在 `config/main.json`,平台据此渲染配置面板和交互选项。
|
|
9
|
-
完整字段说明见 [component-spec.md](references/component-spec.md)。
|
|
9
|
+
完整字段说明见 [component-spec.md](references/component-spec.md)。配置项的控件类型、分组和显隐见 [configuration.md](references/configuration.md)。图片、视频等静态资源的上传、配置和拼接见 [assets.md](references/assets.md)。
|
|
10
|
+
|
|
11
|
+
先读 [component-selection.md](../easyv-screen-build/references/component-selection.md)。命中其中的官方组件时不要从零开发。没有命中的,再用 `easyv-screen component list` 看官方组件,然后用 `easyv-screen component list --source space` 看当前空间已发布的自定义组件。两边都不合适,再从零开发。
|
|
10
12
|
|
|
11
13
|
## 流程
|
|
12
14
|
|
|
@@ -16,7 +18,7 @@ description: 从零开发一个 EasyV 组件并上传到平台。按组件规范
|
|
|
16
18
|
3. 编辑三个文件:
|
|
17
19
|
- `config/main.json`:`configuration` 写配置项,`triggers` 写组件能触发的事件,`actions` 写组件能接收的动作。
|
|
18
20
|
- `config/main.data.json`:默认静态数据和字段说明。
|
|
19
|
-
- `index.jsx`:用 `props` 里的 `configuration`、`data` 渲染;触发事件调用 `emit('<trigger>', data)
|
|
21
|
+
- `index.jsx`:用 `props` 里的 `configuration`、`data` 渲染;触发事件调用 `emit('<trigger>', data)`;接收动作时监听 `document` 上的 `<value>_<id>`。
|
|
20
22
|
4. 按下面的「easyv-cli」准备打包工具和签名密钥。没装好、密钥没配好就不要执行打包。
|
|
21
23
|
5. `easyv-screen component publish <目录名>`。它会打包、签名并上传;如果平台已有同名组件且版本不比本地高,
|
|
22
24
|
会自动把补丁号加一后重新打包再上传。
|
|
@@ -41,10 +43,6 @@ description: 从零开发一个 EasyV 组件并上传到平台。按组件规范
|
|
|
41
43
|
- 只做 React 组件。
|
|
42
44
|
- 配置项的 `name` 要用有意义的英文,渲染时通过 `configuration.<name>` 取值,和声明保持一致。
|
|
43
45
|
- `triggers` 里的 `value` 就是 `emit` 的第一个参数,两者必须一致,否则交互配置了也不会触发。
|
|
44
|
-
- `actions`
|
|
46
|
+
- `actions` 里声明的动作要在组件里监听 `document` 上的 `<value>_<id>` 并处理。配置参数在事件的 `data` 上,数据函数的返回值在 `dynamicData` 上。不要声明做不到的动作。
|
|
45
47
|
- 组件升级后,大屏里已使用的实例不会自动变版本。需要时用 `upgradeComponentVersion` 操作显式升级。
|
|
46
|
-
|
|
47
|
-
## 参考
|
|
48
|
-
|
|
49
|
-
官方组件的写法可以对照 `easyv-components/easyvc_new_repos` 里的源码,例如 `basic-bar-v2` 和 `counter-v2`。
|
|
50
|
-
`counter-v2` 的 `counter-simple` 展示了 `emit('click', data)` 的触发方式。
|
|
48
|
+
- 图片、视频、音频等静态资源,调用 OpenAPI 的 `uploadAsset` 上传。`spec/openapi.v1.yaml` 里的 path 是 `/assets`,要接在服务前缀后面,完整请求是 `POST /api/easyv/open/v1/assets`。返回的 `path` 写进组件配置项的 `value`,这项的 `type` 用对应控件:图片 `image`、视频 `video`、音频 `audio`。组件里用 `window.appConfig.ASSETS_URL + path` 拼接。完整绝对地址写在数据里。详见 [assets.md](references/assets.md)。
|