js-build-tools 2.2.4 → 2.2.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/README.md CHANGED
@@ -148,13 +148,15 @@ Create a `tsconfig.json` file in your project root with the following:
148
148
  "compilerOptions": {
149
149
  "noImplicitAny": true,
150
150
  "target": "es6",
151
- "moduleResolution": "node"
151
+ "moduleResolution": "node",
152
+ "declaration": true
152
153
  }
153
154
  }
154
155
  ```
155
156
 
156
157
  The pattern for `"files"` should match your .ts files, but the essential thing is that it is wrapped in an array.
157
- The actual pattern used comes from `babel.config.js` as `'tsSearch'` setting.
158
+ The actual pattern used comes from `babel.config.js` as `'tsSearch'` setting. In order to create the ts declaration
159
+ files you must add the `"declaration": true`.
158
160
 
159
161
  Add the following to the exports in your `babel.config.js`:
160
162
 
@@ -230,7 +232,7 @@ Export these functions to your own project in order to customize your build pipe
230
232
  * [.compileReadme](#module_js-build-tools.compileReadme) ⇒ <code>stream.Stream</code>
231
233
  * [.watchTest()](#module_js-build-tools.watchTest) ⇒ <code>\*</code>
232
234
  * [.watchFull()](#module_js-build-tools.watchFull) ⇒ <code>FSWatcher</code>
233
- * [.typeScript()](#module_js-build-tools.typeScript) ⇒ <code>stream.Stream</code>
235
+ * [.typeScript()](#module_js-build-tools.typeScript) ⇒ <code>function</code>
234
236
  * [.testQuick()](#module_js-build-tools.testQuick) ⇒ <code>Promise.&lt;\*&gt;</code>
235
237
  * [.testFull()](#module_js-build-tools.testFull) ⇒ <code>Promise.&lt;\*&gt;</code>
236
238
  * [.distMinify()](#module_js-build-tools.distMinify) ⇒ <code>\*</code>
@@ -262,7 +264,7 @@ Watch for changes and run the distribution for the changed files, then bundle an
262
264
  **Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
263
265
  <a name="module_js-build-tools.typeScript"></a>
264
266
 
265
- ### js-build-tools.typeScript() ⇒ <code>stream.Stream</code>
267
+ ### js-build-tools.typeScript() ⇒ <code>function</code>
266
268
  Simplified typescript task using tsFor.
267
269
 
268
270
  **Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
@@ -609,7 +611,7 @@ Micro-functions used as components for the main gulp functions.
609
611
  **Author**: Joshua Heagle <joshuaheagle@gmail.com>
610
612
 
611
613
  * [partials](#module_partials)
612
- * [.tsFor([srcPath], [distPath])](#module_partials.tsFor) ⇒ <code>stream.Stream</code>
614
+ * [.tsFor([srcPath], [distPath])](#module_partials.tsFor) ⇒ <code>function</code>
613
615
  * [.runOnChange(path)](#module_partials.runOnChange) ⇒ <code>stream.Stream</code>
614
616
  * [~pathRegex](#module_partials.runOnChange..pathRegex)
615
617
  * [.removeDirectory(dirPath)](#module_partials.removeDirectory) ⇒ <code>Promise.&lt;\*&gt;</code>
@@ -624,7 +626,7 @@ Micro-functions used as components for the main gulp functions.
624
626
 
625
627
  <a name="module_partials.tsFor"></a>
626
628
 
627
- ### partials.tsFor([srcPath], [distPath]) ⇒ <code>stream.Stream</code>
629
+ ### partials.tsFor([srcPath], [distPath]) ⇒ <code>function</code>
628
630
  Starting at the source directory, find all the ts files and convert them into the distribution directory.
629
631
 
630
632
  **Kind**: static method of [<code>partials</code>](#module_partials)
@@ -20,9 +20,7 @@ var distSeries = function distSeries() {
20
20
  var srcPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : distForSrc();
21
21
  var distFinalPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('distPath');
22
22
  var tsSearch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : gulpConfig.get('tsSearch');
23
- var typescript = function typescript() {
24
- return tsFor(tsSearch, distFinalPath);
25
- };
23
+ var typescript = tsFor(tsSearch, distFinalPath);
26
24
  var dist = function dist() {
27
25
  return distFor(srcPath, distFinalPath);
28
26
  };
@@ -2,10 +2,10 @@
2
2
 
3
3
  var _require = require('gulp'),
4
4
  dest = _require.dest,
5
+ parallel = _require.parallel,
5
6
  src = _require.src;
6
7
  var gulpConfig = require('../../gulp.config.js');
7
8
  var ts = require('gulp-typescript');
8
- var tsProject = ts.createProject(gulpConfig.get('useTsConfig'));
9
9
 
10
10
  /**
11
11
  * Starting at the source directory, find all the ts files and convert them into the distribution directory.
@@ -13,12 +13,20 @@ var tsProject = ts.createProject(gulpConfig.get('useTsConfig'));
13
13
  * @memberOf module:partials
14
14
  * @param {string|array} [srcPath='']
15
15
  * @param {string} [distPath='']
16
- * @returns {stream.Stream}
16
+ * @returns {Function}
17
17
  * @see `https://www.typescriptlang.org/docs/handbook/gulp.html` for more info
