@pi-r/gulp 0.6.2 → 0.6.5

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
- ### @pi-r/gulp
1
+ # @pi-r/gulp
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/task/index.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/task/index.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
2
  const path = require("path");
4
3
  const fs = require("fs");
5
4
  const child_process = require("child_process");
@@ -8,13 +7,13 @@ const which = require("which");
8
7
  const types_1 = require("@e-mc/types");
9
8
  const Task = require('@e-mc/task');
10
9
  const BIN_NPX = Task.sanitizeCmd(which.sync('npx', { nothrow: true }) || 'npx');
11
- const BIN_GULP = Task.sanitizeCmd(which.sync("gulp" /* STRINGS.MODULE_NAME */, { nothrow: true }) || '');
10
+ const BIN_GULP = Task.sanitizeCmd(which.sync("gulp", { nothrow: true }) || '');
12
11
  const REGEXP_TIMESTAMP = /^\[\d+:\d+:\d+\]$/;
13
12
  async function executeTasks(assets, preceding, host) {
14
13
  if (this.aborted) {
15
14
  return Promise.reject((0, types_1.createAbortError)());
16
15
  }
17
- return this.allSettled(this.collate(assets, preceding), ['Execute tasks', "gulp" /* STRINGS.MODULE_NAME */]).then(result => {
16
+ return this.allSettled(this.collate(assets, preceding), ['Execute tasks', "gulp"]).then(result => {
18
17
  if (host) {
19
18
  for (const output of result) {
20
19
  if (output.status === 'fulfilled') {
@@ -31,11 +30,10 @@ async function executeTasks(assets, preceding, host) {
31
30
  });
32
31
  }
33
32
  const normalizePath = (value) => process.platform === 'win32' ? '"' + value.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"' : Task.sanitizeArgs(value);
34
- // @ts-ignore
35
33
  class Gulp extends Task {
36
34
  constructor() {
37
35
  super(...arguments);
38
- this._moduleName = "gulp" /* STRINGS.MODULE_NAME */;
36
+ this._moduleName = "gulp";
39
37
  }
40
38
  static async finalize(instance, assets) {
41
39
  return executeTasks.call(instance, assets, false, this);
@@ -56,13 +54,25 @@ class Gulp extends Task {
56
54
  const origDir = path.dirname(localUri);
57
55
  const scheduled = new Set();
58
56
  for (let { task, handler, preceding } of item.tasks) {
59
- if (task && handler === "gulp" /* STRINGS.MODULE_NAME */ && !!preceding === isPreceding) {
57
+ if (task && handler === "gulp" && !!preceding === isPreceding) {
60
58
  let gulpfile = (0, types_1.isString)(task) ? username && (0, types_1.isObject)(settings.users) && settings.users[username]?.[task] || settings[task] : task, tasks, opts;
61
59
  if ((0, types_1.isObject)(gulpfile)) {
62
60
  ({ path: gulpfile, tasks, opts } = gulpfile);
63
61
  }
64
- if ((0, types_1.isString)(gulpfile) && Task.isPath(gulpfile = path.resolve(gulpfile), true) && ((0, types_1.isString)(task) || !this.canRead(gulpfile, { ownPermissionOnly: true }))) {
62
+ if ((0, types_1.isString)(gulpfile) && Task.isPath(gulpfile = path.resolve(gulpfile), true) && ((0, types_1.isString)(task) || this.canRead(gulpfile, { ownPermissionOnly: true }))) {
65
63
  if (!scheduled.has((0, types_1.isString)(task) ? task : task = JSON.stringify(task))) {
64
+ try {
65
+ const buffer = item.sourceUTF8 || item.buffer;
66
+ if (buffer) {
67
+ fs.writeFileSync(localUri, buffer);
68
+ delete item.sourceUTF8;
69
+ delete item.buffer;
70
+ }
71
+ }
72
+ catch (err) {
73
+ this.writeFail(["Unable to write file", path.basename(localUri)], err, 32);
74
+ continue;
75
+ }
66
76
  let dirMap = taskMap.get(task);
67
77
  if (!dirMap) {
68
78
  taskMap.set(task, dirMap = new Map());
@@ -73,15 +83,13 @@ class Gulp extends Task {
73
83
  }
74
84
  sourceDir.items.push(localUri);
75
85
  scheduled.add(task);
76
- delete item.sourceUTF8;
77
- delete item.buffer;
78
86
  }
79
87
  }
80
88
  else {
81
89
  if (!(0, types_1.isString)(task)) {
82
90
  task = gulpfile && path.basename(gulpfile);
83
91
  }
84
- this.writeFail(["Unable to perform task" /* ERR_MESSAGE.PERFORM_TASK */, task ? "gulp" /* STRINGS.MODULE_NAME */ + ': ' + task : ''], (0, types_1.errorMessage)(task || "gulp" /* STRINGS.MODULE_NAME */, "Unknown" /* ERR_MESSAGE.UNKNOWN */, username), 4 /* LOG_TYPE.PROCESS */);
92
+ this.writeFail(["Unable to perform task", task ? "gulp" + ': ' + task : ''], (0, types_1.errorMessage)(task || "gulp", "Unknown", username), 4);
85
93
  }
86
94
  }
87
95
  }
@@ -181,7 +189,7 @@ class Gulp extends Task {
181
189
  spawn(gulp, callback) {
182
190
  const { task, origDir, data } = gulp;
183
191
  const tempDir = this.getTempDir({ uuidDir: true });
184
- const writeError = (value, err, hint, type = 32 /* LOG_TYPE.FILE */) => {
192
+ const writeError = (value, err, hint, type = 32) => {
185
193
  if (err) {
186
194
  this.writeFail([value, hint || (this.moduleName + ': ' + task)], err, { type, startTime });
187
195
  }
@@ -191,7 +199,7 @@ class Gulp extends Task {
191
199
  }
192
200
  };
193
201
  if (!tempDir) {
194
- writeError("Unable to create temp directory" /* ERR_MESSAGE.TEMP_DIRECTORY */, null, this.getTempDir());
202
+ writeError("Unable to create temp directory", null, this.getTempDir());
195
203
  return;
196
204
  }
197
205
  const exec = this.settings.exec;
@@ -246,7 +254,7 @@ class Gulp extends Task {
246
254
  }
247
255
  const startTime = process.hrtime();
248
256
  const broadcastId = this.broadcastId;
249
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, "gulp" /* STRINGS.MODULE_NAME */, ['Executing task...', task], gulpfile);
257
+ this.formatMessage(4, "gulp", ['Executing task...', task], gulpfile);
250
258
  Promise.all(items.map(async (src) => fs.promises.copyFile(src, path.join(tempDir, path.basename(src)))))
251
259
  .then(() => {
252
260
  try {
@@ -264,7 +272,7 @@ class Gulp extends Task {
264
272
  timeStamp = '';
265
273
  }
266
274
  };
267
- const { stdout, stderr } = child_process.spawn(BIN_GULP || BIN_NPX, args, { cwd: process.cwd(), shell: true, stdio: Task.hasLogType(32768 /* LOG_TYPE.STDOUT */) && !broadcastId ? 'inherit' : undefined, signal: this.signal, uid, gid })
275
+ const { stdout, stderr } = child_process.spawn(BIN_GULP || BIN_NPX, args, { cwd: process.cwd(), shell: true, stdio: Task.hasLogType(32768) && !broadcastId ? 'inherit' : undefined, signal: this.signal, uid, gid })
268
276
  .on('exit', code => {
269
277
  if (!code) {
270
278
  this.addLog(types_1.STATUS_TYPE.INFO, out);
@@ -293,14 +301,14 @@ class Gulp extends Task {
293
301
  --i;
294
302
  }
295
303
  else {
296
- this.writeFail(["Unable to rename file" /* ERR_MESSAGE.RENAME_FILE */, filename], err, 32 /* LOG_TYPE.FILE */);
304
+ this.writeFail(["Unable to rename file", filename], err, 32);
297
305
  }
298
306
  }
299
307
  }
300
- this.writeTimeProcess("gulp" /* STRINGS.MODULE_NAME */, task + ' -> ' + path.basename(items[0]), startTime);
308
+ this.writeTimeProcess("gulp", task + ' -> ' + path.basename(items[0]), startTime);
301
309
  }
302
310
  catch (err) {
303
- writeError("Unable to read directory" /* ERR_MESSAGE.READ_DIRECTORY */, err, false);
311
+ writeError("Unable to read directory", err, false);
304
312
  }
305
313
  items.forEach(value => !result.has(value) && (deleted || (deleted = [])).push(value));
306
314
  result.forEach(value => !items.includes(value) && (added || (added = [])).push(value));
@@ -308,10 +316,10 @@ class Gulp extends Task {
308
316
  callback({ added, deleted });
309
317
  }
310
318
  else {
311
- writeError("Unable to execute file" /* ERR_MESSAGE.EXECUTE_FILE */, new Error(message || "Unknown" /* ERR_MESSAGE.UNKNOWN */), '', 4 /* LOG_TYPE.PROCESS */);
319
+ writeError("Unable to execute file", new Error(message || "Unknown"), '', 4);
312
320
  }
313
321
  })
314
- .on('error', err => writeError("Unknown" /* ERR_MESSAGE.UNKNOWN */, err, false, 4 /* LOG_TYPE.PROCESS */));
322
+ .on('error', err => writeError("Unknown", err, false, 4));
315
323
  if (stdout) {
316
324
  stdout.setEncoding('utf-8').on('data', (value) => {
317
325
  if (broadcastId) {
@@ -330,10 +338,10 @@ class Gulp extends Task {
330
338
  }
331
339
  }
332
340
  catch (err) {
333
- writeError("Unable to execute file" /* ERR_MESSAGE.EXECUTE_FILE */, err);
341
+ writeError("Unable to execute file", err);
334
342
  }
335
343
  })
336
- .catch(err => writeError("Unable to copy file" /* ERR_MESSAGE.COPY_FILE */, err, tempDir));
344
+ .catch(err => writeError("Unable to copy file", err, tempDir));
337
345
  }
338
346
  }
339
347
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gulp",
3
- "version": "0.6.2",
3
+ "version": "0.6.5",
4
4
  "description": "Gulp task constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/anpham6/pi-r.git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
12
  "directory": "src/module/gulp"
13
13
  },
14
14
  "keywords": [
@@ -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.8.2",
24
- "@e-mc/types": "^0.8.2",
23
+ "@e-mc/task": "^0.8.6",
24
+ "@e-mc/types": "^0.8.6",
25
25
  "gulp": "^4.0.2",
26
26
  "gulp-cli": "^2.3.0",
27
27
  "strip-ansi": "6.0.1",
package/types/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface GulpData extends GulpCommand {
10
10
  items: string[];
11
11
  }
12
12
 
13
- export interface GulpSettings extends ObjectMap<GulpTask>, PlainObject {
13
+ export interface GulpSettings extends PlainObject {
14
14
  exec?: ExecAction;
15
15
  users?: GulpUsers;
16
16
  }