Add dart and node sass tests

This commit is contained in:
Jeremy Thomas 2020-11-07 17:19:18 +00:00
parent a22fecb94d
commit f659047462
4 changed files with 158 additions and 67 deletions

View File

@ -1,79 +1,40 @@
const fs = require('fs');
const path = require('path');
const sass = require('sass');
const utils = require('./utils');
const sources = [
`base/animations.sass`,
`base/generic.sass`,
`base/minireset.sass`,
const DART_BASE_PATH = 'test/build/dart-sass/';
`components/breadcrumb.sass`,
`components/card.sass`,
`components/dropdown.sass`,
`components/level.sass`,
`components/media.sass`,
`components/menu.sass`,
`components/message.sass`,
`components/modal.sass`,
`components/navbar.sass`,
`components/pagination.sass`,
`components/panel.sass`,
`components/tabs.sass`,
fs.mkdir(DART_BASE_PATH, { recursive: true }, (err) => {
if (err) throw err;
});
`elements/box.sass`,
`elements/button.sass`,
`elements/container.sass`,
`elements/content.sass`,
`elements/icon.sass`,
`elements/image.sass`,
`elements/notification.sass`,
`elements/other.sass`,
`elements/progress.sass`,
`elements/table.sass`,
`elements/tag.sass`,
`elements/title.sass`,
const exportDartCSS = (filepath, options) => {
utils.exportCSS(sass, fs, DART_BASE_PATH, filepath, options)
}
`form/checkbox-radio.sass`,
`form/file.sass`,
`form/input-textarea.sass`,
`form/select.sass`,
`form/tools.sass`,
// Full import
`grid/columns.sass`,
`grid/tiles.sass`,
exportDartCSS('bulma', {
file: './bulma.sass',
});
`helpers/color.sass`,
`helpers/flexbox.sass`,
`helpers/float.sass`,
`helpers/other.sass`,
`helpers/overflow.sass`,
`helpers/position.sass`,
`helpers/spacing.sass`,
`helpers/typography.sass`,
`helpers/visibility.sass`,
exportDartCSS('bulma-rtl', {
file: './bulma-rtl.sass',
});
`layout/footer.sass`,
`layout/hero.sass`,
`layout/section.sass`,
// Single imports
`utilities/controls.sass`,
`utilities/derived-variables.sass`,
`utilities/functions.sass`,
`utilities/initial-variables.sass`,
`utilities/mixins.sass`,
];
const BULMA_IMPORT_PATH = `./sass/`;
const BULMA_SASS_PATH = `./sass/`;
utils.SOURCES.forEach((source) => {
const parsed = path.parse(source);
sources.forEach(source => {
const result = sass.renderSync({
data: `@use "${BULMA_SASS_PATH}${source}";`,
outputStyle: "expanded"
fs.mkdir(`${DART_BASE_PATH}${parsed.dir}`, { recursive: true }, (err) => {
if (err) throw err;
});
try {
sass.renderSync({
data: `@use "${BULMA_SASS_PATH}${source}";`,
});
} catch(err) {
console.error(err);
}
exportDartCSS(`${parsed.dir}/${parsed.name}`, {
data: `@use "${BULMA_IMPORT_PATH}${source}";`,
});
});

40
test/node-sass.js Normal file
View File

@ -0,0 +1,40 @@
const fs = require('fs');
const path = require('path');
const sass = require('node-sass');
const utils = require('./utils');
const NODE_SASS_BASE_PATH = 'test/build/node-sass/';
fs.mkdir(NODE_SASS_BASE_PATH, { recursive: true }, (err) => {
if (err) throw err;
});
const exportNodeSassCSS = (filepath, options) => {
utils.exportCSS(sass, fs, NODE_SASS_BASE_PATH, filepath, options)
}
// Full import
exportNodeSassCSS('bulma', {
file: './bulma.sass',
});
exportNodeSassCSS('bulma-rtl', {
file: './bulma-rtl.sass',
});
// Single imports
const BULMA_IMPORT_PATH = `./sass/`;
utils.SOURCES.forEach((source) => {
const parsed = path.parse(source);
fs.mkdir(`${NODE_SASS_BASE_PATH}${parsed.dir}`, { recursive: true }, (err) => {
if (err) throw err;
});
exportNodeSassCSS(`${parsed.dir}/${parsed.name}`, {
data: `@use "${BULMA_IMPORT_PATH}${source}";`,
});
});

View File

@ -4,8 +4,8 @@
TEST_DIR=$(dirname $BASH_SOURCE)
FILES=$TEST_DIR/sass/*
CSS_DIR=$TEST_DIR/css
CSS_FILES=$TEST_DIR/css/*.css
CSS_DIR=$TEST_DIR/build/ruby-sass
CSS_FILES=$TEST_DIR/build/ruby-sass/*.css
SASS_OPTIONS=--sourcemap=none
# FUNCTIONS

90
test/utils.js Normal file
View File

@ -0,0 +1,90 @@
module.exports = Object.freeze({
SOURCES: [
`base/animations.sass`,
`base/generic.sass`,
`base/minireset.sass`,
`components/breadcrumb.sass`,
`components/card.sass`,
`components/dropdown.sass`,
`components/level.sass`,
`components/media.sass`,
`components/menu.sass`,
`components/message.sass`,
`components/modal.sass`,
`components/navbar.sass`,
`components/pagination.sass`,
`components/panel.sass`,
`components/tabs.sass`,
`elements/box.sass`,
`elements/button.sass`,
`elements/container.sass`,
`elements/content.sass`,
`elements/icon.sass`,
`elements/image.sass`,
`elements/notification.sass`,
`elements/other.sass`,
`elements/progress.sass`,
`elements/table.sass`,
`elements/tag.sass`,
`elements/title.sass`,
`form/checkbox-radio.sass`,
`form/file.sass`,
`form/input-textarea.sass`,
`form/select.sass`,
`form/tools.sass`,
`grid/columns.sass`,
`grid/tiles.sass`,
`helpers/color.sass`,
`helpers/flexbox.sass`,
`helpers/float.sass`,
`helpers/other.sass`,
`helpers/overflow.sass`,
`helpers/position.sass`,
`helpers/spacing.sass`,
`helpers/typography.sass`,
`helpers/visibility.sass`,
`layout/footer.sass`,
`layout/hero.sass`,
`layout/section.sass`,
`utilities/controls.sass`,
`utilities/derived-variables.sass`,
`utilities/functions.sass`,
`utilities/initial-variables.sass`,
`utilities/mixins.sass`,
],
buildCSS: (fn, name, options) => {
try {
console.log(`Processing ${name}`);
fn.renderSync(options);
} catch (err) {
console.log(`Error with ${name}`);
console.error(err);
}
},
exportCSS: (fn, fs, basepath, filepath, options) => {
const exportFile = `${basepath}${filepath}.css`;
fn.render(
{
...options,
outFile: exportFile,
},
(error, result) => {
if (!error) {
fs.writeFile(exportFile, result.css, (err) => {
if (!err) {
console.log(`File ${exportFile} written on disk`);
}
});
}
}
);
}
});