@easyv/screen-cli 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerScreen = registerScreen;
4
+ const node_fs_1 = require("node:fs");
5
+ const client_1 = require("../client");
6
+ const output_1 = require("../output");
7
+ const auth_1 = require("./auth");
8
+ const config_1 = require("../config");
9
+ function registerScreen(program) {
10
+ const screen = program.command('screen').description('大屏');
11
+ screen.command('groups')
12
+ .description('列出当前团队的大屏分组')
13
+ .action(async function () {
14
+ await runJson(this, () => (0, client_1.createClient)().request('GET', '/groups'));
15
+ });
16
+ screen.command('list')
17
+ .description('列出当前团队的大屏')
18
+ .option('--group <groupId>', '按分组过滤')
19
+ .option('--keyword <keyword>', '按名称过滤')
20
+ .action(async function (options) {
21
+ try {
22
+ const result = await (0, client_1.createClient)().request('GET', '/screens', {
23
+ query: { groupId: options.group, keyword: options.keyword },
24
+ });
25
+ (0, output_1.emit)((0, auth_1.globalJson)(this), result, () => {
26
+ for (const item of result.screens ?? [])
27
+ console.log(`${item.id}\t${item.name}`);
28
+ });
29
+ }
30
+ catch (error) {
31
+ (0, client_1.exitOnError)(error);
32
+ }
33
+ });
34
+ screen.command('create')
35
+ .description('创建大屏')
36
+ .requiredOption('--name <name>', '大屏名称')
37
+ .option('--group <groupId>', '分组 id')
38
+ .action(async function (options) {
39
+ try {
40
+ const result = await (0, client_1.createClient)().request('POST', '/screens', {
41
+ body: { name: options.name, ...(options.group != null ? { groupId: Number(options.group) } : {}) },
42
+ });
43
+ (0, output_1.emit)((0, auth_1.globalJson)(this), result, () => console.log(`已创建大屏 ${result.id}:${result.name}`));
44
+ }
45
+ catch (error) {
46
+ (0, client_1.exitOnError)(error);
47
+ }
48
+ });
49
+ screen.command('get')
50
+ .description('查看大屏详情')
51
+ .argument('<screenId>', '大屏 id')
52
+ .action(async function (screenId) {
53
+ await runJson(this, () => (0, client_1.createClient)().request('GET', `/screens/${screenId}`));
54
+ });
55
+ const document = screen.command('document').description('大屏文档');
56
+ document.command('get')
57
+ .description('读取大屏文档')
58
+ .argument('<screenId>')
59
+ .option('-o, --output <file>', '写入文件')
60
+ .action(async function (screenId, options) {
61
+ try {
62
+ const result = await (0, client_1.createClient)().request('GET', `/screens/${screenId}/document`);
63
+ if (options.output != null)
64
+ (0, node_fs_1.writeFileSync)(options.output, JSON.stringify(result, null, 2));
65
+ (0, output_1.emit)((0, auth_1.globalJson)(this), result, () => {
66
+ console.log(options.output != null ? `已写入 ${options.output}` : JSON.stringify(result, null, 2));
67
+ });
68
+ }
69
+ catch (error) {
70
+ (0, client_1.exitOnError)(error);
71
+ }
72
+ });
73
+ document.command('put')
74
+ .description('用文档文件更新大屏')
75
+ .argument('<screenId>')
76
+ .requiredOption('-f, --file <file>', '文档 JSON 文件')
77
+ .option('--if-match <revision>', '期望的 revision')
78
+ .action(async function (screenId, options) {
79
+ try {
80
+ const documentBody = JSON.parse((0, node_fs_1.readFileSync)(options.file, 'utf8'));
81
+ const result = await (0, client_1.createClient)().request('PUT', `/screens/${screenId}/document`, {
82
+ body: documentBody,
83
+ ifMatch: options.ifMatch,
84
+ });
85
+ (0, output_1.emit)((0, auth_1.globalJson)(this), result, () => reportChanges(result));
86
+ }
87
+ catch (error) {
88
+ (0, client_1.exitOnError)(error);
89
+ }
90
+ });
91
+ screen.command('apply')
92
+ .description('执行一批原子操作')
93
+ .argument('<screenId>')
94
+ .requiredOption('-f, --file <file>', '操作 JSON 文件,形如 {"operations": [...]}')
95
+ .option('--if-match <revision>')
96
+ .action(async function (screenId, options) {
97
+ try {
98
+ const body = JSON.parse((0, node_fs_1.readFileSync)(options.file, 'utf8'));
99
+ const result = await (0, client_1.createClient)().request('POST', `/screens/${screenId}/operations`, {
100
+ body,
101
+ ifMatch: options.ifMatch,
102
+ });
103
+ (0, output_1.emit)((0, auth_1.globalJson)(this), result, () => reportChanges(result));
104
+ }
105
+ catch (error) {
106
+ (0, client_1.exitOnError)(error);
107
+ }
108
+ });
109
+ screen.command('validate')
110
+ .description('校验大屏或一份待写入的文档')
111
+ .argument('<screenId>')
112
+ .option('-f, --file <file>', '校验文件里的文档,而不是已保存内容')
113
+ .action(async function (screenId, options) {
114
+ try {
115
+ const body = options.file != null ? { document: JSON.parse((0, node_fs_1.readFileSync)(options.file, 'utf8')) } : {};
116
+ const result = await (0, client_1.createClient)().request('POST', `/screens/${screenId}/validate`, { body });
117
+ (0, output_1.emit)((0, auth_1.globalJson)(this), result, () => {
118
+ console.log(result.valid ? '校验通过' : '校验未通过');
119
+ for (const issue of result.issues ?? [])
120
+ console.log(`[${issue.severity}] ${issue.message}`);
121
+ });
122
+ if (!result.valid)
123
+ process.exit(1);
124
+ }
125
+ catch (error) {
126
+ (0, client_1.exitOnError)(error);
127
+ }
128
+ });
129
+ screen.command('publish')
130
+ .argument('<screenId>')
131
+ .description('发布大屏')
132
+ .action(async (screenId) => {
133
+ await runVoid('PUT', `/screens/${screenId}/publish`, `已发布大屏 ${screenId}`);
134
+ });
135
+ screen.command('unpublish')
136
+ .argument('<screenId>')
137
+ .description('取消发布')
138
+ .action(async (screenId) => {
139
+ await runVoid('DELETE', `/screens/${screenId}/publish`, `已取消发布大屏 ${screenId}`);
140
+ });
141
+ screen.command('snapshot')
142
+ .description('截图预览页,供搭建后自检布局')
143
+ .argument('<screenId>')
144
+ .option('-o, --output <file>', '输出图片', 'snapshot.png')
145
+ .action(async (screenId, options) => {
146
+ try {
147
+ await takeSnapshot(screenId, options.output);
148
+ }
149
+ catch (error) {
150
+ (0, client_1.exitOnError)(error);
151
+ }
152
+ });
153
+ }
154
+ async function takeSnapshot(screenId, output) {
155
+ const target = (0, config_1.activeTarget)();
156
+ if (target?.web == null)
157
+ throw new Error('截图需要 Web 地址。运行 easyv-screen config add 时带上 --web,或 easyv-screen config web <站点地址>');
158
+ const issued = await (0, client_1.createClient)().request('POST', `/screens/${screenId}/preview-token`);
159
+ const url = `${target.web.replace(/\/$/, '')}${issued.previewPath}`;
160
+ let chromium;
161
+ try {
162
+ chromium = require('playwright').chromium;
163
+ }
164
+ catch {
165
+ throw new Error('没有安装 playwright。运行 npm i -g playwright && npx playwright install chromium 后重试');
166
+ }
167
+ const browser = await chromium.launch({ headless: true });
168
+ try {
169
+ const page = await browser.newPage({ viewport: { width: 1920, height: 1080 } });
170
+ await page.goto(url, { waitUntil: 'networkidle' });
171
+ await page.screenshot({ path: output, fullPage: true });
172
+ }
173
+ finally {
174
+ await browser.close();
175
+ }
176
+ console.log(`已截图到 ${output}`);
177
+ }
178
+ async function runJson(command, call) {
179
+ try {
180
+ const result = await call();
181
+ (0, output_1.emit)((0, auth_1.globalJson)(command), result, () => console.log(JSON.stringify(result, null, 2)));
182
+ }
183
+ catch (error) {
184
+ (0, client_1.exitOnError)(error);
185
+ }
186
+ }
187
+ async function runVoid(method, path, message) {
188
+ try {
189
+ await (0, client_1.createClient)().request(method, path);
190
+ console.log(message);
191
+ }
192
+ catch (error) {
193
+ (0, client_1.exitOnError)(error);
194
+ }
195
+ }
196
+ function reportChanges(result) {
197
+ const { added, updated, removed } = result.changes;
198
+ console.log(`已写入。新增 ${added},修改 ${updated},删除 ${removed}。revision ${result.revision}`);
199
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerSkills = registerSkills;
4
+ const node_fs_1 = require("node:fs");
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
+ ];
14
+ function registerSkills(program) {
15
+ program.command('skills')
16
+ .description('安装随 CLI 附带的技能')
17
+ .command('install')
18
+ .description('安装到 Claude、Cursor、Codex 的技能目录')
19
+ .action(() => {
20
+ const source = (0, node_path_1.join)(__dirname, '..', '..', 'skills');
21
+ if (!(0, node_fs_1.existsSync)(source)) {
22
+ console.error('没有找到技能目录,确认 CLI 安装完整');
23
+ process.exit(1);
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 });
32
+ }
33
+ for (const linkRoot of SKILL_TARGETS.slice(1)) {
34
+ (0, node_fs_1.mkdirSync)(linkRoot, { recursive: true });
35
+ for (const name of names)
36
+ linkSkill((0, node_path_1.join)(canonical, name), (0, node_path_1.join)(linkRoot, name));
37
+ }
38
+ console.log(`已安装 ${names.length} 个技能:${names.join('、')}`);
39
+ });
40
+ }
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
+ }
package/dist/config.js ADDED
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSession = isSession;
4
+ exports.listEnvironments = listEnvironments;
5
+ exports.activeTarget = activeTarget;
6
+ exports.addEnvironment = addEnvironment;
7
+ exports.useEnvironment = useEnvironment;
8
+ exports.removeEnvironment = removeEnvironment;
9
+ exports.updateEnvironmentWeb = updateEnvironmentWeb;
10
+ exports.addKey = addKey;
11
+ exports.addSession = addSession;
12
+ exports.saveCurrentSession = saveCurrentSession;
13
+ exports.useKey = useKey;
14
+ exports.removeKey = removeKey;
15
+ exports.listKeys = listKeys;
16
+ const node_child_process_1 = require("node:child_process");
17
+ const node_fs_1 = require("node:fs");
18
+ const node_os_1 = require("node:os");
19
+ const node_path_1 = require("node:path");
20
+ const HOME = process.env['EASYV_SCREEN_HOME'] ?? (0, node_path_1.join)((0, node_os_1.homedir)(), '.easyv-screen');
21
+ const CONFIG_FILE = (0, node_path_1.join)(HOME, 'config.json');
22
+ const SECRET_FILE = (0, node_path_1.join)(HOME, 'credentials.json');
23
+ const KEYCHAIN_SERVICE = 'easyv-screen';
24
+ const USE_KEYCHAIN = (0, node_os_1.platform)() === 'darwin' && process.env['EASYV_SCREEN_HOME'] == null;
25
+ function isSession(value) {
26
+ return value != null && typeof value === 'object' && typeof value.accessToken === 'string' && typeof value.refreshToken === 'string';
27
+ }
28
+ function listEnvironments() {
29
+ const config = loadConfig();
30
+ return config.environments.map(env => ({
31
+ name: env.name,
32
+ baseUrl: env.baseUrl,
33
+ web: env.web ?? null,
34
+ current: env.name === config.current,
35
+ keys: [...env.keys],
36
+ currentKey: env.currentKey ?? null,
37
+ }));
38
+ }
39
+ function activeTarget() {
40
+ const config = loadConfig();
41
+ const env = config.environments.find(item => item.name === config.current);
42
+ if (env == null)
43
+ return undefined;
44
+ const credential = env.currentKey == null ? undefined : readSecrets()[env.name]?.[env.currentKey];
45
+ const token = credential == null ? undefined : isSession(credential) ? credential.accessToken : credential;
46
+ return { name: env.name, baseUrl: env.baseUrl, web: env.web, keyName: env.currentKey, token, credential };
47
+ }
48
+ /**
49
+ * 新增一个 baseURL。同名或同一个地址已存在时拒绝,避免把 Key 拆到两处。
50
+ * `select` 为 true 时立刻切过去。
51
+ */
52
+ function addEnvironment(input) {
53
+ const name = normalizeName(input.name);
54
+ const baseUrl = normalizeBaseUrl(input.baseUrl);
55
+ const config = loadConfig();
56
+ const sameName = config.environments.find(item => item.name === name);
57
+ if (sameName != null)
58
+ throw new Error(`环境「${name}」已存在。切换用 easyv-screen config use ${name}`);
59
+ const sameUrl = config.environments.find(item => item.baseUrl === baseUrl);
60
+ if (sameUrl != null)
61
+ throw new Error(`这个地址已经在环境「${sameUrl.name}」里。切换用 easyv-screen config use ${sameUrl.name}`);
62
+ const created = { name, baseUrl, keys: [], ...(input.web != null ? { web: trimSlash(input.web) } : {}) };
63
+ config.environments.push(created);
64
+ if (input.select === true || config.current == null)
65
+ config.current = name;
66
+ saveConfig(config);
67
+ return created;
68
+ }
69
+ function useEnvironment(name) {
70
+ const config = loadConfig();
71
+ const env = requireEnvironment(config, normalizeName(name));
72
+ config.current = env.name;
73
+ saveConfig(config);
74
+ return env;
75
+ }
76
+ function removeEnvironment(name) {
77
+ const target = normalizeName(name);
78
+ const config = loadConfig();
79
+ if (!config.environments.some(item => item.name === target))
80
+ throw new Error(`没有环境「${target}」`);
81
+ config.environments = config.environments.filter(item => item.name !== target);
82
+ if (config.current === target)
83
+ config.current = undefined;
84
+ saveConfig(config);
85
+ const secrets = readSecrets();
86
+ delete secrets[target];
87
+ writeSecrets(secrets);
88
+ }
89
+ function updateEnvironmentWeb(web) {
90
+ const config = loadConfig();
91
+ const env = requireCurrent(config);
92
+ env.web = trimSlash(web);
93
+ saveConfig(config);
94
+ }
95
+ function addKey(name, token) {
96
+ const secret = token.trim();
97
+ if (!secret.includes('.'))
98
+ throw new Error('API Key 的格式是 appId.secret');
99
+ writeCredential(name, secret);
100
+ }
101
+ /** 设备码登录成功后保存。之后访问令牌过期会就地换成新的 */
102
+ function addSession(name, session) {
103
+ writeCredential(name, session);
104
+ }
105
+ function saveCurrentSession(session) {
106
+ const config = loadConfig();
107
+ const env = requireCurrent(config);
108
+ if (env.currentKey == null)
109
+ throw new Error('当前环境没有选中的登录状态');
110
+ const secrets = readSecrets();
111
+ secrets[env.name] = { ...secrets[env.name], [env.currentKey]: session };
112
+ writeSecrets(secrets);
113
+ }
114
+ function useKey(name) {
115
+ const keyName = normalizeName(name);
116
+ const config = loadConfig();
117
+ const env = requireCurrent(config);
118
+ if (!env.keys.includes(keyName))
119
+ throw new Error(missingKeyMessage(env, keyName));
120
+ env.currentKey = keyName;
121
+ saveConfig(config);
122
+ }
123
+ function removeKey(name) {
124
+ const keyName = normalizeName(name);
125
+ const config = loadConfig();
126
+ const env = requireCurrent(config);
127
+ if (!env.keys.includes(keyName))
128
+ throw new Error(missingKeyMessage(env, keyName));
129
+ env.keys = env.keys.filter(item => item !== keyName);
130
+ if (env.currentKey === keyName)
131
+ env.currentKey = undefined;
132
+ saveConfig(config);
133
+ const secrets = readSecrets();
134
+ if (secrets[env.name] != null)
135
+ delete secrets[env.name][keyName];
136
+ writeSecrets(secrets);
137
+ }
138
+ function listKeys() {
139
+ const config = loadConfig();
140
+ const env = config.environments.find(item => item.name === config.current);
141
+ if (env == null)
142
+ return [];
143
+ const secrets = readSecrets()[env.name] ?? {};
144
+ return env.keys.map(name => ({
145
+ name,
146
+ appId: labelOf(secrets[name]),
147
+ current: name === env.currentKey,
148
+ }));
149
+ }
150
+ function writeCredential(name, credential) {
151
+ const keyName = normalizeName(name);
152
+ const config = loadConfig();
153
+ const env = requireCurrent(config);
154
+ if (!env.keys.includes(keyName))
155
+ env.keys.push(keyName);
156
+ env.currentKey = keyName;
157
+ saveConfig(config);
158
+ const secrets = readSecrets();
159
+ secrets[env.name] = { ...secrets[env.name], [keyName]: credential };
160
+ writeSecrets(secrets);
161
+ }
162
+ function requireCurrent(config) {
163
+ const env = config.environments.find(item => item.name === config.current);
164
+ if (env == null)
165
+ throw new Error('还没有选择环境。先运行 easyv-screen config add --name <名称> --base-url <地址>');
166
+ return env;
167
+ }
168
+ function requireEnvironment(config, name) {
169
+ const env = config.environments.find(item => item.name === name);
170
+ if (env == null) {
171
+ const names = config.environments.map(item => item.name).join('、');
172
+ throw new Error(names.length > 0 ? `没有环境「${name}」。现有环境:${names}` : `没有环境「${name}」`);
173
+ }
174
+ return env;
175
+ }
176
+ function missingKeyMessage(env, keyName) {
177
+ const available = env.keys.length > 0 ? env.keys.join('、') : '(空)';
178
+ return `环境「${env.name}」下没有 Key「${keyName}」。这个地址下可用的 Key:${available}`;
179
+ }
180
+ function loadConfig() {
181
+ const parsed = readJson(CONFIG_FILE);
182
+ if (parsed == null)
183
+ return { environments: [] };
184
+ if (Array.isArray(parsed.environments))
185
+ return { current: parsed.current, environments: parsed.environments };
186
+ // 旧版本只存了一个地址和一把 Key,读到时收成一个环境
187
+ if (typeof parsed.endpoint === 'string' && parsed.endpoint.length > 0)
188
+ return migrateLegacy(parsed.endpoint, parsed.web);
189
+ return { environments: [] };
190
+ }
191
+ function migrateLegacy(endpoint, web) {
192
+ const name = 'default';
193
+ const legacyToken = readLegacyToken();
194
+ const config = {
195
+ current: name,
196
+ environments: [{
197
+ name,
198
+ baseUrl: normalizeBaseUrl(endpoint),
199
+ keys: legacyToken != null ? [name] : [],
200
+ ...(web != null ? { web: trimSlash(web) } : {}),
201
+ ...(legacyToken != null ? { currentKey: name } : {}),
202
+ }],
203
+ };
204
+ saveConfig(config);
205
+ if (legacyToken != null)
206
+ writeSecrets({ [name]: { [name]: legacyToken } });
207
+ return config;
208
+ }
209
+ function saveConfig(config) {
210
+ (0, node_fs_1.mkdirSync)(HOME, { recursive: true });
211
+ (0, node_fs_1.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2));
212
+ }
213
+ function readSecrets() {
214
+ if (USE_KEYCHAIN) {
215
+ const raw = keychainGet();
216
+ const parsed = parseSecret(raw);
217
+ if (parsed != null)
218
+ return parsed;
219
+ }
220
+ return parseSecret(readText(SECRET_FILE)) ?? {};
221
+ }
222
+ function writeSecrets(secrets) {
223
+ const text = JSON.stringify(secrets);
224
+ if (USE_KEYCHAIN && keychainSet(text))
225
+ return;
226
+ (0, node_fs_1.mkdirSync)(HOME, { recursive: true });
227
+ (0, node_fs_1.writeFileSync)(SECRET_FILE, text);
228
+ (0, node_fs_1.chmodSync)(SECRET_FILE, 0o600);
229
+ }
230
+ /** 旧版钥匙串里存的是单条 token,不是 JSON */
231
+ function readLegacyToken() {
232
+ const candidates = [USE_KEYCHAIN ? keychainGet() : undefined, readText((0, node_path_1.join)(HOME, 'credentials'))];
233
+ for (const raw of candidates) {
234
+ if (raw == null || raw.startsWith('{'))
235
+ continue;
236
+ const token = raw.trim();
237
+ if (token.includes('.'))
238
+ return token;
239
+ }
240
+ return undefined;
241
+ }
242
+ function parseSecret(raw) {
243
+ if (raw == null || !raw.startsWith('{'))
244
+ return undefined;
245
+ try {
246
+ return JSON.parse(raw);
247
+ }
248
+ catch {
249
+ return undefined;
250
+ }
251
+ }
252
+ function readJson(file) {
253
+ const text = readText(file);
254
+ if (text == null)
255
+ return undefined;
256
+ try {
257
+ return JSON.parse(text);
258
+ }
259
+ catch {
260
+ return undefined;
261
+ }
262
+ }
263
+ function readText(file) {
264
+ try {
265
+ const text = (0, node_fs_1.readFileSync)(file, 'utf8');
266
+ return text.length > 0 ? text : undefined;
267
+ }
268
+ catch {
269
+ return undefined;
270
+ }
271
+ }
272
+ function normalizeName(name) {
273
+ const trimmed = name.trim();
274
+ if (trimmed.length === 0)
275
+ throw new Error('名称不能为空');
276
+ return trimmed;
277
+ }
278
+ function normalizeBaseUrl(url) {
279
+ const trimmed = trimSlash(url.trim());
280
+ if (!/^https?:\/\//.test(trimmed))
281
+ throw new Error('baseURL 需要以 http:// 或 https:// 开头');
282
+ return trimmed;
283
+ }
284
+ function trimSlash(url) {
285
+ return url.replace(/\/+$/, '');
286
+ }
287
+ function labelOf(credential) {
288
+ if (credential == null)
289
+ return '';
290
+ if (isSession(credential))
291
+ return '设备登录';
292
+ const dot = credential.indexOf('.');
293
+ return dot > 0 ? credential.slice(0, dot) : credential;
294
+ }
295
+ function keychainGet() {
296
+ try {
297
+ return (0, node_child_process_1.execFileSync)('security', ['find-generic-password', '-a', KEYCHAIN_SERVICE, '-s', KEYCHAIN_SERVICE, '-w'], {
298
+ stdio: ['ignore', 'pipe', 'ignore'],
299
+ }).toString().trim() || undefined;
300
+ }
301
+ catch {
302
+ return undefined;
303
+ }
304
+ }
305
+ function keychainSet(secret) {
306
+ try {
307
+ (0, node_child_process_1.execFileSync)('security', ['add-generic-password', '-U', '-a', KEYCHAIN_SERVICE, '-s', KEYCHAIN_SERVICE, '-w', secret], {
308
+ stdio: 'ignore',
309
+ });
310
+ return true;
311
+ }
312
+ catch {
313
+ return false;
314
+ }
315
+ }
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const auth_1 = require("./commands/auth");
5
+ const component_1 = require("./commands/component");
6
+ const data_1 = require("./commands/data");
7
+ const debug_1 = require("./commands/debug");
8
+ const screen_1 = require("./commands/screen");
9
+ const skills_1 = require("./commands/skills");
10
+ const program = new commander_1.Command();
11
+ program
12
+ .name('easyv-screen')
13
+ .description('用命令驱动 EasyV 大屏:搭建、修改、排查,以及从零开发组件')
14
+ .version('0.1.0')
15
+ .option('--json', '输出 JSON。现在默认就是 JSON,这个参数可以不写');
16
+ (0, auth_1.registerAuth)(program);
17
+ (0, screen_1.registerScreen)(program);
18
+ (0, component_1.registerComponent)(program);
19
+ (0, data_1.registerData)(program);
20
+ (0, debug_1.registerDebug)(program);
21
+ (0, skills_1.registerSkills)(program);
22
+ program.parseAsync(process.argv).catch((error) => {
23
+ console.error(error.message);
24
+ process.exit(1);
25
+ });
package/dist/output.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emit = emit;
4
+ /** 命令输出默认就是 JSON,便于人和 AI 读取。--json 仍然接受,不再改变格式。 */
5
+ function emit(_json, data, _human) {
6
+ console.log(JSON.stringify(data, null, 2));
7
+ }
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@easyv/screen-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "用自然语言驱动 EasyV 大屏的命令行工具:搭建、修改、排查,以及从零开发组件",
5
+ "bin": {
6
+ "easyv-screen": "bin/easyv-screen.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "dist",
11
+ "skills",
12
+ "spec"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json",
16
+ "sync-spec": "node scripts/sync-spec.js",
17
+ "prepack": "npm run sync-spec && npm run build",
18
+ "typecheck": "tsc --noEmit -p tsconfig.json"
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "dependencies": {
24
+ "commander": "^12.1.0"
25
+ },
26
+ "optionalDependencies": {
27
+ "playwright": "^1.48.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^22.9.0",
31
+ "typescript": "^5.6.3"
32
+ },
33
+ "license": "UNLICENSED",
34
+ "publishConfig": {
35
+ "registry": "https://registry.npmjs.org/",
36
+ "access": "public"
37
+ }
38
+ }