Skip to content

Commit

Permalink
feat(packages): use rollup for packages build
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed Feb 1, 2018
1 parent 2c2265f commit f24cb08
Show file tree
Hide file tree
Showing 56 changed files with 337 additions and 505 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Expand Up @@ -9,8 +9,7 @@ package-lock.json

build

/packages/*/lib
/packages/*/es
/packages/*/cjs

*.lerna_backup

38 changes: 29 additions & 9 deletions Makefile
Expand Up @@ -60,7 +60,18 @@ fmt: ##@0 global format code using prettier (js, css, md)
"examples/*/src/**/*.{js,css}" \
"README.md"

fmt-check: ##@0 global check if files were all formatted using prettier
@echo "${YELLOW}Checking formatting${RESET}"
@./node_modules/.bin/prettier --color --list-different \
"packages/*/{src,stories,tests}/**/*.js" \
"packages/*/README.md" \
"website/src/**/*.{js,css}" \
"storybook/stories/**/*.{js,css}" \
"examples/*/src/**/*.{js,css}" \
"README.md"

test-all: ##@0 global run all checks/tests (packages, website & examples)
@make fmt-check
@make packages-lint
@make packages-test

Expand Down Expand Up @@ -102,10 +113,17 @@ packages-test: ##@1 packages run tests for all packages
#@./node_modules/.bin/lerna run --concurrency 1 --stream test
@./node_modules/.bin/lerna run --concurrency 1 test

package-build-%: ##@1 packages build a package
@echo "${YELLOW}Building package ${WHITE}@nivo/${*}${RESET}"
@export PACKAGE=${*}; ./node_modules/.bin/rollup -c conf/rollup.config.js

packages-build: ##@1 packages build all packages
@echo "${YELLOW}Building all packages${RESET}"
@$(foreach source, $(SOURCES), $(call clean-source-lib, $(source)))
@./node_modules/.bin/lerna run build
@find ./packages -type d -name 'nivo-*' \
! -path "*-babel-preset" \
| awk -Fnivo- '{print $$NF}' \
| xargs -I '{}' \
sh -c 'PACKAGE={} make package-build-{}'

packages-screenshots: ##@1 packages generate screenshots for packages readme (website dev server must be running)
@node scripts/capture.js
Expand All @@ -116,19 +134,21 @@ packages-publish: ##@1 packages publish all packages
@echo "${YELLOW}Publishing packages${RESET}"
@./node_modules/.bin/lerna publish ---exact

package-build-watch-%: ##@1 packages build package (es flavor) on change, eg. `package-build-watch-bar`
@echo "${YELLOW}Running build watcher for package ${WHITE}${*}${RESET}"
@cd packages/nivo-${*} && yarn build:es:watch
packages-publish-next: ##@1 packages publish all packages for @next npm tag
@make packages-build

@echo "${YELLOW}Publishing packages${RESET}"
@./node_modules/.bin/lerna publish ---exact --npm-tag=next

package-build-%: ##@1 packages build package (all flavors), eg. `package-build-bar`
@echo "${YELLOW}Build package ${WHITE}${*}${RESET}"
@cd packages/nivo-${*} && yarn build
package-watch-%: ##@1 packages build package (es flavor) on change, eg. `package-build-watch-bar`
@echo "${YELLOW}Running build watcher for package ${WHITE}@nivo/${*}${RESET}"
@export PACKAGE=${*}; ./node_modules/.bin/rollup -c conf/rollup.config.js -w

package-dev-%: ##@1 packages setup package for development, link to website, run watcher
@echo "${YELLOW}Preparing package ${WHITE}${*}${YELLOW} for development${RESET}"
@cd packages/nivo-${*} && yarn link
@cd website && yarn link @nivo/${*}
@make package-build-watch-${*}
@make package-watch-${*}

########################################################################################################################
#
Expand Down
76 changes: 76 additions & 0 deletions conf/rollup.config.js
@@ -0,0 +1,76 @@
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import stripBanner from 'rollup-plugin-strip-banner'

const pkg = process.env.PACKAGE

