Skip to content

Commit

Permalink
refactor: use yargs to organize the scripts into commands
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the ways to run packages-scripts changed

* replace `src`, `dist` with shared variables
  • Loading branch information
chengjianhua committed Jan 15, 2019
1 parent db0d656 commit 550b6df
Show file tree
Hide file tree
Showing 43 changed files with 793 additions and 497 deletions.
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ merge of your pull request!

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->

- [ ] Documentation
- [ ] Tests
- [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->
* [ ] Documentation
* [ ] Tests
* [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
* [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->

<!-- feel free to add additional comments -->
32 changes: 16 additions & 16 deletions other/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

**Table of Contents**

- [Our Pledge](#our-pledge)
- [Our Standards](#our-standards)
- [Our Responsibilities](#our-responsibilities)
- [Scope](#scope)
- [Enforcement](#enforcement)
- [Attribution](#attribution)
* [Our Pledge](#our-pledge)
* [Our Standards](#our-standards)
* [Our Responsibilities](#our-responsibilities)
* [Scope](#scope)
* [Enforcement](#enforcement)
* [Attribution](#attribution)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand All @@ -29,21 +29,21 @@ orientation.
Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities
Expand Down
10 changes: 5 additions & 5 deletions other/MAINTAINING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

**Table of Contents**

- [Code of Conduct](#code-of-conduct)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Release](#release)
- [Thanks!](#thanks)
* [Code of Conduct](#code-of-conduct)
* [Issues](#issues)
* [Pull Requests](#pull-requests)
* [Release](#release)
* [Thanks!](#thanks)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"add-contributor": "node src contributors add",
"test": "node src test",
"test:update": "node src test --updateSnapshot",
"build": "node src build",
"build": "node src compile",
"lint": "node src lint",
"format": "node src format",
"validate": "node src validate",
Expand All @@ -28,7 +28,7 @@
"jest.js"
],
"keywords": [],
"author": "Jianhua Cheng <w.chengjianhua@gmail.com> (http://chengjianhua.github.io/)",
"author": "Jianhua Cheng <w.chengjianhua@gmail.com> (https://chengjianhua.github.io/)",
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.1.5",
Expand All @@ -49,6 +49,7 @@
"babel-plugin-transform-inline-environment-variables": "^0.4.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.13",
"browserslist": "^4.0.0",
"chalk": "^2.4.2",
"concurrently": "^3.5.1",
"cosmiconfig": "^5.0.7",
"cross-env": "^5.1.4",
Expand All @@ -58,7 +59,8 @@
"eslint": "^5.0.0",
"eslint-config-kentcdodds": "^14.0.0",
"eslint-config-prettier": "^2.9.0",
"glob": "^7.1.2",
"fs-extra": "^7.0.1",
"glob": "^7.1.3",
"husky": "^0.14.3",
"is-ci": "^1.1.0",
"jest": "^23.4.2",
Expand All @@ -83,6 +85,7 @@
"rollup-plugin-terser": "^1.0.1",
"semver": "^5.5.1",
"which": "^1.3.0",
"yargs": "^12.0.5",
"yargs-parser": "^10.0.0"
},
"eslintConfig": {
Expand Down
48 changes: 0 additions & 48 deletions src/__tests__/__snapshots__/index.js.snap

This file was deleted.

84 changes: 0 additions & 84 deletions src/__tests__/index.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/cmds/_internal/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function cleanCommandArgs(commandName, rawArgv) {
const args = process.argv.slice(2)
const input = [...rawArgv._]
// if executing this script by another cli program, shift `precommit` itself
if (args[0] === commandName) {
args.shift()
input.shift()
}

const normalizedArgs = {argv: {...rawArgv, _: input}, args}

return normalizedArgs
}

module.exports = {
cleanCommandArgv: cleanCommandArgs,
}
75 changes: 75 additions & 0 deletions src/cmds/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
exports.command = 'bundle'

exports.describe =
'Use rollup to compile and bundle source files through a entry file'

exports.builder = yargs => {
const options = {
'react-native': {
type: 'boolean',
describe: 'Target to React Native execution environment',
defaultDescription: 'false',
},
node: {
type: 'boolean',
describe: 'Target to Node.js execution environment',
defaultDescription: 'false',
},
config: {
type: 'string',
describe: 'Pick the rollup configuration file passed to rollup cli',
defaultDescription: 'rollup.config.js',
},
'size-snapshot': {
type: 'boolean',
describe:
'Enable the output in terminal about the size snapshot of bundles',
default: true,
defaultDescription: 'true',
},
watch: {
type: 'boolean',
describe: 'Enable watching changes to bundle',
defaultDescription: 'false',
},
formats: {
type: 'string',
array: true,
defaultDescription: ['esm', 'cjs', 'umd', 'umd.min'],
default: ['esm', 'cjs', 'umd', 'umd.min'],
},
environment: {
type: 'string',
describe: 'The `--environment` passed to rollup cli',
},
preact: {
type: 'boolean',
describe: 'The project use preact instead of react',
},
clean: {
type: 'boolean',
describe: `Don't clean output directory before bundling`,
default: true,
defaultDescription: 'true',
},
'add-preact-entry': {
type: 'boolean',
describe: `Write an extra entry \`preact\` into package.json`,
default: true,
defaultDescription: 'true',
},
// sourcemap: {
// type: 'boolean',
// describe: `The \`--sourcemap\` passed to rollup cli`,
// defaultDescription: 'false',
// },
}

return yargs.options(options)
}

exports.handler = argv => {
console.log('Bundling...')

require('../scripts/build/rollup')(argv)
}
Loading

0 comments on commit 550b6df

Please # to comment.