Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Use node-sass render file if not making use of obt sass prefix feature (
Browse files Browse the repository at this point in the history
#528)

* Use node-sass render file if not making use of obt sass prefix feature

* Update build.test.js

* Update build.test.js
  • Loading branch information
JakeChampion authored May 17, 2018
1 parent 28e8306 commit 26e6c2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
42 changes: 22 additions & 20 deletions lib/tasks/build-sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = function buildSass(config) {
const cwd = config.cwd || process.cwd();
const src = config.sass ? Promise.resolve(config.sass) : files.getMainSassPath(cwd);

return src.then(code => {
if (code) {
return src.then(sassFile => {
if (sassFile) {
const destFolder = config.buildFolder || files.getBuildFolderPath(cwd);
const dest = config.buildCss || 'main.css';

Expand All @@ -40,32 +40,34 @@ module.exports = function buildSass(config) {
grid: true
};

return readFile(code, 'utf-8')
.then(sassFile => {
let sassConfig;

if (!config.sassPrefix) {
sassConfig = { file: sassFile };
} else {
sassConfig = readFile(sassFile, 'utf-8').then(code => {
// Sass prefixing is used in our origami component specification sass tests
if (config.sassPrefix) {
sassFile = config.sassPrefix + sassFile;
}
return { data: config.sassPrefix + code };
});
}

return Promise.resolve(sassConfig)
.then(sassConfig => {
const includePaths = (config.sassIncludePaths || []).concat('bower_components').map(p => path.join(cwd, p));

// Ensure that the specified current working directory is included as the first path for node-sass to look into
includePaths.unshift(cwd);

const sassConfig = {
data: sassFile,
includePaths,
outputStyle: 'nested',

// This is an experimental LibSass feature. Use with caution.
// https://github.com/sass/node-sass#functions--v300---experimental
// We use this to silence the sass console output when running `obt test`.
// We also use this to hide warnings when building sass without the verbose flag.
functions: config.sassFunctions ? config.sassFunctions : {},
};
sassConfig.includePaths = includePaths;
sassConfig.outputStyle = 'nested';
// This is an experimental LibSass feature. Use with caution.
// https://github.com/sass/node-sass#functions--v300---experimental
// We use this to silence the sass console output when running `obt test`.
// We also use this to hide warnings when building sass without the verbose flag.
sassConfig.functions = config.sassFunctions ? config.sassFunctions : {};

if (useSourceMaps) {
sassConfig.sourceMap = code;
sassConfig.sourceMap = sassFile;
sassConfig.outFile = dest;

// Embeds the source map as a data URI
Expand Down Expand Up @@ -99,7 +101,7 @@ module.exports = function buildSass(config) {
.then(({ css }) => {
if (useSourceMaps) {
return postcss(postCssTransforms).process(css, {
from: code,
from: sassFile,
to: dest,
map: {
inline: true
Expand Down
2 changes: 1 addition & 1 deletion test/integration/build/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ describe('obt build', function () {
.test__visual {
-ms-grid-row: 1;
grid-row: 1; }
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNDO0VBQ0MsZ0JBQWU7RUFDZixrQkFBYTtFQUFiLGNBQWE7RUFDYiwwQkFBOEI7RUFBOUIsK0JBQThCO0VBQzlCLG1CQUF1QjtFQUF2Qix3QkFBdUIsRUFLdkI7RUFKQTtJQUNDLHNCQUFxQjtJQUNyQixhQUFZLEVBQ1o7O0FBRUY7RUFDQyx3QkFBdUI7RUFBdkIsbUJBQXVCO0VBQXZCLHdCQUF1QjtFQUN2QixnQkFBVztFQUFYLFlBQVc7RUFDWCwrQkFBc0I7RUFBdEIsdUJBQXNCO0VBQ3RCLDJCQUFrQjtFQUFsQiw0QkFBa0I7RUFBbEIsMkJBQWtCO0VBQWxCLG1CQUFrQixFQUNsQjs7QUFDRDtFQUNDLGdCQUFXO0VBQVgsWUFBVyxFQUNYIiwiZmlsZSI6Im1haW4uY3NzIn0= */`);
/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQztFQUNDLGdCQUFlO0VBQ2Ysa0JBQWE7RUFBYixj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