18
18
  */
19
19
  var tsFor = function tsFor() {
20
20
  var srcPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : gulpConfig.get('tsSearch');
21
21
  var distPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : gulpConfig.get('distPath');
22
- return src(srcPath).pipe(tsProject()).js.pipe(dest(distPath));
22
+ var declarationProject = ts.createProject(gulpConfig.get('useTsConfig'));
23
+ var tsProject = ts.createProject(gulpConfig.get('useTsConfig'));
24
+ var makeDeclarations = function makeDeclarations() {
25
+ return src(srcPath).pipe(declarationProject()).dts.pipe(dest(distPath));
26
+ };
27
+ var compileJS = function compileJS() {
28
+ return src(srcPath).pipe(tsProject()).js.pipe(dest(distPath));
29
+ };
30
+ return parallel(makeDeclarations, compileJS);
23
31
  };
24
32
  module.exports = tsFor;
@@ -6,9 +6,7 @@ var tsFor = require('./partials/tsFor')
6
6
  * Simplified typescript task using tsFor.
7
7
  * @function
8
8
  * @memberOf module:js-build-tools
9
- * @returns {stream.Stream}
9
+ * @returns {Function}
10
10
  */
11
- var typeScript = function typeScript () {
12
- return tsFor()
13
- }
11
+ var typeScript = tsFor()
14
12
  module.exports = typeScript
@@ -1 +1 @@
1
- "use strict";var tsFor=require("./partials/tsFor"),typeScript=function(){return tsFor()};module.exports=typeScript;
1
+ "use strict";var tsFor=require("./partials/tsFor"),typeScript=tsFor();module.exports=typeScript;
@@ -12,14 +12,6 @@ const genericFunction = () => Promise.resolve(true)
12
12
  jest.mock('./partials/clean', () => jest.fn(genericFunction))
13
13
  jest.mock('./testFull', () => jest.fn(genericFunction))
14
14
 
15
- const file1Typescript = '/**\n' +
16
- ' * Console log out a greeting with given input.\n' +
17
- ' * @param {string} input\n' +
18
- ' */\n' +
19
- 'const file1 = (input: string): void => console.log(`Hello from file1 with ${input}`)\n' +
20
- '\n' +
21
- 'module.exports = file1\n'
22
-
23
15
  const file1Contents = '/**\n' +
24
16
  ' * Console log out a greeting with given input.\n' +
25
17
  ' * @param {string} input\n' +
@@ -28,20 +20,6 @@ const file1Contents = '/**\n' +
28
20
  '\n' +
29
21
  'module.exports = file1\n'
30
22
 
31
- const file2Typescript = '/**\n' +
32
- ' * Farewell with a summation of two numbers returned.\n' +
33
- ' * @param {number} a\n' +
34
- ' * @param {number} b\n' +
35
- ' * @returns {number}\n' +
36
- ' */\n' +
37
- 'const file2 = (a: number, b: number): number => {\n' +
38
- ' const sum = a + b\n' +
39
- ' console.log(`Good-bye from file2 with sum ${sum}`)\n' +
40
- ' return sum\n' +
41
- '}\n' +
42
- '\n' +
43
- 'module.exports = file2\n'
44
-
45
23
  const file2Contents = '/**\n' +
46
24
  ' * Farewell with a summation of two numbers returned.\n' +
47
25
  ' * @param {number} a\n' +
@@ -94,7 +72,9 @@ const tsConfigContents = '{\n' +
94
72
  ' "files": ["test-build/src/**/*.ts"],\n' +
95
73
  ' "compilerOptions": {\n' +
96
74
  ' "noImplicitAny": true,\n' +
97
- ' "target": "es5"\n' +
75
+ ' "target": "es6",\n' +
76
+ ' "moduleResolution": "node",\n' +
77
+ ' "declaration": true,\n' +
98
78
  ' }\n' +
99
79
  '}'
100
80
 
