yargs-file-commands 0.0.20 → 1.1.0

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 (61) hide show
  1. package/README.md +73 -109
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/Command.js +1 -0
  6. package/dist/lib/Command.js.map +1 -0
  7. package/dist/lib/buildSegmentTree.d.ts +1 -1
  8. package/dist/lib/buildSegmentTree.js +7 -3
  9. package/dist/lib/buildSegmentTree.js.map +1 -0
  10. package/dist/lib/buildSegmentTree.test.js +279 -26
  11. package/dist/lib/buildSegmentTree.test.js.map +1 -0
  12. package/dist/lib/defineCommand.d.ts +37 -0
  13. package/dist/lib/defineCommand.js +5 -0
  14. package/dist/lib/defineCommand.js.map +1 -0
  15. package/dist/lib/fileCommands.d.ts +2 -1
  16. package/dist/lib/fileCommands.js +39 -21
  17. package/dist/lib/fileCommands.js.map +1 -0
  18. package/dist/lib/fileCommands.test.js +107 -30
  19. package/dist/lib/fileCommands.test.js.map +1 -0
  20. package/dist/lib/fixtures/commands/$default.js +1 -0
  21. package/dist/lib/fixtures/commands/$default.js.map +1 -0
  22. package/dist/lib/fixtures/commands/create.js +1 -0
  23. package/dist/lib/fixtures/commands/create.js.map +1 -0
  24. package/dist/lib/fixtures/commands/db/health.d.ts +2 -1
  25. package/dist/lib/fixtures/commands/db/health.js +2 -3
  26. package/dist/lib/fixtures/commands/db/health.js.map +1 -0
  27. package/dist/lib/fixtures/commands/db/migration/command.d.ts +9 -2
  28. package/dist/lib/fixtures/commands/db/migration/command.js +6 -7
  29. package/dist/lib/fixtures/commands/db/migration/command.js.map +1 -0
  30. package/dist/lib/importCommand.d.ts +3 -3
  31. package/dist/lib/importCommand.js +39 -27
  32. package/dist/lib/importCommand.js.map +1 -0
  33. package/dist/lib/importCommand.test.js +157 -33
  34. package/dist/lib/importCommand.test.js.map +1 -0
  35. package/dist/lib/scanDirectory.js +54 -25
  36. package/dist/lib/scanDirectory.js.map +1 -0
  37. package/dist/lib/scanDirectory.test.js +148 -25
  38. package/dist/lib/scanDirectory.test.js.map +1 -0
  39. package/dist/lib/segmentPath.js +8 -6
  40. package/dist/lib/segmentPath.js.map +1 -0
  41. package/dist/lib/segmentPath.test.js +10 -38
  42. package/dist/lib/segmentPath.test.js.map +1 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -0
  44. package/package.json +6 -9
  45. package/CHANGELOG.md +0 -62
  46. package/src/index.ts +0 -1
  47. package/src/lib/Command.ts +0 -16
  48. package/src/lib/buildSegmentTree.test.ts +0 -90
  49. package/src/lib/buildSegmentTree.ts +0 -149
  50. package/src/lib/fileCommands.test.ts +0 -55
  51. package/src/lib/fileCommands.ts +0 -149
  52. package/src/lib/fixtures/commands/$default.ts +0 -5
  53. package/src/lib/fixtures/commands/create.ts +0 -6
  54. package/src/lib/fixtures/commands/db/health.ts +0 -9
  55. package/src/lib/fixtures/commands/db/migration/command.ts +0 -12
  56. package/src/lib/importCommand.test.ts +0 -60
  57. package/src/lib/importCommand.ts +0 -196
  58. package/src/lib/scanDirectory.test.ts +0 -75
  59. package/src/lib/scanDirectory.ts +0 -109
  60. package/src/lib/segmentPath.test.ts +0 -71
  61. package/src/lib/segmentPath.ts +0 -38
@@ -1,71 +0,0 @@
1
- import { describe, it } from 'node:test';
2
-
3
- import assert from 'assert';
4
-
5
- import { segmentPath } from './segmentPath.js';
6
-
7
- describe('segmentPath', () => {
8
- it('should segment a path correctly', () => {
9
- const fullPath =
10
- '/Users/username/Coding/Personal/yargs-file-commands/packages/yargs-file-commands/src/lib/segmentPath.ts';
11
- const baseDir = '/Users/username/Coding/Personal/yargs-file-commands/';
12
- const expected = [
13
- 'packages',
14
- 'yargs-file-commands',
15
- 'src',
16
- 'lib',
17
- 'segmentPath',
18
- 'ts'
19
- ];
20
- const result = segmentPath(fullPath, baseDir);
21
- assert.deepStrictEqual(result, expected);
22
- });
23
-
24
- it('should handle paths with periods correctly', () => {
25
- const fullPath =
26
- '/Users/username/Coding/Personal/yargs-file-commands/packages/yargs-file-commands/src/lib/segmentPath.test.ts';
27
- const baseDir = '/Users/username/Coding/Personal/yargs-file-commands/';
28
- const expected = [
29
- 'packages',
30
- 'yargs-file-commands',
31
- 'src',
32
- 'lib',
33
- 'segmentPath',
34
- 'test',
35
- 'ts'
36
- ];
37
- const result = segmentPath(fullPath, baseDir);
38
- assert.deepStrictEqual(result, expected);
39
- });
40
-
41
- it('should filter out "command" segments', () => {
42
- const fullPath =
43
- '/Users/username/Coding/Personal/yargs-file-commands/packages/yargs-file-commands/src/lib/commandPath.ts';
44
- const baseDir = '/Users/username/Coding/Personal/yargs-file-commands/';
45
- const expected = [
46
- 'packages',
47
- 'yargs-file-commands',
48
- 'src',
49
- 'lib',
50
- 'commandPath',
51
- 'ts'
52
- ];
53
- const result = segmentPath(fullPath, baseDir);
54
- assert.deepStrictEqual(result, expected);
55
- });
56
-
57
- it('should handle empty segments correctly', () => {
58
- const fullPath =
59
- '/Users/username/Coding/Personal/yargs-file-commands/packages/yargs-file-commands/src/lib/.hiddenFile';
60
- const baseDir = '/Users/username/Coding/Personal/yargs-file-commands/';
61
- const expected = [
62
- 'packages',
63
- 'yargs-file-commands',
64
- 'src',
65
- 'lib',
66
- 'hiddenFile'
67
- ];
68
- const result = segmentPath(fullPath, baseDir);
69
- assert.deepStrictEqual(result, expected);
70
- });
71
- });
@@ -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
- };