1 | # Web build tools
|
2 |
|
3 | [![npm](https://img.shields.io/npm/v/demurgos-web-build-tools.svg?maxAge=2592000)](https://www.npmjs.com/package/demurgos-web-build-tools)
|
4 | [![Build status](https://img.shields.io/travis/demurgos/web-build-tools/master.svg?maxAge=2592000)](https://travis-ci.org/demurgos/web-build-tools)
|
5 | [![GitHub repository](https://img.shields.io/badge/Github-demurgos%2Fweb--build--tools-blue.svg)](https://github.com/demurgos/web-build-tools)
|
6 |
|
7 | Gulp tasks generator for standard web projects.
|
8 |
|
9 | This package consolidates various tools in a single interface. This is tailored for my personal
|
10 | needs. By using the same tools with a standard structure, I am able to update my build chain in a
|
11 | single place (here) and benefit from this in all my main projects.
|
12 |
|
13 | Here is the list of tools:
|
14 | - Typescript
|
15 | - Webpack: Bundle resource for the browser
|
16 | - Mocha: Tests
|
17 | - Pug: Generate HTML pages from templates
|
18 | - Sass: Generate CSS from Sass files
|
19 |
|
20 | ## Standard project layout
|
21 |
|
22 | ```text
|
23 | .
|
24 | ├── build/ # Development builds
|
25 | ├── dist/ # Distributed files (this goes to npm)
|
26 | ├── docs/ # Advanced documentation for the library
|
27 | ├── src/ # Scripts, assets and tests
|
28 | ├── CHANGELOG.md # Describe all the changes
|
29 | ├── CONTRIBUTING.md # How to build and work on the project
|
30 | ├── LICENSE.md # Generally MIT
|
31 | ├── NOTICE.md # To match requirements of third-party tools
|
32 | ├── README.md # Projects presentation
|
33 | ├── package.json # Project's metadata
|
34 | ├── gulpfile.js # Definition of Gulp tasks
|
35 | └── typings.json # Type declarations settings
|
36 | ```
|
37 |
|
38 | ## Usage
|
39 |
|
40 | This library generate gulp tasks for _targets_ in the context of a _project_.
|
41 | A target is basically a final build, and a project is a set of targets.
|
42 |
|
43 | There are currently 3 supported targets:
|
44 | - Node: Generate a Node package, either an executable or a library. It only
|
45 | compiles Typescript files.
|
46 | - Angular: Generate an Angular application, for the server. It compiles
|
47 | Typescript files, builds Pug and Sass files and copy assets.
|
48 | - Test: Build and run the unit-tests with Node. It is mainly to test a `node`
|
49 | target.
|
50 |
|
51 | The project configuration defines were are the `package.json`, `src` directory,
|
52 | `build` directory, etc.
|
53 |
|
54 | A target configuration defines the files to compile and the specific options.
|
55 |
|
56 | To generate general tasks (`:lint`, `:bump-minor`, etc.), use:
|
57 |
|
58 | ```typescript
|
59 | import * as buildTools from "demurgos-web-build-tools";
|
60 | import gulp = require("gulp");
|
61 |
|
62 | // Project-wide options
|
63 | const projectOptions = Object.assign(
|
64 | {},
|
65 | buildTools.config.DEFAULT_PROJECT_OPTIONS,
|
66 | {
|
67 | root: __dirname
|
68 | }
|
69 | );
|
70 |
|
71 | buildTools.projectTasks.registerAll(gulp, projectOptions);
|
72 | ```
|
73 |
|
74 | To generate a target, use:
|
75 |
|
76 | ```typescript
|
77 | import * as buildTools from "demurgos-web-build-tools";
|
78 | import gulp = require("gulp");
|
79 |
|
80 | // Project-wide options
|
81 | const projectOptions = buildTools.config.DEFAULT_PROJECT_OPTIONS;
|
82 |
|
83 | // Preconfigured targets
|
84 | // Node library
|
85 | const libTarget = buildTools.config.LIB_TARGET;
|
86 | // Mocha tests
|
87 | const libTestTarget = buildTools.config.LIB_TEST_TARGET;
|
88 | // Webpack build for angular config
|
89 | const angularClientTarget = buildTools.config.ANGULAR_CLIENT_TARGET;
|
90 |
|
91 | // buildTools.targetGenerators.<kind>.generateTarget(gulp, project, target);
|
92 | buildTools.targetGenerators.node.generateTarget(gulp, projectOptions, libTarget);
|
93 | buildTools.targetGenerators.test.generateTarget(gulp, projectOptions, libTestTarget);
|
94 | buildTools.targetGenerators.webpack.generateTarget(gulp, projectOptions, angularClientTarget);
|
95 | ```
|
96 |
|
97 | ## Project
|
98 |
|
99 | ### Project Options
|
100 |
|
101 | #### `root`
|
102 |
|
103 | - Type: `string`
|
104 |
|
105 | Path to the root of your project.
|
106 | **This is the only path allowed to be absolute**.
|
107 |
|
108 | ### `packageJson`
|
109 |
|
110 | - Type: `string`
|
111 |
|
112 | Relative path from `project.root` to your **package.json** file.
|
113 |
|
114 | ### `packageJson`
|
115 |
|
116 | - Type: `string`
|
117 |
|
118 | Relative path from `project.root` to your **package.json** file.
|
119 |
|
120 | ### `srcDir`
|
121 |
|
122 | - Type: `string`
|
123 |
|
124 | Relative path from `project.root` to the directory containing the sources of your project.
|
125 |
|
126 | ### `buildDir`
|
127 |
|
128 | - Type: `string`
|
129 |
|
130 | Relative path from `project.root` to the directory where the output of the builds should be placed.
|
131 |
|
132 | This directory is usually ignored by your version control system.
|
133 |
|
134 | ### `distDir`
|
135 |
|
136 | - Type: `string`
|
137 |
|
138 | Relative path from `project.root` to the directory containing the builds you wish to publish
|
139 | or export (distribute).
|
140 |
|
141 | ### `tslint`
|
142 |
|
143 | **TODO**: The configuration of tslint will be updated. It currently uses `tslintJson` and `tslintOptions`.
|
144 |
|
145 | ### Project Tasks
|
146 |
|
147 | #### `:bump-major`
|
148 |
|
149 | 1. Increments the major version of the project
|
150 | 2. Creates a _git_ commit `Release <version>`. (example: `Release 2.2.1`)
|
151 | 3. Creates a _git_ tag `v<version>` with the message `Release <version>`.
|
152 | (Example: name: `v2.2.1`, message: `Release 2.2.1`)
|
153 |
|
154 | #### `:bump-minor`
|
155 |
|
156 | Same as `:bump-major` but increments the minor version.
|
157 |
|
158 | #### `:bump-patch`
|
159 |
|
160 | Same as `:bump-major` but increments the patch version.
|
161 |
|
162 | #### `:lint`
|
163 |
|
164 | Check the Typescript files with [TSLint][github-tslint].
|
165 | See `src/lib/config/tslint.ts` for the default configuration.
|
166 |
|
167 | ## _node_ target
|
168 |
|
169 | ### Options for a _node_ target
|
170 |
|
171 | #### `name`
|
172 |
|
173 | - Type: `string`
|
174 |
|
175 | Name of the target. This is used as the prefix for each task.
|
176 | For example, `"name": "foo"` leads to `gulp foo:build`.
|
177 |
|
178 | #### `targetDir`
|
179 |
|
180 | - Type: `string`
|
181 | - Default: `target.name`
|
182 |
|
183 | Relative path from `project.buildDir` to the directory containing the output of this target.
|
184 | This is usually a subdirectory of `project.buildDir`.
|
185 |
|
186 | #### `scripts`
|
187 |
|
188 | - Type: `string[]`
|
189 |
|
190 | Relative patterns from `project.srcDir` to match the `*.ts` files to compile for this target.
|
191 |
|
192 | #### `typeRoots`
|
193 |
|
194 | - Type: `string[]`
|
195 |
|
196 | Relative paths from `project.srcDir` to the directories containing ths `*.d.ts` type definition files
|
197 | of third-party libraries.
|
198 |
|
199 | #### `typescript`
|
200 |
|
201 | - Type: `TypescriptOptions`
|
202 | - Optional
|
203 |
|
204 | Advanced Typescript options. See `src/lib/config/config.ts`.
|
205 |
|
206 | #### `copy`
|
207 |
|
208 | - Type: `CopyOptions[]`
|
209 | - Optional
|
210 |
|
211 | Copy some files during the build process.
|
212 |
|
213 | #### `pug`
|
214 |
|
215 | - Type: `PugOptions[]`
|
216 | - Optional
|
217 |
|
218 | Render some HTML files from Pug templates during the build process.
|
219 |
|
220 | #### `sass`
|
221 |
|
222 | - Type: `SassOptions[]`
|
223 | - Optional
|
224 |
|
225 | Render some CSS files from `*.scss` files during the build process.
|
226 |
|
227 | ### `mainModule`
|
228 |
|
229 | - Type: `string`
|
230 |
|
231 | Relative module id (path without the extension) from `target.srcDir` of the main module.
|
232 |
|
233 | This is usually the file to start when running the project or the entry point of the library.
|
234 |
|
235 | ### Tasks for a _node_ target
|
236 |
|
237 | #### `<targetName>:build`
|
238 |
|
239 | Build the complete target and output its result to `target.targetDir`.
|
240 |
|
241 | #### `<targetName>:build:scripts`
|
242 |
|
243 | Compile the Typescript files.
|
244 |
|
245 | #### `<targetName>:build:copy`
|
246 |
|
247 | Perform simple copies.
|
248 |
|
249 | #### `<targetName>:build:pug`
|
250 |
|
251 | Compile Pug templates.
|
252 |
|
253 | #### `<targetName>:build:sass`
|
254 |
|
255 | Compile `*.scss` files.
|
256 |
|
257 | #### `<targetName>:clean`
|
258 |
|
259 | Delete the files of this target in `project.buildDir` and `project.distDir`.
|
260 |
|
261 | #### `<targetName>:dist`
|
262 |
|
263 | Clean the files, build the target and then copy it to `distDir` (ready for
|
264 | publication).
|
265 |
|
266 | #### `<targetName>:tsconfig.json`
|
267 |
|
268 | Generate as `tsconfig.json` file in the base directory for this target so
|
269 | you can compile it without `gulp` and just `tsc`:
|
270 |
|
271 | Example for the target `api-server` with the baseDirectory `server`:
|
272 |
|
273 | ```
|
274 | gulp api-server:tsconfig.json
|
275 | cd src/server
|
276 | tsc
|
277 | # The target `api-server` is now built
|
278 | ```
|
279 |
|
280 | #### `<targetName>:watch`
|
281 |
|
282 | Recompile when the files change.
|
283 |
|
284 | ### Target `webpack`
|
285 |
|
286 | Options: see `src/lib/config/config.ts`
|
287 |
|
288 | **TODO**
|
289 |
|
290 | ### Target `test`
|
291 |
|
292 | Options: see `src/lib/config/config.ts`
|
293 |
|
294 | **TODO**
|
295 |
|
296 |
|
297 | [github-tslint]: https://github.com/palantir/tslint
|