js-build-tools 2.2.3 → 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 +102 -28
- package/dist/build.js +3 -0
- package/dist/partials/distSeries.js +1 -3
- package/dist/partials/tsFor.js +11 -3
- package/dist/typeScript.js +2 -4
- package/dist/typeScript.min.js +1 -1
- package/functions/build.test.js +10 -26
- package/functions/partials/distFor.test.js +17 -22
- package/functions/partials/distSeries.js +1 -1
- package/functions/partials/distSeries.test.js +1 -1
- package/functions/partials/runOnChange.test.js +1 -1
- package/functions/partials/tsFor.js +9 -8
- package/functions/partials/tsFor.test.js +6 -11
- package/functions/typeScript.js +2 -2
- package/functions/typeScript.test.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
# js-build-tools
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Centralize the build process for Node.js, JS and TypeScript projects into a single tool suite.
|
|
3
4
|
|
|
4
5
|
### Goals
|
|
6
|
+
|
|
5
7
|
Using this tool suite, you can:
|
|
8
|
+
|
|
9
|
+
* Parse TypeScript into JS distribution files
|
|
6
10
|
* Create formatted distribution files to be used in a node / commonjs environment.
|
|
7
11
|
* Bundle your distribution files to be used in a browser environment.
|
|
8
12
|
* Run tests and watch for changes.
|
|
9
13
|
* Generate jsdoc readme files.
|
|
10
14
|
|
|
11
15
|
## Installation
|
|
16
|
+
|
|
12
17
|
In your project's root directory, run: `npm install --save-dev gulp js-build-tools`
|
|
13
18
|
(or `yarn add --dev gulp js-build-tools` if you use Yarn).
|
|
14
19
|
|
|
15
|
-
It is recommended to install gulp with the `-g` flag, so that you can run it with `gulp` instead
|
|
20
|
+
It is recommended to install gulp with the `-g` flag, so that you can run it with `gulp` instead
|
|
21
|
+
of `node_modules/.bin/gulp`.
|
|
16
22
|
|
|
17
23
|
## Configuration
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
|
|
25
|
+
In your project's root directory, create a `build-tools.config.js` file. This can contain any of the following (values
|
|
26
|
+
provided are the defaults):
|
|
27
|
+
|
|
28
|
+
```js
|
|
20
29
|
module.exports = {
|
|
21
30
|
// The name to use for the browser-bundled output file (.js will be appended).
|
|
22
31
|
browserName: 'my-package',
|
|
23
32
|
|
|
24
33
|
// The output directory for browser-bundled files.
|
|
25
34
|
browserPath: 'browser',
|
|
26
|
-
|
|
35
|
+
|
|
27
36
|
// The paths for directories to delete before build.
|
|
28
37
|
cleanPaths: ['dist', 'browser'],
|
|
29
38
|
|
|
@@ -34,55 +43,71 @@ module.exports = {
|
|
|
34
43
|
distPath: 'dist',
|
|
35
44
|
|
|
36
45
|
// The search pattern used for retrieving compiled distribution files.
|
|
37
|
-
distSearch: 'dist/**/*.js',
|
|
38
|
-
|
|
46
|
+
distSearch: 'dist/**/*.js',
|
|
47
|
+
|
|
39
48
|
// 'true' to only generate node environment files.
|
|
40
49
|
nodeOnly: false,
|
|
41
|
-
|
|
50
|
+
|
|
42
51
|
// The name of the output documentation markdown file.
|
|
43
52
|
readmeFile: 'README.md',
|
|
44
|
-
|
|
53
|
+
|
|
45
54
|
// The directory to output the readme file in.
|
|
46
55
|
readmePath: './',
|
|
47
|
-
|
|
56
|
+
|
|
48
57
|
// Options for formatting the output readme.
|
|
49
58
|
readmeOptions: 'utf8',
|
|
50
59
|
|
|
51
60
|
// The file which will be pre-fixed to your README.md output.
|
|
52
61
|
readmeTemplate: 'MAIN.md',
|
|
53
|
-
|
|
62
|
+
|
|
54
63
|
// Location of files to use for compiling documentation into the readme.
|
|
55
64
|
readmeSearch: ['gulpfile.base.js', 'gulp.config.js', 'functions/**/!(*.test).js'],
|
|
56
65
|
|
|
57
66
|
// Base directory of the project.
|
|
58
67
|
rootPath: './',
|
|
59
|
-
|
|
68
|
+
|
|
60
69
|
// The directory where your source files are stored (the files you manually created).
|
|
61
70
|
srcPath: 'src',
|
|
62
71
|
|
|
63
72
|
// The search pattern used for gathering source files for distribution.
|
|
64
73
|
srcSearch: 'src/**/!(*.test).js',
|
|
65
|
-
|
|
74
|
+
|
|
66
75
|
// Additional flags for programatically running Jest Cli.
|
|
67
76
|
testOptions: null,
|
|
68
77
|
|
|
69
78
|
// The directory where Jest test files are stored.
|
|
70
79
|
// By default stored as *.test.js adjacent with the files they are testing).
|
|
71
80
|
testPath: 'src',
|
|
72
|
-
|
|
81
|
+
|
|
82
|
+
// Pattern for finding the TypeScript files
|
|
83
|
+
tsSearch: 'src/**/*.ts',
|
|
84
|
+
|
|
73
85
|
// The path the tsconfig file for running typescript or false if no ts file given.
|
|
74
86
|
useTsConfig: 'tsconfig.json',
|
|
75
|
-
|
|
87
|
+
|
|
76
88
|
// The search pattern for watching files for changes.
|
|
77
89
|
watchSearch: 'src/**/*.js',
|
|
78
90
|
}
|
|
79
91
|
```
|
|
80
92
|
|
|
81
93
|
### Create your local gulpfile.js
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
|
|
95
|
+
In your project's root directory, create a `gulpfile.js` file, in here you can require any of the functions you need.
|
|
96
|
+
For example:
|
|
97
|
+
|
|
98
|
+
```js
|
|
84
99
|
// Your local gulpfile.js
|
|
85
|
-
const {
|
|
100
|
+
const {
|
|
101
|
+
build,
|
|
102
|
+
defaultCmd,
|
|
103
|
+
partials,
|
|
104
|
+
readme,
|
|
105
|
+
testFull,
|
|
106
|
+
testQuick,
|
|
107
|
+
typescript,
|
|
108
|
+
watchFull,
|
|
109
|
+
watchTest
|
|
110
|
+
} = require('js-build-tools')
|
|
86
111
|
|
|
87
112
|
// Everything you export will be created as a gulp task.
|
|
88
113
|
// You can build your own tasks here as well by using some of the functions `js-build-tools/functions`.
|
|
@@ -99,19 +124,67 @@ exports.watchTest = watchTest
|
|
|
99
124
|
Verify your tasks are available by running `gulp --tasks`.
|
|
100
125
|
|
|
101
126
|
### Configure Babel
|
|
127
|
+
|
|
102
128
|
Depending on how you wrote your test files, Jest may require some Babel configuration.
|
|
103
129
|
Create a `babel.config.js` file in the root directory of your project.
|
|
104
|
-
You can then use the recommended configuration by requiring the babel.config.js file into your own configuration file.
|
|
130
|
+
You can then use the recommended configuration by requiring the `babel.config.js` file into your own configuration file.
|
|
105
131
|
Example:
|
|
106
|
-
|
|
132
|
+
|
|
133
|
+
```js
|
|
107
134
|
const babelConfig = require('js-build-tools/babel.config')
|
|
108
135
|
// You may add additional configuration here. Example: babelConfig.presets.push('@babel/preset-env')
|
|
109
136
|
module.exports = babelConfig
|
|
110
137
|
```
|
|
111
138
|
|
|
112
|
-
### Configure
|
|
113
|
-
|
|
139
|
+
### Configure TypeScript (optional)
|
|
140
|
+
|
|
141
|
+
Create a `tsconfig.json` file in your project root with the following:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"files": [
|
|
146
|
+
"src/**/*.ts"
|
|
147
|
+
],
|
|
148
|
+
"compilerOptions": {
|
|
149
|
+
"noImplicitAny": true,
|
|
150
|
+
"target": "es6",
|
|
151
|
+
"moduleResolution": "node",
|
|
152
|
+
"declaration": true
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The pattern for `"files"` should match your .ts files, but the essential thing is that it is wrapped in an array.
|
|
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`.
|
|
160
|
+
|
|
161
|
+
Add the following to the exports in your `babel.config.js`:
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
module.exports = {
|
|
165
|
+
readmeSearch: 'dist/**/!(*.min).js',
|
|
166
|
+
useTsConfig: 'tsconfig.json',
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The `js-to-markdown` only works on .js files, so we run the readme search on the built dist files. Also, we want to
|
|
171
|
+
register the tsconfig.json we created earlier and will alter the processes to build for TypeScript.
|
|
172
|
+
|
|
173
|
+
Update `babel.config.js` with the following:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
const babelConfig = require('js-build-tools/babel.config')
|
|
177
|
+
// This is the important line, we need to add compatibility for Jest to run tests on .ts files
|
|
178
|
+
babelConfig.presets.push('@babel/preset-typescript')
|
|
179
|
+
module.exports = babelConfig
|
|
114
180
|
```
|
|
181
|
+
|
|
182
|
+
### Configure Scripts
|
|
183
|
+
|
|
184
|
+
In your `package.json` file, add the following scripts:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
115
188
|
"scripts": {
|
|
116
189
|
"build": "gulp build",
|
|
117
190
|
"dev": "gulp",
|
|
@@ -120,12 +193,13 @@ In your package.json file, add the following scripts:
|
|
|
120
193
|
"test:quick": "gulp testQuick",
|
|
121
194
|
"watch": "gulp watchFull",
|
|
122
195
|
"watch:test": "gulp watchTest"
|
|
123
|
-
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
124
198
|
```
|
|
125
199
|
|
|
126
200
|
## Usage
|
|
127
|
-
Run any of the above commands with `gulp` or `npm run`.
|
|
128
201
|
|
|
202
|
+
Run any of the above commands with `gulp` or `npm run`.
|
|
129
203
|
|
|
130
204
|
# Available functions documentation
|
|
131
205
|
|
|
@@ -158,7 +232,7 @@ Export these functions to your own project in order to customize your build pipe
|
|
|
158
232
|
* [.compileReadme](#module_js-build-tools.compileReadme) ⇒ <code>stream.Stream</code>
|
|
159
233
|
* [.watchTest()](#module_js-build-tools.watchTest) ⇒ <code>\*</code>
|
|
160
234
|
* [.watchFull()](#module_js-build-tools.watchFull) ⇒ <code>FSWatcher</code>
|
|
161
|
-
* [.typeScript()](#module_js-build-tools.typeScript) ⇒ <code>
|
|
235
|
+
* [.typeScript()](#module_js-build-tools.typeScript) ⇒ <code>function</code>
|
|
162
236
|
* [.testQuick()](#module_js-build-tools.testQuick) ⇒ <code>Promise.<\*></code>
|
|
163
237
|
* [.testFull()](#module_js-build-tools.testFull) ⇒ <code>Promise.<\*></code>
|
|
164
238
|
* [.distMinify()](#module_js-build-tools.distMinify) ⇒ <code>\*</code>
|
|
@@ -190,7 +264,7 @@ Watch for changes and run the distribution for the changed files, then bundle an
|
|
|
190
264
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
191
265
|
<a name="module_js-build-tools.typeScript"></a>
|
|
192
266
|
|
|
193
|
-
### js-build-tools.typeScript() ⇒ <code>
|
|
267
|
+
### js-build-tools.typeScript() ⇒ <code>function</code>
|
|
194
268
|
Simplified typescript task using tsFor.
|
|
195
269
|
|
|
196
270
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
@@ -537,7 +611,7 @@ Micro-functions used as components for the main gulp functions.
|
|
|
537
611
|
**Author**: Joshua Heagle <joshuaheagle@gmail.com>
|
|
538
612
|
|
|
539
613
|
* [partials](#module_partials)
|
|
540
|
-
* [.tsFor([srcPath], [distPath])](#module_partials.tsFor) ⇒ <code>
|
|
614
|
+
* [.tsFor([srcPath], [distPath])](#module_partials.tsFor) ⇒ <code>function</code>
|
|
541
615
|
* [.runOnChange(path)](#module_partials.runOnChange) ⇒ <code>stream.Stream</code>
|
|
542
616
|
* [~pathRegex](#module_partials.runOnChange..pathRegex)
|
|
543
617
|
* [.removeDirectory(dirPath)](#module_partials.removeDirectory) ⇒ <code>Promise.<\*></code>
|
|
@@ -552,7 +626,7 @@ Micro-functions used as components for the main gulp functions.
|
|
|
552
626
|
|
|
553
627
|
<a name="module_partials.tsFor"></a>
|
|
554
628
|
|
|
555
|
-
### partials.tsFor([srcPath], [distPath]) ⇒ <code>
|
|
629
|
+
### partials.tsFor([srcPath], [distPath]) ⇒ <code>function</code>
|
|
556
630
|
Starting at the source directory, find all the ts files and convert them into the distribution directory.
|
|
557
631
|
|
|
558
632
|
**Kind**: static method of [<code>partials</code>](#module_partials)
|
package/dist/build.js
CHANGED
|
@@ -27,14 +27,17 @@ var build = function build () {
|
|
|
27
27
|
var bundleLintMinify = parallel(bundleLint, bundleMinify)
|
|
28
28
|
var buildActions = [clean, distSeries(), distLintMinify]
|
|
29
29
|
if (gulpConfig.get('useTsConfig')) {
|
|
30
|
+
// For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
|
|
30
31
|
buildActions.push(compileReadme)
|
|
31
32
|
}
|
|
32
33
|
if (!gulpConfig.get('nodeOnly')) {
|
|
34
|
+
// If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
|
|
33
35
|
buildActions.push(bundle)
|
|
34
36
|
buildActions.push(bundleLintMinify)
|
|
35
37
|
}
|
|
36
38
|
var runActions = [series.apply(void 0, buildActions)]
|
|
37
39
|
if (!gulpConfig.get('useTsConfig')) {
|
|
40
|
+
// Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
|
|
38
41
|
runActions.push(compileReadme)
|
|
39
42
|
}
|
|
40
43
|
runActions.push(testFull)
|
|
@@ -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 =
|
|
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
|
};
|
package/dist/partials/tsFor.js
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
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;
|
package/dist/typeScript.js
CHANGED
|
@@ -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 {
|
|
9
|
+
* @returns {Function}
|
|
10
10
|
*/
|
|
11
|
-
var typeScript =
|
|
12
|
-
return tsFor()
|
|
13
|
-
}
|
|
11
|
+
var typeScript = tsFor()
|
|
14
12
|
module.exports = typeScript
|
package/dist/typeScript.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var tsFor=require("./partials/tsFor"),typeScript=
|
|
1
|
+
"use strict";var tsFor=require("./partials/tsFor"),typeScript=tsFor();module.exports=typeScript;
|
package/functions/build.test.js
CHANGED
|
@@ -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": "
|
|
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(
|
|
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
|
|
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(
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.
|
|
116
|
-
|
|
117
|
-
|
|
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 =
|
|
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 {
|
|
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')) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
})
|
package/functions/typeScript.js
CHANGED
|
@@ -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 {
|
|
7
|
+
* @returns {Function}
|
|
8
8
|
*/
|
|
9
|
-
const typeScript =
|
|
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
|
-
|
|
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
|
})
|