@chet.manley/create-node-project
v1.0.1
Published
Quickly generate new node projects from templates.
Downloads
23
Maintainers
Readme
@chet.manley/create-node-project
Quickly generate new node projects from templates.
Releases
- @chet.manley/create-node-project
Quick Start
Dependencies
:warning:
This package requires a properly configured Git installation in order to function properly. It has been tested with Git version 2.26, but lower versions are very likely to work as well.
Install
:information_source:
This package is meant to be used as an npm initializer -- no explicit installation is required.
Usage
npm init @chet.manley/node-project
# or
npx @chet.manley/create-node-project
:information_source:
Running with no arguments will enter interactive mode, rendering a menu that requests the minimum required options. The rest of the configuration will then be calculated from the information you provide.
Positional Arguments
<template name>
default: 'base'
type: positional #0
options: base, cjs, cli, es6, ts
Options listed are the templates provided by @chet.manley/node-project-templates. If using your own templates via the
--templates-dir
flag, you will be able to choose from those instead.npm init @chet.manley/node-project cjs
<project name>
default: $CWD basename
type: positional #1
options: @project-namespace/project-name, project-name
Sets the
name
field inpackage.json
, as well as the target directory (See the--target-dir
flag for more information). Names containing spaces will be transformed to use dashes (E.g.,"my new project" => "my-new-project"
). Names are also lowercased, per the npm documentation.npm init @chet.manley/node-project cjs my-new-project
Flags
User Config
flags: -c, --config
type: string
default: none
Provide a path to a configuration file that will override the defaults.
require
is used to load the file, so it must be a.json
, or a.js
that exports a configuration object. Config file can be any arbitrary name.npm init @chet.manley/node-project -c path/to/my-config.json
:information_source:
If a relative path is provided, file location will be resolved in the following order:
$CWD/
~/
~/.create-node-project/
~/.config/
~/.config/create-node-project/
Available Options
| key | type | default | description | | :--- | :---: | :--- | :--- | | checkoutBranch | string |
"integration"
| Branch to checkout after initial commit (Empty string ornull
to remain on master) | | commitMessage | string |"\"chore: initial commit :feelsgood:\""
| Initial commit message | | gitInit | boolean |true
|--git-init
flag | | npmInstall | boolean |true
|--npm-install
flag | | paths | array |["~/", "~/.create-node-project", "~/.config", "~/.config/create-node-project"]
| Default paths to search (Currently only used when loading user templates) | | projectName | string |$CWD basename
|<project name> positional
| | repository | string | - |--repository
flag | | targetDir | string |$CWD
|--target-dir
flag | | template | string | - |<template name>
positional | | templatesDir | string | - |--templates-dir
flag | | update | boolean |false
|--update
flag | | updateAll | boolean |false
|--update-all
flag | | yes | boolean |false
|--yes
flag |
Disable Git
flags: --no-git-init
type: boolean
default: false
Do not initialize a new git repository for this project.
npm init @chet.manley/node-project --no-git-init
Disable NPM Install
flags: --no-npm-install
type: boolean
default: false
Do not run
npm install
after installing template files.npm init @chet.manley/node-project --no-npm-install
Repository
flags: -r, --repository
type: string
default: none
URL pointing to empty remote repository of the same project name. This adds a Git remote origin, as well as filling the appropriate fields in
package.json
.npm init @chet.manley/node-project \ -r "https://gitlab.com/my-namespace/my-new-project.git"
Target Directory
flags: -t, --target-dir
type: string
default: $CWD | $CWD/<project name>
Where you want your new project to be installed. If a relative path is provided, the computed target will be relative to your current working directory.
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
).The default behavior will create a project-named subdirectory in your current working directory if your CWD differs from the project name.
npm init @chet.manley/node-project -t ~/projects/my-target
Templates Directory
flags: --templates-dir
type: string
default: none
Load user-defined templates from this directory. If a relative path is provided, the computed path will be relative to your current working directory. Browse the @chet.manley/node-project-templates project for details regarding implementing your own templates.
The default behavior loads the templates provided by this package.
npm init @chet.manley/node-project \ --templates-dir path/to/my-templates
:information_source:
If a relative path is provided, directory location will be resolved in the following order (this can be overriden using the--config flag
):
$CWD/
~/
~/.create-node-project/
~/.config/
~/.config/create-node-project/
Update Package
flags: -u, --update
type: boolean
default: false
Check the selected template's
package.json
for dependency updates and apply them before thenpm install
step.npm init @chet.manley/node-project -u
Update All Template Packages
flags: -U, --update-all
type: boolean
default: false
If you have installed this package globally, this will check the
package.json
of each template for dependency updates, apply available updates, then exit. Can also be combined with the--templates-dir
flag to update user-defined templates.create-node-project -U # or npm init @chet.manley/node-project -U \ [--templates-dir path/to/my-templates]
Verbose
flags: -V, --verbose
type: count
default: 0
Set the output verbosity of the program.
npm init @chet.manley/node-project -VVV
Accept Defaults
flags: -y, --yes
type: boolean
default: false
Explicitly enter non-interactive mode, accepting defaults with no prompts.
npm init @chet.manley/node-project -y
Examples
Interactive Mode
npm init @chet.manley/node-project
- Prompts for minimum required options.
Interactive Mode With Options
npm init @chet.manley/node-project cjs my-new-project
- Creates a new project named
my-new-project
usingcjs
template. - Prompts for any missing options.
Apply Defaults
npm init @chet.manley/node-project cjs my-new-project -y
- Creates a new project named
my-new-project
usingcjs
template. - Applies defaults for missing options.
Set Target Directory
npm init @chet.manley/node-project cjs my-new-project -y \
--target-dir projects
- Creates a new project named
my-new-project
usingcjs
template. - Applies defaults for missing options.
- Installs to
$CWD/projects/my-new-project
.
Install in Current Directory
mkdir ./my-new-project
cd ./my-new-project
npm init @chet.manley/node-project cjs my-new-project
- Creates a new project named
my-new-project
usingcjs
template. - Prompts for any missing options.
- Installs to
$CWD
.
Load User Config
~/projects/my-new-project.json
:{ "projectName": "my-new-project", "repository": "https://gitlab.com/name.space/my-new-project.git", "targetDir": "~/projects", "template": "mytmplname", "templatesDir": "~/projects/my-templates", "update": true }
cd ~/
npm init @chet.manley/node-project -c projects/my-new-project.json
- Loads user config from
/home/<username>/projects/my-new-project.json
. - Loads user templates from
/home/<username>/projects/my-templates/
. - Creates a new project named
my-new-project
usingmytmplname
template. - Installs to
/home/username/projects/my-new-project/
. - Updates package dependencies.
- Adds remote origin URL.
User Defined Templates
:information_source:
See the @chet.manley/node-project-templates repository for information regarding creating your own templates.
Quick Reference
Positional Arguments
| Name | Position | Default | Short Description |
| :------------ | :------: | :-------------: | :------------------------ |
| template name | 0 | 'base'
| Name of template to apply |
| project name | 1 | $CWD basename
| Name of project |
Options
| Flags | Type | Default | Short Description |
| :----------------- | :------ | :-----: | :--------------------------------------- |
| -c, --config
| string | - | path/to/user-config.js[on] |
| --no-git-init
| boolean | false
| Do not init Git repo |
| --no-npm-install
| boolean | false
| Do not run npm install
|
| -r, --repository
| string | - | Add Git remote repo URL |
| -t, --target-dir
| string | $CWD
| path/to/target/dir |
| --templates-dir
| string | - | path/to/user/templates |
| -u, --update
| boolean | false
| Update dependencies before npm install
|
| -U, --update-all
| boolean | false
| Update dependencies for all templates, then exit |
| -V, --verbose
| count | 0
| Set output verbosity |
| -y, --yes
| boolean | false
| Accept defaults |
Built with
Contributing
The community is welcome to participate in this open source project. Aspiring contributors should review the contributing guide for details on how to get started. First-time contributors are encouraged to search for issues with the ~"good first issue" label.
License
Copyright © 2020 Chet Manley.