|
| 1 | +--- |
| 2 | +lang: en |
| 3 | +title: 'Generate copyright/license header for JavaScript/TypeScript files' |
| 4 | +keywords: LoopBack 4.0, LoopBack 4 |
| 5 | +sidebar: lb4_sidebar |
| 6 | +permalink: /doc/en/lb4/Copyright-generator.html |
| 7 | +--- |
| 8 | + |
| 9 | +### Synopsis |
| 10 | + |
| 11 | +The `lb4 copyright` command runs inside a Node.js project with `package.json` to |
| 12 | +add or update copyright/license header for JavaScript and TypeScript files based |
| 13 | +on `package.json` and git history. |
| 14 | + |
| 15 | +The command also supports [lerna](https://github.com/lerna/lerna) monorepos. It |
| 16 | +traverses all packages within the monorepo and apply copyright/license headers. |
| 17 | + |
| 18 | +```sh |
| 19 | +lb4 copyright [options] |
| 20 | +``` |
| 21 | + |
| 22 | +The following is an example of such headers. |
| 23 | + |
| 24 | +```js |
| 25 | +// Copyright IBM Corp. 2020. All Rights Reserved. |
| 26 | +// Node module: @loopback/cli |
| 27 | +// This file is licensed under the MIT License. |
| 28 | +// License text available at https://opensource.org/licenses/MIT |
| 29 | +``` |
| 30 | + |
| 31 | +The year(s) is built from the git history of the file and `Node module` is read |
| 32 | +from the `name` property in `package.json`. |
| 33 | + |
| 34 | +Please note the command expects `git` is installed. |
| 35 | + |
| 36 | +### Options |
| 37 | + |
| 38 | +`--owner` : _(Optional)_ The owner of the copyright, such as `IBM Corp.`. |
| 39 | + |
| 40 | +`--license` : _(Optional)_ The name of the license, such as `MIT`. |
| 41 | + |
| 42 | +`--gitOnly` : _(Optional)_ A flag to control if only git tracked files are |
| 43 | +updated. Default to `true`. |
| 44 | + |
| 45 | +### Interactive Prompts |
| 46 | + |
| 47 | +The command prompts you for: |
| 48 | + |
| 49 | +1. The copyright owner. The default value is read from `copyright.owner` or |
| 50 | + `author` in the `package.json`. |
| 51 | + |
| 52 | +2. The license name. The default value is read from `license` in the |
| 53 | + `package.json`. |
| 54 | + |
| 55 | +The default owner is `IBM Corp.` and license is `MIT` with the following |
| 56 | +`package.json`. |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "name": "@loopback/boot", |
| 61 | + "version": "2.0.2", |
| 62 | + "author": "IBM Corp.", |
| 63 | + "copyright.owner": "IBM Corp.", |
| 64 | + "license": "MIT" |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### Output |
| 69 | + |
| 70 | +The following output is captured when `lb4 copyright` is run against |
| 71 | +[`loopback4-example-shopping`](https://github.com/strongloop/loopback4-example-shopping). |
| 72 | + |
| 73 | +``` |
| 74 | +? Copyright owner: IBM Corp. |
| 75 | +? License name: (Use arrow keys or type to search) |
| 76 | +❯ MIT (MIT License) |
| 77 | + ISC (ISC License) |
| 78 | + Artistic-2.0 (Artistic License 2.0) |
| 79 | + Apache-2.0 (Apache License 2.0) |
| 80 | + ... |
| 81 | +Updating project loopback4-example-recommender (packages/recommender) |
| 82 | +Updating project loopback4-example-shopping (packages/shopping) |
| 83 | +Updating project loopback4-example-shopping-monorepo (.) |
| 84 | +``` |
0 commit comments