@kubb/core 0.37.2 → 0.37.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/dist/index.global.js +333011 -0
- package/dist/index.global.js.map +1 -0
- package/package.json +7 -2
- package/dist/index.js +0 -649
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -626
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,626 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module';
|
|
2
|
-
import pathParser from 'path';
|
|
3
|
-
import fse from 'fs-extra';
|
|
4
|
-
import { format as format$1 } from 'prettier';
|
|
5
|
-
import EventEmitter from 'events';
|
|
6
|
-
import { randomUUID } from 'crypto';
|
|
7
|
-
import dirTree from 'directory-tree';
|
|
8
|
-
|
|
9
|
-
createRequire(import.meta.url);
|
|
10
|
-
|
|
11
|
-
// src/utils/isPromise.ts
|
|
12
|
-
var isPromise = (result) => {
|
|
13
|
-
return typeof result?.then === "function";
|
|
14
|
-
};
|
|
15
|
-
var formatOptions = {
|
|
16
|
-
tabWidth: 2,
|
|
17
|
-
printWidth: 160,
|
|
18
|
-
parser: "typescript",
|
|
19
|
-
singleQuote: true,
|
|
20
|
-
semi: false,
|
|
21
|
-
bracketSameLine: false,
|
|
22
|
-
endOfLine: "auto"
|
|
23
|
-
};
|
|
24
|
-
var format = (text) => {
|
|
25
|
-
return format$1(text, formatOptions);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// src/utils/write.ts
|
|
29
|
-
var write = async (data, path, options = { format: false }) => {
|
|
30
|
-
const formattedData = options.format ? format(data) : data;
|
|
31
|
-
try {
|
|
32
|
-
await fse.stat(path);
|
|
33
|
-
const oldContent = await fse.readFile(path, { encoding: "utf-8" });
|
|
34
|
-
if (oldContent?.toString() === formattedData) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
} catch (_err) {
|
|
38
|
-
return fse.outputFile(path, formattedData, { encoding: "utf-8" });
|
|
39
|
-
}
|
|
40
|
-
return fse.outputFile(path, formattedData, { encoding: "utf-8" });
|
|
41
|
-
};
|
|
42
|
-
var clean = async (path) => {
|
|
43
|
-
return fse.remove(path);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// src/utils/cache.ts
|
|
47
|
-
function createPluginCache(cache) {
|
|
48
|
-
return {
|
|
49
|
-
delete(id) {
|
|
50
|
-
return delete cache[id];
|
|
51
|
-
},
|
|
52
|
-
get(id) {
|
|
53
|
-
const item = cache[id];
|
|
54
|
-
if (!item)
|
|
55
|
-
return;
|
|
56
|
-
item[0] = 0;
|
|
57
|
-
return item[1];
|
|
58
|
-
},
|
|
59
|
-
has(id) {
|
|
60
|
-
const item = cache[id];
|
|
61
|
-
if (!item)
|
|
62
|
-
return false;
|
|
63
|
-
item[0] = 0;
|
|
64
|
-
return true;
|
|
65
|
-
},
|
|
66
|
-
set(id, value) {
|
|
67
|
-
cache[id] = [0, value];
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
var getRelativePath = (root, file) => {
|
|
72
|
-
if (!root || !file) {
|
|
73
|
-
throw new Error("Root and file should be filled in when retrieving the relativePath");
|
|
74
|
-
}
|
|
75
|
-
const newPath = pathParser.relative(root, file).replace("../", "").replace(".ts", "").trimEnd();
|
|
76
|
-
return `./${newPath}`;
|
|
77
|
-
};
|
|
78
|
-
var getPathMode = (path) => {
|
|
79
|
-
if (!path) {
|
|
80
|
-
return void 0;
|
|
81
|
-
}
|
|
82
|
-
return pathParser.extname(path) ? "file" : "directory";
|
|
83
|
-
};
|
|
84
|
-
var read = async (path, encoding = "utf8") => {
|
|
85
|
-
try {
|
|
86
|
-
return fse.readFile(path, encoding);
|
|
87
|
-
} catch (err) {
|
|
88
|
-
console.error(err);
|
|
89
|
-
throw err;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/plugin.ts
|
|
94
|
-
function createPlugin(factory) {
|
|
95
|
-
return (options) => {
|
|
96
|
-
const plugin = factory(options);
|
|
97
|
-
if (Array.isArray(plugin)) {
|
|
98
|
-
throw new Error("Not implemented");
|
|
99
|
-
}
|
|
100
|
-
if (!plugin.transform) {
|
|
101
|
-
plugin.transform = function transform(code) {
|
|
102
|
-
return code;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return plugin;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
var name = "core";
|
|
109
|
-
var isEmittedFile = (result) => {
|
|
110
|
-
return !!result.id;
|
|
111
|
-
};
|
|
112
|
-
var definePlugin = createPlugin((options) => {
|
|
113
|
-
const { fileManager, resolveId, load } = options;
|
|
114
|
-
const api = {
|
|
115
|
-
get config() {
|
|
116
|
-
return options.config;
|
|
117
|
-
},
|
|
118
|
-
fileManager,
|
|
119
|
-
async addFile(file, options2) {
|
|
120
|
-
if (isEmittedFile(file)) {
|
|
121
|
-
const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
|
|
122
|
-
const path = resolvedId || file.importer || file.id;
|
|
123
|
-
return fileManager.add({
|
|
124
|
-
path,
|
|
125
|
-
fileName: file.name || file.id,
|
|
126
|
-
source: file.source || ""
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (options2?.root) ;
|
|
130
|
-
return fileManager.addOrAppend(file);
|
|
131
|
-
},
|
|
132
|
-
resolveId,
|
|
133
|
-
load,
|
|
134
|
-
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
135
|
-
};
|
|
136
|
-
return {
|
|
137
|
-
name,
|
|
138
|
-
api,
|
|
139
|
-
resolveId(fileName, directory) {
|
|
140
|
-
if (!directory) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
return pathParser.resolve(directory, fileName);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// src/managers/fileManager/events.ts
|
|
149
|
-
var keys = {
|
|
150
|
-
getFileKey: () => `file`,
|
|
151
|
-
getStatusChangeKey: () => `status-change`,
|
|
152
|
-
getStatusChangeByIdKey: (id) => `${id}-status-change`,
|
|
153
|
-
getSuccessKey: () => `success`,
|
|
154
|
-
getRemoveKey: (id) => `${id}remove`
|
|
155
|
-
};
|
|
156
|
-
var getFileManagerEvents = (emitter) => {
|
|
157
|
-
return {
|
|
158
|
-
emitFile: (id, file) => {
|
|
159
|
-
emitter.emit(keys.getFileKey(), id, file);
|
|
160
|
-
},
|
|
161
|
-
emitStatusChange: (file) => {
|
|
162
|
-
emitter.emit(keys.getStatusChangeKey(), file);
|
|
163
|
-
},
|
|
164
|
-
emitStatusChangeById: (id, status) => {
|
|
165
|
-
emitter.emit(keys.getStatusChangeByIdKey(id), status);
|
|
166
|
-
},
|
|
167
|
-
emitSuccess: () => {
|
|
168
|
-
emitter.emit(keys.getSuccessKey());
|
|
169
|
-
},
|
|
170
|
-
emitRemove: (id, file) => {
|
|
171
|
-
emitter.emit(keys.getRemoveKey(id), file);
|
|
172
|
-
},
|
|
173
|
-
onAdd: (callback) => {
|
|
174
|
-
emitter.on(keys.getFileKey(), callback);
|
|
175
|
-
return () => emitter.removeListener(keys.getFileKey(), callback);
|
|
176
|
-
},
|
|
177
|
-
onStatusChange: (callback) => {
|
|
178
|
-
emitter.on(keys.getStatusChangeKey(), callback);
|
|
179
|
-
return () => emitter.removeListener(keys.getStatusChangeKey(), callback);
|
|
180
|
-
},
|
|
181
|
-
onStatusChangeById: (id, callback) => {
|
|
182
|
-
emitter.on(keys.getStatusChangeByIdKey(id), callback);
|
|
183
|
-
return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback);
|
|
184
|
-
},
|
|
185
|
-
onSuccess: (callback) => {
|
|
186
|
-
emitter.on(keys.getSuccessKey(), callback);
|
|
187
|
-
return () => emitter.removeListener(keys.getSuccessKey(), callback);
|
|
188
|
-
},
|
|
189
|
-
onRemove: (id, callback) => {
|
|
190
|
-
emitter.on(keys.getRemoveKey(id), callback);
|
|
191
|
-
return () => emitter.removeListener(keys.getRemoveKey(id), callback);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// src/managers/fileManager/FileManager.ts
|
|
197
|
-
var FileManager = class {
|
|
198
|
-
cache = /* @__PURE__ */ new Map();
|
|
199
|
-
emitter = new EventEmitter();
|
|
200
|
-
events = getFileManagerEvents(this.emitter);
|
|
201
|
-
constructor() {
|
|
202
|
-
this.events.onStatusChange(() => {
|
|
203
|
-
if (this.getCountByStatus("removed") === this.cache.size) {
|
|
204
|
-
this.events.emitSuccess();
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
getCache(id) {
|
|
209
|
-
return this.cache.get(id);
|
|
210
|
-
}
|
|
211
|
-
getCacheByPath(path) {
|
|
212
|
-
let cache;
|
|
213
|
-
this.cache.forEach((item) => {
|
|
214
|
-
if (item.file.path === path) {
|
|
215
|
-
cache = item;
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
return cache;
|
|
219
|
-
}
|
|
220
|
-
getCountByStatus(status) {
|
|
221
|
-
let count = 0;
|
|
222
|
-
this.cache.forEach((item) => {
|
|
223
|
-
if (item.status === status) {
|
|
224
|
-
count++;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
return count;
|
|
228
|
-
}
|
|
229
|
-
get files() {
|
|
230
|
-
const files = [];
|
|
231
|
-
this.cache.forEach((item) => {
|
|
232
|
-
files.push(item.file);
|
|
233
|
-
});
|
|
234
|
-
return files;
|
|
235
|
-
}
|
|
236
|
-
add(file) {
|
|
237
|
-
const cacheItem = { id: randomUUID(), file, status: "new" };
|
|
238
|
-
this.cache.set(cacheItem.id, cacheItem);
|
|
239
|
-
this.events.emitFile(cacheItem.id, file);
|
|
240
|
-
return new Promise((resolve) => {
|
|
241
|
-
const unsubscribe = this.events.onRemove(cacheItem.id, (file2) => {
|
|
242
|
-
resolve(file2);
|
|
243
|
-
unsubscribe();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
addOrAppend(file) {
|
|
248
|
-
const previousCache = this.getCacheByPath(file.path);
|
|
249
|
-
if (previousCache) {
|
|
250
|
-
this.remove(previousCache.id);
|
|
251
|
-
return this.add({
|
|
252
|
-
...file,
|
|
253
|
-
source: `${previousCache.file.source}
|
|
254
|
-
${file.source}`
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return this.add(file);
|
|
258
|
-
}
|
|
259
|
-
setStatus(id, status) {
|
|
260
|
-
const cacheItem = this.getCache(id);
|
|
261
|
-
if (!cacheItem) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
cacheItem.status = status;
|
|
265
|
-
this.cache.set(id, cacheItem);
|
|
266
|
-
this.events.emitStatusChange(cacheItem.file);
|
|
267
|
-
this.events.emitStatusChangeById(id, status);
|
|
268
|
-
}
|
|
269
|
-
get(id) {
|
|
270
|
-
const cacheItem = this.getCache(id);
|
|
271
|
-
return cacheItem?.file;
|
|
272
|
-
}
|
|
273
|
-
remove(id) {
|
|
274
|
-
const cacheItem = this.getCache(id);
|
|
275
|
-
if (!cacheItem) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
this.setStatus(id, "removed");
|
|
279
|
-
this.events.emitRemove(id, cacheItem.file);
|
|
280
|
-
}
|
|
281
|
-
async write(...params) {
|
|
282
|
-
return write(...params);
|
|
283
|
-
}
|
|
284
|
-
async read(...params) {
|
|
285
|
-
return read(...params);
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
var TreeNode = class {
|
|
289
|
-
data;
|
|
290
|
-
parent;
|
|
291
|
-
children;
|
|
292
|
-
constructor(data, parent) {
|
|
293
|
-
this.data = data;
|
|
294
|
-
this.parent = parent;
|
|
295
|
-
return this;
|
|
296
|
-
}
|
|
297
|
-
addChild(data) {
|
|
298
|
-
const child = new TreeNode(data, this);
|
|
299
|
-
if (!this.children) {
|
|
300
|
-
this.children = [];
|
|
301
|
-
}
|
|
302
|
-
this.children.push(child);
|
|
303
|
-
return child;
|
|
304
|
-
}
|
|
305
|
-
find(data) {
|
|
306
|
-
if (data === this.data) {
|
|
307
|
-
return this;
|
|
308
|
-
}
|
|
309
|
-
if (this.children) {
|
|
310
|
-
for (let i = 0, { length } = this.children, target = null; i < length; i++) {
|
|
311
|
-
target = this.children[i].find(data);
|
|
312
|
-
if (target) {
|
|
313
|
-
return target;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
leaves() {
|
|
320
|
-
if (!this.children || this.children.length === 0) {
|
|
321
|
-
return [this];
|
|
322
|
-
}
|
|
323
|
-
const leaves = [];
|
|
324
|
-
if (this.children) {
|
|
325
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
326
|
-
leaves.push.apply(leaves, this.children[i].leaves());
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return leaves;
|
|
330
|
-
}
|
|
331
|
-
root() {
|
|
332
|
-
if (!this.parent) {
|
|
333
|
-
return this;
|
|
334
|
-
}
|
|
335
|
-
return this.parent.root();
|
|
336
|
-
}
|
|
337
|
-
forEach(callback) {
|
|
338
|
-
if (typeof callback !== "function") {
|
|
339
|
-
throw new TypeError("forEach() callback must be a function");
|
|
340
|
-
}
|
|
341
|
-
callback(this);
|
|
342
|
-
if (this.children) {
|
|
343
|
-
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
344
|
-
this.children[i].forEach(callback);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return this;
|
|
348
|
-
}
|
|
349
|
-
static build(path, options = {}) {
|
|
350
|
-
const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
|
|
351
|
-
if (!filteredTree) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
|
|
355
|
-
const recurse = (node, item) => {
|
|
356
|
-
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
|
|
357
|
-
if (item.children?.length) {
|
|
358
|
-
item.children?.forEach((child) => {
|
|
359
|
-
recurse(subNode, child);
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
364
|
-
return treeNode;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
// src/managers/pluginManager/PluginManager.ts
|
|
369
|
-
var hookNames = {
|
|
370
|
-
validate: 1,
|
|
371
|
-
buildStart: 1,
|
|
372
|
-
resolveId: 1,
|
|
373
|
-
load: 1,
|
|
374
|
-
transform: 1,
|
|
375
|
-
writeFile: 1,
|
|
376
|
-
buildEnd: 1
|
|
377
|
-
};
|
|
378
|
-
var hooks = Object.keys(hookNames);
|
|
379
|
-
var PluginManager = class {
|
|
380
|
-
plugins;
|
|
381
|
-
fileManager;
|
|
382
|
-
logger;
|
|
383
|
-
config;
|
|
384
|
-
core;
|
|
385
|
-
constructor(config, options) {
|
|
386
|
-
this.logger = options.logger;
|
|
387
|
-
this.config = config;
|
|
388
|
-
this.fileManager = new FileManager();
|
|
389
|
-
this.core = definePlugin({
|
|
390
|
-
config,
|
|
391
|
-
fileManager: this.fileManager,
|
|
392
|
-
load: this.load,
|
|
393
|
-
resolveId: this.resolveId
|
|
394
|
-
});
|
|
395
|
-
this.plugins = [this.core, ...config.plugins || []];
|
|
396
|
-
}
|
|
397
|
-
resolveId = (params) => {
|
|
398
|
-
if (params.pluginName) {
|
|
399
|
-
return this.hookForPlugin(params.pluginName, "resolveId", [params.fileName, params.directory, params.options]);
|
|
400
|
-
}
|
|
401
|
-
return this.hookFirst("resolveId", [params.fileName, params.directory, params.options]);
|
|
402
|
-
};
|
|
403
|
-
load = async (id) => {
|
|
404
|
-
return this.hookFirst("load", [id]);
|
|
405
|
-
};
|
|
406
|
-
hookForPlugin(pluginName, hookName, parameters, skipped) {
|
|
407
|
-
let promise = Promise.resolve(null);
|
|
408
|
-
for (const plugin of this.getSortedPlugins(hookName, pluginName)) {
|
|
409
|
-
if (skipped && skipped.has(plugin))
|
|
410
|
-
continue;
|
|
411
|
-
promise = promise.then((result) => {
|
|
412
|
-
if (result != null)
|
|
413
|
-
return result;
|
|
414
|
-
return this.run("hookFirst", hookName, parameters, plugin);
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
return promise;
|
|
418
|
-
}
|
|
419
|
-
hookFirst(hookName, parameters, skipped) {
|
|
420
|
-
let promise = Promise.resolve(null);
|
|
421
|
-
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
422
|
-
if (skipped && skipped.has(plugin))
|
|
423
|
-
continue;
|
|
424
|
-
promise = promise.then((result) => {
|
|
425
|
-
if (result != null)
|
|
426
|
-
return result;
|
|
427
|
-
return this.run("hookFirst", hookName, parameters, plugin);
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
return promise;
|
|
431
|
-
}
|
|
432
|
-
async hookParallel(hookName, parameters) {
|
|
433
|
-
const parallelPromises = [];
|
|
434
|
-
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
435
|
-
if (plugin[hookName]?.sequential) {
|
|
436
|
-
await Promise.all(parallelPromises);
|
|
437
|
-
parallelPromises.length = 0;
|
|
438
|
-
await this.run("hookParallel", hookName, parameters, plugin);
|
|
439
|
-
} else {
|
|
440
|
-
const promise = this.run("hookParallel", hookName, parameters, plugin);
|
|
441
|
-
parallelPromises.push(promise);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return Promise.all(parallelPromises);
|
|
445
|
-
}
|
|
446
|
-
hookReduceArg0(hookName, [argument0, ...rest], reduce) {
|
|
447
|
-
let promise = Promise.resolve(argument0);
|
|
448
|
-
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
449
|
-
promise = promise.then(
|
|
450
|
-
(argument02) => this.run("hookReduceArg0", hookName, [argument02, ...rest], plugin).then(
|
|
451
|
-
(result) => reduce.call(this.core.api, argument02, result, plugin)
|
|
452
|
-
)
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
return promise;
|
|
456
|
-
}
|
|
457
|
-
hookSeq(hookName, parameters) {
|
|
458
|
-
let promise = Promise.resolve();
|
|
459
|
-
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
460
|
-
promise = promise.then(() => this.run("hookSeq", hookName, parameters, plugin));
|
|
461
|
-
}
|
|
462
|
-
return promise.then(noReturn);
|
|
463
|
-
}
|
|
464
|
-
getSortedPlugins(hookName, pluginName) {
|
|
465
|
-
const plugins = [...this.plugins];
|
|
466
|
-
if (pluginName) {
|
|
467
|
-
const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName]);
|
|
468
|
-
if (pluginsByPluginName.length === 0) {
|
|
469
|
-
if (this.config.logLevel === "warn" && this.logger?.spinner) {
|
|
470
|
-
this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`);
|
|
471
|
-
}
|
|
472
|
-
return [this.core];
|
|
473
|
-
}
|
|
474
|
-
return pluginsByPluginName;
|
|
475
|
-
}
|
|
476
|
-
return plugins;
|
|
477
|
-
}
|
|
478
|
-
run(strategy, hookName, parameters, plugin) {
|
|
479
|
-
const hook = plugin[hookName];
|
|
480
|
-
return Promise.resolve().then(() => {
|
|
481
|
-
if (typeof hook !== "function") {
|
|
482
|
-
return hook;
|
|
483
|
-
}
|
|
484
|
-
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
485
|
-
this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
486
|
-
`;
|
|
487
|
-
}
|
|
488
|
-
const hookResult = hook.apply(this.core.api, parameters);
|
|
489
|
-
if (!hookResult?.then) {
|
|
490
|
-
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
491
|
-
this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
492
|
-
`);
|
|
493
|
-
}
|
|
494
|
-
return hookResult;
|
|
495
|
-
}
|
|
496
|
-
return Promise.resolve(hookResult).then((result) => {
|
|
497
|
-
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
498
|
-
this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
499
|
-
`);
|
|
500
|
-
}
|
|
501
|
-
return result;
|
|
502
|
-
});
|
|
503
|
-
}).catch((e) => this.catcher(e, plugin, hookName));
|
|
504
|
-
}
|
|
505
|
-
runSync(hookName, parameters, plugin) {
|
|
506
|
-
const hook = plugin[hookName];
|
|
507
|
-
try {
|
|
508
|
-
return hook.apply(this.core.api, parameters);
|
|
509
|
-
} catch (error) {
|
|
510
|
-
return error;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
catcher(e, plugin, hookName) {
|
|
514
|
-
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
515
|
-
`;
|
|
516
|
-
if (this.logger?.spinner) {
|
|
517
|
-
this.logger.spinner.fail(text);
|
|
518
|
-
throw e;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
function noReturn() {
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// src/managers/pluginManager/validate.ts
|
|
526
|
-
var ValidationPluginError = class extends Error {
|
|
527
|
-
};
|
|
528
|
-
var validatePlugins = (plugins, dependedPluginNames) => {
|
|
529
|
-
let pluginNames = [];
|
|
530
|
-
if (typeof dependedPluginNames === "string") {
|
|
531
|
-
pluginNames = [dependedPluginNames];
|
|
532
|
-
} else {
|
|
533
|
-
pluginNames = dependedPluginNames;
|
|
534
|
-
}
|
|
535
|
-
pluginNames.forEach((pluginName) => {
|
|
536
|
-
const exists = plugins.some((plugin) => plugin.name === pluginName);
|
|
537
|
-
if (!exists) {
|
|
538
|
-
throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
return true;
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
// src/build.ts
|
|
545
|
-
async function transformReducer(_previousCode, result, _plugin) {
|
|
546
|
-
if (result === null) {
|
|
547
|
-
return null;
|
|
548
|
-
}
|
|
549
|
-
return result;
|
|
550
|
-
}
|
|
551
|
-
async function buildImplementation(options, done) {
|
|
552
|
-
const { config, logger } = options;
|
|
553
|
-
if (config.output.clean) {
|
|
554
|
-
await clean(config.output.path);
|
|
555
|
-
}
|
|
556
|
-
const pluginManager = new PluginManager(config, { logger });
|
|
557
|
-
const { plugins, fileManager } = pluginManager;
|
|
558
|
-
try {
|
|
559
|
-
await pluginManager.hookParallel("validate", [plugins]);
|
|
560
|
-
} catch (e) {
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
fileManager.events.onSuccess(async () => {
|
|
564
|
-
await pluginManager.hookParallel("buildEnd");
|
|
565
|
-
setTimeout(() => {
|
|
566
|
-
done({ fileManager });
|
|
567
|
-
}, 1e3);
|
|
568
|
-
});
|
|
569
|
-
fileManager.events.onAdd(async (id, file) => {
|
|
570
|
-
const { path } = file;
|
|
571
|
-
let { source: code } = file;
|
|
572
|
-
const loadedResult = await pluginManager.hookFirst("load", [path]);
|
|
573
|
-
if (loadedResult) {
|
|
574
|
-
code = loadedResult;
|
|
575
|
-
}
|
|
576
|
-
if (code) {
|
|
577
|
-
const transformedCode = await pluginManager.hookReduceArg0("transform", [code, path], transformReducer);
|
|
578
|
-
if (typeof config.input === "object") {
|
|
579
|
-
await pluginManager.hookParallel("writeFile", [transformedCode, path]);
|
|
580
|
-
}
|
|
581
|
-
fileManager.setStatus(id, "success");
|
|
582
|
-
fileManager.remove(id);
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
await pluginManager.hookParallel("buildStart", [config]);
|
|
586
|
-
}
|
|
587
|
-
function build(options) {
|
|
588
|
-
return new Promise((resolve, reject) => {
|
|
589
|
-
try {
|
|
590
|
-
buildImplementation(options, resolve);
|
|
591
|
-
} catch (e) {
|
|
592
|
-
reject(e);
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// src/config.ts
|
|
598
|
-
var defineConfig = (options) => options;
|
|
599
|
-
|
|
600
|
-
// src/generators/Generator.ts
|
|
601
|
-
var Generator = class {
|
|
602
|
-
_options = {};
|
|
603
|
-
constructor(options = {}) {
|
|
604
|
-
if (options) {
|
|
605
|
-
this._options = {
|
|
606
|
-
...this._options,
|
|
607
|
-
...options
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
return this;
|
|
611
|
-
}
|
|
612
|
-
get options() {
|
|
613
|
-
return this._options;
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
// src/generators/SchemaGenerator.ts
|
|
618
|
-
var SchemaGenerator = class extends Generator {
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
// src/index.ts
|
|
622
|
-
var src_default = build;
|
|
623
|
-
|
|
624
|
-
export { FileManager, Generator, PluginManager, SchemaGenerator, TreeNode, ValidationPluginError, build, clean, createPlugin, createPluginCache, src_default as default, defineConfig, format, getPathMode, getRelativePath, hooks, isPromise, read, validatePlugins, write };
|
|
625
|
-
//# sourceMappingURL=out.js.map
|
|
626
|
-
//# sourceMappingURL=index.mjs.map
|