Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!options.tasks.data.sassBundle) {
return;
}
const assets = normalizeAssetPatterns(
options.tasks.data.sassBundle.entries,
syncHost as any,
root,
projectRoot,
sourceRoot,
);
const copyPatterns = buildCopyPatterns(root, assets);
const copyOptions = { ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'] };
log.info('Bundling a sass bundles...');
const promises = copyPatterns.map( pattern => {
const fullPattern = pattern.context + pattern.from.glob;
const opts = { ...copyOptions, dot: pattern.from.dot };
return globby(fullPattern, opts)
.then(entries => {
const entryPromises = entries.map( entry => {
const cleanFilePath = entry.replace(pattern.context, '');
const to = Path.resolve(root, pattern.to, cleanFilePath);
const pathToFolder = Path.dirname(to);
pathToFolder.split('/').reduce((p, folder) => {
p += folder + '/';
if (!FS.existsSync(p)) {
FS.mkdirSync(p);
}
async function bundleScss(root: string, src: string, dest: string) {
log.info('============================================== SCSS BUNDLE ==============================================');
log.info(`= Source: ${src}`);
log.info(`= Dest: ${dest}`);
log.info(`=`);
const { found, bundledContent, imports } = await new Bundler(undefined, root).Bundle(src, ["./!(dist|node_modules)/**/*.scss"], undefined, ["^~"]);
if (imports) {
const filesNotFound = imports
.filter(x => !x.found && !x.ignored)
.map(x => x.filePath);
if (filesNotFound.length) {
log.error(`= Error: SCSS imports failed`);
log.error('= ' + filesNotFound.join('\n= '));
log.info('=========================================================================================================');
throw new Error('One or more SCSS imports failed');
}
}
const filesNotFound = imports
.filter(x => !x.found && !x.ignored)
.map(x => x.filePath);
if (filesNotFound.length) {
log.error(`= Error: SCSS imports failed`);
log.error('= ' + filesNotFound.join('\n= '));
log.info('=========================================================================================================');
throw new Error('One or more SCSS imports failed');
}
}
if (found) {
await writeFile(dest, bundledContent);
log.success(`= Bundle OK`);
log.info('=========================================================================================================');
}
}
async function bundleScss(root: string, src: string, dest: string) {
log.info('============================================== SCSS BUNDLE ==============================================');
log.info(`= Source: ${src}`);
log.info(`= Dest: ${dest}`);
log.info(`=`);
const { found, bundledContent, imports } = await new Bundler(undefined, root).Bundle(src, ["./!(dist|node_modules)/**/*.scss"], undefined, ["^~"]);
if (imports) {
const filesNotFound = imports
.filter(x => !x.found && !x.ignored)
.map(x => x.filePath);
if (filesNotFound.length) {
log.error(`= Error: SCSS imports failed`);
log.error('= ' + filesNotFound.join('\n= '));
log.info('=========================================================================================================');
throw new Error('One or more SCSS imports failed');
return from(discoverPackages({ project: projectRoot }).then(ngPackage => {
log.info('Copying Assets');
const syncHost = new virtualFs.SyncDelegateHost(host);
if (options.assets.length === 0) {
return Promise.resolve();
}
const assets = normalizeAssetPatterns(
options.assets,
syncHost,
projectPath,
projectPath,
undefined,
);
return moveAssets(ngPackage.src, ngPackage.dest, assets);
}));
const syncHost = new virtualFs.SyncDelegateHost(host);
if (!options.tasks.data.sassCompile) {
return;
}
const assets = normalizeAssetPatterns(
options.tasks.data.sassCompile.entries,
syncHost as any,
root,
projectRoot,
sourceRoot,
);
const copyPatterns = buildCopyPatterns(root, assets);
log.info('Compiling sass bundles...');
const destPath = Path.join(root, copyPatterns[0].to);
const taskName = context.epNode.data.entryPoint.moduleId + ':css';
task(taskName, () => {
return buildScssPipeline(copyPatterns[0].context, [ Path.join(root, 'node_modules/') ], true).pipe(dest(destPath));
});
try {
await new Promise( (resolve, reject) => {
series(taskName)( (err?: any) => {
if (err) {
reject(err);
} else {
resolve();
}