js-build-tools 2.2.3 → 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 +96 -24
- package/dist/build.js +3 -0
- 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
|
|
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)
|