Full-fledged CLI tool to generate and package library Node modules compliant with Browser and NodeJS. Packer CLI support all modern style, unit test and script transpiler tools.
This project is using itself to compile self source.
Features
Usage
You can simply run the following command in a preferred directory to generate a new project using Packer CLI,
npx packer-cli generate my-library
or
npm install packer-cli -g && packer generate my-library
Then CLI will query questions associated to custom project generation,
Give us a small description about the library (optional)? Client compliant node module
Give us a set of comma separated package keywords (optional)? lib,awesome library,my library
Author's name (optional)? Yohan Gomez
# Name of the library author.
Author's email address (optional)? yohan.gz@gmail.com
Author's github username (optional)? yohangz
# Web home page of the library. This must be a valid URL.
Library homepage link (optional)? http://www.my-project.com
# Script transpiler to be used. Select none to use vanilla javascript.
What's the script pre processor you want to use?
- typescript
- none
Do you want style sheet support? (Y/n) Yes
What's the style pre processor you want to use?
- scss
- sass
- less
- stylus
- none
# Inline bundle style sheets within bundled script files. Select none to disable support.
Do you want to inline bundle styles within script? (y/N) No
# Target build process to support browser compliant bundling if yes
Are you building a browser compliant library? (Y/n) Yes
# If yes, react framework support will be enabled. Select none to disable support.
Are you building a react library? (y/N) No
# You can chose from the browser compliant flat bundle formats options list.
What's the build bundle format you want to use? umd
- umd
- amd
- iife
- system
What's the AMD id you want to use? (optional) my-lib
# Library namespace will be used when exposing the library via global scope. Applicable for "umd" | "iife" | "systemjs" module formats.
What's the library namespace you want to use? my.lib
Which unit test framework do you want to use?
- jasmine
- mocha
- jest
What is the library copyright year (optional)? 2018
What's the library copyright year (optional)?
- MIT License
- Apache License 2.0
- Mozilla Public License 2.0
- BBSD 2-Clause FreeBSD License
- BSD 3-Clause Revised License
- Internet Systems Consortium (ISC) License
- GNU Lesser General Public License v3.0 only
- GNU General Public License v3.0 only
- The Unlicense
# Use yarn package manager instead of NPM CLI if true.
Do you want to use yarn as package manager? (Y/n) Yes
Once project is generated and dependencies are installed, you can use the following CLI commands:
npm run watch
npm run build
npm run lint
npm run lint:style
npm run lint:script
npm run test
npm run test:coverage
npm run test:ci
npm run test:coverage:ci
npm version major|minor|patch
npm run release
generated project structure can be viewed here
Standalone Usage
You can also use packer CLI standalone on any packer compliant project to customize the NPM scripts generated.
Usage: packer [--version | -v] | [--help | -h] | <command>[<args>]
Arguments supported with all commands
+ Logging flags
[--trace] set console log level to trace
[--info] set console log level to information
[--warn] set console log level to warning
[--error] set console log level to error
[--silent] set console log level to silent
+ Other Flags
[--config | -c] dynamic packer config path
Generate a new library project via packer
generate | g <project name>
[--skipInstall | -sk] skip dependency install after project
These are packer commands can be used on generated project
build | b trigger build
watch | w trigger serve on watch mode
test | t execute project test suite
[--coverage | -C] execute test suite with coverage
clean | c clean project build artifacts and temporary files generated
lint | l execute lint for project source
[--style | -sc] execute only style lint
[--script | -sr] execute only script lint
Build Configuration
Build configuration can be updated after project generation via .packerrc.js
.
module.exports = {
extend: '~/packer-cli/resources/static/.packerrc.base.js',
entry: 'index.js',
source: 'src',
dist: 'dist',
tmp: '.tmp',
compiler: {
dependencyMapMode: 'cross-map-peer-dependency',
sourceMap: true,
customRollupPluginExtractor: null,
build: {
bundleMin: true,
es5: false,
es5Min: false,
esnext: true,
esnextMin: true
},
buildMode: 'browser',
script: {
preprocessor: 'none',
image: {
inlineLimit: 1000000,
outDir: 'images'
},
},
style: {
inline: false,
outDir: 'styles',
preprocessor: 'none',
image: {
inlineLimit: 1000000,
outDir: 'images'
}
},
concurrentBuild: true
},
assetPaths: [
'src/assets'
],
copy: [
'README.md',
'LICENSE',
'assets/**/{.*,*}'
],
ignore: [],
replacePatterns: [
{
test: './config/base-config',
replace: './config/replace-config'
}
],
bundle: {
externals: [
'regenerator-runtime/**',
'@babel/runtime/**',
'@babel/runtime-corejs2/**'
],
globals: {
'react': 'React',
'react-dom': 'ReactDOM'
},
mapExternals: true,
format: 'umd',
namespace: 'com.lib',
amd: {
define: '',
id: 'my-lib'
}
},
testFramework: '{{testFramework}}',
watch: {
demoDir: 'demo/watch',
helperDir: 'demo/helper',
serveDir: [
'node_modules/react/umd',
'node_modules/react-dom/umd'
],
open: true,
port: 4000
},
license: {
banner: true
}
};
Contributions
Feel free to open an issue or create a PR