export default {
input: `./packages/nivo-${pkg}/src/index.js`,
output: {
file: `./packages/nivo-${pkg}/cjs/nivo-${pkg}.js`,
format: 'cjs'
},
name: '@nivo/axes',
external: [
'@nivo/axes',
'@nivo/core',
'@nivo/legends',
'@nivo/scales',
'd3-chord',
'd3-format',
'd3-scale',
'd3-shape',
'd3-voronoi',
'd3-ease',
'd3-time',
'd3-time-format',
'd3-color',
'd3-hierarchy',
'd3-interpolate',
'd3-scale-chromatic',
'd3-sankey',
'react-measure',
'react-motion',
'react',
'prop-types',
'lodash',
'lodash/without',
'lodash/isPlainObject',
'lodash/pick',
'lodash/cloneDeep',
'lodash/min',
'lodash/max',
'lodash.range',
'lodash.random',
'lodash.shuffle',
'uniq',
'recompose/setDisplayName',
'recompose/defaultProps',
'recompose/withState',
'recompose/shouldUpdate',
'recompose/compose',
'recompose/withPropsOnChange',
'recompose/withStateHandlers',
'recompose/setPropTypes',
'recompose/withProps',
'recompose/withHandlers',
'recompose/pure',
'react-motion',
],
plugins: [
stripBanner({
include: `./packages/nivo-${pkg}/src/**/*.js`,
}),
resolve({
module: true,
jsnext: true,
main: true,
browser: true,
extensions: ['.js'],
modulesOnly: true,
}),
babel({
plugins: ['external-helpers']
}),
]
}
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -32,7 +32,12 @@
"prop-types": "^15.5.10",
"puppeteer": "^0.13.0",
"react": "16.2.0",
"react-dom": "16.2.0"
"react-dom": "16.2.0",
"rollup": "^0.55.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-prettier": "^0.4.0",
"rollup-plugin-strip-banner": "^0.2.0"
},
"scripts": {
"fmt": "prettier --print-width=100 --tab-width=4 --bracket-spacing --no-semi --trailing-comma es5 --single-quote --color --write \"{src,specs,test,.storybook,stories}/**/*.js\"",
Expand Down
20 changes: 0 additions & 20 deletions packages/nivo-bar/.npmignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/nivo-bar/index.js
@@ -0,0 +1 @@
module.exports = require('./cjs/nivo-bar')
16 changes: 7 additions & 9 deletions packages/nivo-bar/package.json
Expand Up @@ -2,9 +2,12 @@
"name": "@nivo/bar",
"version": "0.33.0",
"license": "MIT",
"main": "./lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"main": "./index.js",
"files": [
"README.md",
"index.js",
"cjs/"
],
"dependencies": {
"@nivo/core": "0.33.0",
"@nivo/legends": "0.33.0",
Expand Down Expand Up @@ -37,11 +40,6 @@
"scripts": {
"lint": "eslint src stories tests",
"test": "jest --verbose ./tests",
"test:cover": "jest --verbose --coverage ./tests",
"build:commonjs": "rm -rf lib && cross-env NODE_ENV=commonjs babel src --out-dir lib",
"build:commonjs:watch": "npm run build:commonjs -- --watch",
"build:es": "rm -rf es && cross-env NODE_ENV=es babel src --out-dir es",
"build:es:watch": "npm run build:es -- --watch",
"build": "npm run build:commonjs && npm run build:es"
"test:cover": "jest --verbose --coverage ./tests"
}
}
21 changes: 0 additions & 21 deletions packages/nivo-calendar/.npmignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/nivo-calendar/index.js
@@ -0,0 +1 @@
module.exports = require('./cjs/nivo-calendar')
16 changes: 7 additions & 9 deletions packages/nivo-calendar/package.json
Expand Up @@ -2,9 +2,12 @@
"name": "@nivo/calendar",
"version": "0.33.0",
"license": "MIT",
"main": "./lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"main": "./index.js",
"files": [
"README.md",
"index.js",
"cjs/"
],
"dependencies": {
"@nivo/core": "0.33.0",
"@nivo/legends": "0.33.0",
Expand Down Expand Up @@ -33,11 +36,6 @@
"access": "public"
},
"scripts": {
"lint": "eslint src stories tests",
"build:commonjs": "rm -rf lib && cross-env NODE_ENV=commonjs babel src --out-dir lib",
"build:commonjs:watch": "npm run build:commonjs -- --watch",
"build:es": "rm -rf es && cross-env NODE_ENV=es babel src --out-dir es",
"build:es:watch": "npm run build:es -- --watch",
"build": "npm run build:commonjs && npm run build:es"
"lint": "eslint src stories tests"
}
}
21 changes: 0 additions & 21 deletions packages/nivo-chord/.npmignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/nivo-chord/index.js
@@ -0,0 +1 @@
module.exports = require('./cjs/nivo-chord')
16 changes: 7 additions & 9 deletions packages/nivo-chord/package.json
Expand Up @@ -2,9 +2,12 @@
"name": "@nivo/chord",
"version": "0.33.0",
"license": "MIT",
"main": "./lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"main": "./index.js",
"files": [
"README.md",
"index.js",
"cjs/"
],
"dependencies": {
"@nivo/core": "0.33.0",
"@nivo/legends": "0.33.0",
Expand Down Expand Up @@ -35,11 +38,6 @@
"access": "public"
},
"scripts": {
"lint": "eslint src stories tests",
"build:commonjs": "rm -rf lib && cross-env NODE_ENV=commonjs babel src --out-dir lib",
"build:commonjs:watch": "npm run build:commonjs -- --watch",
"build:es": "rm -rf es && cross-env NODE_ENV=es babel src --out-dir es",
"build:es:watch": "npm run build:es -- --watch",
"build": "npm run build:commonjs && npm run build:es"
"lint": "eslint src stories tests"
}
}
21 changes: 0 additions & 21 deletions packages/nivo-circle-packing/.npmignore

This file was deleted.

1 change: 1 addition & 0 deletions packages/nivo-circle-packing/index.js
@@ -0,0 +1 @@
module.exports = require('./cjs/nivo-circle-packing')
14 changes: 6 additions & 8 deletions packages/nivo-circle-packing/package.json
Expand Up @@ -2,9 +2,12 @@
"name": "@nivo/circle-packing",
"version": "0.33.0",
"license": "MIT",
"main": "./lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"main": "./index.js",
"files": [
"README.md",
"index.js",
"cjs/"
],
"dependencies": {
"@nivo/core": "0.33.0",
"d3-hierarchy": "^1.1.5",
Expand All @@ -28,10 +31,5 @@
"access": "public"
},
"scripts": {
"build:commonjs": "rm -rf lib && cross-env NODE_ENV=commonjs babel src --out-dir lib",
"build:commonjs:watch": "npm run build:commonjs -- --watch",
"build:es": "rm -rf es && cross-env NODE_ENV=es babel src --out-dir es",
"build:es:watch": "npm run build:es -- --watch",
"build": "npm run build:commonjs && npm run build:es"
}
}
20 changes: 0 additions & 20 deletions packages/nivo-core/.npmignore

This file was deleted.

0 comments on commit f24cb08

Please sign in to comment.