autosnippet 3.2.21 → 3.3.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.
Files changed (107) hide show
  1. package/dashboard/dist/assets/{icons-C1dUryS-.js → icons-BofcEZ3f.js} +1 -1
  2. package/dashboard/dist/assets/index-SiN1GChm.js +128 -0
  3. package/dashboard/dist/index.html +2 -2
  4. package/dist/bin/cli.d.ts +0 -1
  5. package/dist/bin/cli.js +0 -133
  6. package/dist/lib/cli/SetupService.d.ts +46 -2
  7. package/dist/lib/cli/SetupService.js +2 -27
  8. package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.d.ts +2 -5
  9. package/dist/lib/{platform/ios/spm → core/discovery}/SpmDiscoverer.js +159 -44
  10. package/dist/lib/core/discovery/index.d.ts +1 -1
  11. package/dist/lib/core/discovery/index.js +2 -2
  12. package/dist/lib/external/mcp/handlers/guard.js +6 -3
  13. package/dist/lib/http/HttpServer.js +0 -6
  14. package/dist/lib/http/routes/commands.d.ts +1 -1
  15. package/dist/lib/http/routes/commands.js +1 -66
  16. package/dist/lib/http/routes/remote.js +0 -5
  17. package/dist/lib/injection/ServiceMap.d.ts +0 -9
  18. package/dist/lib/injection/modules/AppModule.d.ts +2 -3
  19. package/dist/lib/injection/modules/AppModule.js +3 -30
  20. package/dist/lib/injection/modules/GuardModule.js +33 -1
  21. package/dist/lib/service/guard/GuardCheckEngine.d.ts +13 -1
  22. package/dist/lib/service/guard/GuardCheckEngine.js +44 -2
  23. package/dist/lib/service/module/ModuleService.js +3 -13
  24. package/dist/lib/service/search/SearchEngine.js +1 -1
  25. package/dist/lib/shared/constants.d.ts +0 -15
  26. package/dist/lib/shared/constants.js +0 -10
  27. package/dist/lib/shared/schemas/config.d.ts +4 -1
  28. package/dist/lib/shared/schemas/config.js +8 -1
  29. package/dist/scripts/release.js +2 -10
  30. package/package.json +4 -19
  31. package/dashboard/dist/assets/index-DdvZE4Yd.js +0 -128
  32. package/dist/lib/http/routes/snippets.d.ts +0 -6
  33. package/dist/lib/http/routes/snippets.js +0 -49
  34. package/dist/lib/platform/ClipboardManager.d.ts +0 -24
  35. package/dist/lib/platform/ClipboardManager.js +0 -142
  36. package/dist/lib/platform/NativeUi.d.ts +0 -53
  37. package/dist/lib/platform/NativeUi.js +0 -284
  38. package/dist/lib/platform/ios/index.d.ts +0 -38
  39. package/dist/lib/platform/ios/index.js +0 -42
  40. package/dist/lib/platform/ios/routes/spm.d.ts +0 -9
  41. package/dist/lib/platform/ios/routes/spm.js +0 -371
  42. package/dist/lib/platform/ios/snippet/PlaceholderConverter.d.ts +0 -21
  43. package/dist/lib/platform/ios/snippet/PlaceholderConverter.js +0 -48
  44. package/dist/lib/platform/ios/snippet/XcodeCodec.d.ts +0 -23
  45. package/dist/lib/platform/ios/snippet/XcodeCodec.js +0 -96
  46. package/dist/lib/platform/ios/spm/DependencyGraph.d.ts +0 -56
  47. package/dist/lib/platform/ios/spm/DependencyGraph.js +0 -195
  48. package/dist/lib/platform/ios/spm/PackageSwiftParser.d.ts +0 -69
  49. package/dist/lib/platform/ios/spm/PackageSwiftParser.js +0 -231
  50. package/dist/lib/platform/ios/spm/PathFinder.d.ts +0 -28
  51. package/dist/lib/platform/ios/spm/PathFinder.js +0 -117
  52. package/dist/lib/platform/ios/spm/PolicyEngine.d.ts +0 -44
  53. package/dist/lib/platform/ios/spm/PolicyEngine.js +0 -79
  54. package/dist/lib/platform/ios/spm/SpmHelper.d.ts +0 -102
  55. package/dist/lib/platform/ios/spm/SpmHelper.js +0 -464
  56. package/dist/lib/platform/ios/xcode/HeaderResolver.d.ts +0 -33
  57. package/dist/lib/platform/ios/xcode/HeaderResolver.js +0 -90
  58. package/dist/lib/platform/ios/xcode/SaveEventFilter.d.ts +0 -66
  59. package/dist/lib/platform/ios/xcode/SaveEventFilter.js +0 -142
  60. package/dist/lib/platform/ios/xcode/XcodeAutomation.d.ts +0 -71
  61. package/dist/lib/platform/ios/xcode/XcodeAutomation.js +0 -327
  62. package/dist/lib/platform/ios/xcode/XcodeImportResolver.d.ts +0 -130
  63. package/dist/lib/platform/ios/xcode/XcodeImportResolver.js +0 -404
  64. package/dist/lib/platform/ios/xcode/XcodeIntegration.d.ts +0 -89
  65. package/dist/lib/platform/ios/xcode/XcodeIntegration.js +0 -588
  66. package/dist/lib/platform/ios/xcode/XcodeWriteUtils.d.ts +0 -99
  67. package/dist/lib/platform/ios/xcode/XcodeWriteUtils.js +0 -190
  68. package/dist/lib/service/automation/ActionPipeline.d.ts +0 -34
  69. package/dist/lib/service/automation/ActionPipeline.js +0 -53
  70. package/dist/lib/service/automation/AutomationOrchestrator.d.ts +0 -86
  71. package/dist/lib/service/automation/AutomationOrchestrator.js +0 -57
  72. package/dist/lib/service/automation/ContextCollector.d.ts +0 -24
  73. package/dist/lib/service/automation/ContextCollector.js +0 -35
  74. package/dist/lib/service/automation/DirectiveDetector.d.ts +0 -51
  75. package/dist/lib/service/automation/DirectiveDetector.js +0 -112
  76. package/dist/lib/service/automation/FileWatcher.d.ts +0 -51
  77. package/dist/lib/service/automation/FileWatcher.js +0 -366
  78. package/dist/lib/service/automation/TriggerResolver.d.ts +0 -36
  79. package/dist/lib/service/automation/TriggerResolver.js +0 -62
  80. package/dist/lib/service/automation/handlers/AlinkHandler.d.ts +0 -7
  81. package/dist/lib/service/automation/handlers/AlinkHandler.js +0 -80
  82. package/dist/lib/service/automation/handlers/CreateHandler.d.ts +0 -11
  83. package/dist/lib/service/automation/handlers/CreateHandler.js +0 -170
  84. package/dist/lib/service/automation/handlers/GuardHandler.d.ts +0 -17
  85. package/dist/lib/service/automation/handlers/GuardHandler.js +0 -218
  86. package/dist/lib/service/automation/handlers/HeaderHandler.d.ts +0 -2
  87. package/dist/lib/service/automation/handlers/HeaderHandler.js +0 -32
  88. package/dist/lib/service/automation/handlers/SearchHandler.d.ts +0 -11
  89. package/dist/lib/service/automation/handlers/SearchHandler.js +0 -278
  90. package/dist/lib/service/snippet/SnippetFactory.d.ts +0 -101
  91. package/dist/lib/service/snippet/SnippetFactory.js +0 -145
  92. package/dist/lib/service/snippet/SnippetInstaller.d.ts +0 -91
  93. package/dist/lib/service/snippet/SnippetInstaller.js +0 -276
  94. package/dist/lib/service/snippet/codecs/SnippetCodec.d.ts +0 -44
  95. package/dist/lib/service/snippet/codecs/SnippetCodec.js +0 -35
  96. package/dist/lib/service/snippet/codecs/VSCodeCodec.d.ts +0 -27
  97. package/dist/lib/service/snippet/codecs/VSCodeCodec.js +0 -82
  98. package/dist/scripts/build-native-ui.d.ts +0 -3
  99. package/dist/scripts/build-native-ui.js +0 -62
  100. package/dist/scripts/init-snippets.d.ts +0 -30
  101. package/dist/scripts/init-snippets.js +0 -298
  102. package/dist/scripts/install-full.d.ts +0 -7
  103. package/dist/scripts/install-full.js +0 -38
  104. package/resources/native-ui/README.md +0 -29
  105. package/resources/native-ui/combined-window.swift +0 -494
  106. package/resources/native-ui/main.swift +0 -598
  107. package/scripts/postinstall-safe.mjs +0 -89
