@pi-r/gulp 0.7.2 → 0.8.0
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/index.js +42 -22
- package/package.json +3 -3
- package/types/index.d.ts +8 -2
package/index.js
CHANGED
|
@@ -9,34 +9,34 @@ const Task = require('@e-mc/task');
|
|
|
9
9
|
const BIN_NPX = Task.sanitizeCmd(which.sync('npx', { nothrow: true }) || 'npx');
|
|
10
10
|
const BIN_GULP = Task.sanitizeCmd(which.sync("gulp", { nothrow: true }) || '');
|
|
11
11
|
const REGEXP_TIMESTAMP = /^\[\d+:\d+:\d+\]$/;
|
|
12
|
-
async function executeTasks(assets, preceding, host) {
|
|
13
|
-
if (
|
|
12
|
+
async function executeTasks(instance, assets, preceding, host) {
|
|
13
|
+
if (instance.aborted) {
|
|
14
14
|
return (0, types_1.createAbortError)(true);
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return instance.allSettled(instance.collate(assets, preceding), ['Execute tasks', "gulp"]).then(result => {
|
|
17
17
|
if (host) {
|
|
18
18
|
for (const output of result) {
|
|
19
19
|
if (output.status === 'fulfilled') {
|
|
20
20
|
const { added, deleted } = output.value;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
21
|
+
deleted?.forEach(file => {
|
|
22
|
+
host.deleteFile(file);
|
|
23
|
+
});
|
|
24
|
+
added?.forEach(file => {
|
|
25
|
+
host.add(file);
|
|
26
|
+
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
const normalizePath = (value) =>
|
|
32
|
+
const normalizePath = (value) => Task.PLATFORM_WIN32 ? '"' + value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"' : Task.sanitizeArgs(value);
|
|
33
33
|
class Gulp extends Task {
|
|
34
34
|
static async finalize(instance, assets) {
|
|
35
|
-
return executeTasks
|
|
35
|
+
return executeTasks(instance, assets, false, this);
|
|
36
36
|
}
|
|
37
37
|
_moduleName = "gulp";
|
|
38
38
|
async using(data) {
|
|
39
|
-
return executeTasks
|
|
39
|
+
return executeTasks(this, [data.file], true, data.host);
|
|
40
40
|
}
|
|
41
41
|
collate(assets, isPreceding = false) {
|
|
42
42
|
const settings = this.settings;
|
|
@@ -142,16 +142,20 @@ class Gulp extends Task {
|
|
|
142
142
|
return 0;
|
|
143
143
|
});
|
|
144
144
|
const result = [];
|
|
145
|
-
if (series.length) {
|
|
145
|
+
if (series.length > 0) {
|
|
146
146
|
result.push(this.series(series));
|
|
147
147
|
}
|
|
148
|
-
if (parallel.length) {
|
|
148
|
+
if (parallel.length > 0) {
|
|
149
149
|
result.push(this.parallel(parallel));
|
|
150
150
|
}
|
|
151
151
|
return result;
|
|
152
152
|
}
|
|
153
153
|
queue(tasks) {
|
|
154
|
-
return tasks.map(async (item) => new Promise(resolve => {
|
|
154
|
+
return tasks.map(async (item) => new Promise(resolve => {
|
|
155
|
+
this.spawn(item, (result) => {
|
|
156
|
+
resolve(result);
|
|
157
|
+
});
|
|
158
|
+
}));
|
|
155
159
|
}
|
|
156
160
|
async series(tasks) {
|
|
157
161
|
let added, deleted;
|
|
@@ -191,7 +195,9 @@ class Gulp extends Task {
|
|
|
191
195
|
this.writeFail([value, hint || (this.moduleName + ': ' + task)], err, { type, startTime });
|
|
192
196
|
}
|
|
193
197
|
if (hint !== false) {
|
|
194
|
-
queueMicrotask(() =>
|
|
198
|
+
queueMicrotask(() => {
|
|
199
|
+
Task.removeDir(tempDir);
|
|
200
|
+
});
|
|
195
201
|
callback();
|
|
196
202
|
}
|
|
197
203
|
};
|
|
@@ -248,7 +254,7 @@ class Gulp extends Task {
|
|
|
248
254
|
Promise.all(items.map(async (src) => fs.promises.copyFile(src, path.join(tempDir, path.basename(src)))))
|
|
249
255
|
.then(() => {
|
|
250
256
|
try {
|
|
251
|
-
const args = [...Task.sanitizeArgs(tasks), ...opts, '--gulpfile',
|
|
257
|
+
const args = [...Task.sanitizeArgs(tasks), ...opts, '--gulpfile', normalizePath(gulpfile), '--cwd', normalizePath(tempDir)];
|
|
252
258
|
if (!BIN_GULP) {
|
|
253
259
|
args.unshift('gulp');
|
|
254
260
|
}
|
|
@@ -300,16 +306,28 @@ class Gulp extends Task {
|
|
|
300
306
|
catch (err) {
|
|
301
307
|
writeError("Unable to read directory", err, false);
|
|
302
308
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
309
|
+
for (const value of items) {
|
|
310
|
+
if (!result.has(value)) {
|
|
311
|
+
(deleted ||= []).push(value);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
for (const value of result) {
|
|
315
|
+
if (!items.includes(value)) {
|
|
316
|
+
(added ||= []).push(value);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
queueMicrotask(() => {
|
|
320
|
+
Task.removeDir(tempDir);
|
|
321
|
+
});
|
|
306
322
|
callback({ added, deleted });
|
|
307
323
|
}
|
|
308
324
|
else {
|
|
309
325
|
writeError("Unable to execute file", new Error(message || "Unknown"), '', 4);
|
|
310
326
|
}
|
|
311
327
|
})
|
|
312
|
-
.on('error', err =>
|
|
328
|
+
.on('error', err => {
|
|
329
|
+
writeError("Unknown", err, false, 4);
|
|
330
|
+
});
|
|
313
331
|
if (stdout) {
|
|
314
332
|
stdout.setEncoding('utf-8').on('data', (value) => {
|
|
315
333
|
if (broadcastId) {
|
|
@@ -331,7 +349,9 @@ class Gulp extends Task {
|
|
|
331
349
|
writeError("Unable to execute file", err);
|
|
332
350
|
}
|
|
333
351
|
})
|
|
334
|
-
.catch((err) =>
|
|
352
|
+
.catch((err) => {
|
|
353
|
+
writeError("Unable to copy file", err, tempDir);
|
|
354
|
+
});
|
|
335
355
|
}
|
|
336
356
|
}
|
|
337
357
|
module.exports = Gulp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gulp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Gulp task constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/task": "^0.
|
|
24
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/task": "^0.10.0",
|
|
24
|
+
"@e-mc/types": "^0.10.0",
|
|
25
25
|
"gulp": "^5.0.0",
|
|
26
26
|
"gulp-cli": "^3.0.0",
|
|
27
27
|
"strip-ansi": "6.0.1",
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IHost, ITask, TaskConstructor } from '@e-mc/types/lib';
|
|
2
|
+
import type { ExecAction, TaskModule } from '@e-mc/types/lib/settings';
|
|
2
3
|
|
|
3
4
|
export interface GulpCommand {
|
|
4
5
|
path?: string;
|
|
@@ -16,4 +17,9 @@ export interface GulpSettings extends PlainObject {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export type GulpTask = string | GulpCommand;
|
|
19
|
-
export type GulpUsers = GulpTask | AnyObject;
|
|
20
|
+
export type GulpUsers = GulpTask | AnyObject;
|
|
21
|
+
|
|
22
|
+
export interface GulpTaskConstructor<T extends IHost, U extends TaskModule = TaskModule<GulpSettings>> extends ConstructorDerived<TaskConstructor<T, U>> {
|
|
23
|
+
readonly prototype: ITask<T, U>;
|
|
24
|
+
new(module?: U, ...args: unknown[]): ITask<T, U>;
|
|
25
|
+
}
|