Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function buildCSS(options) {
// Get the base filename.
let filename = options.file
.split('/')
.pop()
.replace('.scss', '');
// Denote minified CSS.
if (options.outputStyle === 'compressed') {
filename = `${filename}.min`;
}
// Render CSS files.
sass.render(options, (err, result) => {
if (err) {
console.log(err);
process.exit(1);
}
fs.writeFileSync(path.join(OUT_DIR, `${filename}.css`), result.css);
});
}
return new Promise((resolve, reject) => {
sass.render(opt, (err, res) => {
/* istanbul ignore if */
if (err) reject(err)
resolve(res)
})
})
}
function transform(opts, done) {
opts = _.extend({}, SASS_DEFAULTS, opts);
function cssPostProcessorDone(error, css) {
if (error) {
done(error);
return;
}
// JSON.stringify protects against unescaped quotes winding up
// in the modules that get generated.
done(error, sassrModuleWith(JSON.stringify(css)));
}
sass.render(opts, function(error, result) {
var css = error ? '' : result.css.toString();
if (error || !_.isFunction(opts.cssPostProcessor)) {
cssPostProcessorDone(error, css);
} else {
opts.cssPostProcessor(css, cssPostProcessorDone);
}
});
}
return new Promise((resolve, reject) => {
sassConfig.omitSourceMapUrl = false;
if (sassConfig.sourceMap) {
sassConfig.sourceMapContents = true;
}
nodeSassRender(sassConfig, (sassError: SassError, sassResult: Result) => {
const diagnostics = runSassDiagnostics(context, sassError);
if (diagnostics.length) {
printDiagnostics(context, DiagnosticsType.Sass, diagnostics, true, true);
// sass render error :(
reject(new BuildError('Failed to render sass to css'));
} else {
// sass render success :)
renderSassSuccess(context, sassResult, sassConfig).then(outFile => {
resolve(outFile);
}).catch(err => {
reject(new BuildError(err));
});
}
new Promise(resolve =>
nodeSass.render(
{
// Importer allows use of '~' to denote node_modules directory in SCSS files
importer: (url, file, done) =>
url[0] === '~'
? done({ file: resolveImportedModule(url.replace('~', '')) })
: done({ file: url }),
// Add build vars at runtime with the SCSS buffer (which is transformed
// to string in the backticks)
data: `$build: "${state.build}";${scssString}`,
includePaths: [
state.src.stylesheets(),
path.dirname(state.theme.entry),
path.dirname(path.dirname(state.theme.entry)),
],
postcssConfig += ' ' + cssProp;
}
if (!fs.existsSync(path.normalize(outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))))) {
mkdir('-p', path.normalize(outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))));
}
if (cssConfig.env === 'prod' && filePath.indexOf(config.src + '/style') === -1) {
if (!fs.existsSync(path.normalize('ngfactory/' + outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))))) {
mkdir('-p', path.normalize('ngfactory/' + outFile.substring(0, outFile.replace(/\\/g, "/").lastIndexOf("/"))));
}
}
sass.render(cssConfig.sassConfig, function (error, result) {
if (error) {
warn(error.message, 'LINE: ' + error.line);
console.log('');
} else {
fs.writeFile(outFile, result.css, function (err) {
if (err) {
warn(err);
console.log('');
}
if (!err && cssConfig.allowPostCSS === true) {
let postcss = exec(path.normalize(path.join(config.projectRoot, 'node_modules/.bin/postcss')) +
' ' + outFile +
(cssConfig.sourceMap === false ? ' --no-map true' : '') +
' -c ' + path.normalize(path.join(config.projectRoot, 'postcss.' + cssConfig.env + '.js')) +
return new Promise((resolve, reject) => {
nsass.render(options, (err1, result) => {
if (err1) { return reject(err1) }
if (!result) { return reject('Sass: `result` cannot be null.') }
return postcss(autoprefixer(autoprefixerOptions))
.process(result.css)
.then(prefixed =>
fs.writeFile(path.join(outputdir, 'application.css'), prefixed, (err2) => {
if (err2) { reject(err2) }
resolve()
})
)
})
})
}
return new Promise((resolve, reject) => {
const localOptions = options;
localOptions.includePaths.unshift(path.dirname(localOptions.file));
localOptions.includePaths = localOptions.includePaths.unique();
localOptions.sourceMap = localOptions.file;
Logger.debug('Running node-sass with the following options', localOptions);
sass.render(localOptions, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
}
sass(resolve, reject) {
sass.render({
file: srces.css,
outputStyle: 'compressed'
}, (err, result) => {
if (err) {
reject(err.message);
} else {
fs.writeFile(dests.css, result.css, (errr) => {
if (errr) {
reject(errr.message);
} else {
resolve();
}
});
}
});
},
run(inPath: string, outPath: string, callback: any) {
render(Object.assign({}, options, {
file: inPath,
outFile: outPath,
importOnce: this.importOnce,
includePaths: this.includePaths
}), function (e, result) {
if (e) {
return callback(e);
}
callback(null, {code: result.css, map: result.map.toString()});
});
}