@agiflowai/aicode-utils 1.0.18 → 1.0.20
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/dist/index.mjs +56 -56
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import
|
|
2
|
+
import * as path$1 from "node:path";
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
import * as fs from "node:fs/promises";
|
|
5
5
|
import { accessSync, mkdirSync, readFileSync, readFileSync as readFileSync$1, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import * as os from "node:os";
|
|
@@ -84,7 +84,7 @@ async function copy(src, dest) {
|
|
|
84
84
|
* Move a file or directory
|
|
85
85
|
*/
|
|
86
86
|
async function move(src, dest) {
|
|
87
|
-
await ensureDir(
|
|
87
|
+
await ensureDir(path.dirname(dest));
|
|
88
88
|
await fs.rename(src, dest);
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
@@ -120,12 +120,12 @@ const cp = fs.cp;
|
|
|
120
120
|
|
|
121
121
|
//#endregion
|
|
122
122
|
//#region src/utils/logger.ts
|
|
123
|
-
const logsDir = path.join(os.tmpdir(), "scaffold-mcp-logs");
|
|
123
|
+
const logsDir = path$1.join(os.tmpdir(), "scaffold-mcp-logs");
|
|
124
124
|
const logger = pino({
|
|
125
125
|
level: process.env.LOG_LEVEL || "debug",
|
|
126
126
|
timestamp: pino.stdTimeFunctions.isoTime
|
|
127
127
|
}, pino.destination({
|
|
128
|
-
dest: path.join(logsDir, "scaffold-mcp.log"),
|
|
128
|
+
dest: path$1.join(logsDir, "scaffold-mcp.log"),
|
|
129
129
|
mkdir: true,
|
|
130
130
|
sync: true
|
|
131
131
|
}));
|
|
@@ -208,11 +208,11 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
208
208
|
const workspaceRoot = await TemplatesManagerService.findWorkspaceRoot(startPath);
|
|
209
209
|
const config = await TemplatesManagerService.readToolkitConfig(startPath);
|
|
210
210
|
if (config?.templatesPath) {
|
|
211
|
-
const templatesPath$1 =
|
|
211
|
+
const templatesPath$1 = path.isAbsolute(config.templatesPath) ? config.templatesPath : path.join(workspaceRoot, config.templatesPath);
|
|
212
212
|
if (await pathExists(templatesPath$1)) return templatesPath$1;
|
|
213
213
|
return null;
|
|
214
214
|
}
|
|
215
|
-
const templatesPath =
|
|
215
|
+
const templatesPath = path.join(workspaceRoot, TemplatesManagerService.TEMPLATES_FOLDER);
|
|
216
216
|
if (await pathExists(templatesPath)) return templatesPath;
|
|
217
217
|
return null;
|
|
218
218
|
}
|
|
@@ -220,12 +220,12 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
220
220
|
* Find the workspace root by searching upwards for .git folder
|
|
221
221
|
*/
|
|
222
222
|
static async findWorkspaceRoot(startPath) {
|
|
223
|
-
let currentPath =
|
|
224
|
-
const rootPath =
|
|
223
|
+
let currentPath = path.resolve(startPath);
|
|
224
|
+
const rootPath = path.parse(currentPath).root;
|
|
225
225
|
while (true) {
|
|
226
|
-
if (await pathExists(
|
|
226
|
+
if (await pathExists(path.join(currentPath, ".git"))) return currentPath;
|
|
227
227
|
if (currentPath === rootPath) return process.cwd();
|
|
228
|
-
currentPath =
|
|
228
|
+
currentPath = path.dirname(currentPath);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
@@ -239,11 +239,11 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
239
239
|
const workspaceRoot = TemplatesManagerService.findWorkspaceRootSync(startPath);
|
|
240
240
|
const config = TemplatesManagerService.readToolkitConfigSync(startPath);
|
|
241
241
|
if (config?.templatesPath) {
|
|
242
|
-
const templatesPath$1 =
|
|
242
|
+
const templatesPath$1 = path.isAbsolute(config.templatesPath) ? config.templatesPath : path.join(workspaceRoot, config.templatesPath);
|
|
243
243
|
if (pathExistsSync(templatesPath$1)) return templatesPath$1;
|
|
244
244
|
return null;
|
|
245
245
|
}
|
|
246
|
-
const templatesPath =
|
|
246
|
+
const templatesPath = path.join(workspaceRoot, TemplatesManagerService.TEMPLATES_FOLDER);
|
|
247
247
|
if (pathExistsSync(templatesPath)) return templatesPath;
|
|
248
248
|
return null;
|
|
249
249
|
}
|
|
@@ -251,12 +251,12 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
251
251
|
* Find the workspace root synchronously by searching upwards for .git folder
|
|
252
252
|
*/
|
|
253
253
|
static findWorkspaceRootSync(startPath) {
|
|
254
|
-
let currentPath =
|
|
255
|
-
const rootPath =
|
|
254
|
+
let currentPath = path.resolve(startPath);
|
|
255
|
+
const rootPath = path.parse(currentPath).root;
|
|
256
256
|
while (true) {
|
|
257
|
-
if (pathExistsSync(
|
|
257
|
+
if (pathExistsSync(path.join(currentPath, ".git"))) return currentPath;
|
|
258
258
|
if (currentPath === rootPath) return process.cwd();
|
|
259
|
-
currentPath =
|
|
259
|
+
currentPath = path.dirname(currentPath);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
/**
|
|
@@ -295,9 +295,9 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
295
295
|
static async readToolkitConfig(startPath = process.cwd()) {
|
|
296
296
|
const workspaceRoot = await TemplatesManagerService.findWorkspaceRoot(startPath);
|
|
297
297
|
const yaml$1 = await import("js-yaml");
|
|
298
|
-
const toolkitFolder =
|
|
299
|
-
const settingsPath =
|
|
300
|
-
const settingsLocalPath =
|
|
298
|
+
const toolkitFolder = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_FOLDER);
|
|
299
|
+
const settingsPath = path.join(toolkitFolder, TemplatesManagerService.SETTINGS_FILE);
|
|
300
|
+
const settingsLocalPath = path.join(toolkitFolder, TemplatesManagerService.SETTINGS_LOCAL_FILE);
|
|
301
301
|
if (await pathExists(settingsPath)) {
|
|
302
302
|
const baseContent = await fs.readFile(settingsPath, "utf-8");
|
|
303
303
|
const base = yaml$1.load(baseContent);
|
|
@@ -308,7 +308,7 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
308
308
|
}
|
|
309
309
|
return base;
|
|
310
310
|
}
|
|
311
|
-
const legacyConfigPath =
|
|
311
|
+
const legacyConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
|
|
312
312
|
if (!await pathExists(legacyConfigPath)) return null;
|
|
313
313
|
const content = await fs.readFile(legacyConfigPath, "utf-8");
|
|
314
314
|
return yaml$1.load(content);
|
|
@@ -327,9 +327,9 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
327
327
|
static readToolkitConfigSync(startPath = process.cwd()) {
|
|
328
328
|
const workspaceRoot = TemplatesManagerService.findWorkspaceRootSync(startPath);
|
|
329
329
|
const yaml$1 = __require("js-yaml");
|
|
330
|
-
const toolkitFolder =
|
|
331
|
-
const settingsPath =
|
|
332
|
-
const settingsLocalPath =
|
|
330
|
+
const toolkitFolder = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_FOLDER);
|
|
331
|
+
const settingsPath = path.join(toolkitFolder, TemplatesManagerService.SETTINGS_FILE);
|
|
332
|
+
const settingsLocalPath = path.join(toolkitFolder, TemplatesManagerService.SETTINGS_LOCAL_FILE);
|
|
333
333
|
if (pathExistsSync(settingsPath)) {
|
|
334
334
|
const base = yaml$1.load(readFileSync$1(settingsPath, "utf-8"));
|
|
335
335
|
if (pathExistsSync(settingsLocalPath)) {
|
|
@@ -338,7 +338,7 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
338
338
|
}
|
|
339
339
|
return base;
|
|
340
340
|
}
|
|
341
|
-
const legacyConfigPath =
|
|
341
|
+
const legacyConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
|
|
342
342
|
if (!pathExistsSync(legacyConfigPath)) return null;
|
|
343
343
|
return yaml$1.load(readFileSync$1(legacyConfigPath, "utf-8"));
|
|
344
344
|
}
|
|
@@ -351,8 +351,8 @@ var TemplatesManagerService = class TemplatesManagerService {
|
|
|
351
351
|
*/
|
|
352
352
|
static async writeToolkitConfig(config, startPath = process.cwd()) {
|
|
353
353
|
const workspaceRoot = await TemplatesManagerService.findWorkspaceRoot(startPath);
|
|
354
|
-
const toolkitFolder =
|
|
355
|
-
const settingsPath =
|
|
354
|
+
const toolkitFolder = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_FOLDER);
|
|
355
|
+
const settingsPath = path.join(toolkitFolder, TemplatesManagerService.SETTINGS_FILE);
|
|
356
356
|
await fs.mkdir(toolkitFolder, { recursive: true });
|
|
357
357
|
const content = (await import("js-yaml")).dump(config, { indent: 2 });
|
|
358
358
|
await fs.writeFile(settingsPath, content, "utf-8");
|
|
@@ -424,13 +424,13 @@ var ProjectConfigResolver = class ProjectConfigResolver {
|
|
|
424
424
|
*/
|
|
425
425
|
static async resolveProjectConfig(projectPath, explicitTemplate) {
|
|
426
426
|
try {
|
|
427
|
-
const absolutePath =
|
|
427
|
+
const absolutePath = path.resolve(projectPath);
|
|
428
428
|
if (explicitTemplate) return {
|
|
429
429
|
type: ProjectType.MONOLITH,
|
|
430
430
|
sourceTemplate: explicitTemplate,
|
|
431
431
|
configSource: ConfigSource.TOOLKIT_YAML
|
|
432
432
|
};
|
|
433
|
-
const projectJsonPath =
|
|
433
|
+
const projectJsonPath = path.join(absolutePath, "project.json");
|
|
434
434
|
if (await pathExists(projectJsonPath)) {
|
|
435
435
|
const projectJson = await readJson(projectJsonPath);
|
|
436
436
|
if (projectJson.sourceTemplate && typeof projectJson.sourceTemplate === "string" && projectJson.sourceTemplate.trim()) return {
|
|
@@ -521,12 +521,12 @@ Run 'scaffold-mcp scaffold list --help' for more info.`;
|
|
|
521
521
|
* @param sourceTemplate - The template identifier
|
|
522
522
|
*/
|
|
523
523
|
static async createProjectJson(projectPath, projectName, sourceTemplate) {
|
|
524
|
-
const projectJsonPath =
|
|
524
|
+
const projectJsonPath = path.join(projectPath, "project.json");
|
|
525
525
|
try {
|
|
526
526
|
let projectJson;
|
|
527
527
|
if (await pathExists(projectJsonPath)) projectJson = await readJson(projectJsonPath);
|
|
528
528
|
else {
|
|
529
|
-
const relativePath =
|
|
529
|
+
const relativePath = path.relative(projectPath, process.cwd());
|
|
530
530
|
projectJson = {
|
|
531
531
|
name: projectName,
|
|
532
532
|
$schema: relativePath ? `${relativePath}/node_modules/nx/schemas/project-schema.json` : "node_modules/nx/schemas/project-schema.json",
|
|
@@ -578,15 +578,15 @@ var ProjectFinderService = class {
|
|
|
578
578
|
* @returns Project configuration or null if not found
|
|
579
579
|
*/
|
|
580
580
|
async findProjectForFile(filePath) {
|
|
581
|
-
const normalizedPath =
|
|
582
|
-
let currentDir =
|
|
581
|
+
const normalizedPath = path.isAbsolute(filePath) ? filePath : path.join(this.workspaceRoot, filePath);
|
|
582
|
+
let currentDir = path.dirname(normalizedPath);
|
|
583
583
|
while (currentDir !== "/" && currentDir.startsWith(this.workspaceRoot)) {
|
|
584
|
-
const projectJsonPath =
|
|
584
|
+
const projectJsonPath = path.join(currentDir, "project.json");
|
|
585
585
|
try {
|
|
586
586
|
const project = await this.loadProjectConfig(projectJsonPath);
|
|
587
587
|
if (project) return project;
|
|
588
588
|
} catch {}
|
|
589
|
-
currentDir =
|
|
589
|
+
currentDir = path.dirname(currentDir);
|
|
590
590
|
}
|
|
591
591
|
return null;
|
|
592
592
|
}
|
|
@@ -597,15 +597,15 @@ var ProjectFinderService = class {
|
|
|
597
597
|
* @returns Project configuration or null if not found
|
|
598
598
|
*/
|
|
599
599
|
findProjectForFileSync(filePath) {
|
|
600
|
-
const normalizedPath =
|
|
601
|
-
let currentDir =
|
|
600
|
+
const normalizedPath = path.isAbsolute(filePath) ? filePath : path.join(this.workspaceRoot, filePath);
|
|
601
|
+
let currentDir = path.dirname(normalizedPath);
|
|
602
602
|
while (currentDir !== "/" && currentDir.startsWith(this.workspaceRoot)) {
|
|
603
|
-
const projectJsonPath =
|
|
603
|
+
const projectJsonPath = path.join(currentDir, "project.json");
|
|
604
604
|
try {
|
|
605
605
|
const project = this.loadProjectConfigSync(projectJsonPath);
|
|
606
606
|
if (project) return project;
|
|
607
607
|
} catch {}
|
|
608
|
-
currentDir =
|
|
608
|
+
currentDir = path.dirname(currentDir);
|
|
609
609
|
}
|
|
610
610
|
return null;
|
|
611
611
|
}
|
|
@@ -618,8 +618,8 @@ var ProjectFinderService = class {
|
|
|
618
618
|
const content = await fs.readFile(projectJsonPath, "utf-8");
|
|
619
619
|
const config = JSON.parse(content);
|
|
620
620
|
const projectConfig = {
|
|
621
|
-
name: config.name ||
|
|
622
|
-
root:
|
|
621
|
+
name: config.name || path.basename(path.dirname(projectJsonPath)),
|
|
622
|
+
root: path.dirname(projectJsonPath),
|
|
623
623
|
sourceTemplate: config.sourceTemplate,
|
|
624
624
|
projectType: config.projectType
|
|
625
625
|
};
|
|
@@ -638,8 +638,8 @@ var ProjectFinderService = class {
|
|
|
638
638
|
const content = readFileSync$1(projectJsonPath, "utf-8");
|
|
639
639
|
const config = JSON.parse(content);
|
|
640
640
|
const projectConfig = {
|
|
641
|
-
name: config.name ||
|
|
642
|
-
root:
|
|
641
|
+
name: config.name || path.basename(path.dirname(projectJsonPath)),
|
|
642
|
+
root: path.dirname(projectJsonPath),
|
|
643
643
|
sourceTemplate: config.sourceTemplate,
|
|
644
644
|
projectType: config.projectType
|
|
645
645
|
};
|
|
@@ -699,7 +699,7 @@ var ScaffoldProcessingService = class {
|
|
|
699
699
|
* Now supports tracking existing files separately from created files
|
|
700
700
|
*/
|
|
701
701
|
async copyAndProcess(sourcePath, targetPath, variables, createdFiles, existingFiles) {
|
|
702
|
-
await this.fileSystem.ensureDir(
|
|
702
|
+
await this.fileSystem.ensureDir(path.dirname(targetPath));
|
|
703
703
|
if (await this.fileSystem.pathExists(targetPath) && existingFiles) {
|
|
704
704
|
await this.trackExistingFiles(targetPath, existingFiles);
|
|
705
705
|
return;
|
|
@@ -721,7 +721,7 @@ var ScaffoldProcessingService = class {
|
|
|
721
721
|
}
|
|
722
722
|
for (const item of items) {
|
|
723
723
|
if (!item) continue;
|
|
724
|
-
const itemPath =
|
|
724
|
+
const itemPath = path.join(dirPath, item);
|
|
725
725
|
try {
|
|
726
726
|
const stat$1 = await this.fileSystem.stat(itemPath);
|
|
727
727
|
if (stat$1.isDirectory()) await this.trackCreatedFilesRecursive(itemPath, createdFiles);
|
|
@@ -744,7 +744,7 @@ var ScaffoldProcessingService = class {
|
|
|
744
744
|
}
|
|
745
745
|
for (const item of items) {
|
|
746
746
|
if (!item) continue;
|
|
747
|
-
const itemPath =
|
|
747
|
+
const itemPath = path.join(dirPath, item);
|
|
748
748
|
try {
|
|
749
749
|
const stat$1 = await this.fileSystem.stat(itemPath);
|
|
750
750
|
if (stat$1.isDirectory()) await this.trackExistingFilesRecursive(itemPath, existingFiles);
|
|
@@ -892,12 +892,12 @@ async function gitInit(projectPath) {
|
|
|
892
892
|
* }
|
|
893
893
|
*/
|
|
894
894
|
async function findWorkspaceRoot(startPath = process.cwd()) {
|
|
895
|
-
let currentPath =
|
|
896
|
-
const rootPath =
|
|
895
|
+
let currentPath = path.resolve(startPath);
|
|
896
|
+
const rootPath = path.parse(currentPath).root;
|
|
897
897
|
while (true) {
|
|
898
|
-
if (await pathExists(
|
|
898
|
+
if (await pathExists(path.join(currentPath, ".git"))) return currentPath;
|
|
899
899
|
if (currentPath === rootPath) return null;
|
|
900
|
-
currentPath =
|
|
900
|
+
currentPath = path.dirname(currentPath);
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
/**
|
|
@@ -979,7 +979,7 @@ async function cloneSubdirectory(repoUrl, branch, subdirectory, targetFolder) {
|
|
|
979
979
|
"core.sparseCheckout",
|
|
980
980
|
"true"
|
|
981
981
|
], tempFolder);
|
|
982
|
-
await writeFile(
|
|
982
|
+
await writeFile(path.join(tempFolder, ".git", "info", "sparse-checkout"), `${subdirectory}\n`);
|
|
983
983
|
await execGit([
|
|
984
984
|
"pull",
|
|
985
985
|
"--depth=1",
|
|
@@ -987,7 +987,7 @@ async function cloneSubdirectory(repoUrl, branch, subdirectory, targetFolder) {
|
|
|
987
987
|
"--",
|
|
988
988
|
branch
|
|
989
989
|
], tempFolder);
|
|
990
|
-
const sourceDir =
|
|
990
|
+
const sourceDir = path.join(tempFolder, subdirectory);
|
|
991
991
|
if (!await pathExists(sourceDir)) throw new Error(`Subdirectory '${subdirectory}' not found in repository at branch '${branch}'`);
|
|
992
992
|
if (await pathExists(targetFolder)) throw new Error(`Target folder already exists: ${targetFolder}`);
|
|
993
993
|
await move(sourceDir, targetFolder);
|
|
@@ -1014,7 +1014,7 @@ async function cloneRepository(repoUrl, targetFolder) {
|
|
|
1014
1014
|
repoUrl,
|
|
1015
1015
|
targetFolder
|
|
1016
1016
|
]);
|
|
1017
|
-
const gitFolder =
|
|
1017
|
+
const gitFolder = path.join(targetFolder, ".git");
|
|
1018
1018
|
if (await pathExists(gitFolder)) await remove(gitFolder);
|
|
1019
1019
|
}
|
|
1020
1020
|
/**
|
|
@@ -1231,7 +1231,7 @@ const MONOREPO_INDICATOR_FILES = [
|
|
|
1231
1231
|
*/
|
|
1232
1232
|
async function detectProjectType(workspaceRoot) {
|
|
1233
1233
|
const indicators = [];
|
|
1234
|
-
const toolkitYamlPath =
|
|
1234
|
+
const toolkitYamlPath = path.join(workspaceRoot, "toolkit.yaml");
|
|
1235
1235
|
if (await pathExists(toolkitYamlPath)) try {
|
|
1236
1236
|
const content = await fs.readFile(toolkitYamlPath, "utf-8");
|
|
1237
1237
|
const config = yaml.load(content);
|
|
@@ -1243,14 +1243,14 @@ async function detectProjectType(workspaceRoot) {
|
|
|
1243
1243
|
};
|
|
1244
1244
|
}
|
|
1245
1245
|
} catch {}
|
|
1246
|
-
for (const filename of MONOREPO_INDICATOR_FILES) if (await pathExists(
|
|
1246
|
+
for (const filename of MONOREPO_INDICATOR_FILES) if (await pathExists(path.join(workspaceRoot, filename))) {
|
|
1247
1247
|
indicators.push(`${filename} found`);
|
|
1248
1248
|
return {
|
|
1249
1249
|
projectType: ProjectType.MONOREPO,
|
|
1250
1250
|
indicators
|
|
1251
1251
|
};
|
|
1252
1252
|
}
|
|
1253
|
-
const packageJsonPath =
|
|
1253
|
+
const packageJsonPath = path.join(workspaceRoot, "package.json");
|
|
1254
1254
|
if (await pathExists(packageJsonPath)) try {
|
|
1255
1255
|
if ((await readJson(packageJsonPath)).workspaces) {
|
|
1256
1256
|
indicators.push("package.json with workspaces found");
|
package/package.json
CHANGED