@kebab-case/npm-simple-publisher
v2.1.4
Published
nodejs command-line script allowing to easily compile and publish both node and es6 compliant code packages to npm.
Downloads
55
Maintainers
Readme
@kebab-case/npm-simple-publisher
This little nodejs command-line script allows you to easily compile and publish node and es6 compliant code packages to npm. Init your project with minimal babel configuration for es6, compile to cjs and publish to npm with only two commands.
INSTALLATION
This package requires yarn
to behave correctly.
# install yarn
sudo apt install yarn
# or (deprecated)
sudo npm install -g yarn
# TODO install globally
sudo npm install -g @kebab-case/npm-simple-publisher
Migrate from @1.x
This version adds linter before build and breaking init
changes options.
- Run
npm i -g @kebab-case/npm-simple-publisher@latest
- Backup your
package.json
inpackage.bkp.json
and remove thepackage.json.script
andpackage.json.eslintConfig
entries of the original file. - Run
kc-nsp init -su
(it will skip any existing file other thanconfig.local.json
andpackage.json
) - Add your own scripts / eslintConfig in the newly created entries.
- Now the
build
andpublish
scripts won't complete ifeslint
fails - If you have any other problems please report on the github issues page ; in the meanwhile you can revert
package.bkp.json
topackage.json
HOW TO
First, create your new project
your-project-name
and a sub-folderyour-project-name/src
for your source code.Using terminal, navigate to your project root folder, i.e.
cd your-project-name
Enter the following command to init your project:
kc-nsp init
You can re-run this command afterwards, but you will need to add the
-f
option to force overwrite of files, or the-s
to skip existing files. Use the-su
options to only update your package.json (existing scripts / eslint config won't be replaced).Enter prompted values. ~ stands for
null
. You can replace vars later in the newly createdconfig.local.json
with yours:{ "NSP_USERNAME": "your npm username", "NSP_PASSWORD": "your npm password", "NSP_EMAIL": "your public npm email", "NSP_PACKAGE_DESCRIPTION": "your package description", "NSP_PACKAGE_KEYWORDS": "comma,separated,keywords", "NSP_PACKAGE_LICENSE": "license to use - default: MIT", "NSP_PACKAGE_VERSION": "default: 1.0.0", "NSP_PACKAGE_PRIVATE": "true|false", "NSP_SCOPED_PACKAGE": "true|false: use true to scope package as @username/package-name", "NSP_SCOPE_NAME": "scope name - default: @username", "NSP_APP_ENTRY_POINT": "app entry point - relative to ./src directory - default: index.js", "NSP_REPOSITORY_HOMEPAGE": "full URL to your remote git repo homepage - default: null", "NSP_ISSUES": "full URL to your bug tracker - automatically defined if github homepage provided", "NSP_REPOSITORY_REMOTE": "full https URL to your remote .git - automatically defined if github homepage provided" }
N.B.: this file is gitignored, so you can set your npm password confidently.
You can find a list of supported licenses here after - your license field must exactly match a filename without extension: https://github.com/spdx/license-list-data/tree/master/text
You shall modify LICENSE file by replacing some generic fields (, , , and so on) by their literal values.
P.S. Default package name will be
your-project-name
folder name, but it can be changed inconfig.local.json
.You can now write es6 in your
./src
folder and set up your own settings inpackage.json
and.gitignore
.DO NOT forget to add your fantastic
README.md
! If you don't, @kc/NSP will add a placeholder before publishing.Ready to publish to npm ? Use the
kc-nsp publish
script!First, the
kc-nsp build
sub-command will create adist
folder will be created with cjs-compliant code, and yoursrc
entry point will be used as an es6 module. Yourpackage.json
will be modified accordingly (usingkc-nsp generate-pj
subcommand).You can use publish with following options:
# skip build kc-nsp publish --skip-build kc-nsp publish -s # update version kc-nsp publish --update-version=%s # with %s: M => new major version / m : new minor version / r : new revision kc-nsp publish -t %s # skip publish confirmation kc-nsp publish --yes kc-nsp publish -y # override default git commit message kc-nps publish --commit-message="my commit message" kc-nps publish -m "my commit message" # override default git tag message kc-nps publish --tag-message="my tag message" kc-nps publish -v="my tag message" # use custom publish hooks - see detailed help about using hooks here after kc-nps publish --publish-on=hook1 --publish-on=hook2 kc-nps publish --p=hook1 --p=hook2 # deprecate one or more older major versions - in development
PUBLISHING HOOKS
You can define your own publishing hooks, which will be executed after git push
(if configured) and before
npm publish
. Each hook is a command-line of your choice with any arguments you want.
To do so:
- Add your own hook either in
./config.json
(if you want to version your hooks), either in./config.local.json
(if you don't). Format of hooks field:
{
"NSP_HOOKS": {
"hook-name": [
"command-name",
["list of arguments"],
{
"prompt_question1": "answer to prompt_question1"
},
"interactive script (true|false)",
null,
[
"hidden_field1 (should match any of prompt_question)"
]
]
}
}
- Hooks rely on
@kebab-case/node-command-manager/interactiveShell
to be executed. To get more help aboutinteractiveShell
, please visit https://www.npmjs.com/package/@kebab-case/node-command-manager#interactive-shell Note that you can define hooks with blank / undefined entries (like passwords), so you can version it; if you do so, you will be prompted values for these. - Don't modify the null field if you don't exactly know what you are doing
prompt_questions
andhidden_fields
can use regex syntax to match your command prompt.- Use
kc-nps publish -p hook-name1 -p hook-name2 ...
to use your hooks. If you do so, you will have to specify every hook you want to use, evengit
andnpm
, or they'll simply be skipped. You can add ascript
entry inpackage.json
to avoid typing all that hooks every single time :
{
"scripts": {
// bunch of scripts
"kn-publish": "kc-nps publish -p npm -p git -p my hook"
}
}
This way you can publish more quickly using yarn kn-publish [other publish args]
.
FURTHER HELP
Type kc-nsp --help
to get help on all available commands, and kc-nsp [module] --help
for further help on a
specific one.
DEPENDANCIES
- argv
- core-js
- fs
- prompt-async
- request
- @kebab-case/node-command-manager
Powered by @kebab-case/npm-simple-publisher
This package has been brought to you by npm-simple-publisher
This little nodejs command-line script allows you to easily compile and publish node and es6 compliant code packages to npm. Init your project with minimal babel configuration for es6, compile to cjs and publish to npm with only two commands.
Try it now:
sudo apt install yarn
sudo npm install -g @kebab-case/npm-simple-publisher
mkdir my_project
cd my_project
# getting help about command
kc-nsp -h # list of command modules
kc-nsp init -h # and so on
# getting started
kc-nsp init -f # create project
# ... do things in my_project/src, using proposed build or your own (not npm-friendly)
kc-nsp publish -t M|m|r # publish new Major / minor version or revision
Basically, that's all!
Find on npm: https://www.npmjs.com/package/@kebab-case/npm-simple-publisher