draftgo-cli 3.0.1 → 3.0.33

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 (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -124
  3. package/package.json +21 -8
  4. package/resources/skill/SKILL.md +62 -89
  5. package/resources/skill/init/SKILL.md +18 -67
  6. package/resources/skill/manifest.json +27 -0
  7. package/resources/skill/pull/SKILL.md +18 -44
  8. package/resources/skill/push/SKILL.md +30 -247
  9. package/resources/skill/references/aihub.md +86 -0
  10. package/resources/skill/references/api-endpoints.md +178 -0
  11. package/resources/skill/references/api.json +20248 -0
  12. package/resources/skill/{quickref → references}/app-api.md +44 -14
  13. package/resources/skill/{core → references}/architecture.md +6 -26
  14. package/resources/skill/references/chat-sdk.md +201 -0
  15. package/resources/skill/references/custom-services.md +308 -0
  16. package/resources/skill/references/data.md +298 -0
  17. package/resources/skill/references/db-relations.md +227 -0
  18. package/resources/skill/references/frontend.md +788 -0
  19. package/resources/skill/references/modules.md +66 -0
  20. package/resources/skill/references/parallel.md +48 -0
  21. package/resources/skill/{specs → references}/runtime.md +31 -1
  22. package/resources/skill/{specs → references}/security.md +3 -3
  23. package/resources/skill/references/ui-protocol.md +99 -0
  24. package/resources/skill/scripts/draftgo_delete.py +0 -2
  25. package/resources/skill/scripts/draftgo_init.py +15 -3
  26. package/resources/skill/scripts/draftgo_pull.py +154 -87
  27. package/resources/skill/scripts/draftgo_push.py +440 -183
  28. package/resources/skill/story/SKILL.md +13 -23
  29. package/src/cli.js +22 -7
  30. package/src/commandRegistry.js +34 -0
  31. package/src/commands/api.js +204 -0
  32. package/src/commands/autoPush.js +41 -0
  33. package/src/commands/check.js +27 -17
  34. package/src/commands/delete.js +6 -4
  35. package/src/commands/deploy.js +31 -0
  36. package/src/commands/help.js +41 -28
  37. package/src/commands/init.js +34 -20
  38. package/src/commands/local.js +9 -3
  39. package/src/commands/map.js +18 -7
  40. package/src/commands/sync.js +11 -4
  41. package/src/commands/update.js +39 -52
  42. package/src/commands/verifyUi.js +199 -0
  43. package/src/index.js +13 -46
  44. package/src/localdev/compose.js +48 -197
  45. package/src/localdev/index.js +116 -216
  46. package/src/localdev/mysqlClient.js +12 -9
  47. package/src/localdev/services.js +163 -0
  48. package/src/platforms.js +3 -3
  49. package/src/projectConfig.js +12 -2
  50. package/src/projectMap.js +240 -68
  51. package/src/skill.js +113 -29
  52. package/src/updateCheck.js +37 -15
  53. package/resources/skill/core/modules.md +0 -54
  54. package/resources/skill/practices/anti-patterns.md +0 -70
  55. package/resources/skill/practices/best-practices.md +0 -41
  56. package/resources/skill/practices/dev-declaration.md +0 -94
  57. package/resources/skill/quickref/api-endpoints.md +0 -130
  58. package/resources/skill/quickref/api.json +0 -17675
  59. package/resources/skill/quickref/dg-components.md +0 -198
  60. package/resources/skill/rules/dev-workflow.md +0 -652
  61. package/resources/skill/rules/frontend.md +0 -210
  62. package/resources/skill/rules/parallel.md +0 -263
  63. package/resources/skill/specs/data.md +0 -108
  64. package/resources/skill/specs/ui-protocol.md +0 -68
  65. package/src/commands/doctor.js +0 -54
  66. package/src/commands/new.js +0 -183
  67. package/src/commands/projectScript.js +0 -37
  68. /package/resources/skill/{rules → references}/debugging-syntax.md +0 -0
@@ -1,54 +0,0 @@
1
- 'use strict';
2
-
3
- const log = require('../logger');
4
- const { all } = require('../installers');
5
- const { detectTargets } = require('../detect');
6
- const { findPython } = require('../python');
7
- const { readInstalledVersion, getPackageVersion } = require('../skill');
8
- const { fetchLatestVersion, cmpSemver } = require('../updateCheck');
9
-
10
- async function doctor(projectDir, flags = {}) {
11
- log.title('draftgo doctor');
12
-
13
- log.info(`Node 版本:${process.version}`);
14
- log.info(`平台:${process.platform}`);
15
- log.info(`CLI 版本:${getPackageVersion()}`);
16
- log.info(`项目目录:${projectDir}`);
17
-
18
- console.log('');
19
- const py = findPython();
20
- if (py) log.ok(`Python:${py.bin} (${py.version})`);
21
- else log.err('Python 未检测到(DraftGo init/sync 脚本需要 Python 3.9+)。');
22
-
23
- console.log('');
24
- if (!flags['skip-update-check'] && process.env.DRAFTGO_NO_UPDATE_CHECK !== '1') {
25
- const current = getPackageVersion();
26
- const latest = await fetchLatestVersion();
27
- if (!latest) {
28
- log.dim('CLI 最新版查询失败(可能离线或 registry 不可达)');
29
- } else if (cmpSemver(latest, current) > 0) {
30
- log.warn(`CLI 有新版:${current} → ${latest}`);
31
- log.dim(' 下次运行 `draftgo update` 时会自动升级。');
32
- } else {
33
- log.ok(`CLI 已是最新:${current}`);
34
- }
35
- }
36
-
37
- console.log('');
38
- log.info('项目中检测到的 AI 工具信号:');
39
- const hits = detectTargets(projectDir);
40
- if (hits.length === 0) log.dim(' (无)');
41
- else hits.forEach((n) => log.dim(` • ${n}`));
42
-
43
- console.log('');
44
- log.info(`已装 skill 版本:${readInstalledVersion(projectDir) || '未安装'}`);
45
- log.info('各 AI 工具入口状态:');
46
- for (const t of all) {
47
- const st = t.status(projectDir);
48
- const mark = st.installed ? log.c.green('✓') : log.c.gray('·');
49
- console.log(` ${mark} ${t.name.padEnd(12)} ${t.displayName}`);
50
- }
51
- return 0;
52
- }
53
-
54
- module.exports = doctor;
@@ -1,183 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const log = require('../logger');
6
- const { exists, ensureDir } = require('../fsx');
7
-
8
- const TEMPLATES = {
9
- page: (slug) => ({
10
- indexEntry: {
11
- title: slug,
12
- route: `/${slug}`,
13
- tag: null,
14
- menu: null,
15
- status: 'active',
16
- permission: { default: 'public' },
17
- html_file: `.draftgo/pages/page_new_${slug}.html`,
18
- },
19
- file: `.draftgo/pages/page_new_${slug}.html`,
20
- content: `<!DOCTYPE html>
21
- <html>
22
- <head><meta charset="UTF-8"></head>
23
- <body>
24
- <script>
25
- const App = window.parent?.App;
26
- </script>
27
-
28
- <div class="p-6">
29
- <h1 class="text-2xl font-bold">${slug}</h1>
30
- <p class="text-muted-foreground mt-2">页面内容</p>
31
- </div>
32
- </body>
33
- </html>`,
34
- }),
35
-
36
- nav: (code) => ({
37
- indexEntry: {
38
- name: code,
39
- code,
40
- status: 'active',
41
- order: 0,
42
- html_file: `.draftgo/navigations/nav_new_${code}.html`,
43
- },
44
- file: `.draftgo/navigations/nav_new_${code}.html`,
45
- content: `<nav class="flex items-center gap-4 px-4 h-14">
46
- <a href="/" class="font-semibold">首页</a>
47
- </nav>`,
48
- }),
49
-
50
- db_meta: (type) => ({
51
- indexEntry: {
52
- type,
53
- label: type,
54
- describe: '',
55
- schema: {
56
- type: 'object',
57
- properties: {
58
- title: { type: 'string', title: '标题', required: true, searchable: 'fuzzy' },
59
- },
60
- },
61
- permission: {
62
- public: { read: 'none', create: 'none', update: 'none', delete: 'none' },
63
- login: { read: 'all', create: 'all', update: 'owner', delete: 'owner' },
64
- admin: { read: 'all', create: 'all', update: 'all', delete: 'all' },
65
- },
66
- },
67
- file: null,
68
- content: null,
69
- }),
70
-
71
- script: (slug) => ({
72
- indexEntry: {
73
- name: slug,
74
- slug,
75
- mode: 'route',
76
- status: 'active',
77
- triggers: { path: `/${slug}`, methods: ['GET', 'POST'] },
78
- config: {},
79
- permission: { default: 'admin' },
80
- code_file: `.draftgo/custom_scripts/script_new_${slug}.py`,
81
- },
82
- file: `.draftgo/custom_scripts/script_new_${slug}.py`,
83
- content: `# ${slug}
84
- # 路由脚本:/api/x/${slug}
85
-
86
- def handle(request, context):
87
- """
88
- request: { method, path, query, body, headers, user }
89
- context: { db, config, logger }
90
- """
91
- return {"message": "ok"}
92
- `,
93
- }),
94
-
95
- doc: (slug) => ({
96
- indexEntry: {
97
- title: slug,
98
- key: slug,
99
- status: 'published',
100
- category_id: null,
101
- content_file: `.draftgo/docs/articles/doc_new_${slug}.md`,
102
- },
103
- file: `.draftgo/docs/articles/doc_new_${slug}.md`,
104
- content: `# ${slug}\n\n文档内容\n`,
105
- }),
106
- };
107
-
108
- const INDEX_MAP = {
109
- page: 'pages/index.json',
110
- nav: 'navigations/index.json',
111
- db_meta: 'db_meta/index.json',
112
- script: 'custom_scripts/index.json',
113
- doc: 'docs/articles/index.json',
114
- };
115
-
116
- const PUSH_TYPE = {
117
- page: 'pages',
118
- nav: 'nav',
119
- db_meta: 'db_meta',
120
- script: 'custom_scripts',
121
- doc: 'docs',
122
- };
123
-
124
- function newResource(projectDir, positional) {
125
- const [type, slug] = positional;
126
-
127
- if (!type || !TEMPLATES[type]) {
128
- log.err(`用法:draftgo new <type> <slug>`);
129
- log.dim(` 支持类型:${Object.keys(TEMPLATES).join(' | ')}`);
130
- return 1;
131
- }
132
- if (!slug) {
133
- log.err(`缺少 slug/name 参数,例如:draftgo new ${type} my-slug`);
134
- return 1;
135
- }
136
-
137
- const draftgoDir = path.join(projectDir, '.draftgo');
138
- if (!exists(draftgoDir)) {
139
- log.err('未找到 .draftgo/,请先运行 draftgo connect 或 /draftgo init');
140
- return 1;
141
- }
142
-
143
- const tpl = TEMPLATES[type](slug);
144
- const indexRel = INDEX_MAP[type];
145
- const indexPath = path.join(draftgoDir, indexRel);
146
-
147
- if (!exists(indexPath)) {
148
- log.err(`未找到 ${indexPath},请先运行 /draftgo pull`);
149
- return 1;
150
- }
151
-
152
- // 追加 index 条目
153
- const items = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
154
-
155
- // 检查重复
156
- const dupKey = type === 'page' ? 'route' : type === 'nav' ? 'code' : type === 'db_meta' ? 'type' : type === 'script' ? 'slug' : 'key';
157
- const dupVal = tpl.indexEntry[dupKey];
158
- if (dupVal && items.some((it) => it[dupKey] === dupVal)) {
159
- log.err(`已存在 ${dupKey}="${dupVal}",请换一个名称`);
160
- return 1;
161
- }
162
-
163
- items.push(tpl.indexEntry);
164
- fs.writeFileSync(indexPath, JSON.stringify(items, null, 2), 'utf8');
165
-
166
- // 创建模板文件
167
- if (tpl.file && tpl.content !== null) {
168
- const filePath = path.join(projectDir, tpl.file);
169
- ensureDir(path.dirname(filePath));
170
- if (exists(filePath)) {
171
- log.warn(`文件已存在,跳过:${tpl.file}`);
172
- } else {
173
- fs.writeFileSync(filePath, tpl.content, 'utf8');
174
- log.ok(`已创建:${tpl.file}`);
175
- }
176
- }
177
-
178
- log.ok(`已追加到 .draftgo/${indexRel}`);
179
- log.dim(` 编辑完成后运行:draftgo push ${PUSH_TYPE[type]}`);
180
- return 0;
181
- }
182
-
183
- module.exports = newResource;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { spawnSync } = require('child_process');
6
- const log = require('../logger');
7
-
8
- function projectScript(projectDir, scriptName) {
9
- const pkgPath = path.join(projectDir, 'package.json');
10
- if (!fs.existsSync(pkgPath)) {
11
- log.err(`当前项目没有 package.json,无法运行 draftgo ${scriptName}。`);
12
- return 1;
13
- }
14
-
15
- let pkg;
16
- try {
17
- pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
18
- } catch (err) {
19
- log.err(`package.json 解析失败:${err.message}`);
20
- return 1;
21
- }
22
-
23
- if (!pkg.scripts || !pkg.scripts[scriptName]) {
24
- log.err(`package.json 中没有 scripts.${scriptName}。`);
25
- return 1;
26
- }
27
-
28
- const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
29
- const r = spawnSync(npmCmd, ['run', scriptName], {
30
- cwd: projectDir,
31
- stdio: 'inherit',
32
- shell: false,
33
- });
34
- return r.status || 0;
35
- }
36
-
37
- module.exports = projectScript;