yargs-file-commands 0.0.20 → 1.0.1
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/README.md +13 -13
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/Command.js +1 -0
- package/dist/lib/Command.js.map +1 -0
- package/dist/lib/buildSegmentTree.d.ts +1 -1
- package/dist/lib/buildSegmentTree.js +7 -3
- package/dist/lib/buildSegmentTree.js.map +1 -0
- package/dist/lib/buildSegmentTree.test.js +279 -26
- package/dist/lib/buildSegmentTree.test.js.map +1 -0
- package/dist/lib/fileCommands.d.ts +2 -1
- package/dist/lib/fileCommands.js +39 -21
- package/dist/lib/fileCommands.js.map +1 -0
- package/dist/lib/fileCommands.test.js +107 -30
- package/dist/lib/fileCommands.test.js.map +1 -0
- package/dist/lib/fixtures/commands/$default.js +1 -0
- package/dist/lib/fixtures/commands/$default.js.map +1 -0
- package/dist/lib/fixtures/commands/create.js +1 -0
- package/dist/lib/fixtures/commands/create.js.map +1 -0
- package/dist/lib/fixtures/commands/db/health.d.ts +2 -1
- package/dist/lib/fixtures/commands/db/health.js +2 -3
- package/dist/lib/fixtures/commands/db/health.js.map +1 -0
- package/dist/lib/fixtures/commands/db/migration/command.d.ts +9 -2
- package/dist/lib/fixtures/commands/db/migration/command.js +6 -7
- package/dist/lib/fixtures/commands/db/migration/command.js.map +1 -0
- package/dist/lib/importCommand.d.ts +3 -3
- package/dist/lib/importCommand.js +39 -27
- package/dist/lib/importCommand.js.map +1 -0
- package/dist/lib/importCommand.test.js +157 -33
- package/dist/lib/importCommand.test.js.map +1 -0
- package/dist/lib/scanDirectory.js +54 -25
- package/dist/lib/scanDirectory.js.map +1 -0
- package/dist/lib/scanDirectory.test.js +148 -25
- package/dist/lib/scanDirectory.test.js.map +1 -0
- package/dist/lib/segmentPath.js +8 -6
- package/dist/lib/segmentPath.js.map +1 -0
- package/dist/lib/segmentPath.test.js +10 -38
- package/dist/lib/segmentPath.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +6 -9
- package/CHANGELOG.md +0 -62
- package/src/index.ts +0 -1
- package/src/lib/Command.ts +0 -16
- package/src/lib/buildSegmentTree.test.ts +0 -90
- package/src/lib/buildSegmentTree.ts +0 -149
- package/src/lib/fileCommands.test.ts +0 -55
- package/src/lib/fileCommands.ts +0 -149
- package/src/lib/fixtures/commands/$default.ts +0 -5
- package/src/lib/fixtures/commands/create.ts +0 -6
- package/src/lib/fixtures/commands/db/health.ts +0 -9
- package/src/lib/fixtures/commands/db/migration/command.ts +0 -12
- package/src/lib/importCommand.test.ts +0 -60
- package/src/lib/importCommand.ts +0 -196
- package/src/lib/scanDirectory.test.ts +0 -75
- package/src/lib/scanDirectory.ts +0 -109
- package/src/lib/segmentPath.test.ts +0 -71
- package/src/lib/segmentPath.ts +0 -38
package/src/lib/segmentPath.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a file path into an array of command segments
|
|
3
|
-
* @param {string} fullPath - The complete file system path to the command file
|
|
4
|
-
* @param {string} baseDir - The base directory to make the path relative to
|
|
5
|
-
* @returns {string[]} Array of segments representing the command hierarchy
|
|
6
|
-
*
|
|
7
|
-
* @description
|
|
8
|
-
* This function processes a file path into command segments by:
|
|
9
|
-
* 1. Making the path relative to the base directory
|
|
10
|
-
* 2. Splitting on directory separators
|
|
11
|
-
* 3. Removing file extensions
|
|
12
|
-
* 4. Splitting on dots for nested commands
|
|
13
|
-
* 5. Filtering out empty segments and 'command' keyword
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* segmentPath('/base/dir/hello/world.command.ts', '/base/dir')
|
|
17
|
-
* // Returns: ['hello', 'world']
|
|
18
|
-
*/
|
|
19
|
-
export const segmentPath = (fullPath: string, baseDir: string): string[] => {
|
|
20
|
-
// Remove base directory and normalize slashes
|
|
21
|
-
const relativePath = fullPath.replace(baseDir, '').replace(/^[/\\\\]+/, '');
|
|
22
|
-
|
|
23
|
-
// Split into path segments and filename
|
|
24
|
-
const allSegments = relativePath.split(/[/\\\\]/);
|
|
25
|
-
|
|
26
|
-
// Process all segments including filename (without extension)
|
|
27
|
-
const processedSegments = allSegments
|
|
28
|
-
// Remove extension from the last segment (filename)
|
|
29
|
-
.map((segment, index, array) =>
|
|
30
|
-
index === array.length - 1 ? segment.replace(/\\.[^/.]+$/, '') : segment
|
|
31
|
-
)
|
|
32
|
-
// Split segments containing periods
|
|
33
|
-
.flatMap((segment) => segment.split('.'))
|
|
34
|
-
// Filter out empty segments and 'command'
|
|
35
|
-
.filter((segment) => segment !== '' && segment !== 'command');
|
|
36
|
-
|
|
37
|
-
return processedSegments;
|
|
38
|
-
};
|