-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
package.ts
138 lines (125 loc) · 4.9 KB
/
package.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import * as child_process from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
// eslint-disable-next-line import/no-extraneous-dependencies
import { path7za } from '7zip-bin';
import caxa from 'caxa';
import fg, { Options as GlobOptions } from 'fast-glob';
import yargs from 'yargs';
import Logger from './src/console/logger.js';
import LogLevel from './src/console/logLevel.js';
import Package from './src/globals/package.js';
import FsPoly from './src/polyfill/fsPoly.js';
import ExpectedError from './src/types/expectedError.js';
interface FileFilter extends GlobOptions {
include?: string,
exclude?: string,
}
const fileFilter = (filters: FileFilter[]): string[] => {
let results: string[] = [];
filters.forEach((filter) => {
if (filter.include) {
const include = fg.globSync(filter.include.replace(/\\/g, '/'), filter)
.map((file) => path.resolve(file));
if (include.length === 0) {
throw new ExpectedError(`glob pattern '${filter.include}' returned no paths`);
}
results = [...results, ...include];
}
if (filter.exclude) {
const exclude = new Set(fg.globSync(filter.exclude.replace(/\\/g, '/'), filter)
.map((file) => path.resolve(file)));
if (exclude.size === 0) {
throw new ExpectedError(`glob pattern '${filter.exclude}' returned no paths`);
}
results = results.filter((result) => !exclude.has(result));
}
});
return results;
};
(async (): Promise<void> => {
const logger = new Logger(LogLevel.TRACE);
const argv = await yargs(process.argv.slice(2))
.locale('en')
.usage('Usage: $0 <input> <output>')
.positional('input', {