diff --git a/Makefile b/Makefile index 63a97097..4a2f1921 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ -NODE=$(shell which node) -NPM=$(shell which npm) -YARN=$(shell which yarn) -JQ=$(shell which jq) +NODE=$(shell which node 2> /dev/null) +NPM=$(shell which npm 2> /dev/null) +YARN=$(shell which yarn 2> /dev/null) +JQ=$(shell which jq 2> /dev/null) + +PKM?=$(if $(YARN),$(YARN),$(shell which npm)) BABEL=./node_modules/.bin/babel COVERALLS=./node_modules/coveralls/bin/coveralls.js @@ -29,10 +31,9 @@ help: info @echo " make publish-all - publish version and docs." info: - @echo node version: `$(NODE) --version` "($(NODE))" - @echo npm version: `$(NPM) --version` "($(NPM))" - @echo yarn version: `$(YARN) --version` "($(YARN))" - @echo jq version: `$(JQ) --version` "($(JQ))" + @[[ ! -z "$(NODE)" ]] && echo node version: `$(NODE) --version` "$(NODE)" + @[[ ! -z "$(PKM)" ]] && echo $(shell basename $(PKM)) version: `$(PKM) --version` "$(PKM)" + @[[ ! -z "$(JQ)" ]] && echo jq version: `$(JQ) --version` "$(JQ)" deps: deps-project deps-docs @@ -54,7 +55,7 @@ tests-single-run: @npm run test -- --single-run coveralls: - -cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js 2>/dev/null + -cat ./coverage/lcov.info | $(COVERALLS) 2>/dev/null tests-ci: clean lint @COVERAGE=$(COVERAGE) make tests-single-run coveralls @@ -91,7 +92,7 @@ compile: build: compile @echo "[Building dists]" - @./node_modules/.bin/webpack --config webpack.dist.config.js + @./node_modules/.bin/webpack --config ./scripts/webpack.dist.config.js release-commit: git commit --allow-empty -m "Release v`cat .version`." diff --git a/bootstrap.sh b/bootstrap.sh deleted file mode 100644 index 70fc3326..00000000 --- a/bootstrap.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -NODE=`which node` -NPM=`which npm` -YARN=`which yarn` -JQ=`which jq` - -echo $NODE $NPM $YARN $JQ - -if [[ ! -z "$NODE" ]]; then - echo "Node is installed and it's version is: `$NODE --version`" -else - echo "Please, install node.js." - exit 1 -fi - -if [[ ! -z "$NPM" ]]; then - echo "NPM is installed and it's version is: `$NPM --version`" -else - echo "Please, install npm." - exit 1 -fi - -if [[ ! -z "$YARN" ]]; then - echo "yarn is installed and it's version is: `$YARN --version`" -else - echo "yarn is optional." -fi - -if [[ ! -z "$JQ" ]]; then - echo "jq is installed and it's version is: `$JQ --version`" -else - echo "jq is optional and used only for publish purpose." -fi - -npm install -g gitbook-cli diff --git a/karma.conf.js b/karma.conf.js index b9d6408d..57853d94 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,7 +18,7 @@ module.exports = function(config) { files: ['./specs/index.js'], - webpack: require('./webpack.test.config'), + webpack: require('./scripts/webpack.test.config'), webpackMiddleware: { stats: 'errors-only' }, diff --git a/package.json b/package.json index 6e4e3ab9..0e21ccb2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "example": "examples" }, "scripts": { - "start": "./node_modules/.bin/webpack-dev-server --inline --host 127.0.0.1 --content-base examples/", + "start": "npx webpack-dev-server --config ./scripts/webpack.config.js --inline --host 127.0.0.1 --content-base examples/", "test": "cross-env NODE_ENV=test karma start", "lint": "eslint src/ specs/" }, diff --git a/scripts/defaultConfig.js b/scripts/defaultConfig.js new file mode 100644 index 00000000..7f37c77c --- /dev/null +++ b/scripts/defaultConfig.js @@ -0,0 +1,20 @@ +const path = require('path'); + +module.exports = { + mode: 'development', + output: { + filename: '[name].js', + path: path.resolve(__dirname, './examples/__build__'), + publicPath: '/__build__/' + }, + module: { + rules: [ + { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader' } } + ] + }, + resolve: { + alias: { + "react-modal": path.resolve(__dirname, "../src") + } + } +}; diff --git a/scripts/webpack.config.js b/scripts/webpack.config.js new file mode 100644 index 00000000..15e6b2e8 --- /dev/null +++ b/scripts/webpack.config.js @@ -0,0 +1,29 @@ +const fs = require('fs'); +const path = require('path'); +const webpack = require('webpack'); +const defaultConfig = require('./defaultConfig'); + +var EXAMPLES_DIR = path.resolve(__dirname, '../examples'); + +function isDirectory(dir) { + return fs.lstatSync(dir).isDirectory(); +} + +function buildEntries() { + return fs.readdirSync(EXAMPLES_DIR).reduce(function (entries, dir) { + if (dir === 'build') + return entries; + + var isDraft = dir.charAt(0) === '_'; + + if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, dir))) + entries[dir] = path.join(EXAMPLES_DIR, dir, 'app.js'); + + return entries; + }, {}); +} + +module.exports = { + ...defaultConfig, + entry: buildEntries(), +}; diff --git a/webpack.dist.config.js b/scripts/webpack.dist.config.js similarity index 63% rename from webpack.dist.config.js rename to scripts/webpack.dist.config.js index a1510934..7d580129 100644 --- a/webpack.dist.config.js +++ b/scripts/webpack.dist.config.js @@ -1,13 +1,14 @@ -var webpack = require('webpack'); -var path = require('path'); +const webpack = require('webpack'); +const path = require('path'); +const defaultConfig = require('./defaultConfig'); -var reactExternal = { +const reactExternal = { root: 'React', commonjs2: 'react', commonjs: 'react', amd: 'react' }; -var reactDOMExternal = { +const reactDOMExternal = { root: 'ReactDOM', commonjs2: 'react-dom', commonjs: 'react-dom', @@ -15,41 +16,30 @@ var reactDOMExternal = { }; module.exports = { + ...defaultConfig, mode: 'production', - entry: { - 'react-modal': './src/index.js', - 'react-modal.min': './src/index.js' + 'react-modal': path.resolve(__dirname, '../src/index.js'), + 'react-modal.min': path.resolve(__dirname, '../src/index.js') }, - externals: { 'react': reactExternal, 'react-dom': reactDOMExternal }, - output: { filename: '[name].js', chunkFilename: '[id].chunk.js', - path: path.resolve(__dirname, 'dist'), + path: path.resolve(__dirname, '../dist'), publicPath: '/', libraryTarget: 'umd', library: 'ReactModal' }, - optimization: { minimize: true }, - plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }) - ], - - module: { - rules: [ - { test: /\.js?$/, exclude: /node_modules/, use: { loader: 'babel-loader' } } - ] - } - + ] }; diff --git a/scripts/webpack.test.config.js b/scripts/webpack.test.config.js new file mode 100644 index 00000000..ba59a82c --- /dev/null +++ b/scripts/webpack.test.config.js @@ -0,0 +1,21 @@ +const path = require('path'); +const defaultConfig = require('./defaultConfig'); + +module.exports = { + ...defaultConfig, + plugins: [], + entry: path.resolve(__dirname, '../specs/index.js'), + devtool: 'inline-source-map', + module: { + ...defaultConfig.module, + rules: [ + { + test: /\.js$/, + use: { loader: 'istanbul-instrumenter-loader' }, + enforce: 'post', + include: path.resolve(__dirname, '../src') + }, + ...defaultConfig.module.rules + ] + } +}; diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index b7f655fa..00000000 --- a/webpack.config.js +++ /dev/null @@ -1,43 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var webpack = require('webpack'); - -var EXAMPLES_DIR = path.resolve(__dirname, 'examples'); - -function isDirectory(dir) { - return fs.lstatSync(dir).isDirectory(); -} - -function buildEntries() { - return fs.readdirSync(EXAMPLES_DIR).reduce(function (entries, dir) { - if (dir === 'build') - return entries; - - var isDraft = dir.charAt(0) === '_'; - - if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, dir))) - entries[dir] = path.join(EXAMPLES_DIR, dir, 'app.js'); - - return entries; - }, {}); -} - -module.exports = { - mode: 'development', - entry: buildEntries(), - output: { - filename: '[name].js', - path: path.resolve(__dirname, './examples/__build__'), - publicPath: '/__build__/' - }, - module: { - rules: [ - { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader' } } - ] - }, - resolve: { - alias: { - "react-modal": path.resolve(__dirname, "./src") - } - } -}; diff --git a/webpack.test.config.js b/webpack.test.config.js deleted file mode 100644 index 9cd4ce49..00000000 --- a/webpack.test.config.js +++ /dev/null @@ -1,16 +0,0 @@ -const path = require('path'); -const commonConfig = require('./webpack.config'); - -commonConfig.plugins = []; -delete commonConfig.optimization; -commonConfig.entry = './specs/index.js'; -commonConfig.devtool = 'inline-source-map'; - -commonConfig.module.rules.unshift({ - test: /\.js$/, - use: { loader: 'istanbul-instrumenter-loader' }, - enforce: 'post', - include: path.resolve(__dirname, './src') -}); - -module.exports = commonConfig;