autosnippet 1.1.20 → 1.1.21
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/bin/asnip.js +21 -7
- package/bin/watch.js +5 -4
- package/package.json +1 -1
package/bin/asnip.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
4
5
|
// 读取输入命令
|
|
5
6
|
const inquirer = require('inquirer');
|
|
6
7
|
// 命令行工具
|
|
@@ -219,19 +220,32 @@ commander
|
|
|
219
220
|
commander
|
|
220
221
|
.command('w')
|
|
221
222
|
.description('recognize that Snippet automatically injects dependency header files')
|
|
222
|
-
.action(() => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
.action(async () => {
|
|
224
|
+
// ✅ 从执行位置向上查找 AutoSnippetRoot.boxspec.json,找到根目录
|
|
225
|
+
const projectRoot = await findPath.findProjectRoot(CMD_PATH);
|
|
226
|
+
|
|
227
|
+
if (!projectRoot) {
|
|
228
|
+
console.error('未找到项目根目录(AutoSnippetRoot.boxspec.json)。');
|
|
229
|
+
console.error('请先使用 asd root 命令在项目根目录创建根目录标记文件。');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
console.log(`[asd w] 项目根目录: ${projectRoot}`);
|
|
234
|
+
|
|
235
|
+
// ✅ 使用根目录的 AutoSnippetRoot.boxspec.json 作为配置文件
|
|
236
|
+
const rootSpecFile = path.join(projectRoot, findPath.ROOT_MARKER_NAME);
|
|
237
|
+
console.log(`[asd w] 使用配置文件: ${rootSpecFile}`);
|
|
238
|
+
|
|
239
|
+
// 先安装 snippets
|
|
240
|
+
install.addCodeSnippets(rootSpecFile);
|
|
241
|
+
// 在根目录启动监听
|
|
242
|
+
watch.watchFileChange(rootSpecFile, projectRoot);
|
|
227
243
|
});
|
|
228
244
|
|
|
229
245
|
commander
|
|
230
246
|
.command('root')
|
|
231
247
|
.description('mark current directory as project root by creating AutoSnippetRoot.boxspec.json')
|
|
232
248
|
.action(() => {
|
|
233
|
-
const fs = require('fs');
|
|
234
|
-
const path = require('path');
|
|
235
249
|
const rootMarkerPath = path.join(CMD_PATH, 'AutoSnippetRoot.boxspec.json');
|
|
236
250
|
|
|
237
251
|
try {
|
package/bin/watch.js
CHANGED
|
@@ -22,10 +22,11 @@ const importSwiftReg = /^import\s*\w+$/;
|
|
|
22
22
|
let timeoutLink = null;
|
|
23
23
|
let timeoutHead = null;
|
|
24
24
|
|
|
25
|
-
function watchFileChange(specFile) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
function watchFileChange(specFile, watchRootPath) {
|
|
26
|
+
// ✅ 如果指定了监听根目录,使用它;否则使用当前工作目录
|
|
27
|
+
const filePath = watchRootPath || CMD_PATH;
|
|
28
|
+
console.log(`[watchFileChange] 监听目录: ${filePath}`);
|
|
29
|
+
console.log(`[watchFileChange] 配置文件: ${specFile}`);
|
|
29
30
|
let isReading = false;
|
|
30
31
|
|
|
31
32
|
fs.watch(filePath, {recursive: true}, (event, filename) => {
|