@@ -1,276 +0,0 @@
1
- /**
2
- * SnippetInstaller — Codec 驱动的 Snippet 安装器
3
- *
4
- * 支持:
5
- * - Xcode: 每个 snippet 一个 .codesnippet 文件
6
- * - VSCode: 所有 snippets 合并为单个 .code-snippets JSON 文件
7
- *
8
- * 行为由注入的 SnippetCodec 决定。
9
- */
10
- import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync, } from 'node:fs';
11
- import { join } from 'node:path';
12
- export class SnippetInstaller {
13
- #codec;
14
- #snippetFactory;
15
- #snippetsDirOverride;
16
- /**
17
- * @param options.codec IDE codec
18
- * @param [options.snippetsDir] 覆盖 codec 默认目录
19
- */
20
- constructor(options = {}) {
21
- this.#codec = options.codec || null;
22
- this.#snippetFactory = options.snippetFactory || null;
23
- this.#snippetsDirOverride = options.snippetsDir || null;
24
- }
25
- /** codec ID ('xcode' | 'vscode') */
26
- get target() {
27
- return this.#codec?.id || 'unknown';
28
- }
29
- /** 当前安装目录 */
30
- get snippetsDir() {
31
- return this.#snippetsDirOverride || this.#codec?.getInstallDir(process.cwd()) || '';
32
- }
33
- setSnippetFactory(factory) {
34
- this.#snippetFactory = factory;
35
- }
36
- setCodec(codec) {
37
- this.#codec = codec;
38
- }
39
- // ─────────────── 安装 ───────────────
40
- /**
41
- * 安装单个 snippet spec
42
- * @param spec SnippetSpec
43
- * @param [projectRoot] VSCode 需要 projectRoot 确定 .vscode/ 路径
44
- * @returns }
45
- */
46
- install(spec, projectRoot) {
47
- this.#assertCodec();
48
- const codec = this.#codec;
49
- try {
50
- const dir = this.#resolveDir(projectRoot);
51
- this.#ensureDir(dir);
52
- const bundleFilename = codec.getBundleFilename();
53
- if (bundleFilename) {
54
- // Bundle 模式 (VSCode): merge into single JSON file
55
- return this.#installToBundle(spec, dir, bundleFilename);
56
- }
57
- // Per-file 模式 (Xcode): 每个 snippet 一个文件
58
- const content = codec.generate(spec);
59
- const filename = `${spec.identifier}${codec.fileExtension}`;
60
- const filePath = join(dir, filename);
61
- writeFileSync(filePath, content);
62
- return { success: true, path: filePath, message: `Installed: ${filename}` };
63
- }
64
- catch (error) {
65
- const message = error instanceof Error ? error.message : String(error);
66
- return { success: false, path: '', message };
67
- }
68
- }
69
- /**
70
- * 从 Recipe 批量安装
71
- * @returns }
72
- */
73
- installFromRecipes(recipes, projectRoot) {
74
- this.#assertCodec();
75
- this.#assertFactory();
76
- const codec = this.#codec;
77
- const factory = this.#snippetFactory;
78
- const dir = this.#resolveDir(projectRoot);
79
- this.#ensureDir(dir);
80
- const specs = recipes.map((r) => factory.fromRecipe(r));
81
- const bundleFilename = codec.getBundleFilename();
82
- if (bundleFilename) {
83
- // Bundle 模式: 一次性写入整个 bundle
84
- return this.#installBundleFromSpecs(specs, dir, bundleFilename, recipes.length);
85
- }
86
- // Per-file 模式
87
- const details = [];
88
- let successCount = 0;
89
- let errorCount = 0;
90
- for (const spec of specs) {
91
- const result = this.install(spec, projectRoot);
92
- details.push(result);
93
- if (result.success) {
94
- successCount++;
95
- }
96
- else {
97
- errorCount++;
98
- }
99
- }
100
- return { success: errorCount === 0, count: recipes.length, successCount, errorCount, details };
101
- }
102
- // ─────────────── 查询 ───────────────
103
- /**
104
- * 列出已安装的 AutoSnippet 管理的 snippet
105
- * @returns >}
106
- */
107
- listInstalled(projectRoot) {
108
- const dir = this.#resolveDir(projectRoot);
109
- if (!existsSync(dir)) {
110
- return [];
111
- }
112
- const bundleFilename = this.#codec?.getBundleFilename();
113
- if (bundleFilename) {
114
- // VSCode: 检查 bundle 文件是否存在
115
- const bundlePath = join(dir, bundleFilename);
116
- if (!existsSync(bundlePath)) {
117
- return [];
118
- }
119
- try {
120
- const content = JSON.parse(readFileSync(bundlePath, 'utf-8'));
121
- return Object.keys(content).map((key) => ({
122
- filename: key,
123
- path: bundlePath,
124
- }));
125
- }
126
- catch {
127
- return [];
128
- }
129
- }
130
- // Xcode: 列出 com.autosnippet.*.codesnippet 文件
131
- return readdirSync(dir)
132
- .filter((f) => f.startsWith('com.autosnippet.') &&
133
- f.endsWith(this.#codec?.fileExtension || '.codesnippet'))
134
- .map((f) => ({ filename: f, path: join(dir, f) }));
135
- }
136
- // ─────────────── 卸载 ───────────────
137
- /**
138
- * 卸载指定 snippet
139
- * @returns }
140
- */
141
- uninstall(identifier, projectRoot) {
142
- const dir = this.#resolveDir(projectRoot);
143
- const bundleFilename = this.#codec?.getBundleFilename();
144
- if (bundleFilename) {
145
- // VSCode: 从 bundle JSON 中移除对应 key
146
- return this.#removeFromBundle(identifier, dir, bundleFilename);
147
- }
148
- // Xcode: 删除单个文件
149
- const ext = this.#codec?.fileExtension || '.codesnippet';
150
- const filename = identifier.endsWith(ext) ? identifier : `${identifier}${ext}`;
151
- const filePath = join(dir, filename);
152
- if (!existsSync(filePath)) {
153
- return { success: false, message: `Not found: ${filename}` };
154
- }
155
- unlinkSync(filePath);
156
- return { success: true, message: `Uninstalled: ${filename}` };
157
- }
158
- /**
159
- * 清除所有 AutoSnippet 管理的 snippet
160
- * @returns }
161
- */
162
- cleanAll(projectRoot) {
163
- const dir = this.#resolveDir(projectRoot);
164
- const bundleFilename = this.#codec?.getBundleFilename();
165
- if (bundleFilename) {
166
- // VSCode: 删除整个 bundle 文件
167
- const bundlePath = join(dir, bundleFilename);
168
- if (existsSync(bundlePath)) {
169
- unlinkSync(bundlePath);
170
- return { success: true, removed: 1 };
171
- }
172
- return { success: true, removed: 0 };
173
- }
174
- // Xcode: 删除所有 com.autosnippet.* 文件
175
- const installed = this.listInstalled(projectRoot);
176
- let removed = 0;
177
- for (const { path: filePath } of installed) {
178
- try {
179
- unlinkSync(filePath);
180
- removed++;
181
- }
182
- catch {
183
- /* ignore */
184
- }
185
- }
186
- return { success: true, removed };
187
- }
188
- // ─────────────── Private ───────────────
189
- #assertCodec() {
190
- if (!this.#codec) {
191
- throw new Error('SnippetCodec not set');
192
- }
193
- }
194
- #assertFactory() {
195
- if (!this.#snippetFactory) {
196
- throw new Error('SnippetFactory not set');
197
- }
198
- }
199
- #resolveDir(projectRoot) {
200
- if (this.#snippetsDirOverride) {
201
- return this.#snippetsDirOverride;
202
- }
203
- return this.#codec?.getInstallDir(projectRoot || process.cwd()) || '';
204
- }
205
- #ensureDir(dir) {
206
- if (!existsSync(dir)) {
207
- mkdirSync(dir, { recursive: true });
208
- }
209
- }
210
- /** VSCode bundle: 将单个 spec 追加/更新到 bundle JSON */
211
- #installToBundle(spec, dir, bundleFilename) {
212
- const bundlePath = join(dir, bundleFilename);
213
- let bundle = {};
214
- if (existsSync(bundlePath)) {
215
- try {
216
- bundle = JSON.parse(readFileSync(bundlePath, 'utf-8'));
217
- }
218
- catch {
219
- bundle = {};
220
- }
221
- }
222
- const key = `Recipe: ${spec.title || spec.identifier}`;
223
- const content = JSON.parse(this.#codec.generate(spec));
224
- const entryKey = Object.keys(content)[0];
225
- bundle[key] = content[entryKey];
226
- writeFileSync(bundlePath, `${JSON.stringify(bundle, null, 2)}\n`);
227
- return { success: true, path: bundlePath, message: `Installed: ${key}` };
228
- }
229
- /** VSCode bundle: 一次性写入完整 bundle */
230
- #installBundleFromSpecs(specs, dir, bundleFilename, totalCount) {
231
- try {
232
- const content = this.#codec.generateBundle(specs);
233
- const bundlePath = join(dir, bundleFilename);
234
- writeFileSync(bundlePath, typeof content === 'string' ? content : JSON.stringify(content, null, 2));
235
- return {
236
- success: true,
237
- count: totalCount,
238
- successCount: totalCount,
239
- errorCount: 0,
240
- details: [{ success: true, path: bundlePath, message: `Bundle: ${totalCount} snippets` }],
241
- };
242
- }
243
- catch (error) {
244
- const message = error instanceof Error ? error.message : String(error);
245
- return {
246
- success: false,
247
- count: totalCount,
248
- successCount: 0,
249
- errorCount: totalCount,
250
- details: [{ success: false, path: '', message }],
251
- };
252
- }
253
- }
254
- /** VSCode bundle: 从 JSON 中移除一个 snippet */
255
- #removeFromBundle(identifier, dir, bundleFilename) {
256
- const bundlePath = join(dir, bundleFilename);
257
- if (!existsSync(bundlePath)) {
258
- return { success: false, message: `Bundle not found: ${bundleFilename}` };
259
- }
260
- try {
261
- const bundle = JSON.parse(readFileSync(bundlePath, 'utf-8'));
262
- // 按 identifier 或 title 匹配
263
- const keyToRemove = Object.keys(bundle).find((k) => k.includes(identifier) || k === `Recipe: ${identifier}`);
264
- if (!keyToRemove) {
265
- return { success: false, message: `Snippet not found in bundle: ${identifier}` };
266
- }
267
- delete bundle[keyToRemove];
268
- writeFileSync(bundlePath, `${JSON.stringify(bundle, null, 2)}\n`);
269
- return { success: true, message: `Uninstalled: ${keyToRemove}` };
270
- }
271
- catch (error) {
272
- const message = error instanceof Error ? error.message : String(error);
273
- return { success: false, message };
274
- }
275
- }
276
- }
@@ -1,44 +0,0 @@
1
- /**
2
- * SnippetCodec — IDE Snippet 格式抽象接口
3
- *
4
- * 子类实现:
5
- * - XcodeCodec (.codesnippet plist XML)
6
- * - VSCodeCodec (.code-snippets JSON, 兼容 Cursor)
7
- *
8
- * SnippetSpec 结构 (IDE 无关中间表示):
9
- * { identifier, title, completion, summary, code, language }
10
- */
11
- export interface SnippetSpec {
12
- identifier: string;
13
- title?: string;
14
- completion?: string;
15
- trigger?: string;
16
- summary?: string;
17
- code?: string | string[];
18
- language?: string;
19
- [key: string]: unknown;
20
- }
21
- export declare class SnippetCodec {
22
- /** @returns codec 标识 ('xcode' | 'vscode') */
23
- get id(): string;
24
- /** 输出文件的扩展名 ('.codesnippet' | '.code-snippets') */
25
- get fileExtension(): string;
26
- /** 单个 SnippetSpec → IDE 格式字符串 */
27
- generate(spec: SnippetSpec): string;
28
- /**
29
- * 批量 specs → IDE 格式输出
30
- * Xcode: 返回 Array<{ filename, content }>(每个 snippet 一个文件)
31
- * VSCode: 返回 string(单个 JSON bundle 文件内容)
32
- * @returns >}
33
- */
34
- generateBundle(specs: SnippetSpec[]): string | Array<{
35
- filename: string;
36
- content: string;
37
- }>;
38
- /** 目标 snippet 安装目录路径 */
39
- getInstallDir(projectRoot?: string): string;
40
- /** AutoSnippet 语言标识 → IDE 语言标识映射 */
41
- mapLanguage(lang: string): string;
42
- /** 获取 bundle 文件名 (VSCode = 'autosnippet.code-snippets', Xcode = per-file) */
43
- getBundleFilename(): string | null;
44
- }
@@ -1,35 +0,0 @@
1
- export class SnippetCodec {
2
- /** @returns codec 标识 ('xcode' | 'vscode') */
3
- get id() {
4
- throw new Error('SnippetCodec.id is abstract');
5
- }
6
- /** 输出文件的扩展名 ('.codesnippet' | '.code-snippets') */
7
- get fileExtension() {
8
- throw new Error('SnippetCodec.fileExtension is abstract');
9
- }
10
- /** 单个 SnippetSpec → IDE 格式字符串 */
11
- generate(spec) {
12
- throw new Error('SnippetCodec.generate() is abstract');
13
- }
14
- /**
15
- * 批量 specs → IDE 格式输出
16
- * Xcode: 返回 Array<{ filename, content }>(每个 snippet 一个文件)
17
- * VSCode: 返回 string(单个 JSON bundle 文件内容)
18
- * @returns >}
19
- */
20
- generateBundle(specs) {
21
- throw new Error('SnippetCodec.generateBundle() is abstract');
22
- }
23
- /** 目标 snippet 安装目录路径 */
24
- getInstallDir(projectRoot) {
25
- throw new Error('SnippetCodec.getInstallDir() is abstract');
26
- }
27
- /** AutoSnippet 语言标识 → IDE 语言标识映射 */
28
- mapLanguage(lang) {
29
- throw new Error('SnippetCodec.mapLanguage() is abstract');
30
- }
31
- /** 获取 bundle 文件名 (VSCode = 'autosnippet.code-snippets', Xcode = per-file) */
32
- getBundleFilename() {
33
- return null;
34
- }
35
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * VSCodeCodec — VSCode .code-snippets (JSON) 生成器
3
- *
4
- * 特性:
5
- * - 项目级 .vscode/autosnippet.code-snippets 单 bundle 文件
6
- * - 兼容 Cursor (100% VSCode snippet 格式)
7
- * - Xcode 占位符 <#…#> 自动转换为 VSCode ${N:…}
8
- * - 多语言 scope 自动映射
9
- */
10
- import type { SnippetSpec } from './SnippetCodec.js';
11
- import { SnippetCodec } from './SnippetCodec.js';
12
- export declare class VSCodeCodec extends SnippetCodec {
13
- #private;
14
- get id(): string;
15
- get fileExtension(): string;
16
- /** 单个 SnippetSpec → JSON 字符串 */
17
- generate(spec: SnippetSpec): string;
18
- /**
19
- * VSCode: 所有 snippets 合并为单个 JSON bundle 文件
20
- * @returns JSON 字符串
21
- */
22
- generateBundle(specs: SnippetSpec[]): string;
23
- /** VSCode snippets 安装目录 = 项目级 .vscode/ */
24
- getInstallDir(projectRoot: string): string;
25
- mapLanguage(lang: string): string;
26
- getBundleFilename(): string;
27
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * VSCodeCodec — VSCode .code-snippets (JSON) 生成器
3
- *
4
- * 特性:
5
- * - 项目级 .vscode/autosnippet.code-snippets 单 bundle 文件
6
- * - 兼容 Cursor (100% VSCode snippet 格式)
7
- * - Xcode 占位符 <#…#> 自动转换为 VSCode ${N:…}
8
- * - 多语言 scope 自动映射
9
- */
10
- import { join } from 'node:path';
11
- import { PlaceholderConverter } from '#platform/ios/snippet/PlaceholderConverter.js';
12
- import { SnippetCodec } from './SnippetCodec.js';
13
- /** AutoSnippet language → VSCode snippet scope */
14
- const VSCODE_LANGUAGE_MAP = {
15
- swift: 'swift',
16
- 'objective-c': 'objective-c',
17
- objc: 'objective-c',
18
- c: 'c',
19
- 'c++': 'cpp',
20
- go: 'go',
21
- python: 'python',
22
- java: 'java',
23
- kotlin: 'kotlin',
24
- javascript: 'javascript,javascriptreact',
25
- typescript: 'typescript,typescriptreact',
26
- rust: 'rust',
27
- ruby: 'ruby',
28
- };
29
- const BUNDLE_FILENAME = 'autosnippet.code-snippets';
30
- export class VSCodeCodec extends SnippetCodec {
31
- get id() {
32
- return 'vscode';
33
- }
34
- get fileExtension() {
35
- return '.code-snippets';
36
- }
37
- /** 单个 SnippetSpec → JSON 字符串 */
38
- generate(spec) {
39
- const entry = this.#specToEntry(spec);
40
- return JSON.stringify({ [spec.title || spec.identifier]: entry }, null, 2);
41
- }
42
- /**
43
- * VSCode: 所有 snippets 合并为单个 JSON bundle 文件
44
- * @returns JSON 字符串
45
- */
46
- generateBundle(specs) {
47
- const bundle = {};
48
- for (const spec of specs) {
49
- const key = `Recipe: ${spec.title || spec.identifier}`;
50
- bundle[key] = this.#specToEntry(spec);
51
- }
52
- return `${JSON.stringify(bundle, null, 2)}\n`;
53
- }
54
- /** VSCode snippets 安装目录 = 项目级 .vscode/ */
55
- getInstallDir(projectRoot) {
56
- return join(projectRoot, '.vscode');
57
- }
58
- mapLanguage(lang) {
59
- return VSCODE_LANGUAGE_MAP[lang?.toLowerCase()] || '';
60
- }
61
- getBundleFilename() {
62
- return BUNDLE_FILENAME;
63
- }
64
- /** SnippetSpec → VSCode snippet entry */
65
- #specToEntry(spec) {
66
- const code = Array.isArray(spec.code) ? spec.code.join('\n') : spec.code || '';
67
- // 自动将 Xcode 占位符转为 VSCode 格式
68
- const converted = PlaceholderConverter.xcodeToVSCode(code);
69
- const body = converted.split('\n');
70
- const entry = {
71
- prefix: spec.completion || spec.trigger || spec.identifier,
72
- body,
73
- description: spec.summary || '',
74
- };
75
- // 添加语言 scope (空字符串 = 所有语言)
76
- const scope = this.mapLanguage(spec.language || '');
77
- if (scope) {
78
- entry.scope = scope;
79
- }
80
- return entry;
81
- }
82
- }
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- /** 在 macOS 上构建 native-ui 辅助程序(可选) */
3
- export {};
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
- /** 在 macOS 上构建 native-ui 辅助程序(可选) */
3
- const __dirname = import.meta.dirname;
4
- import { execSync } from 'node:child_process';
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import { PACKAGE_ROOT } from '../lib/shared/package-root.js';
8
- if (process.platform !== 'darwin') {
9
- process.exit(0);
10
- }
11
- const root = PACKAGE_ROOT;
12
- const src = path.join(root, 'resources', 'native-ui', 'main.swift');
13
- const combinedSrc = path.join(root, 'resources', 'native-ui', 'combined-window.swift');
14
- const out = path.join(root, 'resources', 'native-ui', 'native-ui');
15
- // 检查是否在发布流程中(npm publish 会设置 npm_lifecycle_event)
16
- const isPublishing = process.env.npm_lifecycle_event === 'prepublishOnly';
17
- try {
18
- // 编译 native-ui(包含所有源文件)
19
- execSync(`swiftc "${src}" "${combinedSrc}" -o "${out}" -framework AppKit`, {
20
- cwd: root,
21
- stdio: 'pipe',
22
- });
23
- // 验证构建结果
24
- if (fs.existsSync(out)) {
25
- }
26
- }
27
- catch (_err) {
28
- // 如果在发布流程中构建失败,应该报错
29
- if (isPublishing) {
30
- console.error('❌ Native UI 构建失败(发布流程中)');
31
- console.error('请确保:');
32
- console.error(' 1. 当前系统是 macOS');
33
- console.error(' 2. 已安装 Xcode Command Line Tools: xcode-select --install');
34
- console.error(' 3. Swift 编译器可用: which swiftc');
35
- process.exit(1);
36
- }
37
- // 在用户安装时,如果已有预编译的二进制文件,静默跳过
38
- if (fs.existsSync(out)) {
39
- }
40
- else {
41
- }
42
- }
43
- // ── 发布流程:最终校验二进制必须存在 ──
44
- if (isPublishing) {
45
- if (!fs.existsSync(out)) {
46
- console.error('❌ 发布中止:native-ui 二进制不存在于', out);
47
- console.error(' prepublishOnly 编译步骤可能被跳过或失败');
48
- process.exit(1);
49
- }
50
- const stat = fs.statSync(out);
51
- if (stat.size < 10_000) {
52
- console.error('❌ 发布中止:native-ui 二进制异常(仅', stat.size, '字节)');
53
- process.exit(1);
54
- }
55
- // 确保有执行权限
56
- try {
57
- fs.chmodSync(out, 0o755);
58
- }
59
- catch {
60
- /* ignore */
61
- }
62
- }
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Snippet 统一初始化脚本
4
- *
5
- * 为 AutoSnippet 生成快速触发 Snippet(ass/asc/asa)到目标 IDE:
6
- * - Xcode: ~/Library/Developer/Xcode/UserData/CodeSnippets/*.codesnippet
7
- * - VSCode: .vscode/autosnippet-triggers.code-snippets (项目级)
8
- *
9
- * 用法:
10
- * node scripts/init-snippets.js [init|list|remove] [--target xcode|vscode|all]
11
- * npm run init:snippets
12
- */
13
- export declare class SnippetInitializer {
14
- vscode: any;
15
- xcode: any;
16
- constructor(projectRoot: any);
17
- /**
18
- * 初始化 snippet 到指定目标
19
- * @param target — 'xcode' | 'vscode' | 'all'
20
- * @returns }
21
- */
22
- initialize(target?: string): Promise<any>;
23
- list(target?: string): any;
24
- remove(target?: string): any;
25
- }
26
- declare const _default: {
27
- SnippetInitializer: typeof SnippetInitializer;
28
- initialize: (projectRoot: any, target: any) => Promise<any>;
29
- };
30
- export default _default;