UNPKG

16.4 kBMarkdownView Raw
1# @chet.manley/create-node-project
2
3> **Quickly generate new node projects from templates.**
4
5[![project vulnerabilities][vulnerabilities-badge]][vulnerabilities-url]
6[![project dependencies][dependencies-badge]][dependencies-url]
7[![code style standardjs][standardjs-badge]][standardjs-url]
8[![versioning strategy][semver-badge]][semver-url]
9[![required Node version][node-version-badge]][node-version-url]
10
11[![CI pipeline status][ci-badge]][ci-url]
12[![code coverage][coverage-badge]][coverage-url]
13
14<!-- badge images and URLs -->
15[ci-badge]: https://gitlab.com/chet.manley/create-node-project/badges/master/pipeline.svg
16[ci-url]: https://gitlab.com/chet.manley/create-node-project
17[coverage-badge]: https://gitlab.com/chet.manley/create-node-project/badges/master/coverage.svg?job=Code%20Coverage
18[coverage-url]: https://chet.manley.gitlab.io/create-node-project/master/coverage
19[dependencies-badge]: https://img.shields.io/librariesio/release/npm/@chet.manley/create-node-project?logo=&style=for-the-badge
20[dependencies-url]: https://www.npmjs.com/package/@chet.manley/create-node-project?activeTab=dependencies
21[node-version-badge]: https://img.shields.io/node/v/@chet.manley/create-node-project?logo=&style=for-the-badge
22[node-version-url]: https://nodejs.org/en/about/releases/
23[semver-badge]: https://img.shields.io/static/v1?label=semver&message=standard-version&color=brightgreen&logo=&style=for-the-badge
24[semver-url]: https://github.com/conventional-changelog/standard-version
25[standardjs-badge]: https://img.shields.io/static/v1?label=style&message=standardJS&color=brightgreen&logo=&style=for-the-badge
26[standardjs-url]: https://standardjs.com/
27[vulnerabilities-badge]: https://img.shields.io/snyk/vulnerabilities/npm/@chet.manley/create-node-project?logo=&style=for-the-badge
28[vulnerabilities-url]: https://snyk.io/vuln/search?q=%40chet.manley%2Fcreate-node-project&type=npm
29
30## Releases
31
32[![latest release version][stable-release-badge]][npm-url]
33[![next release version][next-release-badge]][npm-url]
34[![package install size][install-size-badge]][install-size-url]
35
36<!-- badge images and URLs -->
37[install-size-badge]: https://flat.badgen.net/packagephobia/publish/@chet.manley/create-node-project
38[install-size-url]: https://packagephobia.now.sh/result?p=@chet.manley/create-node-project
39[next-release-badge]: https://img.shields.io/npm/v/@chet.manley/create-node-project/next?label=@next&logo=npm&style=flat-square
40[npm-url]: https://npmjs.org/package/@chet.manley/create-node-project
41[stable-release-badge]: https://img.shields.io/npm/v/@chet.manley/create-node-project/latest?label=%40latest&logo=npm&style=flat-square
42
43---
44
45<!-- [[_TOC_]] -->
46- [@chet.manley/create-node-project](#chetmanleycreate-node-project)
47 - [Releases](#releases)
48 - [Quick Start](#quick-start)
49 - [Dependencies](#dependencies)
50 - [Install](#install)
51 - [Usage](#usage)
52 - [Positional Arguments](#positional-arguments)
53 - [`<template name>`](#template-name)
54 - [`<project name>`](#project-name)
55 - [Flags](#flags)
56 - [User Config](#user-config)
57 - [Disable Git](#disable-git)
58 - [Disable NPM Install](#disable-npm-install)
59 - [Repository](#repository)
60 - [Target Directory](#target-directory)
61 - [Templates Directory](#templates-directory)
62 - [Update Package](#update-package)
63 - [Update All Template Packages](#update-all-template-packages)
64 - [Verbose](#verbose)
65 - [Accept Defaults](#accept-defaults)
66 - [Examples](#examples)
67 - [Interactive Mode](#interactive-mode)
68 - [Interactive Mode With Options](#interactive-mode-with-options)
69 - [Apply Defaults](#apply-defaults)
70 - [Set Target Directory](#set-target-directory)
71 - [Install in Current Directory](#install-in-current-directory)
72 - [Load User Config](#load-user-config)
73 - [User Defined Templates](#user-defined-templates)
74 - [Quick Reference](#quick-reference)
75 - [Positional Arguments](#positional-arguments-1)
76 - [Options](#options)
77 - [Built with](#built-with)
78 - [Contributing](#contributing)
79 - [License](#license)
80
81## Quick Start
82
83### Dependencies
84
85> :warning:\
86> **This package requires a properly configured Git installation in order to function properly.
87> It has been tested with Git version 2.26, but lower versions are very likely to work as well.**
88
89### Install
90
91> :information_source:\
92> **_This package is meant to be used as an npm initializer -- no explicit installation is required._**
93
94### Usage
95
96```shell
97npm init @chet.manley/node-project
98# or
99npx @chet.manley/create-node-project
100```
101
102> :information_source:\
103> **Running with no arguments will enter interactive mode, rendering a menu that requests the minimum required options.
104> The rest of the configuration will then be calculated from the information you provide.**
105
106### Positional Arguments
107
108#### `<template name>`
109
110> `default: 'base'`\
111> `type: positional #0`\
112> `options: base, cjs, cli, es6, ts`
113>
114> Options listed are the templates provided by
115> [@chet.manley/node-project-templates](https://gitlab.com/chet.manley/node-project-templates).
116> If using your own templates via the [`--templates-dir` flag](#templates-directory), you will be able to choose from those instead.
117>
118> ```shell
119> npm init @chet.manley/node-project cjs
120> ```
121
122#### `<project name>`
123
124> `default: $CWD basename`\
125> `type: positional #1`\
126> `options: @project-namespace/project-name, project-name`
127>
128> Sets the `name` field in `package.json`, as well as the target directory
129> (See the [`--target-dir` flag](#target-directory) for more information).
130> Names containing spaces will be transformed to use dashes
131> (E.g., `"my new project" => "my-new-project"`).
132> Names are also lowercased, per the
133> [npm documentation](https://docs.npmjs.com/cli/v6/configuring-npm/package-json#name).
134>
135> ```shell
136> npm init @chet.manley/node-project cjs my-new-project
137> ```
138
139### Flags
140
141#### User Config
142
143> `flags: -c, --config`\
144> `type: string`\
145> `default: none`
146>
147> Provide a path to a configuration file that will override the defaults.
148> `require` is used to load the file, so it must be a `.json`,
149> or a `.js` that exports a configuration object.
150> Config file can be any arbitrary name.
151>
152> ```shell
153> npm init @chet.manley/node-project -c path/to/my-config.json
154> ```
155>
156> > :information_source:\
157> > If a relative path is provided, file location will be resolved in the following order:
158> >
159> > - `$CWD/`
160> > - `~/`
161> > - `~/.create-node-project/`
162> > - `~/.config/`
163> > - `~/.config/create-node-project/`
164>
165> ##### Available Options
166>
167> | key | type | default | description |
168> | :--- | :---: | :--- | :--- |
169> | checkoutBranch | string | `"integration"` | Branch to checkout after initial commit (Empty string or `null` to remain on master) |
170> | commitMessage | string | `"\"chore: initial commit :feelsgood:\""` | Initial commit message |
171> | gitInit | boolean | `true` | [`--git-init` flag](#disable-git) |
172> | npmInstall | boolean | `true` | [`--npm-install` flag](#disable-npm-install) |
173> | paths | array | `["~/", "~/.create-node-project", "~/.config", "~/.config/create-node-project"]` | Default paths to search (Currently only used when loading user templates) |
174> | projectName | string | `$CWD basename` | [`<project name> positional`](#project-name) |
175> | repository | string | - | [`--repository` flag](#repository) |
176> | targetDir | string | `$CWD` | [`--target-dir` flag](#target-directory) |
177> | template | string | - | [`<template name>` positional](#template-name) |
178> | templatesDir | string | - | [`--templates-dir` flag](#templates-directory) |
179> | update | boolean | `false` | [`--update` flag](#update-package) |
180> | updateAll | boolean | `false` | [`--update-all` flag](#update-all-template-packages) |
181> | yes | boolean | `false` | [`--yes` flag](#accept-defaults) |
182
183#### Disable Git
184
185> `flags: --no-git-init`\
186> `type: boolean`\
187> `default: false`
188>
189> Do not initialize a new git repository for this project.
190>
191> ```shell
192> npm init @chet.manley/node-project --no-git-init
193> ```
194
195#### Disable NPM Install
196
197> `flags: --no-npm-install`\
198> `type: boolean`\
199> `default: false`
200>
201> Do not run `npm install` after installing template files.
202>
203> ```shell
204> npm init @chet.manley/node-project --no-npm-install
205> ```
206
207#### Repository
208
209> `flags: -r, --repository`\
210> `type: string`\
211> `default: none`
212>
213> URL pointing to empty remote repository of the same project name.
214> This adds a Git remote origin, as well as filling the appropriate fields in `package.json`.
215>
216> ```shell
217> npm init @chet.manley/node-project \
218> -r "https://gitlab.com/my-namespace/my-new-project.git"
219> ```
220
221#### Target Directory
222
223> `flags: -t, --target-dir`\
224> `type: string`\
225> `default: $CWD | $CWD/<project name>`
226>
227> Where you want your new project to be installed.
228> If a relative path is provided, the computed target will be relative to your current working directory.
229>
230> If the basename (E.g., `my-target` of `/home/username/projects/my-target`) of the computed target path differs from the project name, the project will be created in a project-named subdirectory of the target (E.g., `/home/username/projects/my-target/my-new-project`).
231>
232> The default behavior will create a project-named subdirectory in your current working directory if your CWD differs from the project name.
233>
234> ```shell
235> npm init @chet.manley/node-project -t ~/projects/my-target
236> ```
237
238#### Templates Directory
239
240> `flags: --templates-dir`\
241> `type: string`\
242> `default: none`
243>
244> Load user-defined templates from this directory.
245> If a relative path is provided, the computed path will be relative to your current working directory.
246> Browse the [@chet.manley/node-project-templates][node-project-templates] project for details regarding implementing your own templates.
247>
248> The default behavior loads the templates provided by this package.
249>
250> ```shell
251> npm init @chet.manley/node-project \
252> --templates-dir path/to/my-templates
253> ```
254>
255> > :information_source:\
256> > If a relative path is provided, directory location will be resolved in the following order (this can be overriden using the [`--config flag`](#user-config)):
257> >
258> > - `$CWD/`
259> > - `~/`
260> > - `~/.create-node-project/`
261> > - `~/.config/`
262> > - `~/.config/create-node-project/`
263
264#### Update Package
265
266> `flags: -u, --update`\
267> `type: boolean`\
268> `default: false`
269>
270> Check the selected template's `package.json` for dependency updates and apply them before the `npm install` step.
271>
272> ```shell
273> npm init @chet.manley/node-project -u
274> ```
275
276#### Update All Template Packages
277
278> `flags: -U, --update-all`\
279> `type: boolean`\
280> `default: false`
281>
282> If you have installed this package globally, this will check the `package.json` of each template for dependency updates, apply available updates, then exit.
283> Can also be combined with the [`--templates-dir` flag](#templates-directory) to update user-defined templates.
284>
285> ```shell
286> create-node-project -U
287> # or
288> npm init @chet.manley/node-project -U \
289> [--templates-dir path/to/my-templates]
290> ```
291
292#### Verbose
293
294> `flags: -V, --verbose`\
295> `type: count`\
296> `default: 0`
297>
298> Set the output verbosity of the program.
299>
300> ```shell
301> npm init @chet.manley/node-project -VVV
302> ```
303
304#### Accept Defaults
305
306> `flags: -y, --yes`\
307> `type: boolean`\
308> `default: false`
309>
310> Explicitly enter non-interactive mode, accepting defaults with no prompts.
311>
312> ```shell
313> npm init @chet.manley/node-project -y
314> ```
315
316## Examples
317
318### Interactive Mode
319
320```shell
321npm init @chet.manley/node-project
322```
323
324- Prompts for minimum required options.
325
326### Interactive Mode With Options
327
328```shell
329npm init @chet.manley/node-project cjs my-new-project
330```
331
332- Creates a new project named `my-new-project` using `cjs` template.
333- Prompts for any missing options.
334
335### Apply Defaults
336
337```shell
338npm init @chet.manley/node-project cjs my-new-project -y
339```
340
341- Creates a new project named `my-new-project` using `cjs` template.
342- Applies defaults for missing options.
343
344### Set Target Directory
345
346```shell
347npm init @chet.manley/node-project cjs my-new-project -y \
348--target-dir projects
349```
350
351- Creates a new project named `my-new-project` using `cjs` template.
352- Applies defaults for missing options.
353- Installs to `$CWD/projects/my-new-project`.
354
355### Install in Current Directory
356
357```shell
358mkdir ./my-new-project
359cd ./my-new-project
360npm init @chet.manley/node-project cjs my-new-project
361```
362
363- Creates a new project named `my-new-project` using `cjs` template.
364- Prompts for any missing options.
365- Installs to `$CWD`.
366
367### Load User Config
368
369> `~/projects/my-new-project.json`:
370>
371> ```json
372> {
373> "projectName": "my-new-project",
374> "repository": "https://gitlab.com/name.space/my-new-project.git",
375> "targetDir": "~/projects",
376> "template": "mytmplname",
377> "templatesDir": "~/projects/my-templates",
378> "update": true
379> }
380> ```
381
382```shell
383cd ~/
384npm init @chet.manley/node-project -c projects/my-new-project.json
385```
386
387- Loads user config from `/home/<username>/projects/my-new-project.json`.
388- Loads user templates from `/home/<username>/projects/my-templates/`.
389- Creates a new project named `my-new-project` using `mytmplname` template.
390- Installs to `/home/username/projects/my-new-project/`.
391- Updates package dependencies.
392- Adds remote origin URL.
393
394## User Defined Templates
395
396> :information_source:\
397> See the [@chet.manley/node-project-templates][node-project-templates] repository for information regarding creating your own templates.
398
399## Quick Reference
400
401### Positional Arguments
402
403| Name | Position | Default | Short Description |
404| :------------ | :------: | :-------------: | :------------------------ |
405| template name | 0 | `'base'` | Name of template to apply |
406| project name | 1 | `$CWD basename` | Name of project |
407
408### Options
409
410| Flags | Type | Default | Short Description |
411| :----------------- | :------ | :-----: | :--------------------------------------- |
412| `-c, --config` | string | - | path/to/user-config.js[on] |
413| `--no-git-init` | boolean | `false` | Do not init Git repo |
414| `--no-npm-install` | boolean | `false` | Do not run `npm install` |
415| `-r, --repository` | string | - | Add Git remote repo URL |
416| `-t, --target-dir` | string | `$CWD` | path/to/target/dir |
417| `--templates-dir` | string | - | path/to/user/templates |
418| `-u, --update` | boolean | `false` | Update dependencies before `npm install` |
419| `-U, --update-all` | boolean | `false` | Update dependencies for all templates, then exit |
420| `-V, --verbose` | count | `0` | Set output verbosity |
421| `-y, --yes` | boolean | `false` | Accept defaults |
422
423## Built with
424
425[![Fedora Linux](https://img.shields.io/static/v1?logo=fedora&label=Fedora&message=workstation&color=294172&style=flat)](https://getfedora.org/)
426[![VSCode](https://img.shields.io/static/v1?logo=visual-studio-code&label=VSCode&message=insiders&color=2A917D&style=flat)](https://code.visualstudio.com/)
427[![GitLab](https://img.shields.io/static/v1?logo=gitlab&label=GitLab&message=FOSS&color=DE4020&style=flat)](https://gitlab.com/gitlab-org/gitlab)
428[![Caffeine](https://img.shields.io/static/v1?logo=buy-me-a-coffee&label=Caffeine&message=☕&color=603015&style=flat)](https://en.wikipedia.org/wiki/Caffeine)
429
430## Contributing
431
432The community is welcome to participate in this open source project.
433Aspiring contributors should review the [contributing guide](https://gitlab.com/chet.manley/create-node-project/-/blob/master/CONTRIBUTING.md) for details on how to get started.
434First-time contributors are encouraged to search for issues with the ~"good first issue" label.
435
436## License
437
438[![NPM][license-badge]][license-url]
439
440Copyright © 2020 [Chet Manley](https://gitlab.com/chet.manley).
441
442<!-- badge images and URLs -->
443[license-badge]: https://img.shields.io/npm/l/@chet.manley/create-node-project
444[license-url]: https://gitlab.com/chet.manley/create-node-project/-/blob/master/LICENSE
445
446<!-- ## Acknowledgements -->
447
448<!-- other URLs -->
449[node-project-templates]: https://gitlab.com/chet.manley/node-project-templates/