Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
domlander committed Jun 24, 2024
1 parent fa45588 commit cd06ded
Showing 1 changed file with 71 additions and 69 deletions.
140 changes: 71 additions & 69 deletions tools/compile-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,84 +25,86 @@ const { src, target } = require('./__tasks__/config').paths;
const sassDir = path.resolve(src, 'stylesheets');

const SASS_SETTINGS = {
outputStyle: 'compressed',
sourceMap: true,
precision: 5,
outputStyle: 'compressed',
sourceMap: true,
precision: 5,
};

const BROWSERS_LIST = [
'Firefox >= 45',
'Explorer >= 10',
'Safari >= 7',
'Chrome >= 50',

'iOS >= 7',
'Android >= 5',
'BlackBerry >= 10',
'ExplorerMobile >= 10',

'> 2% in US',
'> 2% in AU',
'> 2% in GB',
'Firefox >= 45',
'Explorer >= 10',
'Safari >= 7',
'Chrome >= 50',

'iOS >= 7',
'Android >= 5',
'BlackBerry >= 10',
'ExplorerMobile >= 10',

'> 2% in US',
'> 2% in AU',
'> 2% in GB',
];

const REMIFICATIONS = {
replace: true,
root_value: 16,
unit_precision: 5,
propList: ['*'],
replace: true,
root_value: 16,
unit_precision: 5,
propList: ['*'],
};

const getFiles = sassGlob => glob.sync(path.resolve(sassDir, sassGlob));
const getFiles = (sassGlob) => glob.sync(path.resolve(sassDir, sassGlob));

module.exports = (
sassGlob,
{ remify = true, browsers = BROWSERS_LIST } = {}
sassGlob,
{ remify = true, browsers = BROWSERS_LIST } = {},
) => {
if (typeof sassGlob !== 'string') {
return Promise.reject(new Error('No glob provided.'));
}

return Promise.all(
getFiles(sassGlob).map(filePath => {
const dest = path.resolve(
target,
'stylesheets',
path.relative(sassDir, filePath).replace('scss', 'css')
);
const sassOptions = Object.assign(
{
file: filePath,
outFile: dest,
sourceMapContents: true,
includePaths: ['node_modules'],
},
SASS_SETTINGS
);

const postcssPlugins = [autoprefixer({ overrideBrowserslist: browsers })];
if (remify) {
postcssPlugins.push(pxtorem(REMIFICATIONS));
}

mkdirp.sync(path.parse(dest).dir);
return sassRenderP(sassOptions)
.then(result =>
postcss(postcssPlugins).process(result.css.toString(), {
from: filePath,
to: dest,
map: {
inline: false,
prev: result.map.toString(),
},
})
)
.then(result =>
Promise.all([
writeFileP(dest, result.css.toString()),
writeFileP(`${dest}.map`, result.map.toString()),
])
);
})
);
if (typeof sassGlob !== 'string') {
return Promise.reject(new Error('No glob provided.'));
}

return Promise.all(
getFiles(sassGlob).map((filePath) => {
const dest = path.resolve(
target,
'stylesheets',
path.relative(sassDir, filePath).replace('scss', 'css'),
);
const sassOptions = Object.assign(
{
file: filePath,
outFile: dest,
sourceMapContents: true,
includePaths: ['node_modules'],
},
SASS_SETTINGS,
);

const postcssPlugins = [
autoprefixer({ overrideBrowserslist: browsers }),
];
if (remify) {
postcssPlugins.push(pxtorem(REMIFICATIONS));
}

mkdirp.sync(path.parse(dest).dir);
return sassRenderP(sassOptions)
.then((result) =>
postcss(postcssPlugins).process(result.css.toString(), {
from: filePath,
to: dest,
map: {
inline: false,
prev: result.map.toString(),
},
}),
)
.then((result) =>
Promise.all([
writeFileP(dest, result.css.toString()),
writeFileP(`${dest}.map`, result.map.toString()),
]),
);
}),
);
};

0 comments on commit cd06ded

Please sign in to comment.