Skip to content

Commit

Permalink
Use webpack for full build, find something else for type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Feb 8, 2018
1 parent 03e244a commit 9c12b35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
14 changes: 14 additions & 0 deletions config/webpack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const webpack = require('webpack');
const MinifyPlugin = require('babel-minify-webpack-plugin');

module.exports = {
entry: './src/index.js',
output: {
filename: 'build/ol.js'
},
devtool: 'source-map',
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
new MinifyPlugin()
]
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"scripts": {
"lint": "eslint tasks test src examples transforms",
"pretest": "npm run lint",
"test": "npm run karma -- --single-run && npm run build-typecheck",
"test": "npm run karma -- --single-run",
"karma": "karma start test/karma.config.js",
"serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --watch & serve build/examples",
"build-examples": "webpack --config examples/webpack/config.js --env=prod",
"build-typecheck": "node tasks/generate-index.js && node tasks/build-typecheck.js"
"build": "webpack --config config/webpack.js"
},
"main": "src/ol/index.js",
"repository": {
Expand Down
33 changes: 8 additions & 25 deletions tasks/generate-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function addImports(symbols, callback) {


/**
* Generate goog code to export a named symbol.
* Generate code to export a named symbol.
* @param {string} name Symbol name.
* @param {Object.<string, string>} namespaces Already defined namespaces.
* @return {string} Export code.
Expand All @@ -61,37 +61,19 @@ function formatSymbolExport(name, namespaces) {
const isNamed = parts[0].indexOf('.') !== -1;
const nsParts = parts[0].replace(/^module\:/, '').split(/[\/\.]/);
const last = nsParts.length - 1;
let importName = isNamed ?
const importName = isNamed ?
'_' + nsParts.slice(0, last).join('_') + '.' + nsParts[last] :
'$' + nsParts.join('$');
if (parts.length > 1 && parts[1].indexOf('.') !== -1) {
const property = parts[1].split('.').pop();
importName += '.' + property;
nsParts.push(property);
}
let line = nsParts[0];
for (let i = 1, ii = nsParts.length; i < ii; ++i) {
line += `['${nsParts[i]}']`;
line += `.${nsParts[i]}`;
namespaces[line] = (line in namespaces ? namespaces[line] : true) && i < ii - 1;
}
line += ` = ${importName};`;
return line;
}


/**
* Generate goog code to export a property.
* @param {string} name Property long name (e.g. foo.Bar#baz).
* @return {string} Export code.
*/
function formatPropertyExport(name) {
const parts = name.split('#');
const prototype = parts[0].split('~')[0].replace(/^module\:/, './').replace(/[.\/]+/g, '$') + '.prototype';
const property = parts[1];
return `${prototype}['${property}'] = ${prototype}.${property};`;
}


/**
* Generate export code given a list symbol names.
* @param {Array.<Object>} symbols List of symbols.
Expand All @@ -103,10 +85,11 @@ function generateExports(symbols, namespaces, imports) {
let blocks = [];
symbols.forEach(function(symbol) {
const name = symbol.name;
if (name.indexOf('#') > 0) {
blocks.push(formatPropertyExport(name));
} else {
blocks.push(formatSymbolExport(name, namespaces));
if (name.indexOf('#') == -1) {
const block = formatSymbolExport(name, namespaces);
if (block !== blocks[blocks.length - 1]) {
blocks.push(block);
}
}
});
const nsdefs = ['const ol = window[\'ol\'] = {};'];
Expand Down

0 comments on commit 9c12b35

Please sign in to comment.