js-build-tools 2.2.2 → 2.2.4
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 +98 -31
- package/dist/build.js +19 -3
- package/dist/build.min.js +1 -1
- package/dist/test-helpers/setUp.js +11 -8
- package/functions/build.js +25 -9
- package/functions/build.test.js +283 -39
- package/functions/partials/addToReadme.test.js +9 -4
- package/functions/partials/clean.test.js +2 -1
- package/functions/test-helpers/setUp.js +11 -8
- 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,65 @@ 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
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
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
|
+
|
|
159
|
+
Add the following to the exports in your `babel.config.js`:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
module.exports = {
|
|
163
|
+
readmeSearch: 'dist/**/!(*.min).js',
|
|
164
|
+
useTsConfig: 'tsconfig.json',
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
The `js-to-markdown` only works on .js files, so we run the readme search on the built dist files. Also, we want to
|
|
169
|
+
register the tsconfig.json we created earlier and will alter the processes to build for TypeScript.
|
|
170
|
+
|
|
171
|
+
Update `babel.config.js` with the following:
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
const babelConfig = require('js-build-tools/babel.config')
|
|
175
|
+
// This is the important line, we need to add compatibility for Jest to run tests on .ts files
|
|
176
|
+
babelConfig.presets.push('@babel/preset-typescript')
|
|
177
|
+
module.exports = babelConfig
|
|
114
178
|
```
|
|
179
|
+
|
|
180
|
+
### Configure Scripts
|
|
181
|
+
|
|
182
|
+
In your `package.json` file, add the following scripts:
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
115
186
|
"scripts": {
|
|
116
187
|
"build": "gulp build",
|
|
117
188
|
"dev": "gulp",
|
|
@@ -120,12 +191,13 @@ In your package.json file, add the following scripts:
|
|
|
120
191
|
"test:quick": "gulp testQuick",
|
|
121
192
|
"watch": "gulp watchFull",
|
|
122
193
|
"watch:test": "gulp watchTest"
|
|
123
|
-
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
124
196
|
```
|
|
125
197
|
|
|
126
198
|
## Usage
|
|
127
|
-
Run any of the above commands with `gulp` or `npm run`.
|
|
128
199
|
|
|
200
|
+
Run any of the above commands with `gulp` or `npm run`.
|
|
129
201
|
|
|
130
202
|
# Available functions documentation
|
|
131
203
|
|
|
@@ -168,7 +240,7 @@ Export these functions to your own project in order to customize your build pipe
|
|
|
168
240
|
* [.bundleMinify()](#module_js-build-tools.bundleMinify) ⇒ <code>\*</code>
|
|
169
241
|
* [.bundleLint()](#module_js-build-tools.bundleLint) ⇒ <code>stream.Stream</code>
|
|
170
242
|
* [.bundle()](#module_js-build-tools.bundle) ⇒ <code>stream.Stream</code>
|
|
171
|
-
* [.build(
|
|
243
|
+
* [.build()](#module_js-build-tools.build) ⇒ <code>stream.Stream</code>
|
|
172
244
|
|
|
173
245
|
<a name="module_js-build-tools.compileReadme"></a>
|
|
174
246
|
|
|
@@ -255,15 +327,10 @@ Starting at the distribution entry point, bundle all the files into a single fil
|
|
|
255
327
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
256
328
|
<a name="module_js-build-tools.build"></a>
|
|
257
329
|
|
|
258
|
-
### js-build-tools.build(
|
|
330
|
+
### js-build-tools.build() ⇒ <code>stream.Stream</code>
|
|
259
331
|
Runs several processes to build and validate the project.
|
|
260
332
|
|
|
261
333
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
262
|
-
|
|
263
|
-
| Param | Type | Default |
|
|
264
|
-
| --- | --- | --- |
|
|
265
|
-
| [done] | <code>function</code> | <code></code> |
|
|
266
|
-
|
|
267
334
|
<a name="module_gulpConfig"></a>
|
|
268
335
|
|
|
269
336
|
## gulpConfig
|
package/dist/build.js
CHANGED
|
@@ -7,7 +7,6 @@ var _require = require('./partials')
|
|
|
7
7
|
var clean = _require.clean
|
|
8
8
|
var distSeries = _require.distSeries
|
|
9
9
|
var compileReadme = require('./compileReadme')
|
|
10
|
-
var dist = require('./dist')
|
|
11
10
|
var distLint = require('./distLint')
|
|
12
11
|
var distMinify = require('./distMinify')
|
|
13
12
|
var _require2 = require('gulp')
|
|
@@ -20,11 +19,28 @@ var testFull = require('./testFull')
|
|
|
20
19
|
* Runs several processes to build and validate the project.
|
|
21
20
|
* Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
|
|
22
21
|
* @memberOf module:js-build-tools
|
|
23
|
-
* @param {function} [done=null]
|
|
24
22
|
* @returns {stream.Stream}
|
|
25
23
|
*/
|
|
26
24
|
var build = function build () {
|
|
27
25
|
var done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
|
|
28
|
-
|
|
26
|
+
var distLintMinify = parallel(distLint, distMinify)
|
|
27
|
+
var bundleLintMinify = parallel(bundleLint, bundleMinify)
|
|
28
|
+
var buildActions = [clean, distSeries(), distLintMinify]
|
|
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
|
|
31
|
+
buildActions.push(compileReadme)
|
|
32
|
+
}
|
|
33
|
+
if (!gulpConfig.get('nodeOnly')) {
|
|
34
|
+
// If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
|
|
35
|
+
buildActions.push(bundle)
|
|
36
|
+
buildActions.push(bundleLintMinify)
|
|
37
|
+
}
|
|
38
|
+
var runActions = [series.apply(void 0, buildActions)]
|
|
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.
|
|
41
|
+
runActions.push(compileReadme)
|
|
42
|
+
}
|
|
43
|
+
runActions.push(testFull)
|
|
44
|
+
return parallel.apply(void 0, runActions)(done)
|
|
29
45
|
}
|
|
30
46
|
module.exports = build
|
package/dist/build.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var bundle=require("./bundle"),bundleLint=require("./bundleLint"),bundleMinify=require("./bundleMinify"),_require=require("./partials"),clean=_require.clean,distSeries=_require.distSeries,compileReadme=require("./compileReadme"),
|
|
1
|
+
"use strict";var bundle=require("./bundle"),bundleLint=require("./bundleLint"),bundleMinify=require("./bundleMinify"),_require=require("./partials"),clean=_require.clean,distSeries=_require.distSeries,compileReadme=require("./compileReadme"),distLint=require("./distLint"),distMinify=require("./distMinify"),_require2=require("gulp"),parallel=_require2.parallel,series=_require2.series,gulpConfig=require("../gulp.config.js"),testFull=require("./testFull"),build=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=parallel(distLint,distMinify),l=parallel(bundleLint,bundleMinify),r=[clean,distSeries(),i];gulpConfig.get("useTsConfig")&&r.push(compileReadme),gulpConfig.get("nodeOnly")||(r.push(bundle),r.push(l));var u=[series.apply(void 0,r)];return gulpConfig.get("useTsConfig")||u.push(compileReadme),u.push(testFull),parallel.apply(void 0,u)(e)};module.exports=build;
|
|
@@ -42,18 +42,21 @@ var setDefaults = function setDefaults() {
|
|
|
42
42
|
var testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
|
|
43
43
|
tempDir = "".concat(testDir, "/");
|
|
44
44
|
srcPath = "".concat(tempDir, "src");
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
gulpConfig.set('
|
|
48
|
-
gulpConfig.set('
|
|
49
|
-
gulpConfig.set('
|
|
45
|
+
var distPath = "".concat(tempDir, "dist");
|
|
46
|
+
var browserPath = "".concat(tempDir, "browser");
|
|
47
|
+
gulpConfig.set('browserPath', browserPath);
|
|
48
|
+
gulpConfig.set('cleanPaths', [distPath, browserPath]);
|
|
49
|
+
gulpConfig.set('distMain', "".concat(distPath, "/main"));
|
|
50
|
+
gulpConfig.set('distPath', distPath);
|
|
51
|
+
gulpConfig.set('distSearch', "".concat(distPath, "/**/*.js"));
|
|
50
52
|
gulpConfig.set('readmeTemplate', "".concat(tempDir, "MAIN.md"));
|
|
51
53
|
gulpConfig.set('readmePath', tempDir);
|
|
54
|
+
gulpConfig.set('readmeSearch', "".concat(srcPath, "/**/!(*.test).js"));
|
|
52
55
|
gulpConfig.set('rootPath', tempDir);
|
|
53
56
|
gulpConfig.set('srcPath', srcPath);
|
|
54
|
-
gulpConfig.set('srcSearch', "".concat(
|
|
55
|
-
gulpConfig.set('tsSearch', "".concat(
|
|
56
|
-
gulpConfig.set('watchSearch', "".concat(
|
|
57
|
+
gulpConfig.set('srcSearch', "".concat(srcPath, "/**/!(*.test).js"));
|
|
58
|
+
gulpConfig.set('tsSearch', "".concat(srcPath, "/**/*.ts"));
|
|
59
|
+
gulpConfig.set('watchSearch', "".concat(srcPath, "/**/*.js"));
|
|
57
60
|
};
|
|
58
61
|
exports.setDefaults = setDefaults;
|
|
59
62
|
exports.gulpConfig = gulpConfig;
|
package/functions/build.js
CHANGED
|
@@ -3,7 +3,6 @@ const bundleLint = require('./bundleLint')
|
|
|
3
3
|
const bundleMinify = require('./bundleMinify')
|
|
4
4
|
const { clean, distSeries } = require('./partials')
|
|
5
5
|
const compileReadme = require('./compileReadme')
|
|
6
|
-
const dist = require('./dist')
|
|
7
6
|
const distLint = require('./distLint')
|
|
8
7
|
const distMinify = require('./distMinify')
|
|
9
8
|
const { parallel, series } = require('gulp')
|
|
@@ -14,15 +13,32 @@ const testFull = require('./testFull')
|
|
|
14
13
|
* Runs several processes to build and validate the project.
|
|
15
14
|
* Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
|
|
16
15
|
* @memberOf module:js-build-tools
|
|
17
|
-
* @param {function} [done=null]
|
|
18
16
|
* @returns {stream.Stream}
|
|
19
17
|
*/
|
|
20
|
-
const build = (done = null) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const build = (done = null) => {
|
|
19
|
+
const distLintMinify = parallel(distLint, distMinify)
|
|
20
|
+
const bundleLintMinify = parallel(bundleLint, bundleMinify)
|
|
21
|
+
const buildActions = [clean, distSeries(), distLintMinify]
|
|
22
|
+
if (gulpConfig.get('useTsConfig')) {
|
|
23
|
+
// For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
|
|
24
|
+
buildActions.push(compileReadme)
|
|
25
|
+
}
|
|
26
|
+
if (!gulpConfig.get('nodeOnly')) {
|
|
27
|
+
// If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
|
|
28
|
+
buildActions.push(bundle)
|
|
29
|
+
buildActions.push(bundleLintMinify)
|
|
30
|
+
}
|
|
31
|
+
const runActions = [
|
|
32
|
+
series(...buildActions),
|
|
33
|
+
]
|
|
34
|
+
if (!gulpConfig.get('useTsConfig')) {
|
|
35
|
+
// Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
|
|
36
|
+
runActions.push(compileReadme)
|
|
37
|
+
}
|
|
38
|
+
runActions.push(testFull)
|
|
39
|
+
return parallel(
|
|
40
|
+
...runActions
|
|
41
|
+
)(done)
|
|
42
|
+
}
|
|
27
43
|
|
|
28
44
|
module.exports = build
|
package/functions/build.test.js
CHANGED
|
@@ -1,59 +1,303 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('./test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-build')
|
|
2
4
|
const gulpConfig = setUp.gulpConfig
|
|
3
5
|
const build = require('./build')
|
|
4
|
-
const
|
|
5
|
-
const bundleLint = require('./bundleLint')
|
|
6
|
-
const bundleMinify = require('./bundleMinify')
|
|
7
|
-
const { clean, distSeries } = require('./partials')
|
|
8
|
-
const compileReadme = require('./compileReadme')
|
|
9
|
-
const dist = require('./dist')
|
|
10
|
-
const distLint = require('./distLint')
|
|
11
|
-
const distMinify = require('./distMinify')
|
|
6
|
+
const clean = require('./partials/clean')
|
|
12
7
|
const testFull = require('./testFull')
|
|
8
|
+
const { countMatches } = require('./testHelpers')
|
|
13
9
|
|
|
14
10
|
const genericFunction = () => Promise.resolve(true)
|
|
15
|
-
|
|
16
|
-
jest.mock('./bundleLint', () => jest.fn(genericFunction))
|
|
17
|
-
jest.mock('./bundleMinify', () => jest.fn(genericFunction))
|
|
11
|
+
|
|
18
12
|
jest.mock('./partials/clean', () => jest.fn(genericFunction))
|
|
19
|
-
jest.mock('./compileReadme', () => jest.fn(genericFunction))
|
|
20
|
-
jest.mock('./dist', () => jest.fn(genericFunction))
|
|
21
|
-
jest.mock('./distLint', () => jest.fn(genericFunction))
|
|
22
|
-
jest.mock('./distMinify', () => jest.fn(genericFunction))
|
|
23
|
-
jest.mock('./partials/distSeries', () => jest.fn(() => genericFunction))
|
|
24
13
|
jest.mock('./testFull', () => jest.fn(genericFunction))
|
|
25
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
|
+
const file1Contents = '/**\n' +
|
|
24
|
+
' * Console log out a greeting with given input.\n' +
|
|
25
|
+
' * @param {string} input\n' +
|
|
26
|
+
' */\n' +
|
|
27
|
+
'const file1 = input => console.log(`Hello from file1 with ${input}`)\n' +
|
|
28
|
+
'\n' +
|
|
29
|
+
'module.exports = file1\n'
|
|
30
|
+
|
|
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
|
+
const file2Contents = '/**\n' +
|
|
46
|
+
' * Farewell with a summation of two numbers returned.\n' +
|
|
47
|
+
' * @param {number} a\n' +
|
|
48
|
+
' * @param {number} b\n' +
|
|
49
|
+
' * @returns {number}\n' +
|
|
50
|
+
' */\n' +
|
|
51
|
+
'const file2 = (a, b) => {\n' +
|
|
52
|
+
' const sum = a + b\n' +
|
|
53
|
+
' console.log(`Good-bye from file2 with sum ${sum}`)\n' +
|
|
54
|
+
' return sum\n' +
|
|
55
|
+
'}\n' +
|
|
56
|
+
'\n' +
|
|
57
|
+
'module.exports = file2\n'
|
|
58
|
+
|
|
59
|
+
const mainTypescript = '/**\n' +
|
|
60
|
+
' * A salutation and summation.\n' +
|
|
61
|
+
' * @param {number} a\n' +
|
|
62
|
+
' * @param {number} b\n' +
|
|
63
|
+
' * @returns {number}\n' +
|
|
64
|
+
' */\n' +
|
|
65
|
+
'const main = (a: number, b: number): number => {\n' +
|
|
66
|
+
' const sum = a + b\n' +
|
|
67
|
+
' console.log(`Greetings from typescript ${sum}`)\n' +
|
|
68
|
+
' return sum\n' +
|
|
69
|
+
'}\n' +
|
|
70
|
+
'\n' +
|
|
71
|
+
'module.exports = main\n'
|
|
72
|
+
|
|
73
|
+
const mainFileContents = '/**\n' +
|
|
74
|
+
' * Some test functions for usage with build tests.\n' +
|
|
75
|
+
' * @file\n' +
|
|
76
|
+
' * @author John Doe <john.doe@example.com>\n' +
|
|
77
|
+
' * @version 1.0.0\n' +
|
|
78
|
+
' * @module test-build\n' +
|
|
79
|
+
' */\n' +
|
|
80
|
+
'\n' +
|
|
81
|
+
'const file1 = require(\'./sources/file1\')\n' +
|
|
82
|
+
'const file2 = require(\'./sources/file2\')\n' +
|
|
83
|
+
'\n' +
|
|
84
|
+
'module.exports = {\n' +
|
|
85
|
+
' file1,\n' +
|
|
86
|
+
' file2,\n' +
|
|
87
|
+
'}\n'
|
|
88
|
+
|
|
89
|
+
const mainMd = '# Welcome\n' +
|
|
90
|
+
'This is the top of the README.md.\n' +
|
|
91
|
+
'\n'
|
|
92
|
+
|
|
93
|
+
const tsConfigContents = '{\n' +
|
|
94
|
+
' "files": ["test-build/src/**/*.ts"],\n' +
|
|
95
|
+
' "compilerOptions": {\n' +
|
|
96
|
+
' "noImplicitAny": true,\n' +
|
|
97
|
+
' "target": "es5"\n' +
|
|
98
|
+
' }\n' +
|
|
99
|
+
'}'
|
|
100
|
+
|
|
101
|
+
beforeEach(
|
|
102
|
+
() => setUp.beforeEach()
|
|
103
|
+
.then(
|
|
104
|
+
async () => {
|
|
105
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
106
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
107
|
+
const sourcesPath = `${srcPath}/sources`
|
|
108
|
+
await fs.mkdirSync(sourcesPath)
|
|
109
|
+
return fs.writeFileSync(`${readmePath}/MAIN.md`, mainMd)
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
afterEach(setUp.afterEach)
|
|
115
|
+
|
|
26
116
|
describe('build', () => {
|
|
27
|
-
test('when nodeOnly true: calls clean,
|
|
117
|
+
test('when nodeOnly true: calls clean, distSeries, distLint, distMinify, compileReadme, testFull', done => {
|
|
118
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
119
|
+
const sourcesPath = `${srcPath}/sources`
|
|
120
|
+
const distPath = gulpConfig.get('distPath')
|
|
121
|
+
const distSourcesPath = `${distPath}/sources`
|
|
122
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
123
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
124
|
+
fs.writeFileSync(`${sourcesPath}/file1.js`, file1Contents)
|
|
125
|
+
fs.writeFileSync(`${sourcesPath}/file2.js`, file2Contents)
|
|
126
|
+
fs.writeFileSync(`${srcPath}/main.js`, mainFileContents)
|
|
28
127
|
gulpConfig.set('nodeOnly', true)
|
|
29
|
-
expect.assertions(
|
|
30
|
-
build()
|
|
31
|
-
|
|
128
|
+
expect.assertions(20)
|
|
129
|
+
build(() => {
|
|
130
|
+
// Called 'clean'
|
|
32
131
|
expect(clean).toHaveBeenCalled()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(
|
|
36
|
-
|
|
132
|
+
|
|
133
|
+
// Created dist directory (distSeries)
|
|
134
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
135
|
+
|
|
136
|
+
// Minify the dist files (distMinify)
|
|
137
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
138
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
139
|
+
// Used single quotes because of distLint
|
|
140
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
141
|
+
|
|
142
|
+
expect(fs.existsSync(`${distSourcesPath}/file1.min.js`)).toBeTruthy()
|
|
143
|
+
const babelifiedFile1 = fs.readFileSync(`${distSourcesPath}/file1.js`).toString()
|
|
144
|
+
expect(countMatches(babelifiedFile1, '\'use strict\'')).toEqual(1)
|
|
145
|
+
expect(countMatches(babelifiedFile1, 'const ')).toEqual(0)
|
|
146
|
+
expect(countMatches(babelifiedFile1, 'var ')).toEqual(1)
|
|
147
|
+
expect(countMatches(babelifiedFile1, 'function ')).toEqual(1)
|
|
148
|
+
expect(countMatches(babelifiedFile1, 'return ')).toEqual(1)
|
|
149
|
+
|
|
150
|
+
expect(fs.existsSync(`${distSourcesPath}/file2.min.js`)).toBeTruthy()
|
|
151
|
+
const babelifiedFile2 = fs.readFileSync(`${distSourcesPath}/file2.js`).toString()
|
|
152
|
+
expect(countMatches(babelifiedFile2, '\'use strict\'')).toEqual(1)
|
|
153
|
+
expect(countMatches(babelifiedFile2, 'const ')).toEqual(0)
|
|
154
|
+
expect(countMatches(babelifiedFile2, 'var ')).toEqual(2)
|
|
155
|
+
expect(countMatches(babelifiedFile2, 'function ')).toEqual(1)
|
|
156
|
+
|
|
157
|
+
// Generated README.md (compileReadme)
|
|
158
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
159
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
160
|
+
expect(countMatches(readmeContents, 'test-build')).toEqual(4)
|
|
161
|
+
expect(countMatches(readmeContents, 'file1')).toEqual(4)
|
|
162
|
+
expect(countMatches(readmeContents, 'file2')).toEqual(4)
|
|
163
|
+
|
|
164
|
+
// Ran 'testFull'
|
|
37
165
|
expect(testFull).toHaveBeenCalled()
|
|
38
166
|
done()
|
|
39
|
-
}
|
|
40
|
-
})
|
|
167
|
+
})
|
|
168
|
+
}, 30000)
|
|
41
169
|
|
|
42
170
|
test('when nodeOnly false: calls clean, distSeries, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull', done => {
|
|
171
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
172
|
+
const sourcesPath = `${srcPath}/sources`
|
|
173
|
+
const distPath = gulpConfig.get('distPath')
|
|
174
|
+
const browserFile = gulpConfig.get('browserName')
|
|
175
|
+
const browserPath = gulpConfig.get('browserPath')
|
|
176
|
+
const bundledFile = `${browserPath}/${browserFile}.js`
|
|
177
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
178
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
179
|
+
fs.writeFileSync(`${sourcesPath}/file1.js`, file1Contents)
|
|
180
|
+
fs.writeFileSync(`${sourcesPath}/file2.js`, file2Contents)
|
|
181
|
+
fs.writeFileSync(`${srcPath}/main.js`, mainFileContents)
|
|
43
182
|
gulpConfig.set('nodeOnly', false)
|
|
44
|
-
expect.assertions(
|
|
45
|
-
build()
|
|
46
|
-
|
|
183
|
+
expect.assertions(13)
|
|
184
|
+
build(() => {
|
|
185
|
+
// Called 'clean'
|
|
47
186
|
expect(clean).toHaveBeenCalled()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
expect(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(
|
|
54
|
-
|
|
187
|
+
|
|
188
|
+
// Created dist directory (distSeries)
|
|
189
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
190
|
+
|
|
191
|
+
// Minify the dist files (distMinify)
|
|
192
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
193
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
194
|
+
// Used single quotes because of distLint
|
|
195
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
196
|
+
|
|
197
|
+
// Created browser directory (bundle)
|
|
198
|
+
expect(fs.existsSync(browserPath)).toBeTruthy()
|
|
199
|
+
|
|
200
|
+
// Minify the browser files (bundleMinify)
|
|
201
|
+
expect(fs.existsSync(`${browserPath}/${browserFile}.min.js`)).toBeTruthy()
|
|
202
|
+
const bundledContents = fs.readFileSync(bundledFile).toString()
|
|
203
|
+
expect(countMatches(bundledContents, 'file1')).toEqual(9)
|
|
204
|
+
expect(countMatches(bundledContents, 'file2')).toEqual(9)
|
|
205
|
+
|
|
206
|
+
// Generated README.md (compileReadme)
|
|
207
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
208
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
209
|
+
expect(countMatches(readmeContents, 'test-build')).toEqual(4)
|
|
210
|
+
expect(countMatches(readmeContents, 'file1')).toEqual(4)
|
|
211
|
+
expect(countMatches(readmeContents, 'file2')).toEqual(4)
|
|
212
|
+
|
|
213
|
+
// Ran 'testFull'
|
|
214
|
+
expect(testFull).toHaveBeenCalled()
|
|
215
|
+
done()
|
|
216
|
+
})
|
|
217
|
+
}, 30000)
|
|
218
|
+
|
|
219
|
+
test('when nodeOnly true and useTsConfig set: calls clean, tsFor, distFor, distLint, distMinify, compileReadme, testFull', done => {
|
|
220
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
221
|
+
const rootPath = gulpConfig.get('rootPath')
|
|
222
|
+
const tsConfig = `${rootPath}/tsconfig.json`
|
|
223
|
+
const distPath = gulpConfig.get('distPath')
|
|
224
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
225
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
226
|
+
fs.writeFileSync(`${srcPath}/main.ts`, mainTypescript)
|
|
227
|
+
fs.writeFileSync(tsConfig, tsConfigContents)
|
|
228
|
+
gulpConfig.set('nodeOnly', true)
|
|
229
|
+
gulpConfig.set('useTsConfig', tsConfig)
|
|
230
|
+
gulpConfig.set('readmeSearch', `${distPath}/**/*.js`)
|
|
231
|
+
expect.assertions(7)
|
|
232
|
+
build(() => {
|
|
233
|
+
// Called 'clean'
|
|
234
|
+
expect(clean).toHaveBeenCalled()
|
|
235
|
+
|
|
236
|
+
// Created dist directory (distSeries)
|
|
237
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
238
|
+
|
|
239
|
+
// Minify the dist files (distMinify)
|
|
240
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
241
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
242
|
+
// Used single quotes because of distLint
|
|
243
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
244
|
+
|
|
245
|
+
// Generated README.md (compileReadme)
|
|
246
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
247
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
248
|
+
expect(countMatches(readmeContents, 'main')).toEqual(2)
|
|
249
|
+
|
|
250
|
+
// Ran 'testFull'
|
|
251
|
+
expect(testFull).toHaveBeenCalled()
|
|
252
|
+
done()
|
|
253
|
+
})
|
|
254
|
+
}, 30000)
|
|
255
|
+
|
|
256
|
+
test('when nodeOnly false and useTsConfig false: calls clean, tsFor, distFor, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull', done => {
|
|
257
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
258
|
+
const rootPath = gulpConfig.get('rootPath')
|
|
259
|
+
const tsConfig = `${rootPath}/tsconfig.json`
|
|
260
|
+
const distPath = gulpConfig.get('distPath')
|
|
261
|
+
const browserFile = gulpConfig.get('browserName')
|
|
262
|
+
const browserPath = gulpConfig.get('browserPath')
|
|
263
|
+
const bundledFile = `${browserPath}/${browserFile}.js`
|
|
264
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
265
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
266
|
+
fs.writeFileSync(`${srcPath}/main.ts`, mainTypescript)
|
|
267
|
+
fs.writeFileSync(tsConfig, tsConfigContents)
|
|
268
|
+
gulpConfig.set('nodeOnly', false)
|
|
269
|
+
gulpConfig.set('useTsConfig', tsConfig)
|
|
270
|
+
gulpConfig.set('readmeSearch', `${distPath}/**/*.js`)
|
|
271
|
+
expect.assertions(10)
|
|
272
|
+
build(() => {
|
|
273
|
+
// Called 'clean'
|
|
274
|
+
expect(clean).toHaveBeenCalled()
|
|
275
|
+
|
|
276
|
+
// Created dist directory (distSeries)
|
|
277
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
278
|
+
|
|
279
|
+
// Minify the dist files (distMinify)
|
|
280
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
281
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
282
|
+
// Used single quotes because of distLint
|
|
283
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
284
|
+
|
|
285
|
+
// Created browser directory (bundle)
|
|
286
|
+
expect(fs.existsSync(browserPath)).toBeTruthy()
|
|
287
|
+
|
|
288
|
+
// Minify the browser files (bundleMinify)
|
|
289
|
+
expect(fs.existsSync(`${browserPath}/${browserFile}.min.js`)).toBeTruthy()
|
|
290
|
+
const bundledContents = fs.readFileSync(bundledFile).toString()
|
|
291
|
+
expect(countMatches(bundledContents, 'main')).toEqual(3)
|
|
292
|
+
|
|
293
|
+
// Generated README.md (compileReadme)
|
|
294
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
295
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
296
|
+
expect(countMatches(readmeContents, 'main')).toEqual(2)
|
|
297
|
+
|
|
298
|
+
// Ran 'testFull'
|
|
55
299
|
expect(testFull).toHaveBeenCalled()
|
|
56
300
|
done()
|
|
57
|
-
}
|
|
58
|
-
})
|
|
301
|
+
})
|
|
302
|
+
}, 30000)
|
|
59
303
|
})
|
|
@@ -5,9 +5,14 @@ const gulpConfig = setUp.gulpConfig
|
|
|
5
5
|
gulpConfig.set('srcSearch', 'test-temp/src/addToReadme.js')
|
|
6
6
|
const addToReadme = require('./addToReadme')
|
|
7
7
|
|
|
8
|
-
const rawContents = '
|
|
9
|
-
'
|
|
10
|
-
'}'
|
|
8
|
+
const rawContents = '/**\n' +
|
|
9
|
+
' * Say hello with a given name.\n' +
|
|
10
|
+
' * @param {string} name\n' +
|
|
11
|
+
' * @returns {string}\n' +
|
|
12
|
+
' */\n' +
|
|
13
|
+
'const sayHello = name => `Hello from ${name}`\n' +
|
|
14
|
+
'\n' +
|
|
15
|
+
'module.exports = sayHello\n'
|
|
11
16
|
|
|
12
17
|
beforeEach(() => setUp.beforeEach()
|
|
13
18
|
.then(() => fs.writeFileSync(gulpConfig.get('srcPath') + '/addToReadme.js', rawContents)))
|
|
@@ -22,6 +27,6 @@ describe('addToReadme', () => {
|
|
|
22
27
|
await expect(fs.existsSync(readmeFilePath)).toBeTruthy()
|
|
23
28
|
const readme = await fs.readFileSync(readmeFilePath)
|
|
24
29
|
// At least the documentation will have the addToReadme documentation
|
|
25
|
-
await expect(readme.includes('
|
|
30
|
+
await expect(readme.includes('sayHello')).toBeTruthy()
|
|
26
31
|
})
|
|
27
32
|
})
|
|
@@ -2,6 +2,8 @@ const fs = require('fs')
|
|
|
2
2
|
const setUp = require('../test-helpers/setUp')
|
|
3
3
|
setUp.setDefaults('test-clean')
|
|
4
4
|
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
6
|
+
gulpConfig.set('cleanPaths', [srcPath])
|
|
5
7
|
const clean = require('./clean')
|
|
6
8
|
|
|
7
9
|
beforeEach(setUp.beforeEach)
|
|
@@ -11,7 +13,6 @@ afterEach(setUp.afterEach)
|
|
|
11
13
|
describe('clean', () => {
|
|
12
14
|
test('removes all contents of directories specified', async () => {
|
|
13
15
|
expect.assertions(2)
|
|
14
|
-
const srcPath = gulpConfig.get('srcPath')
|
|
15
16
|
expect(fs.readdirSync(srcPath)).toBeTruthy()
|
|
16
17
|
// Run the clean script to empty the directories
|
|
17
18
|
await clean()
|
|
@@ -15,18 +15,21 @@ let srcPath = `${tempDir}src`
|
|
|
15
15
|
const setDefaults = (testDir = 'test-temp') => {
|
|
16
16
|
tempDir = `${testDir}/`
|
|
17
17
|
srcPath = `${tempDir}src`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
gulpConfig.set('
|
|
21
|
-
gulpConfig.set('
|
|
22
|
-
gulpConfig.set('
|
|
18
|
+
const distPath = `${tempDir}dist`
|
|
19
|
+
const browserPath = `${tempDir}browser`
|
|
20
|
+
gulpConfig.set('browserPath', browserPath)
|
|
21
|
+
gulpConfig.set('cleanPaths', [distPath, browserPath])
|
|
22
|
+
gulpConfig.set('distMain', `${distPath}/main`)
|
|
23
|
+
gulpConfig.set('distPath', distPath)
|
|
24
|
+
gulpConfig.set('distSearch', `${distPath}/**/*.js`)
|
|
23
25
|
gulpConfig.set('readmeTemplate', `${tempDir}MAIN.md`)
|
|
24
26
|
gulpConfig.set('readmePath', tempDir)
|
|
27
|
+
gulpConfig.set('readmeSearch', `${srcPath}/**/!(*.test).js`)
|
|
25
28
|
gulpConfig.set('rootPath', tempDir)
|
|
26
29
|
gulpConfig.set('srcPath', srcPath)
|
|
27
|
-
gulpConfig.set('srcSearch', `${
|
|
28
|
-
gulpConfig.set('tsSearch', `${
|
|
29
|
-
gulpConfig.set('watchSearch', `${
|
|
30
|
+
gulpConfig.set('srcSearch', `${srcPath}/**/!(*.test).js`)
|
|
31
|
+
gulpConfig.set('tsSearch', `${srcPath}/**/*.ts`)
|
|
32
|
+
gulpConfig.set('watchSearch', `${srcPath}/**/*.js`)
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
exports.setDefaults = setDefaults
|