@@ -228,13 +208,15 @@ describe('build', () => {
228
208
  gulpConfig.set('nodeOnly', true)
229
209
  gulpConfig.set('useTsConfig', tsConfig)
230
210
  gulpConfig.set('readmeSearch', `${distPath}/**/*.js`)
231
- expect.assertions(7)
211
+ expect.assertions(8)
232
212
  build(() => {
233
213
  // Called 'clean'
234
214
  expect(clean).toHaveBeenCalled()
235
215
 
236
216
  // Created dist directory (distSeries)
237
217
  expect(fs.existsSync(distPath)).toBeTruthy()
218
+ // Created declaration file
219
+ expect(fs.existsSync(`${distPath}/main.d.ts`)).toBeTruthy()
238
220
 
239
221
  // Minify the dist files (distMinify)
240
222
  expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
@@ -253,7 +235,7 @@ describe('build', () => {
253
235
  })
254
236
  }, 30000)
255
237
 
256
- test('when nodeOnly false and useTsConfig false: calls clean, tsFor, distFor, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull', done => {
238
+ test('when nodeOnly false and useTsConfig set: calls clean, tsFor, distFor, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull', done => {
257
239
  const srcPath = gulpConfig.get('srcPath')
258
240
  const rootPath = gulpConfig.get('rootPath')
259
241
  const tsConfig = `${rootPath}/tsconfig.json`
@@ -268,13 +250,15 @@ describe('build', () => {
268
250
  gulpConfig.set('nodeOnly', false)
269
251
  gulpConfig.set('useTsConfig', tsConfig)
270
252
  gulpConfig.set('readmeSearch', `${distPath}/**/*.js`)
271
- expect.assertions(10)
253
+ expect.assertions(11)
272
254
  build(() => {
273
255
  // Called 'clean'
274
256
  expect(clean).toHaveBeenCalled()
275
257
 
276
258
  // Created dist directory (distSeries)
277
259
  expect(fs.existsSync(distPath)).toBeTruthy()
260
+ // Created declaration file
261
+ expect(fs.existsSync(`${distPath}/main.d.ts`)).toBeTruthy()
278
262
 
279
263
  // Minify the dist files (distMinify)
280
264
  expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
@@ -99,27 +99,22 @@ describe('distFor', () => {
99
99
  const oldContents = fs.readFileSync(srcFile).toString()
100
100
  expect(countMatches(oldContents, 'const ')).toEqual(3)
101
101
  const distPath = gulpConfig.get('distPath')
102
- typeScript()
103
- .on('finish', () => {
104
- distFor()
105
- .on('finish', () => {
106
- expect(fs.existsSync(distPath)).toBeTruthy()
107
- const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
108
- expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
109
- expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
110
- expect(countMatches(babelifiedContents, 'var ')).toEqual(8)
111
- expect(countMatches(babelifiedContents, 'function')).toEqual(1)
112
- expect(countMatches(babelifiedContents, 'Object.defineProperty(exports, "__esModule", { value: true })')).toEqual(1)
113
- done()
114
- })
115
- .on('error', error => {
116
- console.error('Encountered error with distFor', error)
117
- done()
118
- })
119
- })
120
- .on('error', error => {
121
- console.error('Encountered error with typeScript', error)
122
- done()
123
- })
102
+ typeScript(() => {
103
+ distFor()
104
+ .on('finish', () => {
105
+ expect(fs.existsSync(distPath)).toBeTruthy()
106
+ const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
107
+ expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
108
+ expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
109
+ expect(countMatches(babelifiedContents, 'var ')).toEqual(8)
110
+ expect(countMatches(babelifiedContents, 'function')).toEqual(1)
111
+ expect(countMatches(babelifiedContents, 'Object.defineProperty(exports, "__esModule", { value: true })')).toEqual(1)
112
+ done()
113
+ })
114
+ .on('error', error => {
115
+ console.error('Encountered error with distFor', error)
116
+ done()
117
+ })
118
+ })
124
119
  }, 60000)
125
120
  })
@@ -14,7 +14,7 @@ const tsFor = require('./tsFor')
14
14
  * @returns {function(null=): stream.Stream}
15
15
  */
16
16
  const distSeries = (srcPath = distForSrc(), distFinalPath = gulpConfig.get('distPath'), tsSearch = gulpConfig.get('tsSearch')) => {
17
- const typescript = () => tsFor(tsSearch, distFinalPath)
17
+ const typescript = tsFor(tsSearch, distFinalPath)
18
18
  const dist = () => distFor(srcPath, distFinalPath)
19
19
  return gulpConfig.get('useTsConfig')
20
20
  ? series(typescript, dist)
@@ -7,7 +7,7 @@ const distFor = require('./distFor')
7
7
  const genericFunction = () => Promise.resolve(true)
8
8
 
9
9
  jest.mock('./distFor', () => jest.fn(genericFunction))
10
- jest.mock('./tsFor', () => jest.fn(genericFunction))
10
+ jest.mock('./tsFor', () => jest.fn(() => genericFunction))
11
11
 
12
12
  describe('distSeries', () => {
13
13
  test('when not using ts config only returns runnable distFor', done => {
@@ -12,7 +12,7 @@ const genericFunction = () => Promise.resolve(true)
12
12
 
13
13
  jest.mock('../bundle', () => jest.fn(genericFunction))
14
14
  jest.mock('./distFor', () => jest.fn(genericFunction))
15
- jest.mock('./tsFor', () => jest.fn(genericFunction))
15
+ jest.mock('./tsFor', () => jest.fn(() => genericFunction))
16
16
  jest.mock('../testQuick', () => jest.fn(genericFunction))
17
17
 
18
18
  const rawContents = 'export function sayHello(name: string) {\n' +
@@ -1,21 +1,22 @@
1
- const { dest, src } = require('gulp')
1
+ const { dest, parallel, src } = require('gulp')
2
2
  const gulpConfig = require('../../gulp.config.js')
3
3
  const ts = require('gulp-typescript')
4
4
 
5
- const tsProject = ts.createProject(gulpConfig.get('useTsConfig'))
6
-
7
5
  /**
8
6
  * Starting at the source directory, find all the ts files and convert them into the distribution directory.
9
7
  * @function
10
8
  * @memberOf module:partials
11
9
  * @param {string|array} [srcPath='']
12
10
  * @param {string} [distPath='']
13
- * @returns {stream.Stream}
11
+ * @returns {Function}
14
12
  * @see `https://www.typescriptlang.org/docs/handbook/gulp.html` for more info
15
13
  */
16
- const tsFor = (srcPath = gulpConfig.get('tsSearch'), distPath = gulpConfig.get('distPath')) => src(srcPath)
17
- .pipe(tsProject())
18
- .js
19
- .pipe(dest(distPath))
14
+ const tsFor = (srcPath = gulpConfig.get('tsSearch'), distPath = gulpConfig.get('distPath')) => {
15
+ const declarationProject = ts.createProject(gulpConfig.get('useTsConfig'))
16
+ const tsProject = ts.createProject(gulpConfig.get('useTsConfig'))
17
+ const makeDeclarations = () => src(srcPath).pipe(declarationProject()).dts.pipe(dest(distPath))
18
+ const compileJS = () => src(srcPath).pipe(tsProject()).js.pipe(dest(distPath))
19
+ return parallel(makeDeclarations, compileJS)
20
+ }
20
21
 
21
22
  module.exports = tsFor
@@ -29,16 +29,11 @@ describe('tsFor', () => {
29
29
  expect.assertions(3)
30
30
  const oldContents = fs.readFileSync(srcFile).toString()
31
31
  expect(countMatches(oldContents, 'sayHello(name: string)')).toEqual(1)
32
- tsFor(srcFile, distPath)
33
- .on('finish', () => {
34
- expect(fs.existsSync(distPath)).toBeTruthy()
35
- const compiledContents = fs.readFileSync(`${distPath}/typeScript.js`).toString()
36
- expect(countMatches(compiledContents, 'sayHello(name)')).toEqual(1)
37
- done()
38
- })
39
- .on('error', error => {
40
- console.error('Encountered error', error)
41
- done()
42
- })
32
+ tsFor(srcFile, distPath)(() => {
33
+ expect(fs.existsSync(distPath)).toBeTruthy()
34
+ const compiledContents = fs.readFileSync(`${distPath}/typeScript.js`).toString()
35
+ expect(countMatches(compiledContents, 'sayHello(name)')).toEqual(1)
36
+ done()
37
+ })
43
38
  }, 60000)
44
39
  })
@@ -4,8 +4,8 @@ const tsFor = require('./partials/tsFor')
4
4
  * Simplified typescript task using tsFor.
5
5
  * @function
6
6
  * @memberOf module:js-build-tools
7
- * @returns {stream.Stream}
7
+ * @returns {Function}
8
8
  */
9
- const typeScript = () => tsFor()
9
+ const typeScript = tsFor()
10
10
 
11
11
  module.exports = typeScript
@@ -1,9 +1,11 @@
1
1
  const typeScript = require('./typeScript')
2
2
  const tsFor = require('./partials/tsFor')
3
- jest.mock('./partials/tsFor', () => jest.fn())
3
+ const { logObject } = require('./testHelpers')
4
+ jest.mock('./partials/tsFor', () => jest.fn(() => () => null))
4
5
 
5
6
  describe('typeScript', () => {
6
7
  test('calls tsFor with no parameters', () => {
8
+ logObject(typeScript, 'typescript')
7
9
  typeScript()
8
10
  expect(tsFor).toHaveBeenCalled()
9
11
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "scripts": {