Skip to content

Commit

Permalink
fix(all): Fixed module build (#2)
Browse files Browse the repository at this point in the history
* fix(all): Fixed module build

Added webpack to deploy modules approprietly, fixed lib & tests to work with webpack, created

default sample usage example.

* Update .travis.yml
  • Loading branch information
Tzaphkiel authored and airosa committed Apr 25, 2016
1 parent c315b3d commit 2658dfd
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Thumbs.db
*.sublime-project
*.sublime-workspace

lib
npm-debug.log
coverage
*.swp
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ script:
- npm run test:single
- npm run check-coverage
- npm run lint
- npm run build
after_success:
- npm run report-coverage
- npm run semantic-release
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"name": "sdmxmllib",
"description": "Javascript library for converting SDMX-ML structure messages",
"version": "0.0.0-semantically-released",
"main": "src/sdmxmllib.js",
"main": "lib/sdmxmllib.js",
"scripts": {
"clean": "rm -rf lib/",
"start": "webpack-dev-server --content-base lib/",
"prebuild": "npm run clean",
"build": "webpack --display-chunks --display-reasons --progress --color -p",
"commit": "git-cz",
"check-coverage": "istanbul check-coverage --statements 85 --branches 65 --functions 85 --lines 90",
"report-coverage": "cat ./coverage/lcov.info | codecov",
Expand All @@ -27,16 +31,21 @@
},
"homepage": "https://github.com/airosa/sdmxmllib#readme",
"devDependencies": {
"chai": "3.5.0",
"codecov.io": "0.1.6",
"commitizen": "2.5.0",
"cz-conventional-changelog": "1.1.5",
"ghooks": "1.0.3",
"html-webpack-plugin": "2.16.0",
"istanbul": "0.4.2",
"codecov.io": "0.1.6",
"jsdom": "8.4.0",
"jshint": "2.9.1",
"mocha": "2.4.5",
"chai": "3.5.0",
"ghooks": "1.0.3",
"raw-loader": "0.5.1",
"semantic-release": "^4.3.5",
"jsdom": "8.4.0",
"jshint": "2.9.1"
"webpack": "1.12.14",
"webpack-dev-server": "1.14.1",
"webpack-merge": "0.12.0"
},
"config": {
"commitizen": {
Expand Down
18 changes: 18 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//-- load fixture file instead of fetching content from WS
var fileContent = require("raw!../test/fixtures/ECB_EXR1.xml");

// load lib
var sdmxmllib = require('./sdmxmllib');

// parse
var msg = sdmxmllib.mapSDMXMLResponse(fileContent);

// use to display something
var content = '';
content += '<p>' + msg.header.id + '</p>';
content += '<p>' + msg.resources.length + '</p>';
content += '<p>' + msg.resources[0].id + '</p>';
content += '<p>' + msg.resources[0].name + '</p>';
content += '<p>' + msg.resources[0].items[0].id + '</p>';

document.getElementsByTagName('body')[0].innerHTML = content;
15 changes: 1 addition & 14 deletions src/sdmxmllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// (c) 2014 Sami Airo
// sdmxmllib.js may be freely distributed under the MIT license

(function () {
var _DOMParser;

if (typeof DOMParser === 'object') {
Expand All @@ -14,8 +13,6 @@

var lib = {};

var root = typeof exports !== 'undefined' && exports !== null ? exports : this;

var slice = Function.call.bind(Array.prototype.slice);

var mes = 'http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message';
Expand Down Expand Up @@ -526,15 +523,5 @@

//==============================================================================

if (typeof define === 'function' && define.amd) {
// Require.js - no dependencies
define([], function () {
// no setup
return lib;
});
} else {
// Add to global object
root.sdmxmllib = lib;
}

}).call(this);
module.exports = lib;
3 changes: 1 addition & 2 deletions test/test-message.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function () {
var sdmxmllib = require('../src/sdmxmllib');
var msg;

var mes = 'http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message';
Expand Down Expand Up @@ -366,4 +366,3 @@

});

}).call(this);
96 changes: 96 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Refer to the following great tutorials from Pete Hunt:
*
* http://survivejs.com/webpack/introduction !!!
*
* https://github.com/petehunt/react-howto
* https://github.com/petehunt/webpack-howto
*
*/
const webpack = require('webpack');
const merge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');

// Detect how npm is run and branch based on that
const TARGET = process.env.npm_lifecycle_event;

//---------------------------------------------
const common = {
cache: true,
entry: {sdmxmllib: './src'},
output: {
path: './lib',
filename: '[name].js',
},

resolve: {
// you can now require('file') instead of require('file.coffee')
extensions: ['', '.js']//,
},

plugins: [
new HtmlWebpackPlugin({
title: "Test page",
xhtml: true
})
]
};

//---------------------------------------------
// Default configuration. We will return this if
// Webpack is called outside of npm.
if(TARGET === 'start' || !TARGET) {
module.exports = merge(common, {
devServer: {
// Enable history API fallback so HTML5 History API based routing works. This is a good default that will come in handy in more complicated setups.
historyApiFallback: true,
hot: true,
inline: true,

quiet: false,
progress: true,
colors: true,

// Display only errors to reduce the amount of output.
stats: {
assets: true, modules: false, colors: true, version: false, hash: false, timings: true, chunks: true, chunkModules: false
},
// If you use Vagrant or Cloud9, set
// host: process.env.HOST || '0.0.0.0';
// 0.0.0.0 is available to all network devices
// unlike default localhost
host: process.env.HOST || "127.0.0.1",
port: process.env.PORT || 8888

// If you want defaults, you can use a little trick like this
// port: process.env.PORT || 3000
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
title: "Test page",
xhtml: true
})
]
});
}

//---------------------------------------------
if(TARGET === 'build') {
module.exports = merge(common, {
plugins: [
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
new webpack.optimize.UglifyJsPlugin({
compress:{
warnings: false
}
})
]
});
}


0 comments on commit 2658dfd

Please sign in to comment.