@slidebean/cli-utils v1.7.0
cli-utils
A set of command line utilities
Install as a development dependency
npm insatll --save-dev @slidebean/cli-utils
help
cd /path/to/html-exporter
$ `npm bin`/cli-utils --help
Commands:
notify Notify in Slack #dev channel
config <output> [source] Creates a configuration based on the provided
source
Options:
--help Show help [boolean]
--version Show version number [boolean]
Slack npm publish notify
When a new version of a project is published to npm a notification is sent to #dev
channel.
You must add postpublish
script to package.json
...
scripts : {
...
"postpublish": "sb-cli-utils notify",
...
},
...
Config command
The config
command is used to transform the configuration from one source to an output format.
sb-cli-utils config <output> [source] --[options]
Creates a configuration based on the provided source
Positionals:
output Output format of the configuration result.
[string] [required] [choices: "dotenv", "now", "angular"]
source Source from which the base configuration will be taken. If no source
is provided, it will be the same as the output.
[string] [choices: "dotenv", "now"]
Options:
--help Show help [boolean]
--version Show version number [boolean]
--env Environment for which the configuration will be
created. [string] [default: "dev"]
--safe If this option is provided, the process will throw
an error when it encounters empty values for any
setting. [boolean] [default: false]
--stub If this option is provided, the process will create
stub values for each configuration setting.
[boolean] [default: false]
--schema If this option is provided, the process will create
a schema file for the outputs that support it. For
example, for angular it will create an
environment.ts file with all the values empty.
[boolean] [default: false]
--meta.name Option for now. It will override the name value of
the now.json file [string]
--meta.alias Option for now. It will override the alias value of
the now.json file [array]
--meta.project Option for now. It will override the name and alias
values of the now.json file in conjunction with the
meta.branch option. The meta.name and meta.alias
options have precedence over this. [string]
--meta.branch Option for now. It will override the name and alias
values of the now.json file in conjunction with the
meta.project option. The meta.name and meta.alias
options have precedence over this. [string]
--meta.includeAliasEnvVar Option for now. It will include an environment
variable called SB_HOST with the value of the first
alias in the alias list [boolean] [default: true]
The supported sources are:
dotenv: This source requires a
.env
file or a enviromnent specific.env.<env>
, like.env.prod
, which contains the setting values. For example:# .env.prod NODE_ENV=production PORT=3000
You can provide a
.env.example
file, which list the variables that the.env
file should contain:# .env.example NODE_ENV= PORT=
now: This source will try to read the settings from the
env
property contained in thenow.base.json
file and thenow.<env>.json
file and merge them together. The properties fromnow.<env>.json
will override the properties fromnow.base.json
.
The supported outputs are:
- angular: Creates a
environment.<env>.ts
file with the source values in~/src/environments
directory. - dotenv: Creates a
.env
file in the project's root with the source values. - now: Reads a
now.base.json
file in the project's root and creates a newnow.json
with its content and the source values merged under theenv
property.
Example: Dotenv to Angular
If you want to create Angular's application environment files based on .env
files, you can do it with the following command:
$ npx sb-cli-utils config angular dotenv --schema --env prod
Adding the --schema
option will generate a environment.ts
file with keys and empty values. This will avoid Typescript errors about missing properties.