Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 15 additions & 11 deletions devtools/dashboard_utilities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,24 @@ export function createMocksList(files) {
const jsonFiles = files.filter((file) => file.name.substr(-5) === '.json');

const mocksList = jsonFiles.map((file) => {
const contents = JSON.parse(file.contents);
try {
const contents = JSON.parse(file.contents);

// get plot type keywords from mocks
const types = contents.data
.map((trace) => trace.type || 'scatter')
.reduce((acc, type, i, arr) => (arr.lastIndexOf(type) === i ? [...acc, type] : acc), []);
// get plot type keywords from mocks
const types = contents.data
.map((trace) => trace.type || 'scatter')
.reduce((acc, type, i, arr) => (arr.lastIndexOf(type) === i ? [...acc, type] : acc), []);

const filename = file.name.split(path.sep).pop();
const filename = file.name.split(path.sep).pop();

return {
name: filename.slice(0, -5),
file: filename,
keywords: types.join(', ')
};
return {
name: filename.slice(0, -5),
file: filename,
keywords: types.join(', ')
};
} catch {
console.log(`Couldn't parse ${file.name} as JSON. Excluding from mocks list.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camdecoster Could we still surface the stack trace here, in case the code inside try fails in an unexpected way due to something other than the call to JSON.parse()?

Either that, or put only the JSON.parse() call inside the try.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more specific error handling.

}
});

return mocksList;
Expand Down
61 changes: 29 additions & 32 deletions tasks/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,32 @@ updateVersion(constants.pathToPlotlyVersion);

// convert scss to css to js and static css file
function makeBuildCSS() {
sass.render({
file: constants.pathToSCSS,
outputStyle: 'compressed'
}, function(err, result) {
if(err) throw err;
sass.render(
{
file: constants.pathToSCSS,
outputStyle: 'compressed'
},
function (err, result) {
if (err) throw err;

// To support application with strict CSP where styles cannot be inlined,
// build a static CSS file that can be included into such applications.
var staticCSS = String(result.css);
for(var k in mapBoxGLStyleRules) {
staticCSS = addAdditionalCSSRules(staticCSS, '.js-plotly-plot .plotly .mapboxgl-' + k, mapBoxGLStyleRules[k]);
}
fs.writeFile(constants.pathToCSSDist, staticCSS, function(err) {
if(err) throw err;
});
// To support application with strict CSP where styles cannot be inlined,
// build a static CSS file that can be included into such applications.
var staticCSS = String(result.css);
for (var k in mapBoxGLStyleRules) {
staticCSS = addAdditionalCSSRules(
staticCSS,
'.js-plotly-plot .plotly .mapboxgl-' + k,
mapBoxGLStyleRules[k]
);
}
fs.writeFile(constants.pathToCSSDist, staticCSS, function (err) {
if (err) throw err;
});

// css to js to be inlined
pullCSS(String(result.css), constants.pathToCSSBuild);
});
// css to js to be inlined
pullCSS(String(result.css), constants.pathToCSSBuild);
}
);
}

function addAdditionalCSSRules(staticStyleString, selector, style) {
Expand All @@ -44,40 +51,30 @@ function addAdditionalCSSRules(staticStyleString, selector, style) {
function exposePartsInLib() {
var obj = {};

var insert = function(name, folder) {
var insert = function (name, folder) {
obj[name] = folder + '/' + name;
};

insert('core', 'src');

insert('calendars', 'src/components');

constants.allTraces.forEach(function(k) {
constants.allTraces.forEach(function (k) {
insert(k, 'src/traces');
});

writeLibFiles(obj);
}

function writeLibFiles(obj) {
for(var name in obj) {
for (var name in obj) {
common.writeFile(
path.join(constants.pathToLib, name + '.js'),
[
'\'use strict\';',
'',
'module.exports = require(\'../' + obj[name] + '\');',
''
].join('\n')
["'use strict';", '', "module.exports = require('../" + obj[name] + "');", ''].join('\n')
);
}
}

function copyTopojsonFiles() {
fs.copy(
constants.pathToTopojsonSrc,
constants.pathToTopojsonDist,
{ clobber: true },
common.throwOnError
);
fs.copy(constants.pathToTopojsonSrc, constants.pathToTopojsonDist, { clobber: true }, common.throwOnError);
}