UNPKG

15.7 kBMarkdownView Raw
1# roboter
2
3roboter streamlines software development by automating tasks and enforcing conventions.
4
5![roboter](https://github.com/thenativeweb/roboter/raw/master/images/logo.jpg "roboter")
6
7## Status
8
9| Category | Status |
10|-|-|
11| Version | [![npm](https://img.shields.io/npm/v/roboter)](https://www.npmjs.com/package/roboter) |
12| Dependencies | ![David](https://img.shields.io/david/thenativeweb/roboter) |
13| Dev dependencies | ![David](https://img.shields.io/david/dev/thenativeweb/roboter) |
14| Build | [![CircleCI](https://img.shields.io/circleci/build/github/thenativeweb/roboter)](https://circleci.com/gh/thenativeweb/roboter/tree/master) |
15| License | ![GitHub](https://img.shields.io/github/license/thenativeweb/roboter) |
16
17## Upgrading
18
19### From 6.x to 7.x
20
21roboter 7.x introduced support for TypeScript, but at the same time dropped support for Babel. However, TypeScript support is completely optional. If you want to use TypeScript, simply put a `tsconfig.json` file into the root of your package, and that's it (especially, you do not have to install TypeScript, since roboter includes TypeScript out of the box). The tests' pre and post tasks are now expected to be standalone executables instead of modules exporting `async` functions.
22
23### From 5.x to 6.x
24
25roboter 6.x received a major update with respect to the ESLint rules being used. That means that when you update you should be prepared to adjust some code analysis issues in your code. Additionally, you need to change the name of the ESLint configuration module in your `.eslintrc.json` file: The new base name is now `es/node` (was `es/2015/server`), if you are working on a client project it's `es/browser` (was `es/2015/client`).
26
27### From 4.x to 5.x
28
29roboter 5.x names the directory for unit tests `unit`, not `units`, to streamline things with `integration` and `performance`. This means that you need to rename the `units` directory to `unit` in your projects.
30
31### From 3.x to 4.x
32
33roboter 4.x slightly modifies the way it generates Table of Contents inside your `README.md` during the `publish` task. It is no longer necessary to add a `<!-- toc -->` tag your `README.md`. Instead add a heading called `Table of Contents` and roboter will insert a TOC below this headline. For more details refer to the section [Generating the TOC](#generating-the-toc)
34
35### From 2.x to 3.x
36
37roboter 3.x makes the `license` task fail if incompatible licenses were found. This means that you may need to adjust your build scripts, if you use the `license` task directly (you may have to ignore the exit code).
38
39### From 1.x to 2.x
40
41roboter 2.x introduces `babel` 7. If you have been using the precompilation feature of the `release` task, you might need to take action. If you've been using a local `.babelrc` make sure to upgrade it to the scoped package names of `babel` 7. If you have been using [`babel-runtime`](https://www.npmjs.com/package/babel-runtime) as a dependency in your module, also make sure to switch to the new scoped [`@babel/runtime`](https://www.npmjs.com/package/@babel/runtime) module.
42
43Please refer to the [babel upgrading guide](https://babeljs.io/docs/en/next/v7-migration) and the new [`precompile`](#the-precompile-task) task that has been introduced to verify the precompilation result before a release.
44
45## Installation
46
47```shell
48$ npm install roboter --save-dev
49```
50
51*Please note: Never install roboter globally, but always into the local context of your module or application.*
52
53## Quick start
54
55To run roboter, execute the following command:
56
57```shell
58$ npx roboter
59```
60
61Since you will run this command quite often, you may want to setup a shorter alias. To do so, add the following line to your profile file, such as `.profile` (or the respective file of your platform):
62
63```shell
64alias bot='npx roboter'
65```
66
67Then you can simply run `bot` instead of `npx roboter`. In the following we will assume that you have *not* setup an alias like this.
68
69## Quick start
70
71roboter provides a variety of tasks. To run them, run roboter and provide the task's name as parameter:
72
73| Name | Description |
74|-|-|
75| [`analyse`](#the-analyse-task) | Runs code analysis. |
76| [`deps`](#the-deps-task) | Checks for missing, outdated, and unused dependencies. |
77| `help` | Shows the help. |
78| [`license`](#the-license-task) | Checks dependencies for incompatible licenses. |
79| [`precompile`](#the-precompile-task) | Precompiles source files using TypeScript. |
80| [`qa`](#the-qa-task) | Runs code analysis, tests and checks dependencies. |
81| [`release`](#the-release-task) | Releases a new version. |
82| [`test`](#the-test-task) | Runs tests. |
83
84If you don't specify a task, the `qa` task is run as default task.
85
86To get help, run `npx roboter --help`. To get help for a specific command, run `npx roboter <command> --help`.
87
88If you need more detailed output, provide the `--verbose` flag for any command.
89
90### Running npm scripts
91
92If your `package.json` file contains custom scripts, you can run them using roboter to have a streamlined user experience. Supposed, your `package.json` looks like this:
93
94```json
95{
96 "scripts": {
97 "analyse-css": "..."
98 }
99}
100```
101
102Then you can run the following command. If you specify any options, they will be handed over to the script:
103
104```shell
105$ npx roboter analyse-css
106```
107
108### Setting environment variables
109
110Environment variables you specify when running roboter are also available to the tasks. E.g., if you want to run tests with disabled TLS verification, run roboter as follows:
111
112```shell
113$ NODE_TLS_REJECT_UNAUTHORIZED=0 npx roboter test
114```
115
116## The `analyse` task
117
118This task runs code analysis on your code using [ESLint](http://eslint.org/). By default it uses the rules defined in the [eslint-config-es](https://www.npmjs.com/package/eslint-config-es) module.
119
120### Flags
121
122| Flag | Alias | Description |
123|-|-|-|
124| --watch | -w | Re-runs code analysis when files have been changed. |
125
126### Exit codes
127
128| Exit code | Description |
129|-|-|
130| 0 | Success |
131| 1 | Code analysis failed |
132
133### Details
134
135Code analysis affects all `.js`, `.jsx`, `.ts` and `.tsx` files, but skips the following directories:
136
137- `node_modules` (nested)
138- `build` (only top-level)
139- `coverage` (only top-level)
140- `dist` (only top-level)
141
142To exclude other files or directories, add an [`.eslintignore`](https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories) file to the root directory of your module or application.
143
144To adjust the ESLint rules to be used, add an [`.eslintrc.json`](https://eslint.org/docs/user-guide/configuring) file to the root directory of your module or application. You may [extend](http://eslint.org/docs/user-guide/configuring.html#extending-configuration-files) the built-in `es/node` configuration if you only need to change a few rules:
145
146```json
147{
148 "extends": "es/node",
149 "rules": {
150 "eqeqeq": 0
151 }
152};
153```
154
155## The `deps` task
156
157This task checks for missing, outdated, and unused dependencies.
158
159### Flags
160
161None
162
163### Exit codes
164
165| Exit code | Description |
166|-|-|
167| 0 | Success |
168
169*Please note that missing, outdated, or unused dependencies do not lead to an erroneous exit code. This is by design, since these situations are typically not critical, and you may want to ignore them intentionally.*
170
171### Details
172
173Under some circumstances, dependencies are reported as unused, although they are actually being used. This can be caused by dynamic requires, or similar things.
174
175If you experience such a situation, feel free to ignore the warnings.
176
177## The `license` task
178
179This task checks your dependencies for incompatible licenses.
180
181### Flags
182
183None
184
185### Exit codes
186
187| Exit code | Description |
188|-|-|
189| 0 | Success |
190| 1 | Incompatible licenses found |
191
192### Details
193
194roboter tries to get your dependencies' licenses from their respective `package.json` files and, if necessary, from a variety of [other places](https://github.com/thenativeweb/roboter/blob/master/lib/automation/pkg/getLicense.js), and tries to check the license compatibility based on a compatibility chart and a license list.
195
196If you encounter a license incompatibility, and think that it should be fixed, please submit a pull request for either the [compatibility chart](https://github.com/thenativeweb/roboter/edit/master/configuration/licenseCompatibility.js) or the [license list](https://github.com/thenativeweb/roboter/edit/master/configuration/packageLicenses.js).
197
198*Please note: Consider the license compatibility check of roboter only to be a suggestion, not as legal advice you can rely on. If you want to be on the safe side, consult a lawyer. the native web does not provide any warranty of any kind.*
199
200To disable the license check, omit the `license` field in your `package.json` file, or set it to the value `UNKNOWN`.
201
202## The `precompile` task
203
204If you want to use TypeScript, add the required `tsconfig.json` file to the root of your package to enable precompilation.
205
206*Please note that you do not need to install TypeScript itself, as this is provided by roboter out of the box.*
207
208Any precompilation options are configured using the aforementioned `tsconfig.json` file.
209
210### Flags
211
212None
213
214### Exit codes
215
216| Exit code | Description |
217|-|-|
218| 0 | Success |
219| 1 | Precompilation failed |
220
221*Please note that missing, outdated, or unused dependencies do not lead to an erroneous exit code. This is by design, since these situations are typically not critical, and you may want to ignore them intentionally.*
222
223### Details
224
225None
226
227## The `qa` task
228
229This task runs the tasks [analyse](#the-analyse-task), [test](#the-test-task), and [deps](#the-deps-task) sequentially.
230
231### Flags
232
233None
234
235### Exit codes
236
237| Exit code | Description |
238|-|-|
239| 0 | Success |
240| 1 | Code analysis or tests failed |
241
242*Please note that missing, outdated, or unused dependencies do not lead to an erroneous exit code. This is by design, since these situations are typically not critical, and you may want to ignore them intentionally.*
243
244### Details
245
246None
247
248## The `release` task
249
250This task releases a new version.
251
252It first runs the tasks [analyse](#the-analyse-task), [test](#the-test-task), and [deps](#the-deps-task) sequentially.
253
254Afterwards, it runs the following tasks:
255
256- Check if you're currently in the `master` branch
257- Check if there are any pending, i.e. not yet committed, changes
258- Check if your local `master` branch is up-to-date with the remote one
259- Optional: [Generate the TOC](#generating-the-toc) in the `README.md` file
260- Optional: [Precompile code](#precompiling-the-code-before-releasing) using TypeScript
261- Increase version number
262- Commit all changes
263- Create a tag for the new version
264- Push all changes and the tag
265
266*Please note: This task does not publish your module or application to the npm registry. Instead, you need to do this manually by running `npm publish`.*
267
268### Flags
269
270| Flag | Alias | Description |
271|-|-|-|
272| --force | -f | Releases without running tests, code analysis etc. |
273| --type | -t | Specifies the type of the release, either `patch`, `minor`, or `major`. |
274
275### Exit codes
276
277| Exit code | Description |
278|-|-|
279| 0 | Success |
280| 1 | Code analysis or tests failed |
281
282### Details
283
284For generating version numbers roboter uses [SemVer](https://semver.org/). It omits the leading `v`.
285
286#### Generating the TOC
287
288To automatically generate a TOC for your `README.md` file add the following line to your `README.md`.
289
290```markdown
291## Table of Contents
292```
293
294*Please note: roboter looks for the first heading containing 'Table of Contents', 'toc', or 'table-of-contents'. It removes all following contents until an equal or higher heading is found and inserts a table of contents.*
295
296#### Precompiling the code before releasing
297
298You can use roboter to automatically precompile your code before publishing. roboter will run the [`precompile`](#the-precompile-task) task automatically for you. For details on how to enable and to configure this precompilation step, see the [`precompile`](#the-precompile-task) task.
299
300## The `test` task
301
302This task runs unit, integration, and other tests using [Mocha](https://mochajs.org/).
303
304### Flags
305
306| Flag | Alias | Description |
307|-|-|-|
308| --type | -t | The test type, such as `units`, `integration`, … |
309| --watch | -w | Re-runs tests when files have been changed. |
310
311### Exit codes
312
313| Exit code | Description |
314|-|-|
315| 0 | Success |
316| 1 | Tests failed |
317
318### Details
319
320roboter will look for test types in the `test` directory of your module or application. You can add a type by simply creating a directory with the desired name, e.g. `unit`, `integration`, `performance`, …
321
322If you are running the tests in watch mode, tests are triggered by any change on `.js`, `.jsx`, `.ts` and `.tsx` files, without taking the following directories into account:
323
324- `node_modules` (nested)
325- `build` (only top-level)
326- `coverage` (only top-level)
327- `dist` (only top-level)
328
329#### Creating tests
330
331To create tests, add files with the naming schema `*Tests.js` (or `*Tests.ts`, if you use TypeScript) to your test type directories. Use Mocha's [`tdd` interface](https://mochajs.org/#tdd) when writing tests. Please also note that all your tests must be asynchronous, i.e. they must either use the `done` callback or use the `async` keyword:
332
333```javascript
334// test/integration/databaseTests.js
335
336suite('connect', () => {
337 test('connects to the database.', async () => {
338 // ...
339 });
340});
341```
342
343The test types are run in a specific order. If present, roboter will first run `unit`, `integration`, `e2e`, and `performance`. After those test types, all remaining ones will be run in alphabetical order.
344
345#### Using shared test helpers
346
347If you want to use functions shared across multiple tests or test types, create a directory `test/shared` and put your code into it. This directory is handled as a special case and will not be picked up as a test type.
348
349#### Setting up and tearing down test types
350
351If you need to register any additional pre or post actions (such as starting or stopping Docker containers, …) that shall be run before or after all tests of a given type, add a `pre.js` respectively a `post.js` file (or `pre.ts` and `post.ts`, if you use TypeScript), that act as standalone modules. If you want to use `async` and `await`, you have to wrap the file's content in an asynchronous IIFE:
352
353```javascript
354'use strict';
355
356(async () => {
357 // ...
358})();
359```
360
361*Please note: The `post.js` respectively `post.ts` file will be run no matter whether the tests themselves were run successfully or not.*
362
363#### Setting environment variables
364
365To set environment variables that are available in the tests, you can create a `.env` file per test type:
366
367```shell
368SOME_ENV=foo
369```
370
371#### Configuring test execution
372
373To adjust test execution, you can provide a [`mocha.opts`](https://mochajs.org/#mochaopts) file per test type. However, the following options can not be overwritten, and are always set:
374
375- `--async-only`
376- `--bail`
377- `--colors`
378- `--exit`
379- `--ui tdd`
380
381## Running the tests
382
383To run the tests run the following command:
384
385```shell
386$ npm run test
387```
388
389You can run all integration tests for one task by specifying the task name as an additional argument:
390
391```shell
392$ npm run test release
393```
394
395You can run a single integration test case by specifying the individual test as an additional argument:
396
397```shell
398$ npm run test release/bumps-minor-version
399```
400
401## Running the build
402
403Unfortunately, this module can not be used to build itself. Hence you have to use `npm` for that.
404
405To analyse the source code run the following command:
406
407```shell
408$ npm run analyse
409```
410
411To release a new version run the following command:
412
413```shell
414$ npm run release-patch
415```
416
417Alternatively you may also use `release-minor` and `release-major`, depending on the changes you have made.