Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

release(v2.0.0-rc1) -- adds React JSX support #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions get-offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@
* 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
response.data.pipe(createWriteStream(outFile));

// 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();
});
});
Expand Down
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
43 changes: 23 additions & 20 deletions modules.js
Original file line number Diff line number Diff line change
@@ -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/[email protected]/dist/index.js',
'@financial-times/load-data': 'npm:@financial-times/load-data@^1.0.2/dist/loadData.dist.min.js',
'bertha-client': 'npm:[email protected]/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',
Expand All @@ -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/[email protected]/build/d3-sankey.js',
'd3-sankey': 'npm:[email protected]/build/d3-sankey.js',
'd3-scale': 'https://d3js.org/d3.v4.js',
'd3-selection-multi': 'https://unpkg.com/[email protected]/build/d3-selection-multi.js',
'd3-selection-multi': 'npm:[email protected]/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',
Expand All @@ -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/[email protected]/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/[email protected]/json.js',
'save-svg-as-png': 'https://unpkg.com/[email protected]/lib/saveSvgAsPng.js',
'simple-statistics': 'https://unpkg.com/[email protected]/dist/simple-statistics.js',
'systemjs-babel-build':
'https://unpkg.com/[email protected]/systemjs-babel-browser.js',
'topojson-client': 'https://unpkg.com/[email protected]/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:[email protected]/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:[email protected]/json.js',
'save-svg-as-png': 'npm:[email protected]/lib/saveSvgAsPng.js',
'simple-statistics': 'npm:[email protected]/dist/simple-statistics.js',
'topojson-client': 'npm:[email protected]/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',
};
babel: 'npm:[email protected]',
fbjs: 'npm:[email protected]',
'object-assign': 'npm:[email protected]',
};
9 changes: 8 additions & 1 deletion offline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down
95 changes: 74 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
24 changes: 16 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down