yargs-file-commands 0.0.9 → 0.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.
|
@@ -1,23 +1,18 @@
|
|
|
1
|
+
import { type ScanDirectoryOptions } from './scanDirectory.js';
|
|
1
2
|
/**
|
|
2
3
|
* Configuration options for file-based command generation
|
|
3
4
|
* @interface FileCommandsOptions
|
|
4
5
|
*/
|
|
5
|
-
export type FileCommandsOptions = {
|
|
6
|
+
export type FileCommandsOptions = ScanDirectoryOptions & {
|
|
6
7
|
/** Array of directory paths to scan for command files */
|
|
7
8
|
commandDirs: string[];
|
|
8
|
-
/** File extensions to consider when scanning for command files */
|
|
9
|
-
extensions?: string[];
|
|
10
|
-
/** Regular expressions for patterns to ignore when scanning directories */
|
|
11
|
-
ignorePatterns?: RegExp[];
|
|
12
|
-
/** Logging verbosity level */
|
|
13
|
-
logLevel?: 'info' | 'debug';
|
|
14
9
|
};
|
|
15
10
|
/**
|
|
16
11
|
* Default configuration options for file-based commands
|
|
17
12
|
* @constant
|
|
18
13
|
* @type {Partial<FileCommandsOptions>}
|
|
19
14
|
*/
|
|
20
|
-
export declare const DefaultFileCommandsOptions:
|
|
15
|
+
export declare const DefaultFileCommandsOptions: Required<FileCommandsOptions>;
|
|
21
16
|
/**
|
|
22
17
|
* Generates a command tree structure from files in specified directories
|
|
23
18
|
* @async
|
package/dist/lib/fileCommands.js
CHANGED
|
@@ -9,6 +9,8 @@ import { segmentPath } from './segmentPath.js';
|
|
|
9
9
|
* @type {Partial<FileCommandsOptions>}
|
|
10
10
|
*/
|
|
11
11
|
export const DefaultFileCommandsOptions = {
|
|
12
|
+
/** Default directories to scan for command files */
|
|
13
|
+
commandDirs: [],
|
|
12
14
|
/** Default file extensions to process */
|
|
13
15
|
extensions: ['.js', '.ts'],
|
|
14
16
|
/** Default patterns to ignore when scanning directories */
|
|
@@ -19,7 +21,9 @@ export const DefaultFileCommandsOptions = {
|
|
|
19
21
|
/\.d\.ts$/ // TypeScript declaration files
|
|
20
22
|
],
|
|
21
23
|
/** Default logging level */
|
|
22
|
-
logLevel: 'info'
|
|
24
|
+
logLevel: 'info',
|
|
25
|
+
/** Default log prefix */
|
|
26
|
+
logPrefix: ' '
|
|
23
27
|
};
|
|
24
28
|
/**
|
|
25
29
|
* Generates a command tree structure from files in specified directories
|
|
@@ -41,9 +45,16 @@ export const DefaultFileCommandsOptions = {
|
|
|
41
45
|
export const fileCommands = async (options) => {
|
|
42
46
|
const fullOptions = {
|
|
43
47
|
...DefaultFileCommandsOptions,
|
|
44
|
-
...options
|
|
45
|
-
logPrefix: ' '
|
|
48
|
+
...options
|
|
46
49
|
};
|
|
50
|
+
// validate extensions have dots in them
|
|
51
|
+
if (fullOptions.extensions.some((ext) => !ext.startsWith('.'))) {
|
|
52
|
+
throw new Error(`Invalid extensions provided, must start with a dot: ${fullOptions.extensions.join(', ')}`);
|
|
53
|
+
}
|
|
54
|
+
// check for empty list of directories to scan
|
|
55
|
+
if (fullOptions.commandDirs.length === 0) {
|
|
56
|
+
throw new Error('No command directories provided');
|
|
57
|
+
}
|
|
47
58
|
const commands = [];
|
|
48
59
|
for (const commandDir of fullOptions.commandDirs) {
|
|
49
60
|
const fullPath = path.resolve(commandDir);
|
|
@@ -59,6 +70,10 @@ export const fileCommands = async (options) => {
|
|
|
59
70
|
});
|
|
60
71
|
}
|
|
61
72
|
}
|
|
73
|
+
// check if no commands were found
|
|
74
|
+
if (commands.length === 0) {
|
|
75
|
+
throw new Error(`No commands found in specified directories: ${fullOptions.commandDirs.join(', ')}`);
|
|
76
|
+
}
|
|
62
77
|
const commandRootNodes = buildSegmentTree(commands);
|
|
63
78
|
if (fullOptions.logLevel === 'debug') {
|
|
64
79
|
console.debug('Command tree structure:');
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* @interface ScanDirectoryOptions
|
|
4
4
|
*/
|
|
5
5
|
export interface ScanDirectoryOptions {
|
|
6
|
-
/**
|
|
7
|
-
ignorePatterns?: RegExp[];
|
|
8
|
-
/** File extensions to include in the scan */
|
|
6
|
+
/** File extensions to consider when scanning for command files */
|
|
9
7
|
extensions?: string[];
|
|
8
|
+
/** Regular expressions for patterns to ignore when scanning directories */
|
|
9
|
+
ignorePatterns?: RegExp[];
|
|
10
|
+
/** Logging verbosity level */
|
|
10
11
|
logLevel?: 'info' | 'debug';
|
|
12
|
+
/** Prefix for log messages */
|
|
11
13
|
logPrefix?: string;
|
|
12
14
|
}
|
|
13
15
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs-file-commands",
|
|
3
3
|
"description": "A yargs helper function that lets you define your commands structure via directory and file naming conventions.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|