js-build-tools 2.1.2 → 2.2.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/README.md CHANGED
@@ -23,6 +23,9 @@ module.exports = {
23
23
 
24
24
  // The output directory for browser-bundled files.
25
25
  browserPath: 'browser',
26
+
27
+ // The paths for directories to delete before build.
28
+ cleanPaths: ['dist', 'browser'],
26
29
 
27
30
  // The name of entry the distribution file.
28
31
  distMain: 'dist/main',
@@ -156,8 +159,8 @@ Export these functions to your own project in order to customize your build pipe
156
159
  * [.watchTest()](#module_js-build-tools.watchTest) ⇒ <code>\*</code>
157
160
  * [.watchFull()](#module_js-build-tools.watchFull) ⇒ <code>FSWatcher</code>
158
161
  * [.typeScript()](#module_js-build-tools.typeScript) ⇒ <code>stream.Stream</code>
159
- * [.testQuick([done], [testPath])](#module_js-build-tools.testQuick) ⇒ <code>Promise.&lt;\*&gt;</code>
160
- * [.testFull([done], [testPath])](#module_js-build-tools.testFull) ⇒ <code>Promise.&lt;\*&gt;</code>
162
+ * [.testQuick()](#module_js-build-tools.testQuick) ⇒ <code>Promise.&lt;\*&gt;</code>
163
+ * [.testFull()](#module_js-build-tools.testFull) ⇒ <code>Promise.&lt;\*&gt;</code>
161
164
  * [.distMinify()](#module_js-build-tools.distMinify) ⇒ <code>\*</code>
162
165
  * [.distLint()](#module_js-build-tools.distLint) ⇒ <code>\*</code>
163
166
  * [.dist()](#module_js-build-tools.dist) ⇒ <code>\*</code>
@@ -193,28 +196,16 @@ Simplified typescript task using tsFor.
193
196
  **Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
194
197
  <a name="module_js-build-tools.testQuick"></a>
195
198
 
196
- ### js-build-tools.testQuick([done], [testPath]) ⇒ <code>Promise.&lt;\*&gt;</code>
197
- Run the Jest tests for files which have been modified (based on git status).
199
+ ### js-build-tools.testQuick() ⇒ <code>Promise.&lt;\*&gt;</code>
200
+ Run the Jest tests for files which have been modified (based on git status).
198
201
 
199
202
  **Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
200
-
201
- | Param | Type | Default |
202
- | --- | --- | --- |
203
- | [done] | <code>function</code> | <code></code> |
204
- | [testPath] | <code>Array.&lt;string&gt;</code> \| <code>string</code> | <code>&#x27;path/config/test/files&#x27;</code> |
205
-
206
203
  <a name="module_js-build-tools.testFull"></a>
207
204
 
208
- ### js-build-tools.testFull([done], [testPath]) ⇒ <code>Promise.&lt;\*&gt;</code>
209
- Run all tests with jest.
205
+ ### js-build-tools.testFull() ⇒ <code>Promise.&lt;\*&gt;</code>
206
+ Run all tests with jest.
210
207
 
211
208
  **Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
212
-
213
- | Param | Type | Default |
214
- | --- | --- | --- |
215
- | [done] | <code>function</code> | <code></code> |
216
- | [testPath] | <code>Array.&lt;string&gt;</code> \| <code>string</code> | <code>&#x27;path/config/test/files&#x27;</code> |
217
-
218
209
  <a name="module_js-build-tools.distMinify"></a>
219
210
 
220
211
  ### js-build-tools.distMinify() ⇒ <code>\*</code>
@@ -554,14 +545,15 @@ Micro-functions used as components for the main gulp functions.
554
545
  * [.tsFor([srcPath], [distPath])](#module_partials.tsFor) ⇒ <code>stream.Stream</code>
555
546
  * [.runOnChange(path)](#module_partials.runOnChange) ⇒ <code>stream.Stream</code>
556
547
  * [~pathRegex](#module_partials.runOnChange..pathRegex)
548
+ * [.removeDirectory(dirPath)](#module_partials.removeDirectory) ⇒ <code>Promise.&lt;\*&gt;</code>
557
549
  * [.readmeTemplate()](#module_partials.readmeTemplate) ⇒ <code>\*</code>
558
550
  * [.minifyFor()](#module_partials.minifyFor) ⇒ <code>\*</code>
559
551
  * [.distSeries([srcPath], [distFinalPath], [tsSearch])](#module_partials.distSeries) ⇒ <code>function</code>
560
552
  * [.distForSrc([useTs])](#module_partials.distForSrc) ⇒ <code>string</code>
561
553
  * [.distFor([srcPath], [destPath])](#module_partials.distFor) ⇒ <code>stream.Stream</code>
562
- * [.clean([done], [paths])](#module_partials.clean) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>\*</code>
554
+ * [.clean()](#module_partials.clean) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>\*</code>
563
555
  * [.beginWatcher()](#module_partials.beginWatcher) ⇒ <code>FSWatcher</code>
564
- * [.addToReadme([done])](#module_partials.addToReadme) ⇒ <code>string</code> \| <code>Uint8Array</code>
556
+ * [.addToReadme()](#module_partials.addToReadme) ⇒ <code>string</code> \| <code>Uint8Array</code>
565
557
 
566
558
  <a name="module_partials.tsFor"></a>
567
559
 
@@ -597,6 +589,17 @@ Run this function when the watched files are modified.
597
589
  1. The original path comes in from src and is a .ts
598
590
 
599
591
  **Kind**: inner constant of [<code>runOnChange</code>](#module_partials.runOnChange)
592
+ <a name="module_partials.removeDirectory"></a>
593
+
594
+ ### partials.removeDirectory(dirPath) ⇒ <code>Promise.&lt;\*&gt;</code>
595
+ Return a promise to be completed once the specified directory is deleted.
596
+
597
+ **Kind**: static method of [<code>partials</code>](#module_partials)
598
+
599
+ | Param | Type |
600
+ | --- | --- |
601
+ | dirPath | <code>string</code> |
602
+
600
603
  <a name="module_partials.readmeTemplate"></a>
601
604
 
602
605
  ### partials.readmeTemplate() ⇒ <code>\*</code>
@@ -647,16 +650,10 @@ Build the distribution for a given source pattern.
647
650
 
648
651
  <a name="module_partials.clean"></a>
649
652
 
650
- ### partials.clean([done], [paths]) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>\*</code>
651
- Deletes all the distribution and browser files (used before create a new build).
653
+ ### partials.clean() ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>\*</code>
654
+ Deletes all the distribution and browser files (used before create a new build).
652
655
 
653
656
  **Kind**: static method of [<code>partials</code>](#module_partials)
654
-
655
- | Param | Type | Default |
656
- | --- | --- | --- |
657
- | [done] | <code>function</code> | <code></code> |
658
- | [paths] | <code>Array.&lt;string&gt;</code> | <code>[&#x27;dist/config/path&#x27;, &#x27;browser/config/path&#x27;]</code> |
659
-
660
657
  <a name="module_partials.beginWatcher"></a>
661
658
 
662
659
  ### partials.beginWatcher() ⇒ <code>FSWatcher</code>
@@ -665,12 +662,7 @@ Create a chokidar instance which watches and triggers change when the globed fil
665
662
  **Kind**: static method of [<code>partials</code>](#module_partials)
666
663
  <a name="module_partials.addToReadme"></a>
667
664
 
668
- ### partials.addToReadme([done]) ⇒ <code>string</code> \| <code>Uint8Array</code>
669
- Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
665
+ ### partials.addToReadme() ⇒ <code>string</code> \| <code>Uint8Array</code>
666
+ Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
670
667
 
671
668
  **Kind**: static method of [<code>partials</code>](#module_partials)
672
-
673
- | Param | Type | Default |
674
- | --- | --- | --- |
675
- | [done] | <code>function</code> \| <code>null</code> | <code></code> |
676
-
@@ -8,18 +8,16 @@ var _require = require('glob'),
8
8
 
9
9
  /**
10
10
  * Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
11
+ * Configure this with 'readmeSearch', 'readmePath', 'readmeFile', and 'readmeOptions'.
11
12
  * @function
12
13
  * @memberOf module:partials
13
- * @param {function|null} [done=null]
14
14
  * @returns {string|Uint8Array}
15
15
  */
16
16
  var addToReadme = function addToReadme() {
17
- var done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
18
- var files = globSync(gulpConfig.get('readmeSearch'));
19
- var readme = jsdoc2md.renderSync({
20
- files: files
17
+ return jsdoc2md.render({
18
+ files: globSync(gulpConfig.get('readmeSearch'))
19
+ }).then(function (readme) {
20
+ return fs.appendFileSync(gulpConfig.get('readmePath') + gulpConfig.get('readmeFile'), readme, gulpConfig.get('readmeOptions'));
21
21
  });
22
- fs.appendFileSync(gulpConfig.get('readmePath') + gulpConfig.get('readmeFile'), readme, gulpConfig.get('readmeOptions'));
23
- return done && done();
24
22
  };
25
23
  module.exports = addToReadme;
@@ -1,21 +1,26 @@
1
1
  "use strict";
2
2
 
3
- var del = require('del');
3
+ require("core-js/modules/es.array.reduce.js");
4
+ require("core-js/modules/es.object.to-string.js");
5
+ require("core-js/modules/esnext.async-iterator.reduce.js");
6
+ require("core-js/modules/esnext.iterator.constructor.js");
7
+ require("core-js/modules/esnext.iterator.reduce.js");
8
+ require("core-js/modules/es.promise.js");
4
9
  var gulpConfig = require('../../gulp.config.js');
10
+ var removeDirectory = require('./removeDirectory');
5
11
 
6
12
  /**
7
13
  * Deletes all the distribution and browser files (used before create a new build).
14
+ * Configure array of directories to remove with 'cleanPaths'.
8
15
  * @function
9
16
  * @memberOf module:partials
10
- * @param {function} [done=null]
11
- * @param {string[]} [paths=['dist/config/path', 'browser/config/path']]
12
17
  * @returns {Promise<string[]> | *}
13
18
  */
14
19
  var clean = function clean() {
15
- var done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
16
- var paths = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [gulpConfig.get('distPath'), gulpConfig.get('browserPath')];
17
- return del(paths).then(function () {
18
- return done && done();
19
- });
20
+ return gulpConfig.get('cleanPaths').reduce(function (promise, path) {
21
+ return promise.then(function () {
22
+ return removeDirectory(path);
23
+ });
24
+ }, Promise.resolve());
20
25
  };
21
26
  module.exports = clean;
@@ -14,7 +14,7 @@ var tsFor = require('./tsFor');
14
14
  * @param {string} [srcPath='src/config/path/dist/for']
15
15
  * @param {string} [distFinalPath='dist/config/path']
16
16
  * @param {string} [tsSearch='ts/search/config/path']
17
- * @returns {Function}
17
+ * @returns {function(null=): stream.Stream}
18
18
  */
19
19
  var distSeries = function distSeries() {
20
20
  var srcPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : distForSrc();
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ require("core-js/modules/es.object.to-string.js");
4
+ require("core-js/modules/es.promise.js");
5
+ var _require = require('fs'),
6
+ rm = _require.rm,
7
+ exists = _require.exists;
8
+
9
+ /**
10
+ * Return a promise to be completed once the specified directory is deleted.
11
+ * @function
12
+ * @memberOf module:partials
13
+ * @param {string} dirPath
14
+ * @returns {Promise<*>}
15
+ */
16
+ var removeDirectory = function removeDirectory(dirPath) {
17
+ return new Promise(function (resolve, reject) {
18
+ return exists(dirPath, function (doesExist) {
19
+ return doesExist ? rm(dirPath, {
20
+ recursive: true
21
+ }, function (error) {
22
+ return error ? reject(error) : resolve(dirPath);
23
+ }) : resolve(dirPath);
24
+ });
25
+ });
26
+ };
27
+ module.exports = removeDirectory;
package/dist/partials.js CHANGED
@@ -17,6 +17,7 @@ var distForSrc = require('./partials/distForSrc')
17
17
  var distSeries = require('./partials/distSeries')
18
18
  var minifyFor = require('./partials/minifyFor')
19
19
  var readmeTemplate = require('./partials/readmeTemplate')
20
+ var removeDirectory = require('./partials/removeDirectory')
20
21
  var runOnChange = require('./partials/runOnChange')
21
22
  var tsFor = require('./partials/tsFor')
22
23
  module.exports = {
@@ -28,6 +29,7 @@ module.exports = {
28
29
  distSeries: distSeries,
29
30
  minifyFor: minifyFor,
30
31
  readmeTemplate: readmeTemplate,
32
+ removeDirectory: removeDirectory,
31
33
  runOnChange: runOnChange,
32
34
  tsFor: tsFor
33
35
  }
@@ -1 +1 @@
1
- "use strict";var addToReadme=require("./partials/addToReadme"),beginWatcher=require("./partials/beginWatcher"),clean=require("./partials/clean"),distFor=require("./partials/distFor"),distForSrc=require("./partials/distForSrc"),distSeries=require("./partials/distSeries"),minifyFor=require("./partials/minifyFor"),readmeTemplate=require("./partials/readmeTemplate"),runOnChange=require("./partials/runOnChange"),tsFor=require("./partials/tsFor");module.exports={addToReadme:addToReadme,beginWatcher:beginWatcher,clean:clean,distFor:distFor,distForSrc:distForSrc,distSeries:distSeries,minifyFor:minifyFor,readmeTemplate:readmeTemplate,runOnChange:runOnChange,tsFor:tsFor};
1
+ "use strict";var addToReadme=require("./partials/addToReadme"),beginWatcher=require("./partials/beginWatcher"),clean=require("./partials/clean"),distFor=require("./partials/distFor"),distForSrc=require("./partials/distForSrc"),distSeries=require("./partials/distSeries"),minifyFor=require("./partials/minifyFor"),readmeTemplate=require("./partials/readmeTemplate"),removeDirectory=require("./partials/removeDirectory"),runOnChange=require("./partials/runOnChange"),tsFor=require("./partials/tsFor");module.exports={addToReadme:addToReadme,beginWatcher:beginWatcher,clean:clean,distFor:distFor,distForSrc:distForSrc,distSeries:distSeries,minifyFor:minifyFor,readmeTemplate:readmeTemplate,removeDirectory:removeDirectory,runOnChange:runOnChange,tsFor:tsFor};
@@ -25,9 +25,10 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
25
25
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
26
26
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
27
27
  var fs = require('fs');
28
- var del = require('del');
29
28
  // Import the configurations and override some of them in order to direct to the temp directory.
30
29
  var gulpConfig = require('../../gulp.config.js');
30
+ var _require = require('../partials'),
31
+ removeDirectory = _require.removeDirectory;
31
32
  var tempDir = 'test-temp/';
32
33
  var srcPath = "".concat(tempDir, "src");
33
34
 
@@ -42,6 +43,7 @@ var setDefaults = function setDefaults() {
42
43
  tempDir = "".concat(testDir, "/");
43
44
  srcPath = "".concat(tempDir, "src");
44
45
  gulpConfig.set('browserPath', "".concat(tempDir, "browser"));
46
+ gulpConfig.set('cleanPaths', [srcPath]);
45
47
  gulpConfig.set('distMain', "".concat(tempDir, "dist/main"));
46
48
  gulpConfig.set('distPath', "".concat(tempDir, "dist"));
47
49
  gulpConfig.set('distSearch', "".concat(tempDir, "dist/**/*.js"));
@@ -75,15 +77,16 @@ var createTempDir = /*#__PURE__*/function () {
75
77
  _context.next = 3;
76
78
  break;
77
79
  }
78
- return _context.abrupt("return", del(tempDir).then(function () {
79
- return createTempDir(fs.existsSync(tempDir));
80
+ return _context.abrupt("return", removeDirectory(tempDir).then(function (removedDir) {
81
+ return createTempDir(fs.existsSync(removedDir));
82
+ }).catch(function (error) {
83
+ return console.error('Error: ', error);
80
84
  }));
81
85
  case 3:
82
- _context.next = 5;
83
- return fs.mkdirSync(tempDir);
84
- case 5:
85
- return _context.abrupt("return", fs.mkdirSync(srcPath));
86
- case 6:
86
+ return _context.abrupt("return", fs.mkdirSync(srcPath, {
87
+ recursive: true
88
+ }));
89
+ case 4:
87
90
  case "end":
88
91
  return _context.stop();
89
92
  }
@@ -111,17 +114,6 @@ exports.beforeEach = function () {
111
114
  * @memberOf module:testHelpers
112
115
  * @returns {Promise<*>}
113
116
  */
114
- exports.afterEach = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
115
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
116
- while (1) switch (_context2.prev = _context2.next) {
117
- case 0:
118
- _context2.next = 2;
119
- return del(tempDir);
120
- case 2:
121
- return _context2.abrupt("return", _context2.sent);
122
- case 3:
123
- case "end":
124
- return _context2.stop();
125
- }
126
- }, _callee2);
127
- }));
117
+ exports.afterEach = function () {
118
+ return removeDirectory(tempDir);
119
+ };
package/dist/testFull.js CHANGED
@@ -6,15 +6,13 @@ var runCLI = _require.runCLI
6
6
 
7
7
  /**
8
8
  * Run all tests with jest.
9
+ * Configure where tests are located by using 'testPath'.
9
10
  * @function
10
11
  * @memberOf module:js-build-tools
11
- * @param {function} [done=null]
12
- * @param {Array.<string>|string} [testPath='path/config/test/files']
13
12
  * @returns {Promise<*>}
14
13
  */
15
14
  var testFull = function testFull () {
16
- var done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
17
- var testPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('testPath')
15
+ var testPath = gulpConfig.get('testPath')
18
16
  if (!Array.isArray(testPath)) {
19
17
  // The testPath must be an array of strings
20
18
  testPath = [testPath]
@@ -1 +1 @@
1
- "use strict";var gulpConfig=require("../gulp.config.js"),_require=require("jest"),runCLI=_require.runCLI,testFull=function(){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:gulpConfig.get("testPath");return Array.isArray(r)||(r=[r]),runCLI(gulpConfig.get("testOptions"),r)};module.exports=testFull;
1
+ "use strict";var gulpConfig=require("../gulp.config.js"),_require=require("jest"),runCLI=_require.runCLI,testFull=function(){var r=gulpConfig.get("testPath");return Array.isArray(r)||(r=[r]),runCLI(gulpConfig.get("testOptions"),r)};module.exports=testFull;
package/dist/testQuick.js CHANGED
@@ -6,15 +6,13 @@ var runCLI = _require.runCLI
6
6
 
7
7
  /**
8
8
  * Run the Jest tests for files which have been modified (based on git status).
9
+ * Configure where tests are located by using 'testPath'.
9
10
  * @function
10
11
  * @memberOf module:js-build-tools
11
- * @param {function} [done=null]
12
- * @param {Array.<string>|string} [testPath='path/config/test/files']
13
12
  * @returns {Promise<*>}
14
13
  */
15
14
  var testQuick = function testQuick () {
16
- var done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
17
- var testPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('testPath')
15
+ var testPath = gulpConfig.get('testPath')
18
16
  if (!Array.isArray(testPath)) {
19
17
  // The testPath must be an array of strings
20
18
  testPath = [testPath]
@@ -1 +1 @@
1
- "use strict";var gulpConfig=require("../gulp.config.js"),_require=require("jest"),runCLI=_require.runCLI,testQuick=function(){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:gulpConfig.get("testPath");return Array.isArray(r)||(r=[r]),runCLI({onlyChanged:!0},r)};module.exports=testQuick;
1
+ "use strict";var gulpConfig=require("../gulp.config.js"),_require=require("jest"),runCLI=_require.runCLI,testQuick=function(){var r=gulpConfig.get("testPath");return Array.isArray(r)||(r=[r]),runCLI({onlyChanged:!0},r)};module.exports=testQuick;
@@ -64,5 +64,5 @@ describe('bundle', () => {
64
64
  console.error('Encountered error', error)
65
65
  done()
66
66
  })
67
- }, 500)
67
+ })
68
68
  })
@@ -5,16 +5,15 @@ const { globSync } = require('glob')
5
5
 
6
6
  /**
7
7
  * Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
8
+ * Configure this with 'readmeSearch', 'readmePath', 'readmeFile', and 'readmeOptions'.
8
9
  * @function
9
10
  * @memberOf module:partials
10
- * @param {function|null} [done=null]
11
11
  * @returns {string|Uint8Array}
12
12
  */
13
- const addToReadme = (done = null) => {
14
- const files = globSync(gulpConfig.get('readmeSearch'))
15
- const readme = jsdoc2md.renderSync({ files: files })
16
- fs.appendFileSync(gulpConfig.get('readmePath') + gulpConfig.get('readmeFile'), readme, gulpConfig.get('readmeOptions'))
17
- return done && done()
18
- }
13
+ const addToReadme = () => jsdoc2md
14
+ .render({ files: globSync(gulpConfig.get('readmeSearch')) })
15
+ .then(
16
+ readme => fs.appendFileSync(gulpConfig.get('readmePath') + gulpConfig.get('readmeFile'), readme, gulpConfig.get('readmeOptions'))
17
+ )
19
18
 
20
19
  module.exports = addToReadme
@@ -15,14 +15,13 @@ beforeEach(() => setUp.beforeEach()
15
15
  afterEach(setUp.afterEach)
16
16
 
17
17
  describe('addToReadme', () => {
18
- test('generates the documentation', () => {
18
+ test('generates the documentation', async () => {
19
19
  const readmeFilePath = gulpConfig.get('readmePath') + gulpConfig.get('readmeFile')
20
20
  expect.assertions(2)
21
- addToReadme(async () => {
22
- await expect(fs.existsSync(readmeFilePath)).toBeTruthy()
23
- const readme = await fs.readFileSync(readmeFilePath)
24
- // At least the documentation will have the addToReadme documentation
25
- await expect(readme.includes('addToReadme')).toBeTruthy()
26
- })
21
+ await addToReadme()
22
+ await expect(fs.existsSync(readmeFilePath)).toBeTruthy()
23
+ const readme = await fs.readFileSync(readmeFilePath)
24
+ // At least the documentation will have the addToReadme documentation
25
+ await expect(readme.includes('addToReadme')).toBeTruthy()
27
26
  })
28
27
  })
@@ -1,14 +1,16 @@
1
- const del = require('del')
2
1
  const gulpConfig = require('../../gulp.config.js')
2
+ const removeDirectory = require('./removeDirectory')
3
3
 
4
4
  /**
5
5
  * Deletes all the distribution and browser files (used before create a new build).
6
+ * Configure array of directories to remove with 'cleanPaths'.
6
7
  * @function
7
8
  * @memberOf module:partials
8
- * @param {function} [done=null]
9
- * @param {string[]} [paths=['dist/config/path', 'browser/config/path']]
10
9
  * @returns {Promise<string[]> | *}
11
10
  */
12
- const clean = (done = null, paths = [gulpConfig.get('distPath'), gulpConfig.get('browserPath')]) => del(paths).then(() => done && done())
11
+ const clean = () => gulpConfig.get('cleanPaths').reduce(
12
+ (promise, path) => promise.then(() => removeDirectory(path)),
13
+ Promise.resolve()
14
+ )
13
15
 
14
16
  module.exports = clean
@@ -14,7 +14,7 @@ describe('clean', () => {
14
14
  const srcPath = gulpConfig.get('srcPath')
15
15
  expect(fs.readdirSync(srcPath)).toBeTruthy()
16
16
  // Run the clean script to empty the directories
17
- await clean(null, [srcPath])
17
+ await clean()
18
18
  expect(fs.existsSync(srcPath)).toBeFalsy()
19
19
  })
20
20
  })
@@ -89,7 +89,7 @@ describe('distFor', () => {
89
89
  console.error('Encountered error', error)
90
90
  done()
91
91
  })
92
- })
92
+ }, 60000)
93
93
 
94
94
  test('can process typescript before babel', done => {
95
95
  const srcPath = gulpConfig.get('srcPath')
@@ -121,5 +121,5 @@ describe('distFor', () => {
121
121
  console.error('Encountered error with typeScript', error)
122
122
  done()
123
123
  })
124
- }, 30000)
124
+ }, 60000)
125
125
  })
@@ -0,0 +1,23 @@
1
+ const { rm, exists } = require('fs')
2
+
3
+ /**
4
+ * Return a promise to be completed once the specified directory is deleted.
5
+ * @function
6
+ * @memberOf module:partials
7
+ * @param {string} dirPath
8
+ * @returns {Promise<*>}
9
+ */
10
+ const removeDirectory = dirPath => new Promise(
11
+ (resolve, reject) => exists(
12
+ dirPath,
13
+ doesExist => doesExist
14
+ ? rm(
15
+ dirPath,
16
+ { recursive: true },
17
+ error => error ? reject(error) : resolve(dirPath)
18
+ )
19
+ : resolve(dirPath)
20
+ )
21
+ )
22
+
23
+ module.exports = removeDirectory
@@ -0,0 +1,28 @@
1
+ const fs = require('fs')
2
+ const removeDirectory = require('./removeDirectory')
3
+
4
+ describe('removeDirectory', () => {
5
+ test('able to delete the remove-directory', async () => {
6
+ const dirPath = 'remove-directory'
7
+ fs.mkdirSync(dirPath)
8
+ expect(fs.existsSync(dirPath)).toBeTruthy()
9
+ await removeDirectory(dirPath)
10
+ expect(fs.existsSync(dirPath)).toBeFalsy()
11
+ })
12
+
13
+ test('able to delete directory with sub-directories', async () => {
14
+ const dirPath = 'remove-directory'
15
+ fs.mkdirSync(dirPath)
16
+ const subDir = `${dirPath}/sub`
17
+ fs.mkdirSync(subDir)
18
+ expect(fs.existsSync(subDir)).toBeTruthy()
19
+ await removeDirectory(dirPath)
20
+ expect(fs.existsSync(subDir)).toBeFalsy()
21
+ })
22
+
23
+ test('ends cleanly if directory does not exist', async () => {
24
+ const dirPath = 'remove-directory'
25
+ expect(fs.existsSync(dirPath)).toBeFalsy()
26
+ expect(await removeDirectory(dirPath)).toBe(dirPath)
27
+ })
28
+ })
@@ -40,5 +40,5 @@ describe('tsFor', () => {
40
40
  console.error('Encountered error', error)
41
41
  done()
42
42
  })
43
- }, 30000)
43
+ }, 60000)
44
44
  })
@@ -15,6 +15,7 @@ const distForSrc = require('./partials/distForSrc')
15
15
  const distSeries = require('./partials/distSeries')
16
16
  const minifyFor = require('./partials/minifyFor')
17
17
  const readmeTemplate = require('./partials/readmeTemplate')
18
+ const removeDirectory = require('./partials/removeDirectory')
18
19
  const runOnChange = require('./partials/runOnChange')
19
20
  const tsFor = require('./partials/tsFor')
20
21
 
@@ -27,6 +28,7 @@ module.exports = {
27
28
  distSeries,
28
29
  minifyFor,
29
30
  readmeTemplate,
31
+ removeDirectory,
30
32
  runOnChange,
31
33
  tsFor,
32
34
  }
@@ -2,6 +2,6 @@ const partials = require('./partials')
2
2
 
3
3
  describe('partials', () => {
4
4
  test('is object with all partial exports', () => {
5
- expect(Object.keys(partials).length).toBe(10)
5
+ expect(Object.keys(partials).length).toBe(11)
6
6
  })
7
7
  })
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs')
2
- const del = require('del')
3
2
  // Import the configurations and override some of them in order to direct to the temp directory.
4
3
  const gulpConfig = require('../../gulp.config.js')
4
+ const { removeDirectory } = require('../partials')
5
5
 
6
6
  let tempDir = 'test-temp/'
7
7
  let srcPath = `${tempDir}src`
@@ -16,6 +16,7 @@ const setDefaults = (testDir = 'test-temp') => {
16
16
  tempDir = `${testDir}/`
17
17
  srcPath = `${tempDir}src`
18
18
  gulpConfig.set('browserPath', `${tempDir}browser`)
19
+ gulpConfig.set('cleanPaths', [srcPath])
19
20
  gulpConfig.set('distMain', `${tempDir}dist/main`)
20
21
  gulpConfig.set('distPath', `${tempDir}dist`)
21
22
  gulpConfig.set('distSearch', `${tempDir}dist/**/*.js`)
@@ -41,11 +42,11 @@ exports.gulpConfig = gulpConfig
41
42
  */
42
43
  const createTempDir = async (exists = true) => {
43
44
  if (exists) {
44
- return del(tempDir)
45
- .then(() => createTempDir(fs.existsSync(tempDir)))
45
+ return removeDirectory(tempDir)
46
+ .then(removedDir => createTempDir(fs.existsSync(removedDir)))
47
+ .catch(error => console.error('Error: ', error))
46
48
  }
47
- await fs.mkdirSync(tempDir)
48
- return fs.mkdirSync(srcPath)
49
+ return fs.mkdirSync(srcPath, { recursive: true })
49
50
  }
50
51
 
51
52
  exports.createTempDir = createTempDir
@@ -64,4 +65,4 @@ exports.beforeEach = () => createTempDir()
64
65
  * @memberOf module:testHelpers
65
66
  * @returns {Promise<*>}
66
67
  */
67
- exports.afterEach = async () => await del(tempDir)
68
+ exports.afterEach = () => removeDirectory(tempDir)
@@ -1,5 +1,5 @@
1
- import { afterEach, createTempDir, gulpConfig, setDefaults } from './setUp'
2
- import fs from 'fs'
1
+ const { afterEach, createTempDir, gulpConfig, setDefaults } = require('./setUp')
2
+ const fs = require('fs')
3
3
 
4
4
  setDefaults()
5
5
 
@@ -10,7 +10,7 @@ describe('setUp', () => {
10
10
  expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeTruthy()
11
11
  })
12
12
 
13
- test('able to delete the test-temp/src directory', async () => {
13
+ test('able to delete the test-temp/src directory', async () => {
14
14
  expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeTruthy()
15
15
  await afterEach()
16
16
  expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeFalsy()
@@ -3,13 +3,13 @@ const { runCLI } = require('jest')
3
3
 
4
4
  /**
5
5
  * Run all tests with jest.
6
+ * Configure where tests are located by using 'testPath'.
6
7
  * @function
7
8
  * @memberOf module:js-build-tools
8
- * @param {function} [done=null]
9
- * @param {Array.<string>|string} [testPath='path/config/test/files']
10
9
  * @returns {Promise<*>}
11
10
  */
12
- const testFull = (done = null, testPath = gulpConfig.get('testPath')) => {
11
+ const testFull = () => {
12
+ let testPath = gulpConfig.get('testPath')
13
13
  if (!Array.isArray(testPath)) {
14
14
  // The testPath must be an array of strings
15
15
  testPath = [testPath]
@@ -3,13 +3,13 @@ const { runCLI } = require('jest')
3
3
 
4
4
  /**
5
5
  * Run the Jest tests for files which have been modified (based on git status).
6
+ * Configure where tests are located by using 'testPath'.
6
7
  * @function
7
8
  * @memberOf module:js-build-tools
8
- * @param {function} [done=null]
9
- * @param {Array.<string>|string} [testPath='path/config/test/files']
10
9
  * @returns {Promise<*>}
11
10
  */
12
- const testQuick = (done = null, testPath = gulpConfig.get('testPath')) => {
11
+ const testQuick = () => {
12
+ let testPath = gulpConfig.get('testPath')
13
13
  if (!Array.isArray(testPath)) {
14
14
  // The testPath must be an array of strings
15
15
  testPath = [testPath]
package/gulp.config.js CHANGED
@@ -112,6 +112,7 @@ try {
112
112
  const setDefaults = {
113
113
  browserName: 'default',
114
114
  browserPath: 'browser',
115
+ cleanPaths: ['dist', 'browser'],
115
116
  distMain: 'dist/main',
116
117
  distPath: 'dist',
117
118
  distSearch: 'dist/**/*.js',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "scripts": {
@@ -40,7 +40,6 @@
40
40
  "babel-jest": "^29.6.4",
41
41
  "browserify": "^17.0.0",
42
42
  "core-js": "^3.32.1",
43
- "del": "^6.1.1",
44
43
  "fs": "^0.0.1-security",
45
44
  "glob": "^10.3.4",
46
45
  "gulp": "^4.0.2",