Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
fix(build): move to kcd-scripts (#7)
Browse files Browse the repository at this point in the history
**What**: This moves all the tooling to kcd-scripts

**Why**: Simplifies a bunch of stuff and makes it easier to keep things
updated

**How**: Remove a bunch of code and deps and use kcd-scripts instead
  • Loading branch information
Kent C. Dodds committed Oct 10, 2017
1 parent 0df5637 commit 18e0add
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 359 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

19 changes: 0 additions & 19 deletions .babelrc.js

This file was deleted.

4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

19 changes: 0 additions & 19 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist
.next
.eslintcache
storybook-static
preact/

# these cause more harm than good
# when working with contributors
Expand Down
20 changes: 10 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ sudo: false
language: node_js
cache:
directories:
- node_modules
- ~/.npm
notifications:
email: false
node_js:
- '8'
script:
- npm start validate
after_success:
- npx codecov
- npm i -g semantic-release && semantic-release pre && npm publish && semantic-release post
node_js: '8'
install: npm install
before_script:
- cd stories
- npm install
- cd ..
script: npm run validate
after_success: kcd-scripts travis-after-success
branches:
only:
- master
only: master
38 changes: 6 additions & 32 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ Thanks for being willing to contribute!

1. Fork and clone the repo
2. `$ npm install` to install dependencies
3. `$ npm start validate` to validate you've got it working
3. `$ npm run validate` to validate you've got it working
4. Create a branch for your PR

This project uses [`nps`](https://github.com/kentcdodds/nps) and you can run `npm start help` to see what
scripts are available.

> Tip: Keep your `master` branch pointing at the original repository and make
> pull requests from branches on your fork. To do this, run:
>
Expand All @@ -31,30 +28,14 @@ scripts are available.
> branch. Whenever you want to update your version of `master`, do a regular
> `git pull`.
### Local development

This project uses [Storybook](https://storybook.js.org) for local development. Run the following commands to get setup:

1. `$ cd stories` to change to the `/stories` diretory
2. `$ npm install` to install the Storybook dependencies
3. `$ cd ..` to change back to the root directory

With the Storybook dependancies installed, run the following command to start your local environment:

```console
npm start storybook
```

Open [`http://localhost:6006/`](http://localhost:6006/) in your browser and start developing!

## Add yourself as a contributor

This project follows the [all contributors][all-contributors] specification.
To add yourself to the table of contributors on the README.md, please use the
To add yourself to the table of contributors on the `README.md`, please use the
automated script as part of your PR:

```console
npm start contributors.add
npm run add-contributor
```

Follow the prompt and commit `.all-contributorsrc` and `README.md` in the PR.
Expand All @@ -64,14 +45,8 @@ contribution type.

## Committing and Pushing changes

This project uses [`semantic-release`][semantic-release] to do automatic
releases and generate a changelog based on the commit history. So we follow
[a convention][convention] for commit messages. You don't have to follow this
convention if you don't like to. Just know that when we merge your commit, we'll
probably use "Squash and Merge" so we can change the commit message :)

Please make sure to run the tests before you commit your changes. You can run
`npm start test.update` which will update any snapshots that need updating.
`npm run test:update` which will update any snapshots that need updating.
Make sure to include those changes (if they exist) in your commit.

### opt into git hooks
Expand All @@ -90,10 +65,9 @@ pre-commit

Please checkout the [the open issues][issues]

Also, please watch the repo and respond to questions/bug reports/feature requests! Thanks!
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
[semantic-release]: https://npmjs.com/package/semantic-release
[convention]: https://github.com/conventional-changelog/conventional-changelog-angular/blob/ed32559941719a130bb0327f886d6a32a8cbc2ba/convention.md
[all-contributors]: https://github.com/kentcdodds/all-contributors
[issues]: https://github.com/kentcdodds/react-toggled/issues
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [
react-toggled ⚛️



](#react-toggled-)
- [The problem](#the-problem)
- [This solution](#this-solution)
- [Installation](#installation)
- [Usage](#usage)
- [Props:](#props)
- [Examples](#examples)
- [Inspiration](#inspiration)
- [Other Solutions](#other-solutions)
- [Contributors](#contributors)
- [LICENSE](#license)

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

<h1 align="center">
react-toggled ⚛️
<br>
Expand Down Expand Up @@ -53,8 +76,8 @@ npm install --save react-toggled
> have those installed as well.
> Note also this library supports `preact` out of the box. If you are using
> `preact` then look in the `dist/` folder and use the module you want with the
> `preact` suffix.
> `preact` then look in the `preact/` folder and use the module you want.
> You should be able to simply do: `import Toggle from 'react-toggled/preact'`
## Usage

Expand Down
27 changes: 11 additions & 16 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
module.exports = {
roots: ['./src'],
testEnvironment: 'jsdom',
collectCoverageFrom: ['src/**/*.js'],
testPathIgnorePatterns: ['/node_modules/', '/fixtures/'],
coveragePathIgnorePatterns: ['/node_modules/', '/fixtures/'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
snapshotSerializers: ['jest-serializer-html', 'enzyme-to-json/serializer'],
}
const jestConfig = require('kcd-scripts/config').jest

jestConfig.snapshotSerializers = jestConfig.snapshotSerializers || []
jestConfig.snapshotSerializers.push(
'jest-serializer-html',
'enzyme-to-json/serializer',
)
jestConfig.setupFiles = jestConfig.setupFiles || []
jestConfig.setupFiles.push('<rootDir>/other/setup-tests.js')

module.exports = jestConfig
20 changes: 10 additions & 10 deletions other/build.test.js → other/misc-tests/__tests__/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
*/
import assert from 'assert'

import esImport from '../dist/react-toggled.es'
import esImport from '../../../dist/react-toggled.esm'

import cjsImport from '../' // picks up the main from package.json
import cjsImport from '../../../' // picks up the main from package.json

import umdImport from '../dist/react-toggled.umd'
import umdImport from '../../../dist/react-toggled.umd'

// intentionally left out because you shouldn't ever
// try to require the ES file in CommonJS
// const esRequire = require('../dist/react-toggled.es')
const cjsRequire = require('../') // picks up the main from package.json
const umdRequire = require('../dist/react-toggled.umd')
// const esRequire = require('../../../dist/react-toggled.es')
const cjsRequire = require('../../../') // picks up the main from package.json
const umdRequire = require('../../../dist/react-toggled.umd')

test('stuff is good', () => {
assert(isToggleComponent(esImport), 'ES build has a problem with ES Modules')

assert(
isToggleComponent(cjsImport),
'CJS build has a problem with ES Modules'
'CJS build has a problem with ES Modules',
)

assert(isToggleComponent(cjsRequire), 'CJS build has a problem with CJS')

assert(
isToggleComponent(umdImport),
'UMD build has a problem with ES Modules'
'UMD build has a problem with ES Modules',
)

assert(isToggleComponent(umdRequire), 'UMD build has a problem with CJS')
Expand All @@ -47,8 +47,8 @@ function isToggleComponent(thing) {
if (typeof thing !== 'function') {
console.error(
`react-toggled thing should be a function. It's a ${typeof thing} with the properties of: ${Object.keys(
thing
).join(', ')}`
thing,
).join(', ')}`,
)
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for preact before running this test.

import preact from 'preact'
import render from 'preact-render-to-string'
import Toggle from '../dist/react-toggled.preact.cjs'
import Toggle from '../../../preact/dist/react-toggled.esm'

test('works with preact', () => {
const childSpy = jest.fn(({on, getTogglerProps}) => (
Expand Down
6 changes: 6 additions & 0 deletions other/misc-tests/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const jestConfig = require('kcd-scripts/config').jest

module.exports = Object.assign(jestConfig, {
roots: ['.'],
testEnvironment: 'jsdom',
})
37 changes: 37 additions & 0 deletions other/raf-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable */
/**
* requestAnimationFrame polyfill from https://gist.github.com/paulirish/1579671
* http://paulirish.com/2011/requestanimationframe-for-smart-animating/
* http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
* requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
* MIT license
*/

var lastTime = 0
var vendors = ['ms', 'moz', 'webkit', 'o']
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']
window.cancelAnimationFrame =
window[vendors[x] + 'CancelAnimationFrame'] ||
window[vendors[x] + 'CancelRequestAnimationFrame']
}

if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime()
var timeToCall = Math.max(0, 16 - (currTime - lastTime))
var id = window.setTimeout(function() {
// eslint-disable-next-line consumerweb/no-callback-literal
callback(currTime + timeToCall)
}, timeToCall)
lastTime = currTime + timeToCall
return id
}
global.requestAnimationFrame = window.requestAnimationFrame
}

if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id)
}
}
6 changes: 6 additions & 0 deletions other/setup-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// eslint-disable-next-line import/no-unassigned-import
import './raf-polyfill'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

Enzyme.configure({adapter: new Adapter()})
Loading

0 comments on commit 18e0add

Please sign in to comment.