Skip to content
Merged
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
60 changes: 33 additions & 27 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,39 @@ 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() {
const FILES_TO_EXCLUDE = ['country_names_iso_codes.json'];
fs.copy(
constants.pathToTopojsonSrc,
constants.pathToTopojsonDist,
{ clobber: true },
{
clobber: true,
filter: (filePath) => !FILES_TO_EXCLUDE.includes(path.basename(filePath))
},
common.throwOnError
);
}