Skip to content

Commit

Permalink
Merge pull request #2 from zakangelle/webpack-jest-infra
Browse files Browse the repository at this point in the history
Set up webpack/jest infrastructure
  • Loading branch information
zxqx committed Feb 25, 2017
2 parents d569f89 + e4daeaa commit afe0820
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 118 deletions.
4 changes: 4 additions & 0 deletions .babelrc
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "stage-0"],
"plugins": ["babel-plugin-add-module-exports"]
}
15 changes: 15 additions & 0 deletions .eslintrc
@@ -0,0 +1,15 @@
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"rules": {
"comma-dangle": [2, "never"],
"no-shadow": 0,
"no-new": 0,
"new-cap": 0,
"max-len": 0,
"brace-style": [2, "stroustrup"]
}
}
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,3 +1,3 @@
node_modules
dist
.nyc_output
coverage
24 changes: 18 additions & 6 deletions README.md
Expand Up @@ -14,26 +14,38 @@ $ npm install ical-date-parser

```js
import iCalDateParser from 'ical-date-parser';
```

```
iCalDateParser('20140422T233000Z');
```

## Standalone
## Development

Generate a standalone build in `dist` (for use with `<script>` tags and AMD module loaders):
Install dependencies:

```sh
$ npm run build:standalone
```
$ npm install
```

## Test
Run the example app at [http://localhost:8080](http://localhost:8080):

```
$ npm run example
```

Tests are done with [tape](https://github.com/substack/tape) by running:
Run tests using [jest](https://github.com/facebook/jest):

```
$ npm test
```

Run tests and watch for code changes:

```
$ npm run test:watch
```

## License

MIT
2 changes: 1 addition & 1 deletion circle.yml
@@ -1,3 +1,3 @@
machine:
node:
version: 5.9.0
version: 6.7.0
14 changes: 14 additions & 0 deletions example/index.html
@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<title>ical-date-parser</title>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>

<body>
</body>
</html>
3 changes: 3 additions & 0 deletions example/index.js
@@ -0,0 +1,3 @@
import iCalDateParser from '../src/index';

console.log(iCalDateParser('20140422T233000Z'));
46 changes: 46 additions & 0 deletions example/webpack.config.build.js
@@ -0,0 +1,46 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
entry: path.join(__dirname, 'index.js'),
output: {
path: path.join(__dirname, 'dist'),
filename: 'example.[hash].js'
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'index.html'),
filename: 'index.html'
}),
new ExtractTextPlugin({
filename: 'index.[hash].css',
allChunks: true
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
screw_ie8: true,
warnings: false
}
})
],
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
use: 'babel-loader',
include: [
path.resolve(__dirname),
path.resolve(__dirname, '../src')
],
exclude: /node_modules/
}
]
}
};
42 changes: 42 additions & 0 deletions example/webpack.config.js
@@ -0,0 +1,42 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
devtool: 'cheap-module-source-map',
entry: {
app: path.join(__dirname, './index.js')
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'example.[hash].js'
},
devServer: {
hot: true,
stats: {
colors: true,
},
historyApiFallback: true
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'index.html'),
filename: 'index.html'
}),
],
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
use: 'babel-loader',
include: [
path.resolve(__dirname),
path.resolve(__dirname, '../src')
],
exclude: /node_modules/
}
]
}
};
1 change: 1 addition & 0 deletions lib/iCalDateParser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 36 additions & 6 deletions package.json
Expand Up @@ -2,11 +2,28 @@
"name": "ical-date-parser",
"version": "3.1.1",
"description": "Parse a stringly typed iCal date as a native JS date object.",
"main": "index.js",
"main": "lib/iCalDateParser.min.js",
"scripts": {
"build:standalone": "mkdir -p dist && browserify index.js --standalone iCalDateParser > dist/ical-date-parser.js",
"test": "tape ./test/**/*.js",
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
"build": "webpack",
"test": "jest",
"test:watch": "npm test -- --watchAll",
"coverage": "cat ./coverage/lcov.info | coveralls",
"lint": "eslint src test",
"preversion": "npm run build",
"example": "webpack-dev-server --config example/webpack.config.js",
"example:build": "cross-env NODE_ENV=production webpack --config example/webpack.config.build.js"
},
"jest": {
"testRegex": "(/test/.*|(\\.|/))\\.js?$",
"moduleFileExtensions": [
"js",
"json"
],
"collectCoverage": true,
"coverageDirectory": "coverage",
"coverageReporters": [
"lcov"
]
},
"repository": {
"type": "git",
Expand All @@ -26,9 +43,22 @@
},
"homepage": "https://github.com/zakangelle/ical-date-parser",
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-eslint": "^7.1.1",
"babel-loader": "^6.3.2",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-0": "^6.22.0",
"browserify": "^13.0.0",
"coveralls": "^2.11.9",
"nyc": "^6.4.0",
"tape": "^2.13.1"
"cross-env": "^3.1.4",
"eslint": "^3.16.1",
"eslint-loader": "^1.6.3",
"extract-text-webpack-plugin": "^2.0.0",
"html-webpack-plugin": "^2.28.0",
"jest": "^19.0.2",
"tape": "^2.13.1",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1"
}
}
8 changes: 2 additions & 6 deletions index.js → src/index.js
@@ -1,5 +1,3 @@
module.exports = iCalDateParser;

const T_INDEX = 8;
const Z_INDEX = 15;

Expand All @@ -8,8 +6,7 @@ const Z_INDEX = 15;
* @param {string} date
* @return {Date}
*/
function iCalDateParser(date)
{
export default function iCalDateParser(date) {
if (!_validateFormat(date)) {
throw new Error('Not a valid iCal date format');
}
Expand All @@ -30,8 +27,7 @@ function iCalDateParser(date)
* @return {boolean}
* @private
*/
function _validateFormat(date)
{
function _validateFormat(date) {
const d = date.split('');

if (d.length !== 16) return false;
Expand Down
54 changes: 0 additions & 54 deletions test/bad.js

This file was deleted.

11 changes: 0 additions & 11 deletions test/date.js

This file was deleted.

11 changes: 0 additions & 11 deletions test/hours.js

This file was deleted.

0 comments on commit afe0820

Please sign in to comment.