Scripts for generating the package and legacy build
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,5 +2,3 @@
|
|||||||
/coverage/
|
/coverage/
|
||||||
/dist/
|
/dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
src/index.js
|
|
||||||
src/ol/package.json
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import buble from 'rollup-plugin-buble';
|
|||||||
import sourcemaps from 'rollup-plugin-sourcemaps';
|
import sourcemaps from 'rollup-plugin-sourcemaps';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: 'src/index.js',
|
input: 'build/index.js',
|
||||||
output: [
|
output: [
|
||||||
{file: 'build/ol.js', format: 'iife', sourcemap: true}
|
{file: 'build/ol.js', format: 'iife', sourcemap: true}
|
||||||
],
|
],
|
||||||
|
|||||||
23
package.json
23
package.json
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "openlayers",
|
"name": "ol",
|
||||||
"version": "5.0.3",
|
"version": "5.0.3",
|
||||||
"description": "OpenLayers mapping library",
|
"description": "OpenLayers mapping library",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
"mapping",
|
"mapping",
|
||||||
"ol"
|
"ol"
|
||||||
],
|
],
|
||||||
|
"private": true,
|
||||||
"homepage": "https://openlayers.org/",
|
"homepage": "https://openlayers.org/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint tasks test src/ol examples config",
|
"lint": "eslint tasks test src/ol examples config",
|
||||||
@@ -15,18 +16,13 @@
|
|||||||
"karma": "karma start test/karma.config.js",
|
"karma": "karma start test/karma.config.js",
|
||||||
"serve-examples": "webpack-dev-server --config examples/webpack/config.js --mode development --watch",
|
"serve-examples": "webpack-dev-server --config examples/webpack/config.js --mode development --watch",
|
||||||
"build-examples": "webpack --config examples/webpack/config.js --mode production",
|
"build-examples": "webpack --config examples/webpack/config.js --mode production",
|
||||||
"build-index": "node tasks/generate-index",
|
"build-package": "npm run transpile && node tasks/prepare-package",
|
||||||
"prepare-package": "node tasks/prepare-package",
|
"build-index": "npm run build-package && node tasks/generate-index",
|
||||||
"prebuild": "npm run prepare-package && npm run build-index",
|
"build-legacy": "rm -rf build && npm run build-index && rollup --config config/rollup.js && cleancss --source-map src/ol/ol.css -o build/ol.css",
|
||||||
"prepare": "npm run prepare-package",
|
"transpile": "rm -rf build/ol && mkdir -p build && buble --input src/ol --output build/ol --no modules --sourcemap",
|
||||||
"build": "rollup --config config/rollup.js && cleancss --source-map src/ol/ol.css -o build/ol.css",
|
|
||||||
"presrc-closure": "npm run prebuild",
|
|
||||||
"src-closure": "node tasks/transform-types",
|
|
||||||
"pretypecheck": "npm run src-closure",
|
|
||||||
"typecheck": "node tasks/typecheck",
|
|
||||||
"apidoc": "jsdoc config/jsdoc/api/index.md -c config/jsdoc/api/conf.json -P package.json -d build/apidoc"
|
"apidoc": "jsdoc config/jsdoc/api/index.md -c config/jsdoc/api/conf.json -P package.json -d build/apidoc"
|
||||||
},
|
},
|
||||||
"main": "src/ol/index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/openlayers/openlayers.git"
|
"url": "git://github.com/openlayers/openlayers.git"
|
||||||
@@ -41,8 +37,7 @@
|
|||||||
"rbush": "2.0.2"
|
"rbush": "2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.26.3",
|
"buble": "^0.19.3",
|
||||||
"babel-plugin-jsdoc-closure": "1.5.1",
|
|
||||||
"buble-loader": "^0.5.1",
|
"buble-loader": "^0.5.1",
|
||||||
"chaikin-smooth": "^1.0.4",
|
"chaikin-smooth": "^1.0.4",
|
||||||
"clean-css-cli": "4.1.11",
|
"clean-css-cli": "4.1.11",
|
||||||
@@ -54,7 +49,6 @@
|
|||||||
"front-matter": "^2.1.2",
|
"front-matter": "^2.1.2",
|
||||||
"fs-extra": "^6.0.0",
|
"fs-extra": "^6.0.0",
|
||||||
"glob": "^7.1.2",
|
"glob": "^7.1.2",
|
||||||
"google-closure-compiler": "20180610.0.2",
|
|
||||||
"handlebars": "4.0.11",
|
"handlebars": "4.0.11",
|
||||||
"istanbul": "0.4.5",
|
"istanbul": "0.4.5",
|
||||||
"jquery": "3.3.1",
|
"jquery": "3.3.1",
|
||||||
@@ -72,7 +66,6 @@
|
|||||||
"mustache": "^2.3.0",
|
"mustache": "^2.3.0",
|
||||||
"pixelmatch": "^4.0.2",
|
"pixelmatch": "^4.0.2",
|
||||||
"proj4": "2.4.4",
|
"proj4": "2.4.4",
|
||||||
"recast": "0.15.2",
|
|
||||||
"rollup": "0.62.0",
|
"rollup": "0.62.0",
|
||||||
"rollup-plugin-buble": "0.19.2",
|
"rollup-plugin-buble": "0.19.2",
|
||||||
"rollup-plugin-commonjs": "9.1.3",
|
"rollup-plugin-commonjs": "9.1.3",
|
||||||
|
|||||||
@@ -12,12 +12,6 @@ async function getSymbols() {
|
|||||||
return info.symbols.filter(symbol => symbol.kind != 'member');
|
return info.symbols.filter(symbol => symbol.kind != 'member');
|
||||||
}
|
}
|
||||||
|
|
||||||
const srcPath = path.posix.resolve(__dirname, '../src').replace(/\\/g, '/');
|
|
||||||
function getPath(name) {
|
|
||||||
const fullPath = require.resolve(path.resolve('src', name));
|
|
||||||
return './' + path.posix.relative(srcPath, fullPath.replace(/\\/g, '/'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a list of imports.
|
* Generate a list of imports.
|
||||||
* @param {Array.<Object>} symbols List of symbols.
|
* @param {Array.<Object>} symbols List of symbols.
|
||||||
@@ -31,12 +25,12 @@ function getImports(symbols) {
|
|||||||
if (defaultExport.length > 1) {
|
if (defaultExport.length > 1) {
|
||||||
const from = defaultExport[0].replace(/^module\:/, './');
|
const from = defaultExport[0].replace(/^module\:/, './');
|
||||||
const importName = from.replace(/[.\/]+/g, '$');
|
const importName = from.replace(/[.\/]+/g, '$');
|
||||||
const defaultImport = `import ${importName} from '${getPath(from)}';`;
|
const defaultImport = `import ${importName} from '${from}';`;
|
||||||
imports[defaultImport] = true;
|
imports[defaultImport] = true;
|
||||||
} else if (namedExport.length > 1) {
|
} else if (namedExport.length > 1) {
|
||||||
const from = namedExport[0].replace(/^module\:/, './');
|
const from = namedExport[0].replace(/^module\:/, './');
|
||||||
const importName = from.replace(/[.\/]+/g, '_');
|
const importName = from.replace(/[.\/]+/g, '_');
|
||||||
const namedImport = `import * as ${importName} from '${getPath(from)}';`;
|
const namedImport = `import * as ${importName} from '${from}';`;
|
||||||
imports[namedImport] = true;
|
imports[namedImport] = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -86,14 +80,14 @@ function generateExports(symbols, namespaces, imports) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const nsdefs = ['const ol = window[\'ol\'] = {};'];
|
const nsdefs = [];
|
||||||
const ns = Object.keys(namespaces).sort();
|
const ns = Object.keys(namespaces).sort();
|
||||||
for (let i = 0, ii = ns.length; i < ii; ++i) {
|
for (let i = 0, ii = ns.length; i < ii; ++i) {
|
||||||
if (namespaces[ns[i]]) {
|
if (namespaces[ns[i]]) {
|
||||||
nsdefs.push(`${ns[i]} = {};`);
|
nsdefs.push(`${ns[i]} = {};`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blocks = imports.concat(nsdefs.sort()).concat(blocks.sort());
|
blocks = imports.concat('\nvar ol = window[\'ol\'] = {};\n', nsdefs.sort()).concat(blocks.sort());
|
||||||
blocks.push('');
|
blocks.push('');
|
||||||
return blocks.join('\n');
|
return blocks.join('\n');
|
||||||
}
|
}
|
||||||
@@ -116,7 +110,7 @@ async function main() {
|
|||||||
*/
|
*/
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
main().then(async code => {
|
main().then(async code => {
|
||||||
const filepath = path.join(__dirname, '..', 'src', 'index.js');
|
const filepath = path.join(__dirname, '..', 'build', 'index.js');
|
||||||
await fse.outputFile(filepath, code);
|
await fse.outputFile(filepath, code);
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
||||||
|
|||||||
@@ -2,26 +2,18 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const pkg = require('../package.json');
|
const pkg = require('../package.json');
|
||||||
|
|
||||||
const util = require.resolve('../src/ol/util');
|
const buildDir = path.resolve(__dirname, '../build/ol');
|
||||||
const lines = fs.readFileSync(util, 'utf-8').split('\n');
|
|
||||||
const versionRegEx = /const VERSION = '(.*)';$/;
|
|
||||||
for (let i = 0, ii = lines.length; i < ii; ++i) {
|
|
||||||
const line = lines[i];
|
|
||||||
if (versionRegEx.test(line)) {
|
|
||||||
lines[i] = line.replace(versionRegEx, `const VERSION = '${pkg.version}';`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fs.writeFileSync(util, lines.join('\n'), 'utf-8');
|
|
||||||
|
|
||||||
const src = path.join('src', 'ol');
|
// update the version number in util.js
|
||||||
const packageJson = path.resolve(__dirname, path.join('..', src, 'package.json'));
|
const utilPath = path.join(buildDir, 'util.js');
|
||||||
|
const versionRegEx = /const VERSION = '(.*)';/g;
|
||||||
|
const utilSrc = fs.readFileSync(utilPath, 'utf-8').replace(versionRegEx, `const VERSION = '${pkg.version}';`);
|
||||||
|
fs.writeFileSync(utilPath, utilSrc, 'utf-8');
|
||||||
|
|
||||||
|
// write out simplified package.json
|
||||||
delete pkg.scripts;
|
delete pkg.scripts;
|
||||||
delete pkg.devDependencies;
|
delete pkg.devDependencies;
|
||||||
delete pkg.style;
|
delete pkg.style;
|
||||||
delete pkg.eslintConfig;
|
delete pkg.eslintConfig;
|
||||||
const main = path.posix.relative(src, require.resolve(path.join('..', pkg.main)));
|
delete pkg.private;
|
||||||
pkg.main = pkg.module = main;
|
fs.writeFileSync(path.join(buildDir, 'package.json'), JSON.stringify(pkg, null, 2), 'utf-8');
|
||||||
pkg.name = 'ol';
|
|
||||||
|
|
||||||
fs.writeFileSync(packageJson, JSON.stringify(pkg, null, 2), 'utf-8');
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/**
|
|
||||||
* @filedesc
|
|
||||||
* Transforms type comments in all source files to types that Closure Compiler
|
|
||||||
* understands.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const glob = require('glob');
|
|
||||||
const mkdirp = require('mkdirp').sync;
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const transform = require('babel-core').transformFileSync;
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
plugins: 'jsdoc-closure',
|
|
||||||
parserOpts: {
|
|
||||||
parser: 'recast'
|
|
||||||
},
|
|
||||||
generatorOpts: {
|
|
||||||
generator: 'recast'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const outDir = path.join('build', 'src-closure');
|
|
||||||
|
|
||||||
glob('src/**/*.js', (err, matches) => {
|
|
||||||
matches.forEach(match => {
|
|
||||||
const out = path.join(outDir, path.relative('src', match));
|
|
||||||
mkdirp(path.dirname(out));
|
|
||||||
fs.writeFileSync(out, transform(match, options).code, 'utf-8');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
const Compiler = require('google-closure-compiler').compiler;
|
|
||||||
|
|
||||||
const compiler = new Compiler({
|
|
||||||
js: [
|
|
||||||
'./build/src-closure/**.js',
|
|
||||||
// Resolve dependencies
|
|
||||||
'./node_modules/pbf/package.json', './node_modules/pbf/**.js', './node_modules/ieee754/**.js',
|
|
||||||
'./node_modules/pixelworks/package.json', './node_modules/pixelworks/**.js',
|
|
||||||
'./node_modules/rbush/package.json', './node_modules/rbush/**.js', 'node_modules/quickselect/**.js'
|
|
||||||
],
|
|
||||||
entry_point: './build/src-closure/index.js',
|
|
||||||
module_resolution: 'NODE',
|
|
||||||
dependency_mode: 'STRICT',
|
|
||||||
checks_only: true,
|
|
||||||
jscomp_error: ['newCheckTypes'],
|
|
||||||
// Options to make dependencies work
|
|
||||||
process_common_js_modules: true,
|
|
||||||
hide_warnings_for: 'node_modules'
|
|
||||||
});
|
|
||||||
|
|
||||||
compiler.run((exit, out, err) => {
|
|
||||||
if (exit) {
|
|
||||||
process.stderr.write(err, () => process.exit(exit));
|
|
||||||
} else {
|
|
||||||
process.stderr.write(err);
|
|
||||||
process.stdout.write(out);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user