UNPKG

7.65 kBMarkdownView Raw
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
7Gulp tasks generator for standard web projects.
8
9This package consolidates various tools in a single interface. This is tailored for my personal
10needs. By using the same tools with a standard structure, I am able to update my build chain in a
11single place (here) and benefit from this in all my main projects.
12
13Here 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
40This library generate gulp tasks for _targets_ in the context of a _project_.
41A target is basically a final build, and a project is a set of targets.
42
43There 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
51The project configuration defines were are the `package.json`, `src` directory,
52`build` directory, etc.
53
54A target configuration defines the files to compile and the specific options.
55
56To generate general tasks (`:lint`, `:bump-minor`, etc.), use:
57
58```typescript
59import * as buildTools from "demurgos-web-build-tools";
60import gulp = require("gulp");
61
62// Project-wide options
63const projectOptions = Object.assign(
64 {},
65 buildTools.config.DEFAULT_PROJECT_OPTIONS,
66 {
67 root: __dirname
68 }
69);
70
71buildTools.projectTasks.registerAll(gulp, projectOptions);
72```
73
74To generate a target, use:
75
76```typescript
77import * as buildTools from "demurgos-web-build-tools";
78import gulp = require("gulp");
79
80// Project-wide options
81const projectOptions = buildTools.config.DEFAULT_PROJECT_OPTIONS;
82
83// Preconfigured targets
84// Node library
85const libTarget = buildTools.config.LIB_TARGET;
86// Mocha tests
87const libTestTarget = buildTools.config.LIB_TEST_TARGET;
88// Webpack build for angular config
89const angularClientTarget = buildTools.config.ANGULAR_CLIENT_TARGET;
90
91// buildTools.targetGenerators.<kind>.generateTarget(gulp, project, target);
92buildTools.targetGenerators.node.generateTarget(gulp, projectOptions, libTarget);
93buildTools.targetGenerators.test.generateTarget(gulp, projectOptions, libTestTarget);
94buildTools.targetGenerators.webpack.generateTarget(gulp, projectOptions, angularClientTarget);
95```
96
97## Project
98
99### Project Options
100
101#### `root`
102
103- Type: `string`
104
105Path to the root of your project.
106**This is the only path allowed to be absolute**.
107
108### `packageJson`
109
110- Type: `string`
111
112Relative path from `project.root` to your **package.json** file.
113
114### `packageJson`
115
116- Type: `string`
117
118Relative path from `project.root` to your **package.json** file.
119
120### `srcDir`
121
122- Type: `string`
123
124Relative path from `project.root` to the directory containing the sources of your project.
125
126### `buildDir`
127
128- Type: `string`
129
130Relative path from `project.root` to the directory where the output of the builds should be placed.
131
132This directory is usually ignored by your version control system.
133
134### `distDir`
135
136- Type: `string`
137
138Relative path from `project.root` to the directory containing the builds you wish to publish
139or 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
1491. Increments the major version of the project
1502. Creates a _git_ commit `Release <version>`. (example: `Release 2.2.1`)
1513. 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
156Same as `:bump-major` but increments the minor version.
157
158#### `:bump-patch`
159
160Same as `:bump-major` but increments the patch version.
161
162#### `:lint`
163
164Check the Typescript files with [TSLint][github-tslint].
165See `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
175Name of the target. This is used as the prefix for each task.
176For example, `"name": "foo"` leads to `gulp foo:build`.
177
178#### `targetDir`
179
180- Type: `string`
181- Default: `target.name`
182
183Relative path from `project.buildDir` to the directory containing the output of this target.
184This is usually a subdirectory of `project.buildDir`.
185
186#### `scripts`
187
188- Type: `string[]`
189
190Relative patterns from `project.srcDir` to match the `*.ts` files to compile for this target.
191
192#### `typeRoots`
193
194- Type: `string[]`
195
196Relative paths from `project.srcDir` to the directories containing ths `*.d.ts` type definition files
197of third-party libraries.
198
199#### `typescript`
200
201- Type: `TypescriptOptions`
202- Optional
203
204Advanced Typescript options. See `src/lib/config/config.ts`.
205
206#### `copy`
207
208- Type: `CopyOptions[]`
209- Optional
210
211Copy some files during the build process.
212
213#### `pug`
214
215- Type: `PugOptions[]`
216- Optional
217
218Render some HTML files from Pug templates during the build process.
219
220#### `sass`
221
222- Type: `SassOptions[]`
223- Optional
224
225Render some CSS files from `*.scss` files during the build process.
226
227### `mainModule`
228
229- Type: `string`
230
231Relative module id (path without the extension) from `target.srcDir` of the main module.
232
233This 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
239Build the complete target and output its result to `target.targetDir`.
240
241#### `<targetName>:build:scripts`
242
243Compile the Typescript files.
244
245#### `<targetName>:build:copy`
246
247Perform simple copies.
248
249#### `<targetName>:build:pug`
250
251Compile Pug templates.
252
253#### `<targetName>:build:sass`
254
255Compile `*.scss` files.
256
257#### `<targetName>:clean`
258
259Delete the files of this target in `project.buildDir` and `project.distDir`.
260
261#### `<targetName>:dist`
262
263Clean the files, build the target and then copy it to `distDir` (ready for
264publication).
265
266#### `<targetName>:tsconfig.json`
267
268Generate as `tsconfig.json` file in the base directory for this target so
269you can compile it without `gulp` and just `tsc`:
270
271Example for the target `api-server` with the baseDirectory `server`:
272
273```
274gulp api-server:tsconfig.json
275cd src/server
276tsc
277# The target `api-server` is now built
278```
279
280#### `<targetName>:watch`
281
282Recompile when the files change.
283
284### Target `webpack`
285
286Options: see `src/lib/config/config.ts`
287
288**TODO**
289
290### Target `test`
291
292Options: see `src/lib/config/config.ts`
293
294**TODO**
295
296
297[github-tslint]: https://github.com/palantir/tslint