diff --git a/.all-contributorsrc b/.all-contributorsrc deleted file mode 100644 index 41174c98..00000000 --- a/.all-contributorsrc +++ /dev/null @@ -1,299 +0,0 @@ -{ - "projectName": "kcd-scripts", - "projectOwner": "kentcdodds", - "imageSize": 100, - "commit": false, - "contributorsPerLine": 7, - "repoHost": "https://github.com", - "repoType": "github", - "skipCi": false, - "files": [ - "README.md" - ], - "contributors": [ - { - "login": "kentcdodds", - "name": "Kent C. Dodds", - "avatar_url": "https://avatars.githubusercontent.com/u/1500684?v=3", - "profile": "https://kentcdodds.com", - "contributions": [ - "code", - "doc", - "infra", - "test" - ] - }, - { - "login": "sudo-suhas", - "name": "Suhas Karanth", - "avatar_url": "https://avatars2.githubusercontent.com/u/22251956?v=4", - "profile": "https://github.com/sudo-suhas", - "contributions": [ - "code", - "bug", - "test" - ] - }, - { - "login": "pbomb", - "name": "Matt Parrish", - "avatar_url": "https://avatars0.githubusercontent.com/u/1402095?v=4", - "profile": "https://github.com/pbomb", - "contributions": [ - "code", - "test" - ] - }, - { - "login": "mateuscb", - "name": "Mateus", - "avatar_url": "https://avatars3.githubusercontent.com/u/1319157?v=4", - "profile": "https://github.com/mateuscb", - "contributions": [ - "code", - "test" - ] - }, - { - "login": "macklinu", - "name": "Macklin Underdown", - "avatar_url": "https://avatars1.githubusercontent.com/u/2344137?v=4", - "profile": "http://macklin.underdown.me", - "contributions": [ - "code", - "test" - ] - }, - { - "login": "stereobooster", - "name": "stereobooster", - "avatar_url": "https://avatars2.githubusercontent.com/u/179534?v=4", - "profile": "https://github.com/stereobooster", - "contributions": [ - "code", - "test" - ] - }, - { - "login": "donysukardi", - "name": "Dony Sukardi", - "avatar_url": "https://avatars0.githubusercontent.com/u/410792?v=4", - "profile": "http://dsds.io", - "contributions": [ - "bug", - "code" - ] - }, - { - "login": "alexandernanberg", - "name": "Alexander Nanberg", - "avatar_url": "https://avatars3.githubusercontent.com/u/8997319?v=4", - "profile": "https://alexandernanberg.com", - "contributions": [ - "code" - ] - }, - { - "login": "fobbyal", - "name": "Alex Liang", - "avatar_url": "https://avatars2.githubusercontent.com/u/7818365?v=4", - "profile": "https://github.com/fobbyal", - "contributions": [ - "code" - ] - }, - { - "login": "shellthor", - "name": "Jeff Detmer", - "avatar_url": "https://avatars1.githubusercontent.com/u/649578?v=4", - "profile": "http://www.jeffdetmer.com", - "contributions": [ - "code" - ] - }, - { - "login": "alexzherdev", - "name": "Alex Zherdev", - "avatar_url": "https://avatars3.githubusercontent.com/u/93752?v=4", - "profile": "https://twitter.com/endymion_r", - "contributions": [ - "code" - ] - }, - { - "login": "adamdharrington", - "name": "Adam Harrington", - "avatar_url": "https://avatars0.githubusercontent.com/u/5477801?v=4", - "profile": "https://github.com/adamdharrington", - "contributions": [ - "code", - "test" - ] - }, - { - "login": "afontcu", - "name": "AdriΓ  Fontcuberta", - "avatar_url": "https://avatars0.githubusercontent.com/u/9197791?v=4", - "profile": "https://afontcu.dev", - "contributions": [ - "code" - ] - }, - { - "login": "coderberry", - "name": "Eric Berry", - "avatar_url": "https://avatars2.githubusercontent.com/u/12481?v=4", - "profile": "https://codefund.io", - "contributions": [ - "fundingFinding" - ] - }, - { - "login": "schaab", - "name": "Jared Schaab", - "avatar_url": "https://avatars0.githubusercontent.com/u/1103255?v=4", - "profile": "https://github.com/schaab", - "contributions": [ - "code", - "test" - ] - }, - { - "login": "SerkanSipahi", - "name": "Bitcollage", - "avatar_url": "https://avatars2.githubusercontent.com/u/1880749?v=4", - "profile": "https://www.linkedin.com/in/serkan-sipahi-59b20081/", - "contributions": [ - "code" - ] - }, - { - "login": "MichaelDeBoey", - "name": "MichaΓ«l De Boey", - "avatar_url": "https://avatars3.githubusercontent.com/u/6643991?v=4", - "profile": "https://michaeldeboey.be", - "contributions": [ - "code", - "review" - ] - }, - { - "login": "weyert", - "name": "Weyert de Boer", - "avatar_url": "https://avatars3.githubusercontent.com/u/7049?v=4", - "profile": "https://github.com/weyert", - "contributions": [ - "code" - ] - }, - { - "login": "KubaJastrz", - "name": "Jakub JastrzΔ™bski", - "avatar_url": "https://avatars0.githubusercontent.com/u/6443113?v=4", - "profile": "https://kubajastrz.com", - "contributions": [ - "code" - ] - }, - { - "login": "Lukas-Kullmann", - "name": "Lukas", - "avatar_url": "https://avatars0.githubusercontent.com/u/387547?v=4", - "profile": "https://github.com/Lukas-Kullmann", - "contributions": [ - "code", - "doc" - ] - }, - { - "login": "mihar-22", - "name": "Rahim Alwer", - "avatar_url": "https://avatars2.githubusercontent.com/u/14304599?v=4", - "profile": "https://github.com/mihar-22", - "contributions": [ - "code" - ] - }, - { - "login": "ghostd", - "name": "Vincent Ricard", - "avatar_url": "https://avatars1.githubusercontent.com/u/1098399?v=4", - "profile": "https://github.com/ghostd", - "contributions": [ - "code" - ] - }, - { - "login": "timdeschryver", - "name": "Tim Deschryver", - "avatar_url": "https://avatars1.githubusercontent.com/u/28659384?v=4", - "profile": "http://timdeschryver.dev", - "contributions": [ - "code" - ] - }, - { - "login": "eddyw", - "name": "Eddy Wilson", - "avatar_url": "https://avatars0.githubusercontent.com/u/1407526?v=4", - "profile": "https://github.com/eddyw", - "contributions": [ - "review" - ] - }, - { - "login": "rbusquet", - "name": "Ricardo Busquet", - "avatar_url": "https://avatars1.githubusercontent.com/u/7198302?v=4", - "profile": "https://ricardobusquet.com", - "contributions": [ - "review" - ] - }, - { - "login": "aprillion", - "name": "Peter HozΓ‘k", - "avatar_url": "https://avatars0.githubusercontent.com/u/1087670?v=4", - "profile": "http://peter.hozak.info/", - "contributions": [ - "review" - ] - }, - { - "login": "marcosvega91", - "name": "Marco Moretti", - "avatar_url": "https://avatars2.githubusercontent.com/u/5365582?v=4", - "profile": "https://github.com/marcosvega91", - "contributions": [ - "code" - ] - }, - { - "login": "rafgraph", - "name": "Rafael Pedicini", - "avatar_url": "https://avatars0.githubusercontent.com/u/11911299?v=4", - "profile": "http://rafgraph.dev", - "contributions": [ - "doc" - ] - }, - { - "login": "mpeyper", - "name": "Michael Peyper", - "avatar_url": "https://avatars0.githubusercontent.com/u/23029903?v=4", - "profile": "https://github.com/mpeyper", - "contributions": [ - "code" - ] - }, - { - "login": "HOUCe", - "name": "HOU Ce", - "avatar_url": "https://avatars.githubusercontent.com/u/19988985?v=4", - "profile": "https://www.zhihu.com/people/lucas-hc/activities", - "contributions": [ - "code" - ] - } - ] -} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..e848f859 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +coverage/ +package-lock.json diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b64c2235..87d61059 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -11,7 +11,7 @@ never done that before, that's great! Check this free short video tutorial to learn how: http://kcd.im/pull-request --> -- `kcd-scripts` version: +- `cod-scripts` version: - `node` version: - `npm` (or `yarn`) version: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..1203f0df --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release + +on: + push: + branches: + - master + - main + - alpha + - beta + - next + - 'next-major' + - '+([0-9])?(.{+([0-9]),x}).x' + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: validate before release + run: | + npm install --no-save + npm run build + npm run lint + npm run test + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + CI: true + + - name: semantic release + uses: docker://ghcr.io/codfish/semantic-release-action:v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index e211ba32..245a5eda 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,91 +1,70 @@ -name: validate -on: - push: - branches: - - '+([0-9])?(.{+([0-9]),x}).x' - - 'main' - - 'next' - - 'next-major' - - 'beta' - - 'alpha' - - '!all-contributors/**' - pull_request: {} +name: Validate Code + +on: pull_request + jobs: - main: - # ignore all-contributors PRs - if: ${{ !contains(github.head_ref, 'all-contributors') }} + validate: + runs-on: ubuntu-latest + strategy: matrix: - os: [ubuntu-latest, windows-latest] - node: [10.18, 12, 14, 15] - runs-on: ${{ matrix.os }} - steps: - - name: πŸ›‘ Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{ secrets.GITHUB_TOKEN }} + node: [10.x, 11.x, 12.x, 14.x, 15.x] - - name: ⬇️ Checkout repo - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v1 - - name: βŽ” Setup node - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} - - name: πŸ“₯ Download deps - uses: bahmutov/npm-install@v1 - with: - useLockFile: false + - name: install dependencies + run: npm install --no-save - - name: ▢️ Run validate script - run: npm run validate + - run: npm run build - - name: ⬆️ Upload coverage report - uses: codecov/codecov-action@v1 + - name: lint js + run: npm run lint - release: - needs: main + - name: run tests + run: npm run test + env: + CI: true + + pr-version: runs-on: ubuntu-latest - if: - ${{ github.repository == 'kentcdodds/kcd-scripts' && - contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha', - github.ref) && github.event_name == 'push' }} - steps: - - name: πŸ›‘ Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.6.0 - with: - access_token: ${{ secrets.GITHUB_TOKEN }} - - name: ⬇️ Checkout repo - uses: actions/checkout@v2 + steps: + - uses: actions/checkout@v1 - - name: βŽ” Setup node - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: 14 + node-version: '14' + registry-url: 'https://registry.npmjs.org' - - name: πŸ“₯ Download deps - uses: bahmutov/npm-install@v1 - with: - useLockFile: false + - name: install dependencies + run: npm install --no-save - - name: πŸ— Run build script - run: npm run build + - run: npm run build - - name: πŸš€ Release - uses: cycjimmy/semantic-release-action@v2 - with: - semantic_version: 17 - branches: | - [ - '+([0-9])?(.{+([0-9]),x}).x', - 'main', - 'next', - 'next-major', - {name: 'beta', prerelease: true}, - {name: 'alpha', prerelease: true} - ] + - name: publish to npm + id: pr-publish + run: | + version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)" + npm version $version --no-git-tag-version + npm publish --access public --tag pr + echo "::set-output name=pr_version::$version" env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + PR: ${{ github.event.number }} + SHA: ${{ github.event.pull_request.head.sha }} + + - uses: actions/github-script@v3 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'πŸš€ PR version published: `${{ steps.pr-publish.outputs.pr_version }}`' + }) diff --git a/.npmrc b/.npmrc index a57cc9e5..d2722898 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ registry=http://registry.npmjs.org/ +package-lock=false diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 9c628283..00000000 --- a/.prettierignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -coverage -dist diff --git a/.prettierrc.js b/.prettierrc.js index 698d14b8..f209a68c 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1 +1,9 @@ -module.exports = require('./src/config/prettierrc') +const prettierConfig = require('./src/config/prettierrc') + +module.exports = Object.assign({}, prettierConfig, { + // to prevent additional conflicts with update kcd-scripts, making + // backmerging a little easier. + printWidth: 80, + semi: false, + bracketSpacing: false, +}) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c7daeb12..57d0dda4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ series [How to Contribute to an Open Source Project on GitHub][egghead] > pull requests from branches on your fork. To do this, run: > > ``` -> git remote add upstream https://github.com/kentcdodds/kcd-scripts +> git remote add upstream https://github.com/codfish/cod-scripts.git > git fetch upstream > git branch --set-upstream-to=upstream/master master > ``` @@ -41,6 +41,10 @@ Also, please watch the repo and respond to questions/bug reports/feature requests! Thanks! -[egghead]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github -[issues]: https://github.com/kentcdodds/kcd-scripts/issues - + +[egghead]: + https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github +[semantic-release]: https://npmjs.com/package/semantic-release +[convention]: + https://github.com/conventional-changelog/conventional-changelog-angular/blob/ed32559941719a130bb0327f886d6a32a8cbc2ba/convention.md +[issues]: https://github.com/codfish/cod-scripts/issues diff --git a/LICENSE b/LICENSE index 4c43675b..5e8d3bbb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Kent C. Dodds + +Copyright (c) 2019 Chris O'Donnell (https://codfish.io/) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -8,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 1a099aa3..983d8d40 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@
-

kcd-scripts πŸ› πŸ“¦

+

cod-scripts πŸ› πŸ“¦

CLI toolbox for common scripts for my projects

@@ -7,25 +7,20 @@ --- -[![Build Status][build-badge]][build] -[![Code Coverage][coverage-badge]][coverage] [![version][version-badge]][package] -[![downloads][downloads-badge]][npmtrends] +[![downloads][downloads-badge]][npmcharts] +[![GitHub Workflow Status][actions-badge]][actions-badge] [![MIT License][license-badge]][license] -[![All Contributors][all-contributors-badge]](#contributors-) [![PRs Welcome][prs-badge]][prs] -[![Code of Conduct][coc-badge]][coc] +[![Semantic Release][semantic-release-badge]][semantic-release] +[![Commitizen friendly][commitizen-badge]][commitizen] -## The problem +## Motivation -I do a bunch of open source and want to make it easier to maintain so many -projects. - -## This solution - -This is a CLI that abstracts away all configuration for my open source projects -for linting, testing, building, and more. +This helps me maintain personal & work projects without duplication. This is a +CLI that abstracts away all configuration for my open source projects for +linting, testing, building, and more. ## Table of Contents @@ -36,12 +31,6 @@ for linting, testing, building, and more. - [Usage](#usage) - [Overriding Config](#overriding-config) - [TypeScript Support](#typescript-support) -- [Inspiration](#inspiration) -- [Other Solutions](#other-solutions) -- [Issues](#issues) - - [πŸ› Bugs](#-bugs) - - [πŸ’‘ Feature Requests](#-feature-requests) -- [Contributors ✨](#contributors-) - [LICENSE](#license) @@ -51,28 +40,29 @@ for linting, testing, building, and more. This module is distributed via [npm][npm] which is bundled with [node][node] and should be installed as one of your project's `devDependencies`: -``` -npm install --save-dev kcd-scripts +```sh +npm install --save-dev cod-scripts +npm install --save @babel/runtime ``` ## Usage -This is a CLI and exposes a bin called `kcd-scripts`. I don't really plan on +This is a CLI and exposes a bin called `cod-scripts`. I don't really plan on documenting or testing it super duper well because it's really specific to my needs. You'll find all available scripts in `src/scripts`. This project actually dogfoods itself. If you look in the `package.json`, you'll find scripts with `node src {scriptName}`. This serves as an example of some of -the things you can do with `kcd-scripts`. +the things you can do with `cod-scripts`. ### Overriding Config -Unlike `react-scripts`, `kcd-scripts` allows you to specify your own +Unlike `react-scripts`, `cod-scripts` allows you to specify your own configuration for things and have that plug directly into the way things work -with `kcd-scripts`. There are various ways that it works, but basically if you +with `cod-scripts`. There are various ways that it works, but basically if you want to have your own config for something, just add the configuration and -`kcd-scripts` will use that instead of it's own internal config. In addition, -`kcd-scripts` exposes its configuration so you can use it and override only the +`cod-scripts` will use that instead of it's own internal config. In addition, +`cod-scripts` exposes its configuration so you can use it and override only the parts of the config you need to. This can be a very helpful way to make editor integration work for tools like @@ -82,7 +72,7 @@ So, if we were to do this for ESLint, you could create an `.eslintrc` with the contents of: ``` -{"extends": "./node_modules/kcd-scripts/eslint.js"} +{"extends": "./node_modules/cod-scripts/eslint.js"} ``` > Note: for now, you'll have to include an `.eslintignore` in your project until @@ -91,13 +81,14 @@ contents of: Or, for `babel`, a `.babelrc` with: ``` -{"presets": ["kcd-scripts/babel"]} +{ "presets": ["cod-scripts/babel"] } ``` Or, for `jest`: -```javascript -const {jest: jestConfig} = require('kcd-scripts/config') +```js +const {jest: jestConfig} = require('cod-scripts/config') + module.exports = Object.assign(jestConfig, { // your overrides here @@ -108,7 +99,35 @@ module.exports = Object.assign(jestConfig, { }) ``` -> Note: `kcd-scripts` intentionally does not merge things for you when you start +Or, for `commitlint`, a `commitlint.config.js` file or `commitlint` prop in +package.json: + +```js +// commitlint.config.js or .commitlintrc.js +const {commitlint: commitlintConfig} = require('cod-scripts/commitlint') + +module.exports = { + ...commitlintConfig, + rules: { + // overrides here + }, +} +``` + +```json +// package.json +{ + "commitlint": { + "extends": ["./node_modules/cod-scripts/commitlint"], + "rules": { + // your overrides here + // https://commitlint.js.org/#/reference-rules + } + } +} +``` + +> Note: `cod-scripts` intentionally does not merge things for you when you start > configuring things to make it less magical and more straightforward. Extending > can take place on your terms. I think this is actually a great way to do this. @@ -116,11 +135,11 @@ module.exports = Object.assign(jestConfig, { If the `tsconfig.json`-file is present in the project root directory and `typescript` is a dependency the `@babel/preset-typescript` will automatically -get loaded when you use the default babel config that comes with `kcd-scripts`. -If you customized your `.babelrc`-file you might need to manually add +get loaded when you use the default babel config that comes with `cod-scripts`. +If you customised your `.babelrc`-file you might need to manually add `@babel/preset-typescript` to the `presets`-section. -`kcd-scripts` will automatically load any `.ts` and `.tsx` files, including the +`cod-scripts` will automatically load any `.ts` and `.tsx` files, including the default entry point, so you don't have to worry about any rollup configuration. If you have a `typecheck` script (normally set to `kcd-scripts typecheck`) that @@ -130,92 +149,6 @@ will be run as part of the `validate` script (which is run as part of the TypeScript definition files will also automatically be generated during the `build` script. -## Inspiration - -This is inspired by `react-scripts`. - -## Other Solutions - -If you are aware of any please [make a pull request][prs] and add it -here! Again, this is a very specific-to-me solution. -- [Rollpkg](https://github.com/rafgraph/rollpkg) - convention over config build tool to create packages with TypeScript and Rollup. - -## Issues - -_Looking to contribute? Look for the [Good First Issue][good-first-issue] -label._ - -### πŸ› Bugs - -Please file an issue for bugs, missing documentation, or unexpected behavior. - -[**See Bugs**][bugs] - -### πŸ’‘ Feature Requests - -Please file an issue to suggest new features. Vote on feature requests by adding -a πŸ‘. This helps maintainers prioritize what to work on. - -[**See Feature Requests**][requests] - -## Contributors ✨ - -Thanks goes to these people ([emoji key][emojis]): - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Kent C. Dodds

πŸ’» πŸ“– πŸš‡ ⚠️

Suhas Karanth

πŸ’» πŸ› ⚠️

Matt Parrish

πŸ’» ⚠️

Mateus

πŸ’» ⚠️

Macklin Underdown

πŸ’» ⚠️

stereobooster

πŸ’» ⚠️

Dony Sukardi

πŸ› πŸ’»

Alexander Nanberg

πŸ’»

Alex Liang

πŸ’»

Jeff Detmer

πŸ’»

Alex Zherdev

πŸ’»

Adam Harrington

πŸ’» ⚠️

AdriΓ  Fontcuberta

πŸ’»

Eric Berry

πŸ”

Jared Schaab

πŸ’» ⚠️

Bitcollage

πŸ’»

MichaΓ«l De Boey

πŸ’» πŸ‘€

Weyert de Boer

πŸ’»

Jakub JastrzΔ™bski

πŸ’»

Lukas

πŸ’» πŸ“–

Rahim Alwer

πŸ’»

Vincent Ricard

πŸ’»

Tim Deschryver

πŸ’»

Eddy Wilson

πŸ‘€

Ricardo Busquet

πŸ‘€

Peter HozΓ‘k

πŸ‘€

Marco Moretti

πŸ’»

Rafael Pedicini

πŸ“–

Michael Peyper

πŸ’»

HOU Ce

πŸ’»
- - - - - - -This project follows the [all-contributors][all-contributors] specification. -Contributions of any kind welcome! - ## LICENSE MIT @@ -223,24 +156,18 @@ MIT [npm]: https://www.npmjs.com [node]: https://nodejs.org -[build-badge]: https://img.shields.io/github/workflow/status/kentcdodds/kcd-scripts/validate?logo=github&style=flat-square -[build]: https://github.com/kentcdodds/kcd-scripts/actions?query=workflow%3Avalidate -[coverage-badge]: https://img.shields.io/codecov/c/github/kentcdodds/kcd-scripts.svg?style=flat-square -[coverage]: https://codecov.io/github/kentcdodds/kcd-scripts -[version-badge]: https://img.shields.io/npm/v/kcd-scripts.svg?style=flat-square -[package]: https://www.npmjs.com/package/kcd-scripts -[downloads-badge]: https://img.shields.io/npm/dm/kcd-scripts.svg?style=flat-square -[npmtrends]: http://www.npmtrends.com/kcd-scripts -[license-badge]: https://img.shields.io/npm/l/kcd-scripts.svg?style=flat-square -[license]: https://github.com/kentcdodds/kcd-scripts/blob/master/LICENSE -[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square +[semantic-release]: https://github.com/semantic-release/semantic-release +[semantic-release-badge]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg [prs]: http://makeapullrequest.com -[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square -[coc]: https://github.com/kentcdodds/kcd-scripts/blob/master/other/CODE_OF_CONDUCT.md -[emojis]: https://github.com/all-contributors/all-contributors#emoji-key -[all-contributors]: https://github.com/all-contributors/all-contributors -[all-contributors-badge]: https://img.shields.io/github/all-contributors/kentcdodds/kcd-scripts?color=orange&style=flat-square -[bugs]: https://github.com/kentcdodds/kcd-scripts/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug -[requests]: https://github.com/kentcdodds/kcd-scripts/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement -[good-first-issue]: https://github.com/kentcdodds/kcd-scripts/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement+label%3A%22good+first+issue%22 +[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square +[commitizen]: http://commitizen.github.io/cz-cli/ +[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg +[npmcharts]: http://npmcharts.com/compare/cod-scripts +[version-badge]: https://img.shields.io/npm/v/cod-scripts.svg?style=flat-square +[package]: https://www.npmjs.com/package/cod-scripts +[downloads-badge]: https://img.shields.io/npm/dm/cod-scripts.svg?style=flat-square +[license-badge]: https://img.shields.io/npm/l/cod-scripts.svg?style=flat-square +[license]: https://github.com/codfish/cod-scripts/blob/master/LICENSE +[actions]: https://github.com/codfish/cod-scripts/actions +[actions-badge]: https://img.shields.io/github/workflow/status/codfish/cod-scripts/Release/master diff --git a/commitlint.js b/commitlint.js new file mode 100644 index 00000000..98e2af42 --- /dev/null +++ b/commitlint.js @@ -0,0 +1 @@ +module.exports = require('./dist/config/commitlint.config') diff --git a/jest.config.js b/jest.config.js index d28e0ab1..61f21edc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,4 +2,8 @@ const {jest: jestConfig} = require('./src/config') module.exports = Object.assign(jestConfig, { coverageThreshold: null, + testPathIgnorePatterns: [ + ...jestConfig.testPathIgnorePatterns, + './src/scripts/test.js', + ], }) diff --git a/other/CODE_OF_CONDUCT.md b/other/CODE_OF_CONDUCT.md deleted file mode 100644 index 80a98f60..00000000 --- a/other/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,90 +0,0 @@ -# Contributor Covenant Code of Conduct - - - - - -**Table of Contents** - -- [Our Pledge](#our-pledge) -- [Our Standards](#our-standards) -- [Our Responsibilities](#our-responsibilities) -- [Scope](#scope) -- [Enforcement](#enforcement) -- [Attribution](#attribution) - - - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of -experience, nationality, personal appearance, race, religion, or sexual identity -and orientation. - -## Our Standards - -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 - -Examples of unacceptable behavior by participants include: - -- 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 - address, without explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, or to ban temporarily or permanently any -contributor for other behaviors that they deem inappropriate, threatening, -offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at kent+coc@doddsfamily.us. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an -incident. Further details of specific enforcement policies may be posted -separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/other/USERS.md b/other/USERS.md deleted file mode 100644 index 85c01cf2..00000000 --- a/other/USERS.md +++ /dev/null @@ -1,18 +0,0 @@ -# Users - - - - - - - -If you or your company uses this project, add your name to this list! Eventually -we may have a website to showcase these (wanna build it!?) - -> No users have been added yet! - - diff --git a/other/manual-releases.md b/other/manual-releases.md deleted file mode 100644 index 67044d93..00000000 --- a/other/manual-releases.md +++ /dev/null @@ -1,50 +0,0 @@ -# manual-releases - - - - - - - -This project has an automated release set up. So things are only released when -there are useful changes in the code that justify a release. But sometimes -things get messed up one way or another and we need to trigger the release -ourselves. When this happens, simply bump the number below and commit that with -the following commit message based on your needs: - -**Major** - -``` -fix(release): manually release a major version - -There was an issue with a major release, so this manual-releases.md -change is to release a new major version. - -Reference: # - -BREAKING CHANGE: -``` - -**Minor** - -``` -feat(release): manually release a minor version - -There was an issue with a minor release, so this manual-releases.md -change is to release a new minor version. - -Reference: # -``` - -**Patch** - -``` -fix(release): manually release a patch version - -There was an issue with a patch release, so this manual-releases.md -change is to release a new patch version. - -Reference: # -``` - -The number of times we've had to do a manual release is: 1 diff --git a/package.json b/package.json index 9ae862d0..8f5cb4f0 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,29 @@ { - "name": "kcd-scripts", + "name": "cod-scripts", "version": "0.0.0-semantically-released", "description": "CLI for common scripts for my projects", "engines": { - "node": ">=10.18", + "node": ">=12", "npm": ">=6", "yarn": ">=1" }, "bin": { - "kcd-scripts": "dist/index.js" + "cod-scripts": "dist/index.js" }, "scripts": { "test": "node src test", "test:update": "node src test --updateSnapshot", "build": "node src build", "lint": "node src lint", + "commitlint": "node src commitlint", "format": "node src format", "validate": "node src validate" }, "files": [ "dist", "babel.js", + "commitlint.js", + "eslint.js", "config.js", "eslint.js", "husky.js", @@ -29,24 +32,26 @@ "shared-tsconfig.json" ], "keywords": [], - "author": "Kent C. Dodds (https://kentcdodds.com)", + "author": "Chris O'Donnell (http://codfish.io/)", "license": "MIT", "dependencies": { - "@babel/cli": "^7.12.8", - "@babel/core": "^7.12.9", - "@babel/plugin-proposal-class-properties": "^7.12.1", - "@babel/plugin-transform-modules-commonjs": "^7.12.1", - "@babel/plugin-transform-runtime": "^7.12.1", - "@babel/preset-env": "^7.12.7", - "@babel/preset-react": "^7.12.7", - "@babel/preset-typescript": "^7.12.7", - "@babel/runtime": "^7.12.5", - "@rollup/plugin-babel": "^5.2.2", - "@rollup/plugin-commonjs": "^17.0.0", + "@babel/cli": "^7.13.16", + "@babel/core": "^7.13.16", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/plugin-transform-modules-commonjs": "^7.13.0", + "@babel/plugin-transform-runtime": "^7.13.15", + "@babel/preset-env": "^7.13.15", + "@babel/preset-react": "^7.13.13", + "@babel/preset-typescript": "^7.13.0", + "@babel/runtime": "^7.13.17", + "@commitlint/cli": "^12.1.1", + "@commitlint/config-conventional": "^12.1.1", + "@rollup/plugin-babel": "^5.3.0", + "@rollup/plugin-commonjs": "^18.0.0", "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^10.0.0", - "@rollup/plugin-replace": "^2.3.4", - "@types/jest": "^26.0.16", + "@rollup/plugin-node-resolve": "^11.2.1", + "@rollup/plugin-replace": "^2.4.2", + "@types/jest": "^26.0.22", "arrify": "^2.0.1", "babel-jest": "^26.6.3", "babel-plugin-macros": "^3.0.0", @@ -54,68 +59,96 @@ "babel-plugin-module-resolver": "^4.0.0", "babel-plugin-transform-inline-environment-variables": "^0.4.3", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", - "browserslist": "^4.14.7", + "browserslist": "^4.16.5", "builtin-modules": "^3.2.0", - "chalk": "^4.1.0", - "concurrently": "^5.3.0", + "chalk": "^4.1.1", + "concurrently": "^6.0.2", "cosmiconfig": "^7.0.0", "cross-env": "^7.0.3", "cross-spawn": "^7.0.3", - "doctoc": "^1.4.0", - "eslint": "^7.14.0", - "eslint-config-kentcdodds": "^17.2.0", - "eslint-config-prettier": "^6.15.0", - "glob": "^7.1.6", - "husky": "^4.3.0", - "is-ci": "^2.0.0", - "jest": "^26.6.3", + "doctoc": "^2.0.0", + "eslint": "^7.25.0", + "eslint-config-codfish": "^10.0.0", + "glob": "^7.1.5", + "husky": "^6.0.0", + "is-ci": "^3.0.0", + "jest": "^26.6.1", "jest-serializer-path": "^0.1.15", - "jest-watch-typeahead": "^0.6.1", - "lint-staged": "^10.5.2", + "jest-watch-typeahead": "^0.6.3", + "lint-staged": "^10.5.4", "lodash.camelcase": "^4.3.0", "lodash.has": "^4.5.2", "lodash.omit": "^4.5.0", "mkdirp": "^1.0.4", "prettier": "2.2.1", + "react-app-polyfill": "^2.0.0", "read-pkg-up": "^7.0.1", - "resolve": "^1.19.0", + "resolve": "^1.20.0", "rimraf": "^3.0.2", - "rollup": "^2.34.0", + "rollup": "^2.45.2", "rollup-plugin-node-builtins": "^2.1.2", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-size-snapshot": "^0.12.0", "rollup-plugin-terser": "^7.0.2", - "semver": "^7.3.4", + "semver": "^7.3.5", "which": "^2.0.2", - "yargs-parser": "^20.2.4" + "yargs-parser": "^20.2.7" }, "eslintConfig": { "extends": [ - "kentcdodds", - "kentcdodds/jest" + "./src/config/eslintrc.js" ], "rules": { + "no-console": "off", + "semi": "off", + "@babel/semi": "off", + "object-curly-spacing": "off", + "@babel/object-curly-spacing": "off", "no-process-exit": "off", + "global-require": "off", + "no-prototype-builtins": "off", + "no-useless-catch": "off", "import/no-dynamic-require": "off", "import/no-unassigned-import": "off", - "no-console": "off", "no-nested-ternary": "off", - "no-useless-catch": "off" + "no-use-before-define": "off", + "no-restricted-syntax": "off", + "no-param-reassign": "off", + "max-len": [ + "error", + 80, + 2, + { + "ignoreUrls": true, + "ignoreComments": true, + "ignoreRegExpLiterals": true, + "ignoreStrings": true, + "ignoreTemplateLiterals": true + } + ] + } + }, + "commitlint": { + "extends": [ + "./src/config/commitlint.config" + ], + "rules": { + "scope-case": [ + 0 + ], + "subject-case": [ + 0 + ] } }, - "eslintIgnore": [ - "node_modules", - "coverage", - "dist" - ], "repository": { "type": "git", - "url": "https://github.com/kentcdodds/kcd-scripts" + "url": "https://github.com/codfish/cod-scripts" }, "bugs": { - "url": "https://github.com/kentcdodds/kcd-scripts/issues" + "url": "https://github.com/codfish/cod-scripts/issues" }, - "homepage": "https://github.com/kentcdodds/kcd-scripts#readme", + "homepage": "https://github.com/codfish/cod-scripts#readme", "devDependencies": { "jest-in-case": "^1.0.2", "slash": "^3.0.0" diff --git a/src/__tests__/__snapshots__/index.js.snap b/src/__tests__/__snapshots__/index.js.snap index 343a16e8..e11a482a 100644 --- a/src/__tests__/__snapshots__/index.js.snap +++ b/src/__tests__/__snapshots__/index.js.snap @@ -30,6 +30,7 @@ Usage: ../ [script] [--flags] Available Scripts: build + commitlint format lint pre-commit diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 00dab083..83150096 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -28,7 +28,7 @@ cases( if (signal) { crossSpawnSyncMock.mockReturnValueOnce({result: 1, signal}) } - require('../') + require('..') if (snapshotLog) { expect(console.log.mock.calls).toMatchSnapshot() } else if (signal) { diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index e3b8b24f..ade59b09 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -8,7 +8,8 @@ jest.mock('cosmiconfig', () => { return {...cosmiconfigExports, cosmiconfigSync: jest.fn()} }) -let whichSyncMock, readPkgUpSyncMock +let whichSyncMock +let readPkgUpSyncMock beforeEach(() => { jest.resetModules() @@ -28,17 +29,17 @@ test('appDirectory is the dirname to the package.json', () => { expect(require('../utils').appDirectory).toBe(pkgPath) }) -test('resolveKcdScripts resolves to src/index.js when in the kcd-scripts package', () => { - mockPkg({package: {name: 'kcd-scripts'}}) - expect(require('../utils').resolveKcdScripts()).toBe( +test('resolveCodScripts resolves to src/index.js when in the cod-scripts package', () => { + mockPkg({package: {name: 'cod-scripts'}}) + expect(require('../utils').resolveCodScripts()).toBe( require.resolve('../').replace(process.cwd(), '.'), ) }) -test('resolveKcdScripts resolves to kcd-scripts if not in the kcd-scripts package', () => { - mockPkg({package: {name: 'not-kcd-scripts'}}) +test('resolveCodScripts resolves to cod-scripts if not in the cod-scripts package', () => { + mockPkg({package: {name: 'not-cod-scripts'}}) whichSyncMock.mockImplementationOnce(() => require.resolve('../')) - expect(require('../utils').resolveKcdScripts()).toBe('kcd-scripts') + expect(require('../utils').resolveCodScripts()).toBe('cod-scripts') }) test(`resolveBin resolves to the full path when it's not in $PATH`, () => { @@ -61,8 +62,9 @@ describe('for windows', () => { beforeEach(() => { jest.doMock('fs', () => ({realpathSync: jest.fn()})) - realpathSync = require('fs').realpathSync + realpathSync = require('fs').realpathSync; // eslint-disable-line }) + afterEach(() => { jest.unmock('fs') }) diff --git a/src/config/__tests__/umbrella.js b/src/config/__tests__/umbrella.js index c1e9c065..51af51e9 100644 --- a/src/config/__tests__/umbrella.js +++ b/src/config/__tests__/umbrella.js @@ -1,10 +1,11 @@ test('requiring some files does not blow up', () => { require('../babel-transform') require('../babelrc') + require('../commitlint.config') require('../eslintrc') require('../jest.config') require('../lintstagedrc') require('../prettierrc') require('../rollup.config') - require('../').getRollupConfig() + require('..').getRollupConfig() }) diff --git a/src/config/babelrc.js b/src/config/babelrc.js index 4f7f73ad..ba3f5f65 100644 --- a/src/config/babelrc.js +++ b/src/config/babelrc.js @@ -1,6 +1,5 @@ const browserslist = require('browserslist') const semver = require('semver') - const { ifDep, ifAnyDep, @@ -33,9 +32,25 @@ if (!treeshake && !hasBabelRuntimeDep && !isTest) { console.warn(RUNTIME_HELPERS_WARN) } +function getNodeVersion({engines: {node: nodeVersion = '10.13'} = {}}) { + const oldestVersion = semver + .validRange(nodeVersion) + .replace(/[>=<|]/g, ' ') + .split(' ') + .filter(Boolean) + .sort(semver.compare)[0] + if (!oldestVersion) { + throw new Error( + `Unable to determine the oldest version in the range in your package.json at engines.node: "${nodeVersion}". Please attempt to make it less ambiguous.`, + ) + } + return oldestVersion +} + /** * use the strategy declared by browserslist to load browsers configuration. * fallback to the default if don't found custom configuration + * * @see https://github.com/browserslist/browserslist/blob/master/node.js#L139 */ const browsersConfig = browserslist.loadConfig({path: appDirectory}) || [ @@ -50,61 +65,54 @@ const envTargets = isTest : {node: getNodeVersion(pkg)} const envOptions = {modules: false, loose: true, targets: envTargets} -module.exports = () => ({ - presets: [ - [require.resolve('@babel/preset-env'), envOptions], - ifAnyDep( - ['react', 'preact'], +module.exports = api => { + // Cache the returned value forever and don't call this function again. + api.cache(true) + + return { + presets: [ + [require.resolve('@babel/preset-env'), envOptions], + ifAnyDep( + ['react', 'preact'], + [ + require.resolve('@babel/preset-react'), + {pragma: isPreact ? ifDep('react', 'React.h', 'h') : undefined}, + ], + ), + ifTypescript([require.resolve('@babel/preset-typescript')]), + ].filter(Boolean), + plugins: [ [ - require.resolve('@babel/preset-react'), - {pragma: isPreact ? ifDep('react', 'React.h', 'h') : undefined}, + require.resolve('@babel/plugin-transform-runtime'), + {useESModules: treeshake && !isCJS}, ], - ), - ifTypescript([require.resolve('@babel/preset-typescript')]), - ].filter(Boolean), - plugins: [ - [ - require.resolve('@babel/plugin-transform-runtime'), - {useESModules: treeshake && !isCJS}, - ], - require.resolve('babel-plugin-macros'), - alias - ? [ - require.resolve('babel-plugin-module-resolver'), - {root: ['./src'], alias}, - ] - : null, - ifAnyDep( - ['react', 'preact'], + require.resolve('babel-plugin-macros'), + alias + ? [ + require.resolve('babel-plugin-module-resolver'), + {root: ['./src'], alias}, + ] + : null, + ifAnyDep( + ['react', 'preact'], + [ + require.resolve('babel-plugin-transform-react-remove-prop-types'), + isPreact ? {removeImport: true} : {mode: 'unsafe-wrap'}, + ], + ), + isUMD + ? require.resolve('babel-plugin-transform-inline-environment-variables') + : null, [ - require.resolve('babel-plugin-transform-react-remove-prop-types'), - isPreact ? {removeImport: true} : {mode: 'unsafe-wrap'}, + require.resolve('@babel/plugin-proposal-class-properties'), + {loose: true}, ], - ), - isUMD - ? require.resolve('babel-plugin-transform-inline-environment-variables') - : null, - [require.resolve('@babel/plugin-proposal-class-properties'), {loose: true}], - isMinify - ? require.resolve('babel-plugin-minify-dead-code-elimination') - : null, - treeshake - ? null - : require.resolve('@babel/plugin-transform-modules-commonjs'), - ].filter(Boolean), -}) - -function getNodeVersion({engines: {node: nodeVersion = '10.13'} = {}}) { - const oldestVersion = semver - .validRange(nodeVersion) - .replace(/[>=<|]/g, ' ') - .split(' ') - .filter(Boolean) - .sort(semver.compare)[0] - if (!oldestVersion) { - throw new Error( - `Unable to determine the oldest version in the range in your package.json at engines.node: "${nodeVersion}". Please attempt to make it less ambiguous.`, - ) + isMinify + ? require.resolve('babel-plugin-minify-dead-code-elimination') + : null, + treeshake + ? null + : require.resolve('@babel/plugin-transform-modules-commonjs'), + ].filter(Boolean), } - return oldestVersion } diff --git a/src/config/commitlint.config.js b/src/config/commitlint.config.js new file mode 100644 index 00000000..6768bc91 --- /dev/null +++ b/src/config/commitlint.config.js @@ -0,0 +1,5 @@ +// https://commitlint.js.org/#/reference-rules +module.exports = { + // https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum + extends: ['@commitlint/config-conventional'], +} diff --git a/src/config/eslintignore b/src/config/eslintignore index 5ab667c9..1d8518c4 100644 --- a/src/config/eslintignore +++ b/src/config/eslintignore @@ -1,6 +1,9 @@ node_modules/ -coverage/ dist/ build/ +coverage/ out/ .next/ +docs/ +package-lock.json +serviceWorker.js diff --git a/src/config/eslintrc.js b/src/config/eslintrc.js index 741a3944..8cd8326a 100644 --- a/src/config/eslintrc.js +++ b/src/config/eslintrc.js @@ -1,11 +1,25 @@ -const {ifAnyDep} = require('../utils') +const path = require('path') +const prettierConfig = require('./prettierrc') +const {hasLocalConfig} = require('../utils') + +const here = p => path.join(__dirname, p) +const hereRelative = p => here(p).replace(process.cwd(), '.') + +const useBuiltinPrettierConfig = !hasLocalConfig('prettier') +const useBuiltinBabelConfig = !hasLocalConfig('babel') module.exports = { - extends: [ - require.resolve('eslint-config-kentcdodds'), - require.resolve('eslint-config-kentcdodds/jest'), - ifAnyDep('react', require.resolve('eslint-config-kentcdodds/jsx-a11y')), - ifAnyDep('react', require.resolve('eslint-config-kentcdodds/react')), - ].filter(Boolean), - rules: {}, + extends: [require.resolve('eslint-config-codfish')].filter(Boolean), + parserOptions: { + babelOptions: useBuiltinBabelConfig + ? {configFile: hereRelative('./babelrc.js')} + : {}, + }, + rules: { + // Explicitly set prettier rules to use our built in config if no + // local prettier config is found. + 'prettier/prettier': useBuiltinPrettierConfig + ? ['error', prettierConfig] + : 'error', + }, } diff --git a/src/config/huskyrc.js b/src/config/huskyrc.js index 51d61008..b74b6480 100644 --- a/src/config/huskyrc.js +++ b/src/config/huskyrc.js @@ -1,9 +1,10 @@ -const {resolveKcdScripts} = require('../utils') +const {resolveCodScripts} = require('../utils') -const kcdScripts = resolveKcdScripts() +const codScripts = resolveCodScripts() module.exports = { hooks: { - 'pre-commit': `"${kcdScripts}" pre-commit`, + 'pre-commit': `"${codScripts}" pre-commit`, + 'commit-msg': `"${codScripts}" commitlint -E HUSKY_GIT_PARAMS`, }, } diff --git a/src/config/index.js b/src/config/index.js index 77325da6..a616a205 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,5 +1,6 @@ module.exports = { babel: require('./babelrc'), + commitlint: require('./commitlint.config'), eslint: require('./eslintrc'), husky: require('./huskyrc'), jest: require('./jest.config'), diff --git a/src/config/jest.config.js b/src/config/jest.config.js index a628aa80..8e979623 100644 --- a/src/config/jest.config.js +++ b/src/config/jest.config.js @@ -1,9 +1,10 @@ const path = require('path') -const {ifAnyDep, hasFile, hasPkgProp, fromRoot} = require('../utils') +const {ifAnyDep, hasFile, ifFile, hasPkgProp, fromRoot} = require('../utils') const here = p => path.join(__dirname, p) -const useBuiltInBabelConfig = !hasFile('.babelrc') && !hasPkgProp('babel') +const useBuiltInBabelConfig = + !hasFile('.babelrc') && !hasFile('.babelrc.js') && !hasPkgProp('babel') const ignores = [ '/node_modules/', @@ -15,12 +16,8 @@ const ignores = [ ] const jestConfig = { - roots: [fromRoot('src')], - testEnvironment: ifAnyDep( - ['webpack', 'rollup', 'react', 'preact'], - 'jsdom', - 'node', - ), + roots: [fromRoot(hasFile('src') ? 'src' : '')], + testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'), testURL: 'http://localhost', moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], moduleDirectories: [ @@ -30,7 +27,10 @@ const jestConfig = { fromRoot('tests'), ], collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'], - testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'], + testMatch: [ + '**/__tests__/**/*.+(js|jsx|ts|tsx)', + '**/?(*.)+(spec|test).[jt]s?(x)', + ], testPathIgnorePatterns: [...ignores], coveragePathIgnorePatterns: [...ignores, 'src/(umd|cjs|esm)-entry.js$'], transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'], @@ -46,22 +46,33 @@ const jestConfig = { require.resolve('jest-watch-typeahead/filename'), require.resolve('jest-watch-typeahead/testname'), ], - snapshotSerializers: [require.resolve('jest-serializer-path')], } -const setupFiles = [ - 'tests/setup-env.js', - 'tests/setup-env.ts', - 'tests/setup-env.tsx', -] -for (const setupFile of setupFiles) { - if (hasFile(setupFile)) { - jestConfig.setupFilesAfterEnv = [fromRoot(setupFile)] - } +const setupFilesAfterEnv = [ + ifAnyDep( + '@testing-library/jest-dom', + '@testing-library/jest-dom/extend-expect', + ), + ifFile('jest.setup.js', fromRoot('jest.setup.js')), + ifFile('setupTests.js', fromRoot('setupTests.js')), + ifFile('setupTests.js', fromRoot('setupTests.js')), + ifFile('tests/setup-env.js', fromRoot('tests/setup-env.js')), + ifFile('tests/setup-env.ts', fromRoot('tests/setup-env.ts')), + ifFile('tests/setup-env.tsx', fromRoot('tests/setup-env.tsx')), +].filter(Boolean) + +if (setupFilesAfterEnv.length) { + jestConfig.setupFilesAfterEnv = setupFilesAfterEnv } if (useBuiltInBabelConfig) { - jestConfig.transform = {'^.+\\.(js|jsx|ts|tsx)$': here('./babel-transform')} + jestConfig.transform = { + '^.+\\.(js|jsx|ts|tsx)$': here('./babel-transform'), + } +} + +if (jestConfig.testEnvironment === 'jsdom') { + jestConfig.setupFiles = [require.resolve('react-app-polyfill/jsdom')] } module.exports = jestConfig diff --git a/src/config/lintstagedrc.js b/src/config/lintstagedrc.js index b367b89d..097ac432 100644 --- a/src/config/lintstagedrc.js +++ b/src/config/lintstagedrc.js @@ -1,13 +1,17 @@ -const {resolveKcdScripts, resolveBin} = require('../utils') +const {resolveCodScripts, resolveBin} = require('../utils') -const kcdScripts = resolveKcdScripts() +const codScripts = resolveCodScripts() const doctoc = resolveBin('doctoc') +// differs from kcd because of my eslint setup. Want to format everything other +// than js first, then format + lint js using eslint with prettier plugin module.exports = { 'README.md': [`${doctoc} --maxlevel 3 --notitle`], - '*.+(js|jsx|json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)': [ - `${kcdScripts} format`, - `${kcdScripts} lint`, - `${kcdScripts} test --findRelatedTests`, - ], + '*.+(json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)': [ + `${codScripts} format --no-eslint`, + ].filter(Boolean), + '*.js': [ + `${codScripts} lint --fix`, + `${codScripts} test --findRelatedTests`, + ].filter(Boolean), } diff --git a/src/config/prettierignore b/src/config/prettierignore index 5ab667c9..7bd6773f 100644 --- a/src/config/prettierignore +++ b/src/config/prettierignore @@ -4,3 +4,6 @@ dist/ build/ out/ .next/ +docs/ +package-lock.json +serviceWorker.js diff --git a/src/config/prettierrc.js b/src/config/prettierrc.js index 88af7683..2dff51a0 100644 --- a/src/config/prettierrc.js +++ b/src/config/prettierrc.js @@ -1,19 +1,20 @@ module.exports = { + printWidth: 100, + tabWidth: 2, + useTabs: false, + semi: true, arrowParens: 'avoid', - bracketSpacing: false, + bracketSpacing: true, embeddedLanguageFormatting: 'auto', endOfLine: 'lf', htmlWhitespaceSensitivity: 'css', insertPragma: false, - jsxBracketSameLine: false, jsxSingleQuote: false, - printWidth: 80, - proseWrap: 'always', quoteProps: 'as-needed', requirePragma: false, - semi: false, singleQuote: true, - tabWidth: 2, trailingComma: 'all', - useTabs: false, + jsxBracketSameLine: false, + proseWrap: 'always', + vueIndentScriptAndStyle: false, } diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js index 35b30cf8..dfdf5092 100644 --- a/src/config/rollup.config.js +++ b/src/config/rollup.config.js @@ -42,6 +42,7 @@ const umd = format === 'umd' const defaultGlobals = Object.keys(pkg.peerDependencies || {}).reduce( (deps, dep) => { + // eslint-disable-next-line no-param-reassign deps[dep] = capitalize(camelcase(dep)) return deps }, @@ -161,6 +162,7 @@ module.exports = { codeSplitting && ((writes = 0) => ({ onwrite() { + // eslint-disable-next-line if (++writes !== input.length) { return } diff --git a/src/index.js b/src/index.js index 6754c2b2..2dcdb9d1 100755 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,8 @@ let shouldThrow = false try { const [major, minor] = process.version.slice(1).split('.').map(Number) shouldThrow = - require(`${process.cwd()}/package.json`).name === 'kcd-scripts' && + // eslint-disable-next-line global-require,import/no-dynamic-require + require(`${process.cwd()}/package.json`).name === 'cod-scripts' && (major < 10 || (major === 10 && minor < 18)) } catch (error) { // ignore @@ -12,7 +13,7 @@ try { if (shouldThrow) { throw new Error( - 'You must use Node version 10.18 or greater to run the scripts within kcd-scripts, because we dogfood the untranspiled version of the scripts.', + 'You must use Node version 10.18 or greater to run the scripts within cod-scripts, because we dogfood the untranspiled version of the scripts.', ) } diff --git a/src/run-script.js b/src/run-script.js index 9cf4de1f..66705135 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -41,19 +41,39 @@ function getEnv() { // https://github.com/kentcdodds/kcd-scripts/issues/4 return Object.keys(process.env) .filter(key => process.env[key] !== undefined) - .reduce( - (envCopy, key) => { - envCopy[key] = process.env[key] - return envCopy - }, - { - [`SCRIPTS_${script.toUpperCase()}`]: true, - }, + .reduce((envCopy, key) => ({...envCopy, [key]: process.env[key]}), { + [`SCRIPTS_${script.toUpperCase()}`]: true, + }) +} + +function handleSignal(result) { + if (result.signal === 'SIGKILL') { + console.log( + `The script "${script}" failed because the process exited too early. ` + + 'This probably means the system ran out of memory or someone called ' + + '`kill -9` on the process.', ) + } else if (result.signal === 'SIGTERM') { + console.log( + `The script "${script}" failed because the process exited too early. ` + + 'Someone might have called `kill` or `killall`, or the system could ' + + 'be shutting down.', + ) + } + process.exit(1) +} + +function attemptResolve(...resolveArgs) { + try { + return require.resolve(...resolveArgs) + } catch (error) { + return null + } } function spawnScript() { - // get all the arguments of the script and find the position of our script commands + // get all the arguments of the script and find the position of our script + // commands const args = process.argv.slice(2) const scriptIndex = args.findIndex(x => [ @@ -63,6 +83,7 @@ function spawnScript() { 'pre-commit', 'test', 'validate', + 'commitlint', 'typecheck', ].includes(x), ) @@ -97,28 +118,3 @@ function spawnScript() { process.exit(result.status) } } - -function handleSignal(result) { - if (result.signal === 'SIGKILL') { - console.log( - `The script "${script}" failed because the process exited too early. ` + - 'This probably means the system ran out of memory or someone called ' + - '`kill -9` on the process.', - ) - } else if (result.signal === 'SIGTERM') { - console.log( - `The script "${script}" failed because the process exited too early. ` + - 'Someone might have called `kill` or `killall`, or the system could ' + - 'be shutting down.', - ) - } - process.exit(1) -} - -function attemptResolve(...resolveArgs) { - try { - return require.resolve(...resolveArgs) - } catch (error) { - return null - } -} diff --git a/src/scripts/__tests__/__snapshots__/format.js.snap b/src/scripts/__tests__/__snapshots__/format.js.snap index e24746ef..6452d6e2 100644 --- a/src/scripts/__tests__/__snapshots__/format.js.snap +++ b/src/scripts/__tests__/__snapshots__/format.js.snap @@ -1,9 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`format --config arg can be used for a custom config 1`] = `prettier --write **/*.+(js|json|less|css|ts|tsx|md) --config ./my-config.js`; +exports[`format --config arg can be used for a custom config 1`] = `prettier --ignore-path ./src/config/prettierignore --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --config ./my-config.js`; -exports[`format --ignore-path arg can be used for a custom ignore file 1`] = `prettier --write **/*.+(js|json|less|css|ts|tsx|md) --ignore-path ./.myignore`; +exports[`format --config arg can be used for a custom config 2`] = `prettier --ignore-path ./src/config/prettierignore --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --config ./my-config.js`; -exports[`format --no-write prevents --write argument from being added 1`] = `prettier **/*.+(js|json|less|css|ts|tsx|md) --no-write`; +exports[`format --ignore-path arg can be used for a custom ignore file 1`] = `prettier --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --ignore-path ./.myignore`; -exports[`format calls prettier CLI with args 1`] = `prettier --write my-src/**/*.js`; +exports[`format --ignore-path arg can be used for a custom ignore file 2`] = `prettier --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --ignore-path ./.myignore`; + +exports[`format --no-write prevents --write argument from being added 1`] = `prettier --ignore-path ./src/config/prettierignore **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --no-write`; + +exports[`format --no-write prevents --write argument from being added 2`] = `prettier --ignore-path ./src/config/prettierignore **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --no-write`; + +exports[`format calls prettier CLI with args 1`] = `prettier --ignore-path ./src/config/prettierignore --write my-src/**/*.js`; + +exports[`format calls prettier CLI with args 2`] = `prettier --ignore-path ./src/config/prettierignore --write my-src/**/*.js`; diff --git a/src/scripts/__tests__/__snapshots__/precommit.js.snap b/src/scripts/__tests__/__snapshots__/pre-commit.js.snap similarity index 100% rename from src/scripts/__tests__/__snapshots__/precommit.js.snap rename to src/scripts/__tests__/__snapshots__/pre-commit.js.snap diff --git a/src/scripts/__tests__/format.js b/src/scripts/__tests__/format.js index ec798516..489d0fc6 100644 --- a/src/scripts/__tests__/format.js +++ b/src/scripts/__tests__/format.js @@ -18,10 +18,13 @@ cases( // tests process.argv = ['node', '../format', ...args] require('../format') - expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1) + expect(crossSpawnSyncMock).toHaveBeenCalledTimes(2) const [firstCall] = crossSpawnSyncMock.mock.calls const [script, calledArgs] = firstCall expect([script, ...calledArgs].join(' ')).toMatchSnapshot() + const [secondCall] = crossSpawnSyncMock.mock.calls + const [secondScript, secondCalledArgs] = secondCall + expect([secondScript, ...secondCalledArgs].join(' ')).toMatchSnapshot() // afterEach process.exit = originalExit diff --git a/src/scripts/__tests__/helpers/serializers.js b/src/scripts/__tests__/helpers/serializers.js index 683d9dee..3cded83a 100644 --- a/src/scripts/__tests__/helpers/serializers.js +++ b/src/scripts/__tests__/helpers/serializers.js @@ -12,14 +12,14 @@ export const winPathSerializer = { test: val => typeof val === 'string' && val.includes('\\'), } -export const relativePathSerializer = { - print: val => normalizePaths(val), - test: val => normalizePaths(val) !== val, -} - function normalizePaths(value) { if (typeof value !== 'string') { return value } return slash(value.split(process.cwd()).join('')) } + +export const relativePathSerializer = { + print: val => normalizePaths(val), + test: val => normalizePaths(val) !== val, +} diff --git a/src/scripts/__tests__/precommit.js b/src/scripts/__tests__/pre-commit.js similarity index 100% rename from src/scripts/__tests__/precommit.js rename to src/scripts/__tests__/pre-commit.js diff --git a/src/scripts/__tests__/validate.js b/src/scripts/__tests__/validate.js index b0eed6ed..c92380e3 100644 --- a/src/scripts/__tests__/validate.js +++ b/src/scripts/__tests__/validate.js @@ -3,6 +3,46 @@ import {unquoteSerializer} from './helpers/serializers' expect.addSnapshotSerializer(unquoteSerializer) +function setupWithScripts(scripts = ['test', 'lint', 'build', 'typecheck']) { + return function setup() { + const utils = require('../../utils') + const originalIfScript = utils.ifScript + utils.ifScript = (script, t, f) => (scripts.includes(script) ? t : f) + return function teardown() { + utils.ifScript = originalIfScript + } + } +} + +function setupWithArgs(args = []) { + return function setup() { + const utils = require('../../utils') + const originalResolveBin = utils.resolveBin + utils.resolveBin = (modName, {executable = modName} = {}) => executable + const originalArgv = process.argv + process.argv = ['node', '../format', ...args] + return function teardown() { + process.argv = originalArgv + utils.resolveBin = originalResolveBin + } + } +} + +function withDefaultSetup(setupFn) { + return function defaultSetup() { + const utils = require('../../utils') + utils.resolveBin = (modName, {executable = modName} = {}) => executable + const argsTeardown = setupWithArgs()() + const teardownScripts = setupWithScripts()() + const teardownFn = setupFn() + return function defaultTeardown() { + argsTeardown() + teardownFn() + teardownScripts() + } + } +} + cases( 'validate', ({setup = () => () => {}}) => { @@ -62,43 +102,3 @@ cases( }, }, ) - -function setupWithScripts(scripts = ['test', 'lint', 'build', 'typecheck']) { - return function setup() { - const utils = require('../../utils') - const originalIfScript = utils.ifScript - utils.ifScript = (script, t, f) => (scripts.includes(script) ? t : f) - return function teardown() { - utils.ifScript = originalIfScript - } - } -} - -function setupWithArgs(args = []) { - return function setup() { - const utils = require('../../utils') - const originalResolveBin = utils.resolveBin - utils.resolveBin = (modName, {executable = modName} = {}) => executable - const originalArgv = process.argv - process.argv = ['node', '../format', ...args] - return function teardown() { - process.argv = originalArgv - utils.resolveBin = originalResolveBin - } - } -} - -function withDefaultSetup(setupFn) { - return function defaultSetup() { - const utils = require('../../utils') - utils.resolveBin = (modName, {executable = modName} = {}) => executable - const argsTeardown = setupWithArgs()() - const teardownScripts = setupWithScripts()() - const teardownFn = setupFn() - return function defaultTeardown() { - argsTeardown() - teardownFn() - teardownScripts() - } - } -} diff --git a/src/scripts/build/index.js b/src/scripts/build/index.js index 9b96498f..a209b7aa 100644 --- a/src/scripts/build/index.js +++ b/src/scripts/build/index.js @@ -2,7 +2,7 @@ if (process.argv.includes('--browser')) { console.error('--browser has been deprecated, use --bundle instead') } -if (process.argv.includes('--bundle') || process.argv.includes('--browser')) { +if (process.argv.includes('--bundle')) { require('./rollup') } else { require('./babel') diff --git a/src/scripts/build/rollup.js b/src/scripts/build/rollup.js index 6ac88a6f..19b858ed 100644 --- a/src/scripts/build/rollup.js +++ b/src/scripts/build/rollup.js @@ -25,6 +25,7 @@ const parsedArgs = yargsParser(args) const useBuiltinConfig = !args.includes('--config') && !hasFile('rollup.config.js') +// eslint-disable-next-line const config = useBuiltinConfig ? `--config ${hereRelative('../../config/rollup.config.js')}` : args.includes('--config') diff --git a/src/scripts/commitlint.js b/src/scripts/commitlint.js new file mode 100644 index 00000000..fbbaa1ee --- /dev/null +++ b/src/scripts/commitlint.js @@ -0,0 +1,26 @@ +const path = require('path') +const spawn = require('cross-spawn') +const {hasPkgProp, resolveBin, hasFile} = require('../utils') + +const args = process.argv.slice(2) +const here = p => path.join(__dirname, p) +const hereRelative = p => here(p).replace(process.cwd(), '.') + +const useBuiltinConfig = + !args.includes('--config') && + !args.includes('-g') && + !hasFile('commitlint.config.js') && + !hasFile('.commitlintrc.js') && + !hasFile('.commitlintrc.json') && + !hasFile('.commitlintrc.yml') && + !hasPkgProp('commitlint') + +const config = useBuiltinConfig + ? ['--config', hereRelative('../config/commitlint.config.js')] + : [] + +const result = spawn.sync(resolveBin('commitlint'), [...config, ...args], { + stdio: 'inherit', +}) + +process.exit(result.status) diff --git a/src/scripts/format.js b/src/scripts/format.js index 2142084d..148da7b5 100644 --- a/src/scripts/format.js +++ b/src/scripts/format.js @@ -1,7 +1,12 @@ const path = require('path') const spawn = require('cross-spawn') const yargsParser = require('yargs-parser') -const {resolveBin, hasFile, hasLocalConfig} = require('../utils') +const { + resolveBin, + hasFile, + hasLocalConfig, + resolveCodScripts, +} = require('../utils') const args = process.argv.slice(2) const parsedArgs = yargsParser(args) @@ -14,7 +19,6 @@ const useBuiltinConfig = const config = useBuiltinConfig ? ['--config', hereRelative('../config/prettierrc.js')] : [] - const useBuiltinIgnore = !args.includes('--ignore-path') && !hasFile('.prettierignore') const ignore = useBuiltinIgnore @@ -27,15 +31,28 @@ const write = args.includes('--no-write') ? [] : ['--write'] // the full file path, we make that non-absolute so it is treated as a glob, // This way the prettierignore will be applied const relativeArgs = args.map(a => a.replace(`${process.cwd()}/`, '')) - const filesToApply = parsedArgs._.length ? [] - : ['**/*.+(js|json|less|css|ts|tsx|md)'] + : ['**/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx)'] -const result = spawn.sync( +// run prettier on all non-js files +const prettierResult = spawn.sync( resolveBin('prettier'), [...config, ...ignore, ...write, ...filesToApply].concat(relativeArgs), {stdio: 'inherit'}, ) -process.exit(result.status) +if (prettierResult.status !== 0 || args.includes('--no-eslint')) { + process.exit(prettierResult.status) +} + +// run eslint for js files (`eslint-plugin-prettier` will run prettier for us) +const eslintResult = spawn.sync( + resolveCodScripts(), + ['lint', '--fix'].concat(args), + { + stdio: 'inherit', + }, +) + +process.exit(eslintResult.status) diff --git a/src/scripts/lint.js b/src/scripts/lint.js index 93aadc3d..9baeebb2 100644 --- a/src/scripts/lint.js +++ b/src/scripts/lint.js @@ -40,7 +40,6 @@ const cache = args.includes('--no-cache') ] const filesGiven = parsedArgs._.length > 0 - const filesToApply = filesGiven ? [] : ['.'] if (filesGiven) { diff --git a/src/scripts/pre-commit.js b/src/scripts/pre-commit.js index 2c1fdc48..97f084aa 100644 --- a/src/scripts/pre-commit.js +++ b/src/scripts/pre-commit.js @@ -1,6 +1,6 @@ const path = require('path') const spawn = require('cross-spawn') -const {hasPkgProp, hasFile, resolveBin} = require('../utils') +const {hasPkgProp, hasFile, resolveBin, ifScript} = require('../utils') const here = p => path.join(__dirname, p) const hereRelative = p => here(p).replace(process.cwd(), '.') @@ -26,11 +26,15 @@ function go() { if (result.status !== 0) return result.status - result = spawn.sync('npm', ['run', 'validate'], { - stdio: 'inherit', - }) + if (ifScript('validate', true)) { + result = spawn.sync('npm', ['run', 'validate'], { + stdio: 'inherit', + }) + + return result.status + } - return result.status + return 0 } process.exit(go()) diff --git a/src/scripts/validate.js b/src/scripts/validate.js index 7d67c285..a3b74c6c 100644 --- a/src/scripts/validate.js +++ b/src/scripts/validate.js @@ -38,7 +38,9 @@ if (scriptCount > 0) { const result = spawn.sync( resolveBin('concurrently'), getConcurrentlyArgs(scripts), - {stdio: 'inherit'}, + { + stdio: 'inherit', + }, ) process.exit(result.status) diff --git a/src/utils.js b/src/utils.js index fdb00820..9fc7f921 100644 --- a/src/utils.js +++ b/src/utils.js @@ -15,18 +15,6 @@ const {packageJson: pkg, path: pkgPath} = readPkgUp.sync({ }) const appDirectory = path.dirname(pkgPath) -function resolveKcdScripts() { - if ( - pkg.name === 'kcd-scripts' || - // this happens on install of husky within kcd-scripts locally - appDirectory.includes(path.join(__dirname, '..')) - ) { - return require.resolve('./').replace(process.cwd(), '.') - } - return resolveBin('kcd-scripts') -} - -// eslint-disable-next-line complexity function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) { let pathFromWhich try { @@ -38,7 +26,7 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) { try { const modPkgPath = require.resolve(`${modName}/package.json`) const modPkgDir = path.dirname(modPkgPath) - const {bin} = require(modPkgPath) + const { bin } = require(modPkgPath); // eslint-disable-line const binPath = typeof bin === 'string' ? bin : bin[executable] const fullPathToBin = path.join(modPkgDir, binPath) if (fullPathToBin === pathFromWhich) { @@ -53,6 +41,17 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) { } } +function resolveCodScripts() { + if ( + pkg.name === 'cod-scripts' || + // this happens on install of husky within cod-scripts locally + appDirectory.includes(path.join(__dirname, '..')) + ) { + return require.resolve('./').replace(process.cwd(), '.') + } + return resolveBin('cod-scripts') +} + const fromRoot = (...p) => path.join(appDirectory, ...p) const hasFile = (...p) => fs.existsSync(fromRoot(...p)) const ifFile = (files, t, f) => @@ -78,6 +77,14 @@ const ifDevDep = ifPkgSubProp('devDependencies') const ifAnyDep = (deps, t, f) => (hasAnyDep(arrify(deps)) ? t : f) const ifScript = ifPkgSubProp('scripts') +function envIsSet(name) { + return ( + process.env.hasOwnProperty(name) && + process.env[name] && + process.env[name] !== 'undefined' + ) +} + const hasTypescript = hasAnyDep('typescript') && hasFile('tsconfig.json') const ifTypescript = (t, f) => (hasTypescript ? t : f) @@ -92,14 +99,6 @@ function parseEnv(name, def) { return def } -function envIsSet(name) { - return ( - process.env.hasOwnProperty(name) && - process.env[name] && - process.env[name] !== 'undefined' - ) -} - function getConcurrentlyArgs(scripts, {killOthers = true} = {}) { const colors = [ 'bgBlue', @@ -111,8 +110,10 @@ function getConcurrentlyArgs(scripts, {killOthers = true} = {}) { 'bgBlack', 'bgYellow', ] + // eslint-disable-next-line no-param-reassign scripts = Object.entries(scripts).reduce((all, [name, script]) => { if (script) { + // eslint-disable-next-line no-param-reassign all[name] = script } return all @@ -131,8 +132,9 @@ function getConcurrentlyArgs(scripts, {killOthers = true} = {}) { '--prefix', '[{name}]', '--names', Object.keys(scripts).join(','), '--prefix-colors', prefixColors, - ...Object.values(scripts).map(s => JSON.stringify(s)), // stringify escapes quotes ✨ - ].filter(Boolean) + ...Object.values(scripts) + .map(s => JSON.stringify(s)), // stringify escapes quotes ✨ + ].filter(Boolean); } function uniq(arr) { @@ -235,7 +237,7 @@ module.exports = { parseEnv, pkg, resolveBin, - resolveKcdScripts, + resolveCodScripts, uniq, writeExtraEntry, generateTypeDefs,