1.0.1 • Published 5 years ago

@chet.manley/create-node-project v1.0.1

Weekly downloads
4
License
MIT
Repository
gitlab
Last release
5 years ago

@chet.manley/create-node-project

Quickly generate new node projects from templates.

project vulnerabilities project dependencies code style standardjs versioning strategy required Node version

CI pipeline status code coverage

Releases

latest release version next release version package install size


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

:informationsource:\ **_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 in package.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
keytypedefaultdescription
checkoutBranchstring"integration"Branch to checkout after initial commit (Empty string or null to remain on master)
commitMessagestring"\"chore: initial commit :feelsgood:\""Initial commit message
gitInitbooleantrue--git-init flag
npmInstallbooleantrue--npm-install flag
pathsarray["~/", "~/.create-node-project", "~/.config", "~/.config/create-node-project"]Default paths to search (Currently only used when loading user templates)
projectNamestring$CWD basename<project name> positional
repositorystring---repository flag
targetDirstring$CWD--target-dir flag
templatestring-<template name> positional
templatesDirstring---templates-dir flag
updatebooleanfalse--update flag
updateAllbooleanfalse--update-all flag
yesbooleanfalse--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 the npm 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 using cjs 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 using cjs 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 using cjs 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 using cjs 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 using mytmplname 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

NamePositionDefaultShort Description
template name0'base'Name of template to apply
project name1$CWD basenameName of project

Options

FlagsTypeDefaultShort Description
-c, --configstring-path/to/user-config.json
--no-git-initbooleanfalseDo not init Git repo
--no-npm-installbooleanfalseDo not run npm install
-r, --repositorystring-Add Git remote repo URL
-t, --target-dirstring$CWDpath/to/target/dir
--templates-dirstring-path/to/user/templates
-u, --updatebooleanfalseUpdate dependencies before npm install
-U, --update-allbooleanfalseUpdate dependencies for all templates, then exit
-V, --verbosecount0Set output verbosity
-y, --yesbooleanfalseAccept defaults

Built with

Fedora Linux VSCode GitLab Caffeine

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

NPM

Copyright © 2020 Chet Manley.

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago

1.0.0-alpha.3

5 years ago

1.0.0-alpha.2

5 years ago

1.0.0-alpha.1

5 years ago

1.0.0-alpha.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago