Skip to content

Commit

Permalink
chore: validate commit and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
shirotech committed Aug 19, 2017
1 parent 4c9dc37 commit b4b1acd
Show file tree
Hide file tree
Showing 10 changed files with 772 additions and 222 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = false

[*.js]
insert_final_newline = true
13 changes: 13 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,13 @@
{
"env": {
"jasmine": true
},
"rules": {
"global-require": 0,
"no-cond-assign": 0,
"no-param-reassign": 0,
"no-underscore-dangle": 0,
"import/no-dynamic-require": 0
},
"extends": "airbnb-base"
}
2 changes: 1 addition & 1 deletion example/app.js
@@ -1,2 +1,2 @@
require('istanbul');
require('jasmine');
require('jasmine');
12 changes: 6 additions & 6 deletions example/webpack.config.js
Expand Up @@ -8,17 +8,17 @@ module.exports = {
output: {
path: path.join(__dirname, 'dist/assets'),
publicPath: '/assets',
filename: 'app.js'
filename: 'app.js',
},
plugins: [
new HtmlWebpackPlugin({ filename: '../index.html' }), // output file relative to output.path
new WebpackCdnPlugin({
modules: [
{ name: 'istanbul' },
{ name: 'jasmine' }
{ name: 'jasmine' },
],
prod: process.env.NODE_ENV === 'production',
publicPath: '/node_modules' // override when prod is false
})
]
};
publicPath: '/node_modules', // override when prod is false
}),
],
};
2 changes: 1 addition & 1 deletion index.js
@@ -1,3 +1,3 @@
const semver = require('semver');

module.exports = require(semver.gt(process.version, '6.0.0') ? './src' : './dist');
module.exports = require(semver.gt(process.version, '6.0.0') ? './src' : './dist');
10 changes: 8 additions & 2 deletions package.json
Expand Up @@ -5,8 +5,10 @@
"main": "index.js",
"scripts": {
"start": "webpack --config example/webpack.config.js",
"test": "istanbul cover jasmine",
"test": "eslint {src.js,spec/*.js} --fix && istanbul cover jasmine",
"build": "buble -i src.js -o dist.js",
"commitmsg": "validate-commit-msg",
"precommit": "npm test",
"prepublish": "npm run build"
},
"repository": {
Expand Down Expand Up @@ -53,11 +55,15 @@
"homepage": "https://github.com/van-nguyen/webpack-cdn-plugin",
"devDependencies": {
"buble": "^0.15.2",
"eslint": "^4.5.0",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-plugin-import": "^2.7.0",
"html-webpack-plugin": "^2.30.1",
"husky": "^0.14.3",
"istanbul": "^0.4.5",
"jasmine": "^2.7.0",
"jasmine-spec-reporter": "^4.2.1",
"semver": "^5.4.1",
"validate-commit-msg": "^2.14.0",
"webpack": "^3.5.5"
}
}
3 changes: 2 additions & 1 deletion spec/helpers/reporter.js
@@ -1,4 +1,5 @@
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;

const env = jasmine.getEnv();
env.clearReporters();
env.addReporter(new SpecReporter());
env.addReporter(new SpecReporter());
172 changes: 80 additions & 92 deletions spec/webpack.spec.js
Expand Up @@ -6,28 +6,86 @@ const WebpackCdnPlugin = require('../');
const cssMatcher = /<link href="(.+?)" rel="stylesheet">/g;
const jsMatcher = /<script type="text\/javascript" src="(.+?)">/g;

let cssAssets, jsAssets;
let cssAssets;
let jsAssets;

const versions = {
jasmine: WebpackCdnPlugin._getVersion('jasmine'),
jasmineSpecReporter: WebpackCdnPlugin._getVersion('jasmine-spec-reporter'),
istanbul: WebpackCdnPlugin._getVersion('istanbul')
jasmine: WebpackCdnPlugin.getVersion('jasmine'),
jasmineSpecReporter: WebpackCdnPlugin.getVersion('jasmine-spec-reporter'),
istanbul: WebpackCdnPlugin.getVersion('istanbul'),
};

describe('Webpack Integration', () => {
const fs = new webpack.MemoryOutputFileSystem();

describe('When `prod` is true', () => {
function runWebpack(callback, config) {
cssAssets = [];
jsAssets = [];

describe('When `prodUrl` is default', () => {
const compiler = webpack(config);
compiler.outputFileSystem = fs;

compiler.run((err, stats) => {
const html = stats.compilation.assets['../index.html'].source();

let matches;
while (matches = cssMatcher.exec(html)) {
cssAssets.push(matches[1]);
}

while (matches = jsMatcher.exec(html)) {
jsAssets.push(matches[1]);
}

callback();
});
}

function getConfig({ prod, publicPath = '/node_modules', publicPath2 = '/assets', prodUrl }) {
const output = {
path: path.join(__dirname, 'dist/assets'),
filename: 'app.js',
};

if (publicPath2) {
output.publicPath = publicPath2;
}

const options = {
modules: [
{ name: 'jasmine-spec-reporter', path: 'index.js' },
{ name: 'istanbul', style: 'style.css' },
{ name: 'jasmine', cdn: 'jasmine2', style: 'style.css' },
],
prod,
prodUrl,
};

if (publicPath) {
options.publicPath = publicPath;
}

return {
entry: path.join(__dirname, '../example/app.js'),
output,
plugins: [
new HtmlWebpackPlugin({ filename: '../index.html' }),
new WebpackCdnPlugin(options),
],
};
}


describe('Webpack Integration', () => {
describe('When `prod` is true', () => {
describe('When `prodUrl` is default', () => {
beforeAll((done) => {
runWebpack(done, getConfig({prod: true}));
runWebpack(done, getConfig({ prod: true }));
});

it('should output the right assets (css)', () => {
expect(cssAssets).toEqual([
`//unpkg.com/istanbul@${versions.istanbul}/style.css`,
`//unpkg.com/jasmine2@${versions.jasmine}/style.css`
`//unpkg.com/jasmine2@${versions.jasmine}/style.css`,
]);
});

Expand All @@ -36,22 +94,20 @@ describe('Webpack Integration', () => {
`//unpkg.com/jasmine-spec-reporter@${versions.jasmineSpecReporter}/index.js`,
`//unpkg.com/istanbul@${versions.istanbul}/index.js`,
`//unpkg.com/jasmine2@${versions.jasmine}/lib/jasmine.js`,
'/assets/app.js'
'/assets/app.js',
]);
});

});

describe('When `prodUrl` is set', () => {

beforeAll((done) => {
runWebpack(done, getConfig({prod: true, prodUrl: '//cdnjs.cloudflare.com/ajax/libs/:name/:version/:path'}));
runWebpack(done, getConfig({ prod: true, prodUrl: '//cdnjs.cloudflare.com/ajax/libs/:name/:version/:path' }));
});

it('should output the right assets (css)', () => {
expect(cssAssets).toEqual([
`//cdnjs.cloudflare.com/ajax/libs/istanbul/${versions.istanbul}/style.css`,
`//cdnjs.cloudflare.com/ajax/libs/jasmine2/${versions.jasmine}/style.css`
`//cdnjs.cloudflare.com/ajax/libs/jasmine2/${versions.jasmine}/style.css`,
]);
});

Expand All @@ -60,26 +116,22 @@ describe('Webpack Integration', () => {
`//cdnjs.cloudflare.com/ajax/libs/jasmine-spec-reporter/${versions.jasmineSpecReporter}/index.js`,
`//cdnjs.cloudflare.com/ajax/libs/istanbul/${versions.istanbul}/index.js`,
`//cdnjs.cloudflare.com/ajax/libs/jasmine2/${versions.jasmine}/lib/jasmine.js`,
'/assets/app.js'
'/assets/app.js',
]);
});

});

});

describe('When `prod` is false', () => {

describe('When `publicPath` is default', () => {

beforeAll((done) => {
runWebpack(done, getConfig({prod: false, publicPath: null, publicPath2: null}));
runWebpack(done, getConfig({ prod: false, publicPath: null, publicPath2: null }));
});

it('should output the right assets (css)', () => {
expect(cssAssets).toEqual([
'/istanbul/style.css',
'/jasmine/style.css'
'/jasmine/style.css',
]);
});

Expand All @@ -88,22 +140,20 @@ describe('Webpack Integration', () => {
'/jasmine-spec-reporter/index.js',
'/istanbul/index.js',
'/jasmine/lib/jasmine.js',
'/app.js'
'/app.js',
]);
});

});

describe('When `publicPath` is `/`', () => {

beforeAll((done) => {
runWebpack(done, getConfig({prod: false, publicPath: null, publicPath2: '/'}));
runWebpack(done, getConfig({ prod: false, publicPath: null, publicPath2: '/' }));
});

it('should output the right assets (css)', () => {
expect(cssAssets).toEqual([
'/istanbul/style.css',
'/jasmine/style.css'
'/jasmine/style.css',
]);
});

Expand All @@ -112,22 +162,20 @@ describe('Webpack Integration', () => {
'/jasmine-spec-reporter/index.js',
'/istanbul/index.js',
'/jasmine/lib/jasmine.js',
'/app.js'
'/app.js',
]);
});

});

describe('When `publicPath` is set', () => {

beforeAll((done) => {
runWebpack(done, getConfig({prod: false}));
runWebpack(done, getConfig({ prod: false }));
});

it('should output the right assets (css)', () => {
expect(cssAssets).toEqual([
'/node_modules/istanbul/style.css',
'/node_modules/jasmine/style.css'
'/node_modules/jasmine/style.css',
]);
});

Expand All @@ -136,69 +184,9 @@ describe('Webpack Integration', () => {
'/node_modules/jasmine-spec-reporter/index.js',
'/node_modules/istanbul/index.js',
'/node_modules/jasmine/lib/jasmine.js',
'/assets/app.js'
'/assets/app.js',
]);
});

});

});

});

const fs = new webpack.MemoryOutputFileSystem();

function runWebpack(callback, config) {
cssAssets = [];
jsAssets = [];

const compiler = webpack(config);
compiler.outputFileSystem = fs;

compiler.run((err, stats) => {
const html = stats.compilation.assets['../index.html'].source();

let matches;
while (matches = cssMatcher.exec(html)) {
cssAssets.push(matches[1]);
}

while (matches = jsMatcher.exec(html)) {
jsAssets.push(matches[1]);
}

callback();
});
}

function getConfig({prod, publicPath = '/node_modules', publicPath2 = '/assets', prodUrl}) {
const output = {
path: path.join(__dirname, 'dist/assets'),
filename: 'app.js'
};

if (publicPath2) {
output.publicPath = publicPath2;
}

const options = {
modules: [
{ name: 'jasmine-spec-reporter', path: 'index.js' },
{ name: 'istanbul', style: 'style.css' },
{ name: 'jasmine', cdn: 'jasmine2', style: 'style.css' }
], prod, prodUrl
};

if (publicPath) {
options.publicPath = publicPath;
}

return {
entry: path.join(__dirname, '../example/app.js'),
output,
plugins: [
new HtmlWebpackPlugin({ filename: '../index.html' }),
new WebpackCdnPlugin(options)
]
}
}

0 comments on commit b4b1acd

Please sign in to comment.