@agiflowai/aicode-utils 1.0.7 → 1.0.9
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.cjs +276 -70
- package/dist/index.d.cts +129 -47
- package/dist/index.d.mts +129 -47
- package/dist/index.mjs +304 -92
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -267,10 +267,9 @@ declare class TemplatesManagerService {
|
|
|
267
267
|
* 4. Verify the templates directory exists
|
|
268
268
|
*
|
|
269
269
|
* @param startPath - The path to start searching from (defaults to process.cwd())
|
|
270
|
-
* @returns The absolute path to the templates directory
|
|
271
|
-
* @throws Error if templates directory is not found
|
|
270
|
+
* @returns The absolute path to the templates directory, or null if not found
|
|
272
271
|
*/
|
|
273
|
-
static findTemplatesPath(startPath?: string): Promise<string>;
|
|
272
|
+
static findTemplatesPath(startPath?: string): Promise<string | null>;
|
|
274
273
|
/**
|
|
275
274
|
* Find the workspace root by searching upwards for .git folder
|
|
276
275
|
*/
|
|
@@ -280,10 +279,9 @@ declare class TemplatesManagerService {
|
|
|
280
279
|
* Use this when you need immediate access and are sure templates exist.
|
|
281
280
|
*
|
|
282
281
|
* @param startPath - The path to start searching from (defaults to process.cwd())
|
|
283
|
-
* @returns The absolute path to the templates directory
|
|
284
|
-
* @throws Error if templates directory is not found
|
|
282
|
+
* @returns The absolute path to the templates directory, or null if not found
|
|
285
283
|
*/
|
|
286
|
-
static findTemplatesPathSync(startPath?: string): string;
|
|
284
|
+
static findTemplatesPathSync(startPath?: string): string | null;
|
|
287
285
|
/**
|
|
288
286
|
* Find the workspace root synchronously by searching upwards for .git folder
|
|
289
287
|
*/
|
|
@@ -353,10 +351,6 @@ declare function pathExistsSync(filePath: string): boolean;
|
|
|
353
351
|
* Ensure a directory exists, creating it recursively if needed
|
|
354
352
|
*/
|
|
355
353
|
declare function ensureDir(dirPath: string): Promise<void>;
|
|
356
|
-
/**
|
|
357
|
-
* Ensure a directory exists (sync), creating it recursively if needed
|
|
358
|
-
*/
|
|
359
|
-
declare function ensureDirSync(dirPath: string): void;
|
|
360
354
|
/**
|
|
361
355
|
* Remove a file or directory recursively
|
|
362
356
|
*/
|
|
@@ -377,31 +371,11 @@ declare function readJson<T = unknown>(filePath: string): Promise<T>;
|
|
|
377
371
|
* Read and parse a JSON file (sync)
|
|
378
372
|
*/
|
|
379
373
|
declare function readJsonSync<T = unknown>(filePath: string): T;
|
|
380
|
-
/**
|
|
381
|
-
* Write an object as JSON to a file
|
|
382
|
-
*/
|
|
383
|
-
declare function writeJson(filePath: string, data: unknown, options?: {
|
|
384
|
-
spaces?: number;
|
|
385
|
-
}): Promise<void>;
|
|
386
|
-
/**
|
|
387
|
-
* Write an object as JSON to a file (sync)
|
|
388
|
-
*/
|
|
389
|
-
declare function writeJsonSync(filePath: string, data: unknown, options?: {
|
|
390
|
-
spaces?: number;
|
|
391
|
-
}): void;
|
|
392
|
-
/**
|
|
393
|
-
* Output file - writes content ensuring directory exists
|
|
394
|
-
*/
|
|
395
|
-
declare function outputFile(filePath: string, content: string): Promise<void>;
|
|
396
374
|
declare const readFile: typeof fs.readFile;
|
|
397
375
|
declare const writeFile: typeof fs.writeFile;
|
|
398
376
|
declare const readdir: typeof fs.readdir;
|
|
399
377
|
declare const mkdir: typeof fs.mkdir;
|
|
400
378
|
declare const stat: typeof fs.stat;
|
|
401
|
-
declare const unlink: typeof fs.unlink;
|
|
402
|
-
declare const rename: typeof fs.rename;
|
|
403
|
-
declare const rm: typeof fs.rm;
|
|
404
|
-
declare const cp: typeof fs.cp;
|
|
405
379
|
//#endregion
|
|
406
380
|
//#region src/utils/generateStableId.d.ts
|
|
407
381
|
/**
|
|
@@ -421,6 +395,130 @@ declare const cp: typeof fs.cp;
|
|
|
421
395
|
*/
|
|
422
396
|
declare function generateStableId(length?: number): string;
|
|
423
397
|
//#endregion
|
|
398
|
+
//#region src/utils/git.d.ts
|
|
399
|
+
/**
|
|
400
|
+
* Git Utilities
|
|
401
|
+
*
|
|
402
|
+
* DESIGN PATTERNS:
|
|
403
|
+
* - Safe command execution: Use execa with array arguments to prevent shell injection
|
|
404
|
+
* - Defense in depth: Use '--' separator to prevent option injection attacks
|
|
405
|
+
*
|
|
406
|
+
* CODING STANDARDS:
|
|
407
|
+
* - All git commands must use execGit helper with array arguments
|
|
408
|
+
* - Use '--' separator before user-provided arguments (URLs, branches, paths)
|
|
409
|
+
* - Validate inputs where appropriate
|
|
410
|
+
*
|
|
411
|
+
* AVOID:
|
|
412
|
+
* - Shell string interpolation
|
|
413
|
+
* - Passing unsanitized user input as command options
|
|
414
|
+
*
|
|
415
|
+
* NOTE: These utilities perform I/O operations (git commands, file system) by necessity.
|
|
416
|
+
* Pure utility functions like parseGitHubUrl are side-effect free.
|
|
417
|
+
*/
|
|
418
|
+
/**
|
|
419
|
+
* Parsed GitHub URL result
|
|
420
|
+
*/
|
|
421
|
+
interface ParsedGitHubUrl {
|
|
422
|
+
owner?: string;
|
|
423
|
+
repo?: string;
|
|
424
|
+
repoUrl: string;
|
|
425
|
+
branch?: string;
|
|
426
|
+
subdirectory?: string;
|
|
427
|
+
isSubdirectory: boolean;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* GitHub directory entry
|
|
431
|
+
*/
|
|
432
|
+
interface GitHubDirectoryEntry {
|
|
433
|
+
name: string;
|
|
434
|
+
type: string;
|
|
435
|
+
path: string;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Execute git init safely using execa to prevent command injection
|
|
439
|
+
* Uses '--' to prevent projectPath from being interpreted as an option
|
|
440
|
+
* @param projectPath - Path where to initialize the git repository
|
|
441
|
+
* @throws Error when git init fails
|
|
442
|
+
*/
|
|
443
|
+
declare function gitInit(projectPath: string): Promise<void>;
|
|
444
|
+
/**
|
|
445
|
+
* Find the workspace root by searching upwards for .git folder
|
|
446
|
+
* Returns null if no .git folder is found (indicating a new project setup is needed)
|
|
447
|
+
* @param startPath - The path to start searching from (default: current working directory)
|
|
448
|
+
* @returns The workspace root path or null if not in a git repository
|
|
449
|
+
* @example
|
|
450
|
+
* const root = await findWorkspaceRoot('/path/to/project/src');
|
|
451
|
+
* if (root) {
|
|
452
|
+
* console.log('Workspace root:', root);
|
|
453
|
+
* } else {
|
|
454
|
+
* console.log('No git repository found');
|
|
455
|
+
* }
|
|
456
|
+
*/
|
|
457
|
+
declare function findWorkspaceRoot(startPath?: string): Promise<string | null>;
|
|
458
|
+
/**
|
|
459
|
+
* Parse GitHub URL to detect if it's a subdirectory
|
|
460
|
+
* Supports formats:
|
|
461
|
+
* - https://github.com/user/repo
|
|
462
|
+
* - https://github.com/user/repo/tree/branch/path/to/dir
|
|
463
|
+
* - https://github.com/user/repo/tree/main/path/to/dir
|
|
464
|
+
* @param url - The GitHub URL to parse
|
|
465
|
+
* @returns Parsed URL components including owner, repo, branch, and subdirectory
|
|
466
|
+
* @example
|
|
467
|
+
* const result = parseGitHubUrl('https://github.com/user/repo/tree/main/src');
|
|
468
|
+
* // result.owner === 'user'
|
|
469
|
+
* // result.repo === 'repo'
|
|
470
|
+
* // result.branch === 'main'
|
|
471
|
+
* // result.subdirectory === 'src'
|
|
472
|
+
* // result.isSubdirectory === true
|
|
473
|
+
*/
|
|
474
|
+
declare function parseGitHubUrl(url: string): ParsedGitHubUrl;
|
|
475
|
+
/**
|
|
476
|
+
* Clone a subdirectory from a git repository using sparse checkout
|
|
477
|
+
* Uses '--' to mark end of options - prevents malicious URLs like '--upload-pack=evil'
|
|
478
|
+
* from being interpreted as git options
|
|
479
|
+
* @param repoUrl - The git repository URL
|
|
480
|
+
* @param branch - The branch to clone from
|
|
481
|
+
* @param subdirectory - The subdirectory path within the repository
|
|
482
|
+
* @param targetFolder - The local folder to clone into
|
|
483
|
+
* @throws Error if subdirectory not found or target folder already exists
|
|
484
|
+
* @example
|
|
485
|
+
* await cloneSubdirectory(
|
|
486
|
+
* 'https://github.com/user/repo.git',
|
|
487
|
+
* 'main',
|
|
488
|
+
* 'packages/core',
|
|
489
|
+
* './my-project'
|
|
490
|
+
* );
|
|
491
|
+
*/
|
|
492
|
+
declare function cloneSubdirectory(repoUrl: string, branch: string, subdirectory: string, targetFolder: string): Promise<void>;
|
|
493
|
+
/**
|
|
494
|
+
* Clone entire repository
|
|
495
|
+
* Uses '--' to mark end of options - prevents malicious URLs like '--upload-pack=evil'
|
|
496
|
+
* from being interpreted as git options
|
|
497
|
+
* @param repoUrl - The git repository URL to clone
|
|
498
|
+
* @param targetFolder - The local folder path to clone into
|
|
499
|
+
* @throws Error if git clone fails
|
|
500
|
+
* @example
|
|
501
|
+
* await cloneRepository('https://github.com/user/repo.git', './my-project');
|
|
502
|
+
*/
|
|
503
|
+
declare function cloneRepository(repoUrl: string, targetFolder: string): Promise<void>;
|
|
504
|
+
/**
|
|
505
|
+
* Fetch directory listing from GitHub API
|
|
506
|
+
* @param owner - The GitHub repository owner/organization
|
|
507
|
+
* @param repo - The repository name
|
|
508
|
+
* @param dirPath - The directory path within the repository
|
|
509
|
+
* @param branch - The branch to fetch from (default: 'main')
|
|
510
|
+
* @returns Array of directory entries with name, type, and path
|
|
511
|
+
* @throws Error if the API request fails or returns non-directory content
|
|
512
|
+
* @remarks
|
|
513
|
+
* - Requires network access to GitHub API
|
|
514
|
+
* - Subject to GitHub API rate limits (60 requests/hour unauthenticated)
|
|
515
|
+
* - Only works with public repositories without authentication
|
|
516
|
+
* @example
|
|
517
|
+
* const contents = await fetchGitHubDirectoryContents('facebook', 'react', 'packages', 'main');
|
|
518
|
+
* // contents: [{ name: 'react', type: 'dir', path: 'packages/react' }, ...]
|
|
519
|
+
*/
|
|
520
|
+
declare function fetchGitHubDirectoryContents(owner: string, repo: string, dirPath: string, branch?: string): Promise<GitHubDirectoryEntry[]>;
|
|
521
|
+
//#endregion
|
|
424
522
|
//#region src/utils/logger.d.ts
|
|
425
523
|
declare const logger: pino.Logger<never, boolean>;
|
|
426
524
|
declare const log: {
|
|
@@ -581,21 +679,5 @@ interface ProjectTypeDetectionResult {
|
|
|
581
679
|
* @returns Detection result with project type and indicators
|
|
582
680
|
*/
|
|
583
681
|
declare function detectProjectType(workspaceRoot: string): Promise<ProjectTypeDetectionResult>;
|
|
584
|
-
/**
|
|
585
|
-
* Check if a workspace is a monorepo
|
|
586
|
-
* Convenience function that returns a boolean
|
|
587
|
-
*
|
|
588
|
-
* @param workspaceRoot - Absolute path to the workspace root directory
|
|
589
|
-
* @returns True if workspace is detected as monorepo, false otherwise
|
|
590
|
-
*/
|
|
591
|
-
declare function isMonorepo(workspaceRoot: string): Promise<boolean>;
|
|
592
|
-
/**
|
|
593
|
-
* Check if a workspace is a monolith
|
|
594
|
-
* Convenience function that returns a boolean
|
|
595
|
-
*
|
|
596
|
-
* @param workspaceRoot - Absolute path to the workspace root directory
|
|
597
|
-
* @returns True if workspace is detected as monolith, false otherwise
|
|
598
|
-
*/
|
|
599
|
-
declare function isMonolith(workspaceRoot: string): Promise<boolean>;
|
|
600
682
|
//#endregion
|
|
601
|
-
export { ConfigSource, GeneratorContext, GeneratorFunction, IFileSystemService, IVariableReplacementService, NxProjectJson, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType,
|
|
683
|
+
export { ConfigSource, GeneratorContext, GeneratorFunction, type GitHubDirectoryEntry, IFileSystemService, IVariableReplacementService, NxProjectJson, type ParsedGitHubUrl, ParsedInclude, ProjectConfig, ProjectConfigResolver, ProjectConfigResult, ProjectFinderService, ProjectType, ScaffoldProcessingService, ScaffoldResult, TemplatesManagerService, ToolkitConfig, accessSync, cloneRepository, cloneSubdirectory, copy, detectProjectType, ensureDir, fetchGitHubDirectoryContents, findWorkspaceRoot, generateStableId, gitInit, icons, log, logger, messages, mkdir, mkdirSync, move, parseGitHubUrl, pathExists, pathExistsSync, print, readFile, readFileSync, readJson, readJsonSync, readdir, remove, sections, stat, statSync, writeFile, writeFileSync };
|