my-gadgetry 1.0.11 → 1.1.2
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/dist/_core/fs.d.ts +9 -0
- package/dist/_core/fs.js +28 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-aliases.js +2 -2
- package/dist/_internal/fs.d.ts +1 -0
- package/dist/_internal/fs.js +1 -0
- package/dist/modules/fs.d.ts +1 -0
- package/dist/modules/fs.js +1 -0
- package/fs/package.json +6 -0
- package/package.json +6 -6
- package/src/_core/__tests__/fs.spec.ts +73 -0
- package/src/_core/fs.ts +36 -0
- package/src/_internal/dev-ops/package-generator/generate-alias/get-aliases.ts +2 -2
- package/src/_internal/fs.ts +1 -0
- package/src/modules/fs.ts +1 -0
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-files.d.ts +0 -1
- package/dist/_internal/dev-ops/package-generator/generate-alias/get-files.js +0 -14
- package/src/_internal/dev-ops/package-generator/generate-alias/get-files.ts +0 -14
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Options {
|
|
2
|
+
include: string[];
|
|
3
|
+
exclude: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare const OPTIONS: {
|
|
6
|
+
include: never[];
|
|
7
|
+
exclude: never[];
|
|
8
|
+
};
|
|
9
|
+
export declare const getAllFiles: (dir: string, _files?: string[], { include, exclude }?: Options) => string[];
|
package/dist/_core/fs.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { statSync, readdirSync } from 'fs';
|
|
2
|
+
import { minimatch } from 'minimatch';
|
|
3
|
+
export const OPTIONS = {
|
|
4
|
+
include: [],
|
|
5
|
+
exclude: [],
|
|
6
|
+
};
|
|
7
|
+
const isMatch = (path, patterns) => {
|
|
8
|
+
return patterns.some(pattern => minimatch(path, pattern));
|
|
9
|
+
};
|
|
10
|
+
export const getAllFiles = (dir, _files = [], { include, exclude } = OPTIONS) => {
|
|
11
|
+
const files = readdirSync(dir);
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
const name = dir + '/' + file;
|
|
14
|
+
if (isMatch(name, exclude)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (statSync(name).isDirectory()) {
|
|
18
|
+
getAllFiles(name, _files, { include, exclude });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (include.length > 0 && !isMatch(name, include)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
_files.push(name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return _files;
|
|
28
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAllFiles } from '../../../../_core/fs.js';
|
|
2
2
|
export const getAliases = (path, excludes) => {
|
|
3
3
|
const regExp = new RegExp(`^${path}/`);
|
|
4
4
|
const excludesExp = new RegExp(excludes.join('|'));
|
|
5
|
-
const aliases =
|
|
5
|
+
const aliases = getAllFiles(path).map(path => path.replace(regExp, '').replace(/\.ts$/, ''));
|
|
6
6
|
if (excludes.length) {
|
|
7
7
|
return aliases.filter(path => !excludesExp.test(path));
|
|
8
8
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_core/fs.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_core/fs.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_internal/fs.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../_internal/fs.js';
|
package/fs/package.json
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-gadgetry",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.2",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"repository": {
|
|
@@ -29,20 +29,17 @@
|
|
|
29
29
|
"tsc": "tsc -p tsconfig.publish.json && tsc-alias -p tsconfig.publish.json",
|
|
30
30
|
"generate": "tsx --tsconfig ./tsconfig.zx.json ./tools/generate-alias.zx.ts",
|
|
31
31
|
"ci:update-version": "tsx --tsconfig ./tsconfig.zx.json ./tools/update-version.zx.ts",
|
|
32
|
-
|
|
33
32
|
"//--- test ---//": "",
|
|
34
33
|
"test": "run-s test:*",
|
|
35
34
|
"test:lint": "npm run lint",
|
|
36
35
|
"test:prettier": "npm run prettier:check",
|
|
37
36
|
"test:jest": "npm run jest",
|
|
38
|
-
|
|
39
37
|
"//--- build ---//": "",
|
|
40
38
|
"build": "run-s build:*",
|
|
41
39
|
"build:test": "npm run test",
|
|
42
40
|
"build:clean": "npm run clean",
|
|
43
41
|
"build:tsc": "npm run tsc",
|
|
44
42
|
"build:generate": "npm run generate",
|
|
45
|
-
|
|
46
43
|
"//--- publish ---//": "",
|
|
47
44
|
"publish:build": "run-s build:{clean,tsc,generate}"
|
|
48
45
|
},
|
|
@@ -51,6 +48,7 @@
|
|
|
51
48
|
"@actions/exec": "^1.1.1",
|
|
52
49
|
"@actions/github": "^6.0.0",
|
|
53
50
|
"fs-extra": "^11.2.0",
|
|
51
|
+
"minimatch": "^9.0.4",
|
|
54
52
|
"zx": "^8.1.0"
|
|
55
53
|
},
|
|
56
54
|
"devDependencies": {
|
|
@@ -72,12 +70,12 @@
|
|
|
72
70
|
"husky": "^9.0.11",
|
|
73
71
|
"jest": "^29.7.0",
|
|
74
72
|
"lint-staged": "^15.2.2",
|
|
75
|
-
"npm-run-all2": "^6.
|
|
73
|
+
"npm-run-all2": "^6.2.0",
|
|
76
74
|
"prettier": "^3.2.5",
|
|
77
75
|
"ts-jest": "^29.1.2",
|
|
78
76
|
"ts-node": "^10.9.2",
|
|
79
77
|
"tsc-alias": "^1.8.10",
|
|
80
|
-
"tsx": "^4.10.
|
|
78
|
+
"tsx": "^4.10.4",
|
|
81
79
|
"typescript": "^5.4.5",
|
|
82
80
|
"typescript-eslint": "^7.9.0"
|
|
83
81
|
},
|
|
@@ -88,6 +86,7 @@
|
|
|
88
86
|
"./converters/number": "./dist/modules/converters/number.js",
|
|
89
87
|
"./converters/string": "./dist/modules/converters/string.js",
|
|
90
88
|
"./dev-ops/package-generator/generate-alias": "./dist/modules/dev-ops/package-generator/generate-alias.js",
|
|
89
|
+
"./fs": "./dist/modules/fs.js",
|
|
91
90
|
"./type-check": "./dist/modules/type-check.js",
|
|
92
91
|
"./package.json": "./package.json"
|
|
93
92
|
},
|
|
@@ -97,6 +96,7 @@
|
|
|
97
96
|
"color",
|
|
98
97
|
"converters",
|
|
99
98
|
"dev-ops",
|
|
99
|
+
"fs",
|
|
100
100
|
"type-check",
|
|
101
101
|
"src",
|
|
102
102
|
"package.json",
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { resolve, join } from 'path'
|
|
2
|
+
import { getAllFiles } from '../fs.js'
|
|
3
|
+
|
|
4
|
+
describe('getAllFiles', () => {
|
|
5
|
+
const path = resolve(__dirname, '../../..', 'fs-test')
|
|
6
|
+
it('no exclude & include', () => {
|
|
7
|
+
const exclude: string[] = []
|
|
8
|
+
const include: string[] = []
|
|
9
|
+
const expects = [
|
|
10
|
+
join(path, 'foo/piyo/index.ts'),
|
|
11
|
+
join(path, 'foo/piyo.ts'),
|
|
12
|
+
join(path, 'foo.ts'),
|
|
13
|
+
join(path, 'hoge/foo/piyo/index.ts'),
|
|
14
|
+
join(path, 'hoge/foo/piyo.ts'),
|
|
15
|
+
join(path, 'hoge/foo.ts'),
|
|
16
|
+
join(path, 'hoge.ts'),
|
|
17
|
+
]
|
|
18
|
+
expect(JSON.stringify(getAllFiles(path, [], { include, exclude }))).toBe(JSON.stringify(expects))
|
|
19
|
+
})
|
|
20
|
+
describe('set exclude', () => {
|
|
21
|
+
it('filename', () => {
|
|
22
|
+
const exclude: string[] = ['**/index.ts']
|
|
23
|
+
const include: string[] = []
|
|
24
|
+
const expects = [
|
|
25
|
+
join(path, 'foo/piyo.ts'),
|
|
26
|
+
join(path, 'foo.ts'),
|
|
27
|
+
join(path, 'hoge/foo/piyo.ts'),
|
|
28
|
+
join(path, 'hoge/foo.ts'),
|
|
29
|
+
join(path, 'hoge.ts'),
|
|
30
|
+
]
|
|
31
|
+
expect(JSON.stringify(getAllFiles(path, [], { include, exclude }))).toBe(JSON.stringify(expects))
|
|
32
|
+
})
|
|
33
|
+
it('dirname', () => {
|
|
34
|
+
const exclude: string[] = ['**/piyo/**/*']
|
|
35
|
+
const include: string[] = []
|
|
36
|
+
const expects = [
|
|
37
|
+
join(path, 'foo/piyo.ts'),
|
|
38
|
+
join(path, 'foo.ts'),
|
|
39
|
+
join(path, 'hoge/foo/piyo.ts'),
|
|
40
|
+
join(path, 'hoge/foo.ts'),
|
|
41
|
+
join(path, 'hoge.ts'),
|
|
42
|
+
]
|
|
43
|
+
expect(JSON.stringify(getAllFiles(path, [], { include, exclude }))).toBe(JSON.stringify(expects))
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
describe('set include', () => {
|
|
47
|
+
it('filename', () => {
|
|
48
|
+
const exclude: string[] = []
|
|
49
|
+
const include: string[] = ['**/index.ts']
|
|
50
|
+
const expects = [join(path, 'foo/piyo/index.ts'), join(path, 'hoge/foo/piyo/index.ts')]
|
|
51
|
+
expect(JSON.stringify(getAllFiles(path, [], { include, exclude }))).toBe(JSON.stringify(expects))
|
|
52
|
+
})
|
|
53
|
+
it('dirname', () => {
|
|
54
|
+
const exclude: string[] = []
|
|
55
|
+
const include: string[] = ['**/foo/**/*']
|
|
56
|
+
const expects = [
|
|
57
|
+
join(path, 'foo/piyo/index.ts'),
|
|
58
|
+
join(path, 'foo/piyo.ts'),
|
|
59
|
+
join(path, 'hoge/foo/piyo/index.ts'),
|
|
60
|
+
join(path, 'hoge/foo/piyo.ts'),
|
|
61
|
+
]
|
|
62
|
+
expect(JSON.stringify(getAllFiles(path, [], { include, exclude }))).toBe(JSON.stringify(expects))
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
describe('set include & exclude', () => {
|
|
66
|
+
it('filename & dirname', () => {
|
|
67
|
+
const exclude: string[] = ['**/p*.ts']
|
|
68
|
+
const include: string[] = ['**/foo/**/*']
|
|
69
|
+
const expects = [join(path, 'foo/piyo/index.ts'), join(path, 'hoge/foo/piyo/index.ts')]
|
|
70
|
+
expect(JSON.stringify(getAllFiles(path, [], { include, exclude }))).toBe(JSON.stringify(expects))
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
})
|
package/src/_core/fs.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { statSync, readdirSync } from 'fs'
|
|
2
|
+
|
|
3
|
+
import { minimatch } from 'minimatch'
|
|
4
|
+
|
|
5
|
+
export interface Options {
|
|
6
|
+
include: string[]
|
|
7
|
+
exclude: string[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const OPTIONS = {
|
|
11
|
+
include: [],
|
|
12
|
+
exclude: [],
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const isMatch = (path: string, patterns: string[]) => {
|
|
16
|
+
return patterns.some(pattern => minimatch(path, pattern))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const getAllFiles = (dir: string, _files: string[] = [], { include, exclude }: Options = OPTIONS) => {
|
|
20
|
+
const files = readdirSync(dir)
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
const name = dir + '/' + file
|
|
23
|
+
if (isMatch(name, exclude)) {
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
if (statSync(name).isDirectory()) {
|
|
27
|
+
getAllFiles(name, _files, { include, exclude })
|
|
28
|
+
} else {
|
|
29
|
+
if (include.length > 0 && !isMatch(name, include)) {
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
_files.push(name)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return _files
|
|
36
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAllFiles } from '~core/fs.js'
|
|
2
2
|
|
|
3
3
|
export const getAliases = (path: string, excludes: string[]) => {
|
|
4
4
|
const regExp = new RegExp(`^${path}/`)
|
|
5
5
|
const excludesExp = new RegExp(excludes.join('|'))
|
|
6
|
-
const aliases =
|
|
6
|
+
const aliases = getAllFiles(path).map(path => path.replace(regExp, '').replace(/\.ts$/, ''))
|
|
7
7
|
if (excludes.length) {
|
|
8
8
|
return aliases.filter(path => !excludesExp.test(path))
|
|
9
9
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~core/fs.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '~internal/fs.js'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getFiles: (dir: string, _files?: string[]) => string[];
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { statSync, readdirSync } from 'fs';
|
|
2
|
-
export const getFiles = (dir, _files = []) => {
|
|
3
|
-
const files = readdirSync(dir);
|
|
4
|
-
for (const file of files) {
|
|
5
|
-
const name = dir + '/' + file;
|
|
6
|
-
if (statSync(name).isDirectory()) {
|
|
7
|
-
getFiles(name, _files);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
_files.push(name);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return _files;
|
|
14
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { statSync, readdirSync } from 'fs'
|
|
2
|
-
|
|
3
|
-
export const getFiles = (dir: string, _files: string[] = []) => {
|
|
4
|
-
const files = readdirSync(dir)
|
|
5
|
-
for (const file of files) {
|
|
6
|
-
const name = dir + '/' + file
|
|
7
|
-
if (statSync(name).isDirectory()) {
|
|
8
|
-
getFiles(name, _files)
|
|
9
|
-
} else {
|
|
10
|
-
_files.push(name)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return _files
|
|
14
|
-
}
|