@baeta/generator-sdk 2.0.0-next.2 → 2.0.0-next.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/CHANGELOG.md +6 -0
- package/README.md +42 -17
- package/dist/index.d.ts +204 -190
- package/dist/index.js +353 -404
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,433 +1,382 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import path, { dirname, extname, posixPath, resolve } from "@baeta/util-path";
|
|
2
|
+
import fs, { mkdir, open, writeFile } from "node:fs/promises";
|
|
3
|
+
import { pascalCase } from "change-case-all";
|
|
4
|
+
import { PluginType } from "@baeta/plugin";
|
|
5
|
+
import { subscribe } from "@parcel/watcher";
|
|
6
|
+
import micromatch, { default as micromatch$1 } from "micromatch";
|
|
7
|
+
|
|
8
|
+
//#region lib/config.ts
|
|
3
9
|
function loadOptions(options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
10
|
+
const cwd = posixPath(options.cwd ?? process.cwd());
|
|
11
|
+
const schemas = options.schemas ?? ["src/**/*.graphql"];
|
|
12
|
+
const modulesDir = posixPath(resolve(cwd, options.modulesDir || "src/modules"));
|
|
13
|
+
const moduleDefinitionName = options.moduleDefinitionName || "typedef.ts";
|
|
14
|
+
const defaultTypesDir = resolve(modulesDir, "../__generated__/");
|
|
15
|
+
return {
|
|
16
|
+
cwd,
|
|
17
|
+
schemas,
|
|
18
|
+
modulesDir,
|
|
19
|
+
moduleDefinitionName,
|
|
20
|
+
typesDir: resolve(cwd, options.typesDir || defaultTypesDir),
|
|
21
|
+
fileOptions: options.fileOptions,
|
|
22
|
+
loaders: options.loaders,
|
|
23
|
+
importExtension: options.importExtension === false ? "" : options.importExtension ?? ".ts"
|
|
24
|
+
};
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import { dirname, extname } from "@baeta/util-path";
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region lib/file.ts
|
|
25
29
|
var File = class {
|
|
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
|
-
createComment(comment) {
|
|
90
|
-
const extension = extname(this.filename);
|
|
91
|
-
if ([".gql", ".graphql"].includes(extension)) {
|
|
92
|
-
return `# ${comment}`;
|
|
93
|
-
}
|
|
94
|
-
return `/* ${comment} */`;
|
|
95
|
-
}
|
|
30
|
+
persisted = false;
|
|
31
|
+
filename;
|
|
32
|
+
content;
|
|
33
|
+
tag;
|
|
34
|
+
options;
|
|
35
|
+
constructor(filename, content, tag, options) {
|
|
36
|
+
this.filename = filename;
|
|
37
|
+
this.content = content;
|
|
38
|
+
this.tag = tag;
|
|
39
|
+
this.options = options;
|
|
40
|
+
}
|
|
41
|
+
write = async () => {
|
|
42
|
+
if (this.persisted) return;
|
|
43
|
+
this.persisted = true;
|
|
44
|
+
if (this.options?.allowOverwrite === false) {
|
|
45
|
+
if (await fs.stat(this.filename).then((res) => res.isFile()).catch(() => false)) return;
|
|
46
|
+
}
|
|
47
|
+
const dir = dirname(this.filename);
|
|
48
|
+
await fs.mkdir(dir, { recursive: true });
|
|
49
|
+
const content = await this.buildContent();
|
|
50
|
+
return fs.writeFile(this.filename, content, "utf-8");
|
|
51
|
+
};
|
|
52
|
+
unlink = async () => {
|
|
53
|
+
this.persisted = false;
|
|
54
|
+
return fs.unlink(this.filename);
|
|
55
|
+
};
|
|
56
|
+
async buildContent() {
|
|
57
|
+
const content = this.buildHeader() + this.content;
|
|
58
|
+
if (this.options?.transformContent) return this.options.transformContent(this.filename, content, this.tag);
|
|
59
|
+
return content;
|
|
60
|
+
}
|
|
61
|
+
buildHeader() {
|
|
62
|
+
const headerItems = [];
|
|
63
|
+
if (this.options?.disableGenerationNoticeHeader !== true) {
|
|
64
|
+
const comment = this.createComment("This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.");
|
|
65
|
+
headerItems.push(comment);
|
|
66
|
+
}
|
|
67
|
+
if (this.options?.disableEslintHeader !== true) {
|
|
68
|
+
const comment = this.createComment("eslint-disable");
|
|
69
|
+
headerItems.push(comment);
|
|
70
|
+
}
|
|
71
|
+
if (this.options?.disableBiomeV1Header !== true) {
|
|
72
|
+
const comment = this.createComment("@biome-ignore-all: generated file");
|
|
73
|
+
headerItems.push(comment);
|
|
74
|
+
}
|
|
75
|
+
if (this.options?.disableBiomeV2Header !== true) {
|
|
76
|
+
const comment = this.createComment("biome-ignore-all lint: generated file");
|
|
77
|
+
headerItems.push(comment);
|
|
78
|
+
}
|
|
79
|
+
if (this.options?.addHeader) {
|
|
80
|
+
const customHeader = this.options.addHeader(this.filename, this.content, this.tag);
|
|
81
|
+
headerItems.push(customHeader);
|
|
82
|
+
}
|
|
83
|
+
if (headerItems.length === 0) return "";
|
|
84
|
+
return `${headerItems.join("\n")}\n\n`;
|
|
85
|
+
}
|
|
86
|
+
createComment(comment) {
|
|
87
|
+
const extension = extname(this.filename);
|
|
88
|
+
if ([".gql", ".graphql"].includes(extension)) return `# ${comment}`;
|
|
89
|
+
return `/* ${comment} */`;
|
|
90
|
+
}
|
|
96
91
|
};
|
|
97
92
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
import { dirname as dirname2 } from "@baeta/util-path";
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region lib/file-block.ts
|
|
101
95
|
var FileBlock = class extends File {
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
buildPadding(existingContent) {
|
|
177
|
-
if (existingContent === "") {
|
|
178
|
-
return "";
|
|
179
|
-
}
|
|
180
|
-
if (existingContent.endsWith("\n\n")) {
|
|
181
|
-
return "";
|
|
182
|
-
}
|
|
183
|
-
if (existingContent.endsWith("\n")) {
|
|
184
|
-
return "\n";
|
|
185
|
-
}
|
|
186
|
-
return "\n\n";
|
|
187
|
-
}
|
|
96
|
+
filename;
|
|
97
|
+
content;
|
|
98
|
+
start;
|
|
99
|
+
end;
|
|
100
|
+
tag;
|
|
101
|
+
constructor(filename, content, start, end, tag, options) {
|
|
102
|
+
super(filename, content, tag, {
|
|
103
|
+
disableBiomeV1Header: options?.disableBiomeV1Header ?? true,
|
|
104
|
+
disableBiomeV2Header: options?.disableBiomeV2Header ?? true,
|
|
105
|
+
disableEslintHeader: options?.disableEslintHeader ?? true,
|
|
106
|
+
disableGenerationNoticeHeader: options?.disableGenerationNoticeHeader ?? true
|
|
107
|
+
});
|
|
108
|
+
this.filename = filename;
|
|
109
|
+
this.content = content;
|
|
110
|
+
this.start = start;
|
|
111
|
+
this.end = end;
|
|
112
|
+
this.tag = tag;
|
|
113
|
+
}
|
|
114
|
+
write = async () => {
|
|
115
|
+
if (this.persisted) return;
|
|
116
|
+
this.persisted = true;
|
|
117
|
+
await mkdir(dirname(this.filename), { recursive: true });
|
|
118
|
+
const [existingContent, fd] = await this.getExistingContent();
|
|
119
|
+
this.content = this.addBlockToContent(existingContent);
|
|
120
|
+
const content = await this.buildContent();
|
|
121
|
+
if (fd) {
|
|
122
|
+
await fd.truncate(0);
|
|
123
|
+
await fd.write(content, 0, "utf-8");
|
|
124
|
+
await fd.close();
|
|
125
|
+
} else await writeFile(this.filename, content, "utf-8");
|
|
126
|
+
};
|
|
127
|
+
unlink = async () => {
|
|
128
|
+
this.persisted = false;
|
|
129
|
+
const [existingContent, fd] = await this.getExistingContent();
|
|
130
|
+
if (fd) {
|
|
131
|
+
const [start, end] = this.getSlices(existingContent);
|
|
132
|
+
await fd.truncate(0);
|
|
133
|
+
await fd.write(start + end, 0, "utf-8");
|
|
134
|
+
await fd.close();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
async getExistingContent() {
|
|
138
|
+
try {
|
|
139
|
+
const fd = await open(this.filename, "r+");
|
|
140
|
+
return [await fd.readFile("utf-8"), fd];
|
|
141
|
+
} catch {
|
|
142
|
+
return ["", null];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
getSlices(existingContent) {
|
|
146
|
+
const startMarkerIndex = existingContent.indexOf(this.start);
|
|
147
|
+
const endMarkerIndex = existingContent.lastIndexOf(this.end);
|
|
148
|
+
if (startMarkerIndex === -1 || endMarkerIndex === -1) return [
|
|
149
|
+
existingContent,
|
|
150
|
+
"",
|
|
151
|
+
false
|
|
152
|
+
];
|
|
153
|
+
return [
|
|
154
|
+
existingContent.slice(0, startMarkerIndex),
|
|
155
|
+
existingContent.slice(endMarkerIndex + this.end.length),
|
|
156
|
+
true
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
addBlockToContent(existingContent) {
|
|
160
|
+
const block = `${this.start}\n${this.content}\n${this.end}`;
|
|
161
|
+
const [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);
|
|
162
|
+
return startSlice + (hasMarkers ? "" : this.buildPadding(existingContent)) + block + endSlice;
|
|
163
|
+
}
|
|
164
|
+
buildPadding(existingContent) {
|
|
165
|
+
if (existingContent === "") return "";
|
|
166
|
+
if (existingContent.endsWith("\n\n")) return "";
|
|
167
|
+
if (existingContent.endsWith("\n")) return "\n";
|
|
168
|
+
return "\n\n";
|
|
169
|
+
}
|
|
188
170
|
};
|
|
189
171
|
|
|
190
|
-
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region lib/file-manager.ts
|
|
191
174
|
var FileManager = class {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
175
|
+
files = [];
|
|
176
|
+
fileOptions;
|
|
177
|
+
constructor(fileOptions) {
|
|
178
|
+
this.fileOptions = fileOptions;
|
|
179
|
+
}
|
|
180
|
+
createAndAdd(filename, content, tag, options) {
|
|
181
|
+
const file = new File(filename, content, tag, {
|
|
182
|
+
...this.fileOptions,
|
|
183
|
+
...options
|
|
184
|
+
});
|
|
185
|
+
this.add(file);
|
|
186
|
+
return file;
|
|
187
|
+
}
|
|
188
|
+
add(...file) {
|
|
189
|
+
this.files.push(...file);
|
|
190
|
+
}
|
|
191
|
+
get(filename) {
|
|
192
|
+
return this.files.find((file) => file.filename === filename);
|
|
193
|
+
}
|
|
194
|
+
getAll() {
|
|
195
|
+
return this.files;
|
|
196
|
+
}
|
|
197
|
+
getByTag(tag) {
|
|
198
|
+
return this.files.filter((file) => file.tag === tag);
|
|
199
|
+
}
|
|
200
|
+
remove(filename) {
|
|
201
|
+
const index = this.files.findIndex((file) => file.filename === filename);
|
|
202
|
+
this.files.splice(index, 1);
|
|
203
|
+
}
|
|
204
|
+
removeAll() {
|
|
205
|
+
this.files = [];
|
|
206
|
+
}
|
|
207
|
+
removeByTag(tag) {
|
|
208
|
+
this.files = this.files.filter((file) => file.tag !== tag);
|
|
209
|
+
}
|
|
210
|
+
writeAll() {
|
|
211
|
+
const toWrite = this.files.filter((file) => !file.persisted);
|
|
212
|
+
return Promise.all(toWrite.map((file) => file.write()));
|
|
213
|
+
}
|
|
214
|
+
writeByTag(tag) {
|
|
215
|
+
const toWrite = this.getByTag(tag).filter((file) => !file.persisted);
|
|
216
|
+
return Promise.all(toWrite.map((file) => file.write()));
|
|
217
|
+
}
|
|
218
|
+
unlinkAll() {
|
|
219
|
+
return Promise.all(this.files.map((file) => file.unlink())).then(() => {});
|
|
220
|
+
}
|
|
221
|
+
getPersistedFiles() {
|
|
222
|
+
return this.files.filter((file) => file.persisted);
|
|
223
|
+
}
|
|
240
224
|
};
|
|
241
225
|
|
|
242
|
-
|
|
243
|
-
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region lib/module.ts
|
|
244
228
|
function getModuleExportName(name) {
|
|
245
|
-
|
|
229
|
+
return `${pascalCase(name)}Module`;
|
|
246
230
|
}
|
|
247
231
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
var defaultPluginFn = async (_ctx, next) => {
|
|
254
|
-
return next();
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region lib/plugin.ts
|
|
234
|
+
const GeneratorPluginVersion = { V1: "v1" };
|
|
235
|
+
const defaultPluginFn = async (_ctx, next) => {
|
|
236
|
+
return next();
|
|
255
237
|
};
|
|
256
|
-
|
|
238
|
+
const defaultWatchFn = () => ({
|
|
239
|
+
include: [],
|
|
240
|
+
ignore: []
|
|
241
|
+
});
|
|
257
242
|
function createPluginV1(options) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
243
|
+
return {
|
|
244
|
+
name: options.name,
|
|
245
|
+
actionName: options.actionName,
|
|
246
|
+
version: GeneratorPluginVersion.V1,
|
|
247
|
+
type: PluginType.Generator,
|
|
248
|
+
end: options.end ?? defaultPluginFn,
|
|
249
|
+
generate: options.generate ?? defaultPluginFn,
|
|
250
|
+
setup: options.setup ?? defaultPluginFn,
|
|
251
|
+
watch: options.watch ?? defaultWatchFn
|
|
252
|
+
};
|
|
268
253
|
}
|
|
269
254
|
function isGeneratorPlugin(plugin) {
|
|
270
|
-
|
|
255
|
+
return plugin.type === PluginType.Generator;
|
|
271
256
|
}
|
|
272
257
|
function getGeneratorPlugins(plugins) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
return plugins.filter(isGeneratorPlugin);
|
|
258
|
+
if (!plugins) return [];
|
|
259
|
+
return plugins.filter(isGeneratorPlugin);
|
|
277
260
|
}
|
|
278
261
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
import {
|
|
282
|
-
subscribe
|
|
283
|
-
} from "@parcel/watcher";
|
|
284
|
-
import micromatch2 from "micromatch";
|
|
285
|
-
|
|
286
|
-
// lib/watcher-ignore.ts
|
|
287
|
-
import path from "@baeta/util-path";
|
|
288
|
-
import micromatch from "micromatch";
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region lib/watcher-ignore.ts
|
|
289
264
|
var WatcherIgnore = class {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (this.regexps.some((r) => r.test(path3))) {
|
|
347
|
-
return true;
|
|
348
|
-
}
|
|
349
|
-
if (this.functions.some((f) => f(path3))) {
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
265
|
+
cwd;
|
|
266
|
+
files = [];
|
|
267
|
+
regexps = [];
|
|
268
|
+
functions = [];
|
|
269
|
+
globs = [];
|
|
270
|
+
globsMap = /* @__PURE__ */ new Map();
|
|
271
|
+
constructor(cwd) {
|
|
272
|
+
this.cwd = cwd;
|
|
273
|
+
}
|
|
274
|
+
ignore(pattern) {
|
|
275
|
+
if (pattern instanceof RegExp) {
|
|
276
|
+
this.regexps.push(pattern);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (typeof pattern === "function") {
|
|
280
|
+
this.functions.push(pattern);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (!this.isMicromatch(pattern)) {
|
|
284
|
+
this.files.push(this.resolveFile(pattern));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
this.globsMap.set(pattern, micromatch$1.matcher(pattern));
|
|
288
|
+
this.globs = Array.from(this.globsMap.values());
|
|
289
|
+
}
|
|
290
|
+
isMicromatch(pattern) {
|
|
291
|
+
const result = micromatch$1.scan(pattern);
|
|
292
|
+
return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;
|
|
293
|
+
}
|
|
294
|
+
resolveFile(file) {
|
|
295
|
+
return path.isAbsolute(file) ? file : path.join(this.cwd, file);
|
|
296
|
+
}
|
|
297
|
+
unignore(pattern) {
|
|
298
|
+
if (pattern instanceof RegExp) {
|
|
299
|
+
this.regexps = this.regexps.filter((p) => p !== pattern);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (typeof pattern === "function") {
|
|
303
|
+
this.functions = this.functions.filter((p) => p !== pattern);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!this.isMicromatch(pattern)) {
|
|
307
|
+
const file = this.resolveFile(pattern);
|
|
308
|
+
this.files = this.files.filter((p) => p !== file);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
this.globsMap.delete(pattern);
|
|
312
|
+
this.globs = Array.from(this.globsMap.values());
|
|
313
|
+
}
|
|
314
|
+
isIgnored(path$1) {
|
|
315
|
+
if (this.files.includes(path$1)) return true;
|
|
316
|
+
if (this.globs.some((f) => f(path$1))) return true;
|
|
317
|
+
if (this.regexps.some((r) => r.test(path$1))) return true;
|
|
318
|
+
if (this.functions.some((f) => f(path$1))) return true;
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
354
321
|
};
|
|
355
322
|
|
|
356
|
-
|
|
357
|
-
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region lib/watcher.ts
|
|
325
|
+
const isMatch = micromatch.isMatch;
|
|
358
326
|
var Watcher = class {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return {
|
|
411
|
-
unsubscribe
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
close() {
|
|
415
|
-
return this.subscription.unsubscribe();
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
export {
|
|
419
|
-
File,
|
|
420
|
-
FileBlock,
|
|
421
|
-
FileManager,
|
|
422
|
-
GeneratorPluginVersion,
|
|
423
|
-
Watcher,
|
|
424
|
-
WatcherIgnore,
|
|
425
|
-
createPluginV1,
|
|
426
|
-
getGeneratorPlugins,
|
|
427
|
-
getModuleExportName,
|
|
428
|
-
isGeneratorPlugin,
|
|
429
|
-
isMatch,
|
|
430
|
-
loadOptions,
|
|
431
|
-
micromatch2 as micromatch
|
|
327
|
+
cwd;
|
|
328
|
+
options;
|
|
329
|
+
subscription;
|
|
330
|
+
listeners = {
|
|
331
|
+
create: [],
|
|
332
|
+
update: [],
|
|
333
|
+
delete: []
|
|
334
|
+
};
|
|
335
|
+
watcherIgnore;
|
|
336
|
+
constructor(cwd, options) {
|
|
337
|
+
this.cwd = cwd;
|
|
338
|
+
this.options = options;
|
|
339
|
+
this.watcherIgnore = new WatcherIgnore(cwd);
|
|
340
|
+
this.subscription = this.createSubscription();
|
|
341
|
+
}
|
|
342
|
+
onEvents = (err, events) => {
|
|
343
|
+
if (err) {
|
|
344
|
+
console.error(err);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const filteredEvents = events.filter((event) => {
|
|
348
|
+
return !this.watcherIgnore.isIgnored(posixPath(event.path));
|
|
349
|
+
});
|
|
350
|
+
for (const event of filteredEvents) for (const listener of this.listeners[event.type]) listener({
|
|
351
|
+
type: event.type,
|
|
352
|
+
path: posixPath(event.path),
|
|
353
|
+
relativePath: posixPath(path.relative(this.cwd, event.path))
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
on(event, listener) {
|
|
357
|
+
this.listeners[event].push(listener);
|
|
358
|
+
}
|
|
359
|
+
off(event, listener) {
|
|
360
|
+
this.listeners[event] = this.listeners[event].filter((l) => l !== listener);
|
|
361
|
+
}
|
|
362
|
+
ignore(pattern) {
|
|
363
|
+
this.watcherIgnore.ignore(pattern);
|
|
364
|
+
}
|
|
365
|
+
unignore(pattern) {
|
|
366
|
+
this.watcherIgnore.unignore(pattern);
|
|
367
|
+
}
|
|
368
|
+
createSubscription() {
|
|
369
|
+
const promise = subscribe(this.cwd, this.onEvents, this.options);
|
|
370
|
+
const unsubscribe = async () => {
|
|
371
|
+
await (await promise).unsubscribe();
|
|
372
|
+
};
|
|
373
|
+
return { unsubscribe };
|
|
374
|
+
}
|
|
375
|
+
close() {
|
|
376
|
+
return this.subscription.unsubscribe();
|
|
377
|
+
}
|
|
432
378
|
};
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
export { File, FileBlock, FileManager, GeneratorPluginVersion, Watcher, WatcherIgnore, createPluginV1, getGeneratorPlugins, getModuleExportName, isGeneratorPlugin, isMatch, loadOptions, micromatch };
|
|
433
382
|
//# sourceMappingURL=index.js.map
|