diff --git a/get-offline.js b/get-offline.js index 07a3d24..fa877f2 100644 --- a/get-offline.js +++ b/get-offline.js @@ -3,29 +3,30 @@ * Offline support */ -import Axios from "axios"; -import path from "path"; -import { createWriteStream } from "fs"; -import modules from "./modules"; +import Axios from 'axios'; +import path from 'path'; +import { createWriteStream } from 'fs'; +import modules from './modules'; Promise.all(Object.entries(modules).map(item => downloadDependency(...item))) - .then(() => console.log("Done!")) + .then(() => console.log('Done!')) .catch(console.error); -async function downloadDependency(pkg, url) { +async function downloadDependency(pkg, origUrl) { + const url = origUrl.replace('npm:', 'https://unpkg.com/'); const pkgName = /d3js\.org\/d3\./.test(url) - ? "d3" + ? 'd3' : /^@/.test(pkg) - ? pkg.slice(pkg.indexOf("/") + 1) + ? pkg.slice(pkg.indexOf('/') + 1) : pkg; - const outFile = path.resolve(__dirname, "offline", `${pkgName}.js`); + const outFile = path.resolve(__dirname, 'offline', `${pkgName}.js`); console.log(pkgName, url); // axios image download with response type "stream" const response = await Axios({ - method: "GET", - url: url, - responseType: "stream" + method: 'GET', + url, + responseType: 'stream', }); // pipe the result stream into a file on disc @@ -33,11 +34,11 @@ async function downloadDependency(pkg, url) { // return a promise and resolve when download finishes return new Promise((resolve, reject) => { - response.data.on("end", () => { + response.data.on('end', () => { resolve(); }); - response.data.on("error", () => { + response.data.on('error', () => { reject(); }); }); diff --git a/index.js b/index.js index 0307c05..7711e77 100644 --- a/index.js +++ b/index.js @@ -9,15 +9,29 @@ * in-browser tool for creating static print visualisations). */ -import SystemJS from "systemjs"; -import modules from "./modules.js"; +import SystemJS from 'systemjs'; +import modules from './modules.js'; var config = { + paths: { + 'npm:': 'https://unpkg.com/', + }, + packages: { + babel: { + main: 'browser.min.js', + }, + react: { + main: 'react.js', + }, + 'react-dom': { + main: 'index.js', + }, + }, map: Object.assign({}, modules, window.D3_BOOTLOADER_MODULES), - meta: { "*.json": { loader: "plugin-json" } }, - transpiler: "plugin-babel" + meta: { '*.json': { loader: 'plugin-json' } }, + transpiler: 'babel', }; SystemJS.config(config); -export default SystemJS.import("./index.js"); +export default SystemJS.import('./index.js'); diff --git a/modules.js b/modules.js index e164451..52b8feb 100644 --- a/modules.js +++ b/modules.js @@ -1,7 +1,6 @@ export default { - '@financial-times/load-data': - 'https://unpkg.com/@financial-times/load-data@^1.0.2/dist/loadData.dist.min.js', - 'bertha-client': 'https://unpkg.com/bertha-client@4.0.1/dist/index.js', + '@financial-times/load-data': 'npm:@financial-times/load-data@^1.0.2/dist/loadData.dist.min.js', + 'bertha-client': 'npm:bertha-client@4.0.1/dist/index.js', d3: 'https://d3js.org/d3.v4.js', 'd3-array': 'https://d3js.org/d3.v4.js', 'd3-axis': 'https://d3js.org/d3.v4.js', @@ -24,9 +23,9 @@ export default { 'd3-queue': 'https://d3js.org/d3.v4.js', 'd3-random': 'https://d3js.org/d3.v4.js', 'd3-request': 'https://d3js.org/d3.v4.js', - 'd3-sankey': 'https://unpkg.com/d3-sankey@0.7.1/build/d3-sankey.js', + 'd3-sankey': 'npm:d3-sankey@0.7.1/build/d3-sankey.js', 'd3-scale': 'https://d3js.org/d3.v4.js', - 'd3-selection-multi': 'https://unpkg.com/d3-selection-multi@1.0.1/build/d3-selection-multi.js', + 'd3-selection-multi': 'npm:d3-selection-multi@1.0.1/build/d3-selection-multi.js', 'd3-selection': 'https://d3js.org/d3.v4.js', 'd3-shape': 'https://d3js.org/d3.v4.js', 'd3-time-format': 'https://d3js.org/d3.v4.js', @@ -35,19 +34,23 @@ export default { 'd3-transition': 'https://d3js.org/d3.v4.js', 'd3-voronoi': 'https://d3js.org/d3.v4.js', 'd3-zoom': 'https://d3js.org/d3.v4.js', - 'g-annotations': 'https://unpkg.com/g-annotations@^1/build/g-annotations.js', - 'g-axis': 'https://unpkg.com/g-axis@^1/build/g-axis.js', - 'g-chartcolour': 'https://unpkg.com/g-chartcolour@0.8.26/build/g-chartcolour.js', - 'g-chartframe': 'https://unpkg.com/g-chartframe@^5/build/g-chartframe.js', - 'g-legend': 'https://unpkg.com/g-legend@^1/build/g-legend.js', - 'g-xaxisdate': 'https://unpkg.com/g-axis@^1/build/g-axis.js', - 'g-yaxislinear': 'https://unpkg.com/g-axis@^1/build/g-axis.js', - 'plugin-babel': 'https://unpkg.com/systemjs-plugin-babel/plugin-babel.js', - 'plugin-json': 'https://unpkg.com/systemjs-plugin-json@0.3.0/json.js', - 'save-svg-as-png': 'https://unpkg.com/save-svg-as-png@1.4.6/lib/saveSvgAsPng.js', - 'simple-statistics': 'https://unpkg.com/simple-statistics@5.4.0/dist/simple-statistics.js', - 'systemjs-babel-build': - 'https://unpkg.com/systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js', - 'topojson-client': 'https://unpkg.com/topojson-client@3.0.0/dist/topojson-client.js', + 'g-annotations': 'npm:g-annotations@^1/build/g-annotations.js', + 'g-axis': 'npm:g-axis@^1/build/g-axis.js', + 'g-chartcolour': 'npm:g-chartcolour@0.8.26/build/g-chartcolour.js', + 'g-chartframe': 'npm:g-chartframe@^5/build/g-chartframe.js', + 'g-legend': 'npm:g-legend@^1/build/g-legend.js', + 'g-xaxisdate': 'npm:g-axis@^1/build/g-axis.js', + 'g-yaxislinear': 'npm:g-axis@^1/build/g-axis.js', + 'plugin-json': 'npm:systemjs-plugin-json@0.3.0/json.js', + 'save-svg-as-png': 'npm:save-svg-as-png@1.4.6/lib/saveSvgAsPng.js', + 'simple-statistics': 'npm:simple-statistics@5.4.0/dist/simple-statistics.js', + 'topojson-client': 'npm:topojson-client@3.0.0/dist/topojson-client.js', + '@financial-times/g-components': 'npm:object-assign@^2', + react: 'npm:react@^16.8', + 'react-dom': 'npm:react-dom@^16.8', + 'prop-types': 'npm:prop-types@^15', chai: 'https://www.chaijs.com/chai.js', -}; \ No newline at end of file + babel: 'npm:babel-core@5.8.38', + fbjs: 'npm:fbjs@0.8.12', + 'object-assign': 'npm:object-assign@4.1.1', +}; diff --git a/offline/index.js b/offline/index.js index 8d23f57..2234a92 100644 --- a/offline/index.js +++ b/offline/index.js @@ -24,7 +24,14 @@ const offlineModules = Object.entries(modules).reduce( const config = { map: offlineModules, - meta: { '*.json': { loader: 'plugin-json' } }, + meta: { + '*.json': { loader: 'plugin-json' }, + '*.js': { + babelOptions: { + react: true, + }, + }, + }, transpiler: 'plugin-babel', }; diff --git a/package-lock.json b/package-lock.json index 7e36108..32243b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,15 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.12.tgz", "integrity": "sha512-Pr+6JRiKkfsFvmU/LK68oBRCQeEg36TyAbPhc2xpez24OOZZCuoIhWGTd39VZy6nGafSbxzGouFPTFD/rR1A0A==" }, + "@types/resolve": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", + "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -178,9 +187,9 @@ "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" }, "builtin-modules": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-2.0.0.tgz", - "integrity": "sha512-3U5kUA5VPsRUA3nofm/BXX7GVHKfxz0hOBAPxXrIvHzlDRkQVqEn6yi8QJegxl4LzOHLdvb7XF5dVawa/VVYBg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", + "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", "dev": true }, "builtins": { @@ -1367,6 +1376,15 @@ "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=", "dev": true }, + "is-reference": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.2.tgz", + "integrity": "sha512-Kn5g8c7XHKejFOpTf2QN9YjiHHKl5xRj+2uAZf9iM2//nkBNi/NNeB5JMoun28nEaUVHyPUzqzhfRlfAirEjXg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39" + } + }, "is-regex": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", @@ -2187,25 +2205,41 @@ } }, "rollup": { - "version": "0.67.4", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.67.4.tgz", - "integrity": "sha512-AVuP73mkb4BBMUmksQ3Jw0jTrBTU1i7rLiUYjFxLZGb3xiFmtVEg40oByphkZAsiL0bJC3hRAJUQos/e5EBd+w==", + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.16.3.tgz", + "integrity": "sha512-iXINUUEk2NTZXE3GcUtLQt2cvfQsAUXBQ8AFsDK8tg7Wp5bwTKdZXPdzB2IJQwHpdUNfsIgYMAfajurh7SVTnA==", "dev": true, "requires": { "@types/estree": "0.0.39", - "@types/node": "*" + "@types/node": "^12.0.8", + "acorn": "^6.1.1" + }, + "dependencies": { + "@types/node": { + "version": "12.0.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.10.tgz", + "integrity": "sha512-LcsGbPomWsad6wmMNv7nBLw7YYYyfdYcz6xryKYQhx89c3XXan+8Q6AJ43G5XDIaklaVkK3mE4fCb0SBvMiPSQ==", + "dev": true + }, + "acorn": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", + "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==", + "dev": true + } } }, "rollup-plugin-commonjs": { - "version": "9.3.4", - "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-9.3.4.tgz", - "integrity": "sha512-DTZOvRoiVIHHLFBCL4pFxOaJt8pagxsVldEXBOn6wl3/V21wVaj17HFfyzTsQUuou3sZL3lEJZVWKPFblJfI6w==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.0.1.tgz", + "integrity": "sha512-x0PcCVdEc4J8igv1qe2vttz8JKAKcTs3wfIA3L8xEty3VzxgORLrzZrNWaVMc+pBC4U3aDOb9BnWLAQ8J11vkA==", "dev": true, "requires": { - "estree-walker": "^0.6.0", + "estree-walker": "^0.6.1", + "is-reference": "^1.1.2", "magic-string": "^0.25.2", - "resolve": "^1.10.0", - "rollup-pluginutils": "^2.6.0" + "resolve": "^1.11.0", + "rollup-pluginutils": "^2.8.1" }, "dependencies": { "path-parse": { @@ -2226,14 +2260,33 @@ } }, "rollup-plugin-node-resolve": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.4.0.tgz", - "integrity": "sha512-PJcd85dxfSBWih84ozRtBkB731OjXk0KnzN0oGp7WOWcarAFkVa71cV5hTJg2qpVsV2U8EUwrzHP3tvy9vS3qg==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz", + "integrity": "sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==", "dev": true, "requires": { - "builtin-modules": "^2.0.0", + "@types/resolve": "0.0.8", + "builtin-modules": "^3.1.0", "is-module": "^1.0.0", - "resolve": "^1.1.6" + "resolve": "^1.11.1", + "rollup-pluginutils": "^2.8.1" + }, + "dependencies": { + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "resolve": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.11.1.tgz", + "integrity": "sha512-vIpgF6wfuJOZI7KKKSP+HmiKggadPQAdsp5HiC1mvqnfp0gF1vdwgBWZIdrVft9pgqoMFQN+R7BSWZiBxx+BBw==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } } }, "rollup-pluginutils": { @@ -2477,9 +2530,9 @@ "dev": true }, "systemjs": { - "version": "0.20.19", - "resolved": "https://registry.npmjs.org/systemjs/-/systemjs-0.20.19.tgz", - "integrity": "sha512-H/rKwNEEyej/+IhkmFNmKFyJul8tbH/muiPq5TyNoVTwsGhUjRsN3NlFnFQUvFXA3+GQmsXkCNXU6QKPl779aw==" + "version": "0.21.6", + "resolved": "https://registry.npmjs.org/systemjs/-/systemjs-0.21.6.tgz", + "integrity": "sha512-R+5S9eV9vcQgWOoS4D87joZ4xkFJHb19ZsyKY07D1+VBDE9bwYcU+KXE0r5XlDA8mFoJGyuWDbfrNoh90JsA8g==" }, "table": { "version": "3.8.3", diff --git a/package.json b/package.json index df22fc4..0537beb 100644 --- a/package.json +++ b/package.json @@ -40,16 +40,16 @@ "eslint-plugin-import": "^2.18.0", "esm": "^3.2.25", "npm-prepublish": "^1.2.3", - "rollup": "^0.67.4", - "rollup-plugin-commonjs": "^9.3.4", - "rollup-plugin-node-resolve": "^3.4.0", + "rollup": "^1.16.3", + "rollup-plugin-commonjs": "^10.0.1", + "rollup-plugin-node-resolve": "^5.2.0", "uglify-js": "^3.6.0" }, "dependencies": { "cheerio": "^1.0.0-rc.3", "execa": "^1.0.0", "pacote": "^9.5.1", - "systemjs": "^0.20.19", + "systemjs": "^0.21.6", "tmp": "0.0.33" }, "eslintConfig": { diff --git a/rollup.config.js b/rollup.config.js index 64b57e3..f12d02c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,11 +3,16 @@ import resolve from 'rollup-plugin-node-resolve'; export default [ { - entry: 'index.js', - dest: 'dist/d3-bootloader.js', - format: 'umd', + input: 'index.js', + output: { + file: 'dist/d3-bootloader.js', + format: 'umd', + name: 'bootD3', + sourcemap: true, + }, + external: ['fs'], - moduleName: 'bootD3', + plugins: [ resolve(), commonjs({ @@ -19,11 +24,14 @@ export default [ ], }, { - entry: 'offline/index.js', - dest: 'offline/d3-bootloader.js', - format: 'umd', + input: 'offline/index.js', + output: { + file: 'offline/d3-bootloader.js', + format: 'umd', + name: 'bootD3', + sourcemap: true, + }, external: ['fs'], - moduleName: 'bootD3', plugins: [ resolve(), commonjs({