Skip to content

Commit

Permalink
Enhance build tooling; add a tdd target
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Nason committed Oct 23, 2016
1 parent 419f245 commit ed7f70c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 87 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ Runs node tests only
$ npm run test:node
```

### TDD
Runs browser and node tests in watch mode, re-bundles on src file change
```shell
$ npm run tdd
```

### Docs
Regenerate `API.md` docs from JSDoc comments
```shell
Expand Down
33 changes: 21 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@
"browser": "dist/client.js",
"scripts": {
"test": "npm run test:browser && npm run test:node",
"tdd": "npm-run-all --parallel test:*:tdd",
"test:ci": "npm run test:browser && npm run test:node:ci",
"test:browser": "NODE_ENV=test karma start test/karma.conf.js",
"test:node": "NODE_ENV=test nyc mocha -r test/runner test/specs/**/*.js",
"test:browser:tdd": "npm run test:browser -- --auto-watch --no-single-run",
"test:node": "NODE_ENV=test nyc mocha test/runner test/specs/**/*.js",
"test:node:tdd": "npm run test:node -- --cache --watch",
"test:node:ci": "npm run test:node && nyc report --reporter=text-lcov | coveralls",
"test:bundle:tdd": "npm-run-all -l --parallel 'bundle:* -- --watch'",
"eslint": "eslint src test",
"clean": "rimraf dist && mkdirp dist",
"bundle": "rollup -c rollup.client.config.js && rollup -c rollup.node.config.js",
"bundle": "npm-run-all -l --parallel bundle:node bundle:browser",
"bundle:node": "rollup -c --environment RUNTIME_ENV:node",
"bundle:browser": "rollup -c --environment RUNTIME_ENV:client",
"start": "npm test && npm run dist",
"dist": "npm run eslint && npm run clean && npm run bundle && npm run docs",
"docs": "documentation build src/client.js src/node.js --github --format md --output API.md",
"pretest": "npm run bundle",
"preversion": "npm run dist; git add API.md",
"version": "auto-changelog --package; git add CHANGELOG.md",
"version": "auto-changelog --template compact --package; git add CHANGELOG.md",
"release": "np"
},
"repository": {
Expand All @@ -53,7 +59,14 @@
"logentries",
"bunyan"
],
"peerDependencies": {},
"dependencies": {
"bunyan": "^1.8.2",
"bunyan-format": "^0.2.1",
"le_js": "git://github.com/logentries/le_js.git#56addf6c71c7f9454eb49b1a12d97037c3715bb9",
"le_node": "^1.6.7",
"lodash": "^4.16.4",
"rollbar": "^0.6.2"
},
"devDependencies": {
"auto-changelog": "0.3.1",
"babel-core": "6.17.0",
Expand Down Expand Up @@ -81,23 +94,19 @@
"mkdirp": "0.5.1",
"mocha": "3.1.2",
"np": "2.9.0",
"npm-run-all": "3.1.1",
"nyc": "8.3.1",
"phantomjs-prebuilt": "2.1.13",
"rimraf": "2.5.4",
"rollup": "0.36.3",
"rollup-plugin-babel": "2.6.1",
"rollup-plugin-cleanup": "0.1.4",
"rollup-plugin-conditional": "0.1.4",
"rollup-plugin-filesize": "1.0.0",
"rollup-watch": "2.5.0",
"semver": "5.3.0",
"sinon": "1.17.6",
"sinon-chai": "2.8.0",
"webpack": "1.13.2"
},
"dependencies": {
"bunyan": "1.8.2",
"bunyan-format": "0.2.1",
"le_js": "git://github.com/logentries/le_js.git#56addf6c71c7f9454eb49b1a12d97037c3715bb9",
"le_node": "1.6.7",
"lodash": "4.16.4",
"rollbar": "0.6.2"
}
}
36 changes: 0 additions & 36 deletions rollup.client.config.js

This file was deleted.

60 changes: 60 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import babel from 'rollup-plugin-babel';
import filesize from 'rollup-plugin-filesize';
import conditional from 'rollup-plugin-conditional';
import cleanup from 'rollup-plugin-cleanup';

// Valid build targets
const supportedRuntimes = [
'client',
'node'
];

// NPM injects the name from `package.json` to this env var
const pkgName = process.env.npm_package_name;

// Pass to rollup via --environment flag
const runtimeEnv = process.env.RUNTIME_ENV;

if (!supportedRuntimes.includes(runtimeEnv)) {
throw new Error(
`Invalid runtime environment ${runtimeEnv} sepcified. Valid options: ${supportedRuntimes.join(', ')}`
);
}

export default {
entry: `src/${runtimeEnv}.js`,
targets: [
{
dest: `dist/${runtimeEnv}.js`,
sourceMap: `dist/${runtimeEnv}.map.js`,
format: 'cjs'
}
],
moduleId: pkgName,
moduleName: pkgName,
plugins: [
conditional({
condition: runtimeEnv === 'client',
plugin: babel({
exclude: './node_modules/**',
moduleIds: true,

// Custom babelrc for build
babelrc: false,
presets: [
[ 'es2015', { 'modules': false } ],
'stage-0'
],
plugins: [
'external-helpers'
]
})
}),

cleanup({
comments: ['some', 'jsdoc']
}),

filesize()
]
};
36 changes: 0 additions & 36 deletions rollup.node.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions test/browser.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('./runner');
// shim global rollbar
global.Rollbar = {
options: {
accessToken: 'testShim',
accessToken: 'testShim'
},
configure: _.noop,
scope: _.noop,
Expand All @@ -13,8 +13,8 @@ global.Rollbar = {
warning: _.noop,
info: _.noop,
debug: _.noop,
log: _.noop,
}
log: _.noop
};

// require all `/test/specs/**/*.js`
const testsContext = require.context('./specs/', true, /\.js$/);
Expand Down

0 comments on commit ed7f70c

Please sign in to comment.