Skip to content

Commit 0c28e38

Browse files
committed
Add readFiles() utility to normalize path slashes
1 parent 5512270 commit 0c28e38

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

cli-argv-util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// cli-argv-util ~~ MIT License
22

3+
// Imports
34
import { execSync } from 'node:child_process';
5+
import fs from 'fs';
6+
import slash from 'slash';
47

8+
// Types
59
export type StringFlagMap = { [flag: string]: string | undefined };
610
export type BooleanFlagMap = { [flag: string]: boolean };
711
export type Result = {
@@ -46,6 +50,11 @@ const cliArgvUtil = {
4650
return execSync(command.replace(name, 'node bin/cli.js'), { stdio: 'inherit' });
4751
},
4852

53+
54+
readFiles(folder: string): string[] {
55+
return fs.readdirSync(folder, { recursive: true }).map(file => slash(String(file))).sort();
56+
},
57+
4958
};
5059

5160
export { cliArgvUtil };

package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,30 @@
6060
"clean": [
6161
"rimraf build dist"
6262
],
63-
"build": [
63+
"lint": [
6464
"jshint . --exclude-path .gitignore",
65-
"eslint --max-warnings 0 . --ext .ts",
65+
"eslint --max-warnings 0 . --ext .ts"
66+
],
67+
"build": [
6668
"tsc",
6769
"add-dist-header build dist"
6870
]
6971
},
7072
"scripts": {
71-
"pretest": "run-scripts clean build",
73+
"pretest": "run-scripts clean lint build",
7274
"test": "mocha spec/*.spec.js"
7375
},
76+
"dependencies": {
77+
"slash": "~5.1"
78+
},
7479
"devDependencies": {
75-
"@types/node": "~20.4",
76-
"@typescript-eslint/eslint-plugin": "~6.0",
77-
"@typescript-eslint/parser": "~6.0",
78-
"add-dist-header": "~1.1",
80+
"@types/node": "~20.5",
81+
"@typescript-eslint/eslint-plugin": "~6.4",
82+
"@typescript-eslint/parser": "~6.4",
83+
"add-dist-header": "~1.2",
7984
"assert-deep-strict-equal": "~1.1",
8085
"copy-file-util": "~1.1",
81-
"eslint": "~8.44",
86+
"eslint": "~8.47",
8287
"jshint": "~2.13",
8388
"mocha": "~10.2",
8489
"rimraf": "~5.0",

spec/mocha.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ describe('Library module', () => {
3232
assertDeepStrictEqual(actual, expected);
3333
});
3434

35-
it('has functions named parse() and run()', () => {
35+
it('has functions named parse(), run(), and readFiles()', () => {
3636
const actual = {
3737
names: Object.keys(cliArgvUtil),
3838
types: Object.values(cliArgvUtil).map(fn => typeof fn),
3939
};
4040
const expected = {
41-
names: ['parse', 'run'],
42-
types: ['function', 'function'],
41+
names: ['parse', 'run', 'readFiles'],
42+
types: ['function', 'function', 'function'],
4343
};
4444
assertDeepStrictEqual(actual, expected);
4545
});

0 commit comments

Comments
 (0)