mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-07-23 00:34:55 +00:00
Convert build scripts into ESM (#8610)
This commit is contained in:
@ -10,7 +10,6 @@ module.exports = {
|
||||
'docs/examples/extending/extending-2-layers.md',
|
||||
'docs/_posts/201*',
|
||||
'docs/_site',
|
||||
'build/integrity.js'
|
||||
],
|
||||
root: true,
|
||||
globals: {
|
||||
|
@ -1,6 +1,8 @@
|
||||
import LeafDoc from 'leafdoc';
|
||||
import {writeFileSync} from 'node:fs';
|
||||
|
||||
console.log('Building Leaflet documentation with Leafdoc ...');
|
||||
|
||||
const LeafDoc = require('leafdoc');
|
||||
const doc = new LeafDoc({
|
||||
templateDir: 'build/leafdoc-templates',
|
||||
showInheritancesWhenEmpty: true,
|
||||
@ -25,7 +27,5 @@ doc.addFile('build/docs-misc.leafdoc', false);
|
||||
const out = doc.outputStr();
|
||||
const path = 'docs/reference.html';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
fs.writeFileSync(path, out);
|
||||
writeFileSync(path, out);
|
||||
console.log(`Successfully built ${path}`);
|
@ -1,34 +0,0 @@
|
||||
// This script calculates the integrity hashes of the files in dist/ , and
|
||||
// **overwrites** the values in the documentation.
|
||||
|
||||
const ssri = require('ssri');
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
const version = require('../package.json').version;
|
||||
|
||||
const getIntegrity = async (path) => new Promise((resolve) => {
|
||||
https.get(`https://unpkg.com/leaflet@${version}/dist/${path}`, (res) => {
|
||||
ssri.fromStream(res, {algorithms: ['sha256']}).then(integrity => resolve(integrity.toString()));
|
||||
});
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const integrityUglified = await getIntegrity('leaflet.js');
|
||||
const integritySrc = await getIntegrity('leaflet-src.js');
|
||||
const integrityCss = await getIntegrity('leaflet.css');
|
||||
|
||||
console.log(`Integrity hashes for ${version}:`);
|
||||
console.log(`dist/leaflet.js: ${integrityUglified}`);
|
||||
console.log(`dist/leaflet-src.js: ${integritySrc}`);
|
||||
console.log(`dist/leaflet.css: ${integrityCss}`);
|
||||
|
||||
let docConfig = fs.readFileSync('docs/_config.yml', 'utf8');
|
||||
|
||||
docConfig = docConfig
|
||||
.replace(/latest_leaflet_version:.*/, 'latest_leaflet_version: ' + version)
|
||||
.replace(/integrity_hash_source:.*/, 'integrity_hash_source: "' + integritySrc + '"')
|
||||
.replace(/integrity_hash_uglified:.*/, 'integrity_hash_uglified: "' + integrityUglified + '"')
|
||||
.replace(/integrity_hash_css:.*/, 'integrity_hash_css: "' + integrityCss + '"');
|
||||
|
||||
fs.writeFileSync('docs/_config.yml', docConfig);
|
||||
})();
|
34
build/integrity.mjs
Executable file
34
build/integrity.mjs
Executable file
@ -0,0 +1,34 @@
|
||||
// This script calculates the integrity hashes of the files in dist/ , and
|
||||
// **overwrites** the values in the documentation.
|
||||
import {readFileSync, writeFileSync} from 'node:fs';
|
||||
import https from 'node:https';
|
||||
import ssri from 'ssri';
|
||||
|
||||
// TODO: Replace this with a regular import when ESLint adds support for import assertions.
|
||||
// See: https://rollupjs.org/guide/en/#importing-packagejson
|
||||
const {version} = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)));
|
||||
|
||||
const getIntegrity = async path => new Promise((resolve) => {
|
||||
https.get(`https://unpkg.com/leaflet@${version}/dist/${path}`, (res) => {
|
||||
ssri.fromStream(res, {algorithms: ['sha256']}).then(integrity => resolve(integrity.toString()));
|
||||
});
|
||||
});
|
||||
|
||||
const integrityUglified = await getIntegrity('leaflet.js');
|
||||
const integritySrc = await getIntegrity('leaflet-src.js');
|
||||
const integrityCss = await getIntegrity('leaflet.css');
|
||||
|
||||
console.log(`Integrity hashes for ${version}:`);
|
||||
console.log(`dist/leaflet.js: ${integrityUglified}`);
|
||||
console.log(`dist/leaflet-src.js: ${integritySrc}`);
|
||||
console.log(`dist/leaflet.css: ${integrityCss}`);
|
||||
|
||||
let docConfig = readFileSync('docs/_config.yml', 'utf8');
|
||||
|
||||
docConfig = docConfig
|
||||
.replace(/latest_leaflet_version:.*/, `latest_leaflet_version: ${version}`)
|
||||
.replace(/integrity_hash_source:.*/, `integrity_hash_source: "${integritySrc}"`)
|
||||
.replace(/integrity_hash_uglified:.*/, `integrity_hash_uglified: "${integrityUglified}"`)
|
||||
.replace(/integrity_hash_css:.*/, `integrity_hash_css: "${integrityCss}"`);
|
||||
|
||||
writeFileSync('docs/_config.yml', docConfig);
|
@ -42,7 +42,7 @@
|
||||
"CHANGELOG.md"
|
||||
],
|
||||
"scripts": {
|
||||
"docs": "node ./build/docs.js && node ./build/integrity.js",
|
||||
"docs": "node ./build/docs.mjs && node ./build/integrity.mjs",
|
||||
"test": "karma start ./spec/karma.conf.js",
|
||||
"build": "npm run rollup && npm run uglify",
|
||||
"lint": "eslint .",
|
||||
@ -64,6 +64,6 @@
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"lint-staged": {
|
||||
"*.(js|md)": "eslint --cache --fix"
|
||||
"*.(js|mjs|md)": "eslint --cache --fix"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user