@agiflowai/aicode-utils 1.0.9 → 1.0.10

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 (2) hide show
  1. package/dist/index.mjs +51 -51
  2. 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 nodePath from "node:path";
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(nodePath.dirname(dest));
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
  }));
@@ -181,18 +181,18 @@ var TemplatesManagerService = class TemplatesManagerService {
181
181
  */
182
182
  static async findTemplatesPath(startPath = process.cwd()) {
183
183
  const workspaceRoot = await TemplatesManagerService.findWorkspaceRoot(startPath);
184
- const toolkitConfigPath = nodePath.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
184
+ const toolkitConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
185
185
  if (await pathExists(toolkitConfigPath)) {
186
186
  const yaml$1 = await import("js-yaml");
187
187
  const content = await fs.readFile(toolkitConfigPath, "utf-8");
188
188
  const config = yaml$1.load(content);
189
189
  if (config?.templatesPath) {
190
- const templatesPath$1 = nodePath.isAbsolute(config.templatesPath) ? config.templatesPath : nodePath.join(workspaceRoot, config.templatesPath);
190
+ const templatesPath$1 = path.isAbsolute(config.templatesPath) ? config.templatesPath : path.join(workspaceRoot, config.templatesPath);
191
191
  if (await pathExists(templatesPath$1)) return templatesPath$1;
192
192
  else return null;
193
193
  }
194
194
  }
195
- const templatesPath = nodePath.join(workspaceRoot, TemplatesManagerService.TEMPLATES_FOLDER);
195
+ const templatesPath = path.join(workspaceRoot, TemplatesManagerService.TEMPLATES_FOLDER);
196
196
  if (await pathExists(templatesPath)) return templatesPath;
197
197
  return null;
198
198
  }
@@ -200,12 +200,12 @@ var TemplatesManagerService = class TemplatesManagerService {
200
200
  * Find the workspace root by searching upwards for .git folder
201
201
  */
202
202
  static async findWorkspaceRoot(startPath) {
203
- let currentPath = nodePath.resolve(startPath);
204
- const rootPath = nodePath.parse(currentPath).root;
203
+ let currentPath = path.resolve(startPath);
204
+ const rootPath = path.parse(currentPath).root;
205
205
  while (true) {
206
- if (await pathExists(nodePath.join(currentPath, ".git"))) return currentPath;
206
+ if (await pathExists(path.join(currentPath, ".git"))) return currentPath;
207
207
  if (currentPath === rootPath) return process.cwd();
208
- currentPath = nodePath.dirname(currentPath);
208
+ currentPath = path.dirname(currentPath);
209
209
  }
210
210
  }
211
211
  /**
@@ -217,18 +217,18 @@ var TemplatesManagerService = class TemplatesManagerService {
217
217
  */
218
218
  static findTemplatesPathSync(startPath = process.cwd()) {
219
219
  const workspaceRoot = TemplatesManagerService.findWorkspaceRootSync(startPath);
220
- const toolkitConfigPath = nodePath.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
220
+ const toolkitConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
221
221
  if (pathExistsSync(toolkitConfigPath)) {
222
222
  const yaml$1 = __require("js-yaml");
223
223
  const content = readFileSync$1(toolkitConfigPath, "utf-8");
224
224
  const config = yaml$1.load(content);
225
225
  if (config?.templatesPath) {
226
- const templatesPath$1 = nodePath.isAbsolute(config.templatesPath) ? config.templatesPath : nodePath.join(workspaceRoot, config.templatesPath);
226
+ const templatesPath$1 = path.isAbsolute(config.templatesPath) ? config.templatesPath : path.join(workspaceRoot, config.templatesPath);
227
227
  if (pathExistsSync(templatesPath$1)) return templatesPath$1;
228
228
  else return null;
229
229
  }
230
230
  }
231
- const templatesPath = nodePath.join(workspaceRoot, TemplatesManagerService.TEMPLATES_FOLDER);
231
+ const templatesPath = path.join(workspaceRoot, TemplatesManagerService.TEMPLATES_FOLDER);
232
232
  if (pathExistsSync(templatesPath)) return templatesPath;
233
233
  return null;
234
234
  }
@@ -236,12 +236,12 @@ var TemplatesManagerService = class TemplatesManagerService {
236
236
  * Find the workspace root synchronously by searching upwards for .git folder
237
237
  */
238
238
  static findWorkspaceRootSync(startPath) {
239
- let currentPath = nodePath.resolve(startPath);
240
- const rootPath = nodePath.parse(currentPath).root;
239
+ let currentPath = path.resolve(startPath);
240
+ const rootPath = path.parse(currentPath).root;
241
241
  while (true) {
242
- if (pathExistsSync(nodePath.join(currentPath, ".git"))) return currentPath;
242
+ if (pathExistsSync(path.join(currentPath, ".git"))) return currentPath;
243
243
  if (currentPath === rootPath) return process.cwd();
244
- currentPath = nodePath.dirname(currentPath);
244
+ currentPath = path.dirname(currentPath);
245
245
  }
246
246
  }
247
247
  /**
@@ -274,7 +274,7 @@ var TemplatesManagerService = class TemplatesManagerService {
274
274
  */
275
275
  static async readToolkitConfig(startPath = process.cwd()) {
276
276
  const workspaceRoot = await TemplatesManagerService.findWorkspaceRoot(startPath);
277
- const toolkitConfigPath = nodePath.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
277
+ const toolkitConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
278
278
  if (!await pathExists(toolkitConfigPath)) return null;
279
279
  const yaml$1 = await import("js-yaml");
280
280
  const content = await fs.readFile(toolkitConfigPath, "utf-8");
@@ -288,7 +288,7 @@ var TemplatesManagerService = class TemplatesManagerService {
288
288
  */
289
289
  static readToolkitConfigSync(startPath = process.cwd()) {
290
290
  const workspaceRoot = TemplatesManagerService.findWorkspaceRootSync(startPath);
291
- const toolkitConfigPath = nodePath.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
291
+ const toolkitConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
292
292
  if (!pathExistsSync(toolkitConfigPath)) return null;
293
293
  const yaml$1 = __require("js-yaml");
294
294
  const content = readFileSync$1(toolkitConfigPath, "utf-8");
@@ -302,7 +302,7 @@ var TemplatesManagerService = class TemplatesManagerService {
302
302
  */
303
303
  static async writeToolkitConfig(config, startPath = process.cwd()) {
304
304
  const workspaceRoot = await TemplatesManagerService.findWorkspaceRoot(startPath);
305
- const toolkitConfigPath = nodePath.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
305
+ const toolkitConfigPath = path.join(workspaceRoot, TemplatesManagerService.TOOLKIT_CONFIG_FILE);
306
306
  const content = (await import("js-yaml")).dump(config, { indent: 2 });
307
307
  await fs.writeFile(toolkitConfigPath, content, "utf-8");
308
308
  }
@@ -373,13 +373,13 @@ var ProjectConfigResolver = class ProjectConfigResolver {
373
373
  */
374
374
  static async resolveProjectConfig(projectPath, explicitTemplate) {
375
375
  try {
376
- const absolutePath = nodePath.resolve(projectPath);
376
+ const absolutePath = path.resolve(projectPath);
377
377
  if (explicitTemplate) return {
378
378
  type: ProjectType.MONOLITH,
379
379
  sourceTemplate: explicitTemplate,
380
380
  configSource: ConfigSource.TOOLKIT_YAML
381
381
  };
382
- const projectJsonPath = nodePath.join(absolutePath, "project.json");
382
+ const projectJsonPath = path.join(absolutePath, "project.json");
383
383
  if (await pathExists(projectJsonPath)) {
384
384
  const projectJson = await readJson(projectJsonPath);
385
385
  if (projectJson.sourceTemplate && typeof projectJson.sourceTemplate === "string" && projectJson.sourceTemplate.trim()) return {
@@ -470,12 +470,12 @@ Run 'scaffold-mcp scaffold list --help' for more info.`;
470
470
  * @param sourceTemplate - The template identifier
471
471
  */
472
472
  static async createProjectJson(projectPath, projectName, sourceTemplate) {
473
- const projectJsonPath = nodePath.join(projectPath, "project.json");
473
+ const projectJsonPath = path.join(projectPath, "project.json");
474
474
  try {
475
475
  let projectJson;
476
476
  if (await pathExists(projectJsonPath)) projectJson = await readJson(projectJsonPath);
477
477
  else {
478
- const relativePath = nodePath.relative(projectPath, process.cwd());
478
+ const relativePath = path.relative(projectPath, process.cwd());
479
479
  projectJson = {
480
480
  name: projectName,
481
481
  $schema: relativePath ? `${relativePath}/node_modules/nx/schemas/project-schema.json` : "node_modules/nx/schemas/project-schema.json",
@@ -527,15 +527,15 @@ var ProjectFinderService = class {
527
527
  * @returns Project configuration or null if not found
528
528
  */
529
529
  async findProjectForFile(filePath) {
530
- const normalizedPath = nodePath.isAbsolute(filePath) ? filePath : nodePath.join(this.workspaceRoot, filePath);
531
- let currentDir = nodePath.dirname(normalizedPath);
530
+ const normalizedPath = path.isAbsolute(filePath) ? filePath : path.join(this.workspaceRoot, filePath);
531
+ let currentDir = path.dirname(normalizedPath);
532
532
  while (currentDir !== "/" && currentDir.startsWith(this.workspaceRoot)) {
533
- const projectJsonPath = nodePath.join(currentDir, "project.json");
533
+ const projectJsonPath = path.join(currentDir, "project.json");
534
534
  try {
535
535
  const project = await this.loadProjectConfig(projectJsonPath);
536
536
  if (project) return project;
537
537
  } catch {}
538
- currentDir = nodePath.dirname(currentDir);
538
+ currentDir = path.dirname(currentDir);
539
539
  }
540
540
  return null;
541
541
  }
@@ -546,15 +546,15 @@ var ProjectFinderService = class {
546
546
  * @returns Project configuration or null if not found
547
547
  */
548
548
  findProjectForFileSync(filePath) {
549
- const normalizedPath = nodePath.isAbsolute(filePath) ? filePath : nodePath.join(this.workspaceRoot, filePath);
550
- let currentDir = nodePath.dirname(normalizedPath);
549
+ const normalizedPath = path.isAbsolute(filePath) ? filePath : path.join(this.workspaceRoot, filePath);
550
+ let currentDir = path.dirname(normalizedPath);
551
551
  while (currentDir !== "/" && currentDir.startsWith(this.workspaceRoot)) {
552
- const projectJsonPath = nodePath.join(currentDir, "project.json");
552
+ const projectJsonPath = path.join(currentDir, "project.json");
553
553
  try {
554
554
  const project = this.loadProjectConfigSync(projectJsonPath);
555
555
  if (project) return project;
556
556
  } catch {}
557
- currentDir = nodePath.dirname(currentDir);
557
+ currentDir = path.dirname(currentDir);
558
558
  }
559
559
  return null;
560
560
  }
@@ -567,8 +567,8 @@ var ProjectFinderService = class {
567
567
  const content = await fs.readFile(projectJsonPath, "utf-8");
568
568
  const config = JSON.parse(content);
569
569
  const projectConfig = {
570
- name: config.name || nodePath.basename(nodePath.dirname(projectJsonPath)),
571
- root: nodePath.dirname(projectJsonPath),
570
+ name: config.name || path.basename(path.dirname(projectJsonPath)),
571
+ root: path.dirname(projectJsonPath),
572
572
  sourceTemplate: config.sourceTemplate,
573
573
  projectType: config.projectType
574
574
  };
@@ -587,8 +587,8 @@ var ProjectFinderService = class {
587
587
  const content = readFileSync$1(projectJsonPath, "utf-8");
588
588
  const config = JSON.parse(content);
589
589
  const projectConfig = {
590
- name: config.name || nodePath.basename(nodePath.dirname(projectJsonPath)),
591
- root: nodePath.dirname(projectJsonPath),
590
+ name: config.name || path.basename(path.dirname(projectJsonPath)),
591
+ root: path.dirname(projectJsonPath),
592
592
  sourceTemplate: config.sourceTemplate,
593
593
  projectType: config.projectType
594
594
  };
@@ -648,7 +648,7 @@ var ScaffoldProcessingService = class {
648
648
  * Now supports tracking existing files separately from created files
649
649
  */
650
650
  async copyAndProcess(sourcePath, targetPath, variables, createdFiles, existingFiles) {
651
- await this.fileSystem.ensureDir(nodePath.dirname(targetPath));
651
+ await this.fileSystem.ensureDir(path.dirname(targetPath));
652
652
  if (await this.fileSystem.pathExists(targetPath) && existingFiles) {
653
653
  await this.trackExistingFiles(targetPath, existingFiles);
654
654
  return;
@@ -670,7 +670,7 @@ var ScaffoldProcessingService = class {
670
670
  }
671
671
  for (const item of items) {
672
672
  if (!item) continue;
673
- const itemPath = nodePath.join(dirPath, item);
673
+ const itemPath = path.join(dirPath, item);
674
674
  try {
675
675
  const stat$1 = await this.fileSystem.stat(itemPath);
676
676
  if (stat$1.isDirectory()) await this.trackCreatedFilesRecursive(itemPath, createdFiles);
@@ -693,7 +693,7 @@ var ScaffoldProcessingService = class {
693
693
  }
694
694
  for (const item of items) {
695
695
  if (!item) continue;
696
- const itemPath = nodePath.join(dirPath, item);
696
+ const itemPath = path.join(dirPath, item);
697
697
  try {
698
698
  const stat$1 = await this.fileSystem.stat(itemPath);
699
699
  if (stat$1.isDirectory()) await this.trackExistingFilesRecursive(itemPath, existingFiles);
@@ -820,12 +820,12 @@ async function gitInit(projectPath) {
820
820
  * }
821
821
  */
822
822
  async function findWorkspaceRoot(startPath = process.cwd()) {
823
- let currentPath = nodePath.resolve(startPath);
824
- const rootPath = nodePath.parse(currentPath).root;
823
+ let currentPath = path.resolve(startPath);
824
+ const rootPath = path.parse(currentPath).root;
825
825
  while (true) {
826
- if (await pathExists(nodePath.join(currentPath, ".git"))) return currentPath;
826
+ if (await pathExists(path.join(currentPath, ".git"))) return currentPath;
827
827
  if (currentPath === rootPath) return null;
828
- currentPath = nodePath.dirname(currentPath);
828
+ currentPath = path.dirname(currentPath);
829
829
  }
830
830
  }
831
831
  /**
@@ -907,7 +907,7 @@ async function cloneSubdirectory(repoUrl, branch, subdirectory, targetFolder) {
907
907
  "core.sparseCheckout",
908
908
  "true"
909
909
  ], tempFolder);
910
- await writeFile(nodePath.join(tempFolder, ".git", "info", "sparse-checkout"), `${subdirectory}\n`);
910
+ await writeFile(path.join(tempFolder, ".git", "info", "sparse-checkout"), `${subdirectory}\n`);
911
911
  await execGit([
912
912
  "pull",
913
913
  "--depth=1",
@@ -915,7 +915,7 @@ async function cloneSubdirectory(repoUrl, branch, subdirectory, targetFolder) {
915
915
  "--",
916
916
  branch
917
917
  ], tempFolder);
918
- const sourceDir = nodePath.join(tempFolder, subdirectory);
918
+ const sourceDir = path.join(tempFolder, subdirectory);
919
919
  if (!await pathExists(sourceDir)) throw new Error(`Subdirectory '${subdirectory}' not found in repository at branch '${branch}'`);
920
920
  if (await pathExists(targetFolder)) throw new Error(`Target folder already exists: ${targetFolder}`);
921
921
  await move(sourceDir, targetFolder);
@@ -942,7 +942,7 @@ async function cloneRepository(repoUrl, targetFolder) {
942
942
  repoUrl,
943
943
  targetFolder
944
944
  ]);
945
- const gitFolder = nodePath.join(targetFolder, ".git");
945
+ const gitFolder = path.join(targetFolder, ".git");
946
946
  if (await pathExists(gitFolder)) await remove(gitFolder);
947
947
  }
948
948
  /**
@@ -1159,7 +1159,7 @@ const MONOREPO_INDICATOR_FILES = [
1159
1159
  */
1160
1160
  async function detectProjectType(workspaceRoot) {
1161
1161
  const indicators = [];
1162
- const toolkitYamlPath = nodePath.join(workspaceRoot, "toolkit.yaml");
1162
+ const toolkitYamlPath = path.join(workspaceRoot, "toolkit.yaml");
1163
1163
  if (await pathExists(toolkitYamlPath)) try {
1164
1164
  const content = await fs.readFile(toolkitYamlPath, "utf-8");
1165
1165
  const config = yaml.load(content);
@@ -1171,14 +1171,14 @@ async function detectProjectType(workspaceRoot) {
1171
1171
  };
1172
1172
  }
1173
1173
  } catch {}
1174
- for (const filename of MONOREPO_INDICATOR_FILES) if (await pathExists(nodePath.join(workspaceRoot, filename))) {
1174
+ for (const filename of MONOREPO_INDICATOR_FILES) if (await pathExists(path.join(workspaceRoot, filename))) {
1175
1175
  indicators.push(`${filename} found`);
1176
1176
  return {
1177
1177
  projectType: ProjectType.MONOREPO,
1178
1178
  indicators
1179
1179
  };
1180
1180
  }
1181
- const packageJsonPath = nodePath.join(workspaceRoot, "package.json");
1181
+ const packageJsonPath = path.join(workspaceRoot, "package.json");
1182
1182
  if (await pathExists(packageJsonPath)) try {
1183
1183
  if ((await readJson(packageJsonPath)).workspaces) {
1184
1184
  indicators.push("package.json with workspaces found");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agiflowai/aicode-utils",
3
3
  "description": "Shared utilities and types for AI-powered code generation, scaffolding, and analysis",
4
- "version": "1.0.9",
4
+ "version": "1.0.10",
5
5
  "license": "AGPL-3.0",
6
6
  "author": "AgiflowIO",
7
7
  "repository": {