html-snapshots 1.7.0 → 1.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.
@@ -13,9 +13,8 @@
13
13
  const spawn = require("child_process").spawn;
14
14
  const path = require("path");
15
15
  const EventEmitter = require("events").EventEmitter;
16
- const rimraf = require("rimraf").sync;
16
+ const fs = require("fs");
17
17
  const asyncLib = require("async");
18
-
19
18
  const common = require("./common");
20
19
  const inputFactory = require("./input-generators");
21
20
  const Notifier = require("./async").Notifier;
@@ -239,83 +238,85 @@ function prepOptions (options) {
239
238
  }
240
239
  }
241
240
 
242
- module.exports = {
243
- /**
244
- * Run all the snapshots using the requested inputGenerator
245
- *
246
- * @param {Object} options - ALL user supplied html snapshots options.
247
- * @param {String} options.outputDir - Directory to write the html files to.
248
- * @param {String} [options.input] - Input source type "robots", "sitemap", "array";
249
- * Defaults to "robots".
250
- * @param {Boolean} [options.outputDirClean] - True if output dir should be rm -rf;
251
- * Defaults to false.
252
- * @param {Number} [options.pollInterval] -
253
- * @param {Function} [listener] - User supplied optional callback.
254
- * @returns {Promise} Resolves on completion.
255
- */
256
- run: function (options, listener) {
257
- options = options || {};
258
- prepOptions(options);
259
-
260
- // create the inputGenerator, default to robots
261
- const inputGenerator = inputFactory.create(options.input);
262
-
263
- // clean the snapshot output directory
264
- if (options.outputDirClean) {
265
- rimraf(options.outputDir);
266
- }
241
+ /**
242
+ * Run all the snapshots using the requested inputGenerator
243
+ *
244
+ * @param {Object} options - ALL user supplied html snapshots options.
245
+ * @param {String} options.outputDir - Directory to write the html files to.
246
+ * @param {String} [options.input] - Input source type "robots", "sitemap", "array";
247
+ * Defaults to "robots".
248
+ * @param {Boolean} [options.outputDirClean] - True if output dir should be rm -rf;
249
+ * Defaults to false.
250
+ * @param {Number} [options.pollInterval] -
251
+ * @param {Function} [listener] - User supplied optional callback.
252
+ * @returns {Promise} Resolves on completion.
253
+ */
254
+ function run (options, listener) {
255
+ options = options || {};
256
+ prepOptions(options);
267
257
 
268
- // start async completion notification.
269
- const notifier = new Notifier();
270
- const emitter = new EventEmitter();
271
- const started = notifier.start(
272
- options.pollInterval,
273
- inputGenerator,
274
- (err, completed) => emitter.emit("complete", err, completed)
275
- );
258
+ // clean the snapshot output directory
259
+ if (options.outputDirClean) {
260
+ fs.rmSync(options.outputDir, { recursive: true, force: true });
261
+ }
276
262
 
277
- if (started) {
278
- // create the completion Promise.
279
- const completion = new Promise((resolve, reject) => {
280
- function completionResolver (err, completed) {
281
- try {
282
- common.isFunction(listener) && listener(err, completed);
283
- } catch (e) {
284
- console.error("User supplied listener exception", e);
285
- }
286
- if (err) {
287
- err.notCompleted = notifier.filesNotDone;
288
- err.completed = completed;
289
- reject(err);
290
- } else {
291
- resolve(completed);
292
- }
263
+ // create the inputGenerator, default to robots
264
+ const inputGenerator = inputFactory.create(options.input);
265
+
266
+ // start async completion notification.
267
+ const notifier = new Notifier();
268
+ const emitter = new EventEmitter();
269
+ const started = notifier.start(
270
+ options.pollInterval,
271
+ inputGenerator,
272
+ (err, completed) => emitter.emit("complete", err, completed)
273
+ );
274
+
275
+ if (started) {
276
+ // create the completion Promise.
277
+ const completion = new Promise((resolve, reject) => {
278
+ function completionResolver (err, completed) {
279
+ try {
280
+ common.isFunction(listener) && listener(err, completed);
281
+ } catch (e) {
282
+ console.error("User supplied listener exception", e);
283
+ }
284
+ if (err) {
285
+ err.notCompleted = notifier.filesNotDone;
286
+ err.completed = completed;
287
+ reject(err);
288
+ } else {
289
+ resolve(completed);
293
290
  }
294
- emitter.addListener("complete", completionResolver);
295
- });
291
+ }
292
+ emitter.addListener("complete", completionResolver);
293
+ });
296
294
 
297
- // create a worker queue with a parallel process limit.
298
- const q = asyncLib.queue(
299
- (task, callback) => { task(common.once(callback)); },
300
- options.processLimit
301
- );
295
+ // create a worker queue with a parallel process limit.
296
+ const q = asyncLib.queue(
297
+ (task, callback) => { task(common.once(callback)); },
298
+ options.processLimit
299
+ );
302
300
 
303
- // have the queue call notifier.empty when last item
304
- // from the queue is given to a worker.
305
- q.empty(notifier.qEmpty.bind(notifier));
301
+ // have the queue call notifier.empty when last item
302
+ // from the queue is given to a worker.
303
+ q.empty(notifier.qEmpty.bind(notifier));
306
304
 
307
- // expose abort callback to input generators via options.
308
- options._abort = notifier.abort.bind(notifier, q);
305
+ // expose abort callback to input generators via options.
306
+ options._abort = notifier.abort.bind(notifier, q);
309
307
 
310
- const worker =
311
- options.browser === 'puppeteer' ? puppeteerWorker : phantomjsWorker;
308
+ const worker =
309
+ options.browser === 'puppeteer' ? puppeteerWorker : phantomjsWorker;
312
310
 
313
- // generate input for the snapshots.
314
- return inputGenerator.run(options, input => {
315
- q.push(worker.bind(worker, input, options, notifier));
316
- }).then(() => completion)
317
- }
318
-
319
- return Promise.reject("failed to start async notifier");
311
+ // generate input for the snapshots.
312
+ return inputGenerator.run(options, input => {
313
+ q.push(worker.bind(worker, input, options, notifier));
314
+ }).then(() => completion)
320
315
  }
316
+
317
+ return Promise.reject("failed to start async notifier");
318
+ }
319
+
320
+ module.exports = {
321
+ run
321
322
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-snapshots",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "author": {
5
5
  "name": "Alex Grant",
6
6
  "email": "alex@localnerve.com",
@@ -58,12 +58,11 @@
58
58
  "combine-errors": "3.0.3",
59
59
  "got": "12.5.3",
60
60
  "phantomjs-prebuilt": "2.1.16",
61
- "puppeteer": "^19.5.0",
62
- "rimraf": "3.0.2",
61
+ "puppeteer": "^19.6.0",
63
62
  "xml2js": "0.4.23"
64
63
  },
65
64
  "devDependencies": {
66
- "eslint": "8.31.0",
65
+ "eslint": "8.32.0",
67
66
  "express": "4.18.2",
68
67
  "mocha": "10.2.0",
69
68
  "c8": "7.12.0",