yargs-file-commands 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,6 @@
1
1
  # Yargs File Commands
2
2
 
3
3
  [![NPM Package][npm]][npm-url]
4
- [![Build Size][build-size]][build-size-url]
5
4
  [![NPM Downloads][npm-downloads]][npmtrends-url]
6
5
 
7
6
  This Yargs helper function lets you define all your commands as individual files and their file names and directory structure defines via implication your nested command structure.
@@ -19,21 +18,15 @@ npm install yargs-file-commands
19
18
  ## Example
20
19
 
21
20
  ```ts
22
- import { createRequire } from 'module';
23
- import path from 'path';
24
- import yargs from 'yargs';
25
- import { fileCommands } from 'yargs-file-commands';
26
-
27
- const require = createRequire(import.meta.url);
28
-
29
21
  export const main = async () => {
30
- const rootCommandDir = path.join(
31
- import.meta.url.replace('file://', ''),
32
- '../commands'
33
- );
34
-
35
- return yargs(process.argv)
36
- .command(await fileCommands({ rootDirs: [rootCommandDir] }))
22
+ const commandsDir = path.join(distDir, 'commands');
23
+
24
+ return yargs(hideBin(process.argv))
25
+ .scriptName(packageInfo.name!)
26
+ .version(packageInfo.version!)
27
+ .command(
28
+ await fileCommands({ commandDirs: [commandsDir], logLevel: 'debug' })
29
+ )
37
30
  .help().argv;
38
31
  };
39
32
  ```
@@ -90,7 +83,7 @@ studio start
90
83
 
91
84
  The "fileCommands" method takes the following options:
92
85
 
93
- **routesDirs**
86
+ **commandDirs**
94
87
 
95
88
  - An array of directories where the routes are located relative to the build root folder.
96
89
  - Required
@@ -100,11 +93,10 @@ The "fileCommands" method takes the following options:
100
93
  - An array of file extensions for the route files. Files without matching extensions are ignored
101
94
  - Default: `[".js", ".ts"]`
102
95
 
103
- ** ignorePatterns?: RegExp[];
104
- **
96
+ **ignorePatterns**
105
97
 
106
98
  - An array of regexs which if matched against a filename or directory, lead it to being ignored/skipped over.
107
- - Default: `[ /^[\.|_].*/, /\.(test|spec)\.[jt]s$/, /__(test|spec)__/, /\.d\.ts$/ ]`
99
+ - Default: `[ /^[.|_].*/, /\.(?:test|spec)\.[jt]s$/, /__(?:test|spec)__/, /\.d\.ts$/ ]`
108
100
 
109
101
  **logLevel**
110
102
 
@@ -140,3 +132,10 @@ npm run publish
140
132
  # run example cli
141
133
  npx example-cli
142
134
  ```
135
+
136
+ Underneath the hood, we are using [NX](https://nx.dev) to manage the monorepo and shared scripts.
137
+
138
+ [npm]: https://img.shields.io/npm/v/yargs-file-commands
139
+ [npm-url]: https://www.npmjs.com/package/yargs-file-commands
140
+ [npm-downloads]: https://img.shields.io/npm/dw/yargs-file-commands
141
+ [npmtrends-url]: https://www.npmtrends.com/yargs-file-commands
@@ -1,5 +1,5 @@
1
1
  export type FileCommandsOptions = {
2
- rootDirs: string[];
2
+ commandDirs: string[];
3
3
  extensions?: string[];
4
4
  ignorePatterns?: RegExp[];
5
5
  logLevel?: 'info' | 'debug';
@@ -5,9 +5,9 @@ import { segmentPath } from './segmentPath.js';
5
5
  export const DefaultFileCommandsOptions = {
6
6
  extensions: ['.js', '.ts'],
7
7
  ignorePatterns: [
8
- /^[\.|_].*/,
9
- /\.(test|spec)\.[jt]s$/,
10
- /__(test|spec)__/,
8
+ /^[.|_].*/,
9
+ /\.(?:test|spec)\.[jt]s$/,
10
+ /__(?:test|spec)__/,
11
11
  /\.d\.ts$/
12
12
  ],
13
13
  logLevel: 'info'
@@ -15,13 +15,13 @@ export const DefaultFileCommandsOptions = {
15
15
  export const fileCommands = async (options) => {
16
16
  const fullOptions = { ...DefaultFileCommandsOptions, ...options };
17
17
  const commands = [];
18
- await Promise.all(options.rootDirs.map(async (rootCommandDir) => {
19
- const filePaths = await scanDirectory(rootCommandDir, fullOptions);
18
+ await Promise.all(options.commandDirs.map(async (commandDir) => {
19
+ const filePaths = await scanDirectory(commandDir, fullOptions);
20
20
  const rootDirCommands = await Promise.all(filePaths.map(async (filePath) => {
21
- const segments = segmentPath(filePath, rootCommandDir);
21
+ const segments = segmentPath(filePath, commandDir);
22
22
  return {
23
23
  fullPath: filePath,
24
- segments: segmentPath(filePath, rootCommandDir),
24
+ segments: segmentPath(filePath, commandDir),
25
25
  commandModule: await importCommandFromFile(filePath, segments[segments.length - 1])
26
26
  };
27
27
  }));
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.2",
4
+ "version": "0.0.3",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",