Scripts for generating the package and legacy build
This commit is contained in:
@@ -12,12 +12,6 @@ async function getSymbols() {
|
||||
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.
|
||||
* @param {Array.<Object>} symbols List of symbols.
|
||||
@@ -31,12 +25,12 @@ function getImports(symbols) {
|
||||
if (defaultExport.length > 1) {
|
||||
const from = defaultExport[0].replace(/^module\:/, './');
|
||||
const importName = from.replace(/[.\/]+/g, '$');
|
||||
const defaultImport = `import ${importName} from '${getPath(from)}';`;
|
||||
const defaultImport = `import ${importName} from '${from}';`;
|
||||
imports[defaultImport] = true;
|
||||
} else if (namedExport.length > 1) {
|
||||
const from = namedExport[0].replace(/^module\:/, './');
|
||||
const importName = from.replace(/[.\/]+/g, '_');
|
||||
const namedImport = `import * as ${importName} from '${getPath(from)}';`;
|
||||
const namedImport = `import * as ${importName} from '${from}';`;
|
||||
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();
|
||||
for (let i = 0, ii = ns.length; i < ii; ++i) {
|
||||
if (namespaces[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('');
|
||||
return blocks.join('\n');
|
||||
}
|
||||
@@ -116,7 +110,7 @@ async function main() {
|
||||
*/
|
||||
if (require.main === module) {
|
||||
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);
|
||||
}).catch(err => {
|
||||
process.stderr.write(`${err.message}\n`, () => process.exit(1));
|
||||
|
||||
@@ -2,26 +2,18 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const pkg = require('../package.json');
|
||||
|
||||
const util = require.resolve('../src/ol/util');
|
||||
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 buildDir = path.resolve(__dirname, '../build/ol');
|
||||
|
||||
const src = path.join('src', 'ol');
|
||||
const packageJson = path.resolve(__dirname, path.join('..', src, 'package.json'));
|
||||
// update the version number in util.js
|
||||
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.devDependencies;
|
||||
delete pkg.style;
|
||||
delete pkg.eslintConfig;
|
||||
const main = path.posix.relative(src, require.resolve(path.join('..', pkg.main)));
|
||||
pkg.main = pkg.module = main;
|
||||
pkg.name = 'ol';
|
||||
|
||||
fs.writeFileSync(packageJson, JSON.stringify(pkg, null, 2), 'utf-8');
|
||||
delete pkg.private;
|
||||
fs.writeFileSync(path.join(buildDir, 'package.json'), 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