yargs-file-commands 0.0.12 → 0.0.14

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/CHANGELOG.md CHANGED
@@ -1,32 +1,41 @@
1
1
  # yargs-file-commands
2
2
 
3
- ## 0.0.12
3
+ ## 0.0.14
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - More explicit exceptions when bad parameters are passed in
8
+ - Validate that provided command directories are aboslute
8
9
  - More robust parameter checking and logging
9
10
  - Improved debugging logging
10
11
  - More robust debug messages
11
12
 
13
+ ## 0.0.13
14
+
15
+ ### Patch Changes
16
+
17
+ - Validate that provided command directories are aboslute
18
+
19
+ ## 0.0.12
20
+
21
+ ### Patch Changes
22
+
23
+ - More robust parameter checking and logging
24
+
12
25
  ## 0.0.11
13
26
 
14
27
  ### Patch Changes
15
28
 
16
29
  - More explicit exceptions when bad parameters are passed in
17
- - Improved debugging logging
18
- - More robust debug messages
19
30
 
20
31
  ## 0.0.10
21
32
 
22
33
  ### Patch Changes
23
34
 
24
35
  - Improved debugging logging
25
- - More robust debug messages
26
36
 
27
37
  ## 0.0.9
28
38
 
29
39
  ### Patch Changes
30
40
 
31
- - Improved debugging logging
32
41
  - More robust debug messages
@@ -55,12 +55,21 @@ export const fileCommands = async (options) => {
55
55
  if (fullOptions.commandDirs.length === 0) {
56
56
  throw new Error('No command directories provided');
57
57
  }
58
+ // throw if some command directories are not absolute, first filter to find non-absolute an then throw, listing those that are not absolute
59
+ const nonAbsoluteDirs = fullOptions.commandDirs.filter((dir) => !path.isAbsolute(dir));
60
+ if (nonAbsoluteDirs.length > 0) {
61
+ throw new Error(`Command directories must be absolute paths: ${nonAbsoluteDirs.join(', ')}`);
62
+ }
58
63
  const commands = [];
59
64
  for (const commandDir of fullOptions.commandDirs) {
60
65
  const fullPath = path.resolve(commandDir);
61
- console.debug(`Scanning directory for commands: ${fullPath}`);
66
+ if (fullOptions.logLevel === 'debug') {
67
+ console.debug(`Scanning directory for commands: ${fullPath}`);
68
+ }
62
69
  const filePaths = await scanDirectory(commandDir, commandDir, fullOptions);
63
- console.debug(`Importing found commands:`);
70
+ if (fullOptions.logLevel === 'debug') {
71
+ console.debug(`Importing found commands:`);
72
+ }
64
73
  for (const filePath of filePaths) {
65
74
  const localPath = path.relative(commandDir, filePath);
66
75
  const segments = segmentPath(filePath, commandDir);
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.12",
4
+ "version": "0.0.14",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -55,7 +55,6 @@
55
55
  "typecheck": "tsc --noEmit",
56
56
  "test": "tsc && node --test dist/**/*.test.js --test-concurrency=1",
57
57
  "lint": "eslint --fix \"src/**/*.{ts,tsx}\"",
58
- "format": "prettier \"src/**/*.{js,jsx,css,md,html,ts,tsx,json,yaml}\" --check",
59
- "prePublishOnly": "pnpm build && pnpm test"
58
+ "format": "prettier \"src/**/*.{js,jsx,css,md,html,ts,tsx,json,yaml}\" --check"
60
59
  }
61
60
  }
@@ -82,15 +82,31 @@ export const fileCommands = async (options: FileCommandsOptions) => {
82
82
  throw new Error('No command directories provided');
83
83
  }
84
84
 
85
+ // throw if some command directories are not absolute, first filter to find non-absolute an then throw, listing those that are not absolute
86
+ const nonAbsoluteDirs = fullOptions.commandDirs.filter(
87
+ (dir) => !path.isAbsolute(dir)
88
+ );
89
+ if (nonAbsoluteDirs.length > 0) {
90
+ throw new Error(
91
+ `Command directories must be absolute paths: ${nonAbsoluteDirs.join(
92
+ ', '
93
+ )}`
94
+ );
95
+ }
96
+
85
97
  const commands: Command[] = [];
86
98
 
87
99
  for (const commandDir of fullOptions.commandDirs) {
88
100
  const fullPath = path.resolve(commandDir);
89
- console.debug(`Scanning directory for commands: ${fullPath}`);
101
+ if (fullOptions.logLevel === 'debug') {
102
+ console.debug(`Scanning directory for commands: ${fullPath}`);
103
+ }
90
104
 
91
105
  const filePaths = await scanDirectory(commandDir, commandDir, fullOptions);
92
106
 
93
- console.debug(`Importing found commands:`);
107
+ if (fullOptions.logLevel === 'debug') {
108
+ console.debug(`Importing found commands:`);
109
+ }
94
110
  for (const filePath of filePaths) {
95
111
  const localPath = path.relative(commandDir, filePath);
96
112
  const segments = segmentPath(filePath, commandDir);