All files / packages/design-system/scripts/compile modular-css.js

0% Statements 0/22
0% Branches 0/3
0% Functions 0/1
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                                                                                                                 
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
const fs = require('fs-extra');
const glob = require('fast-glob');
const sass = require('sass');
const readline = require('readline');
 
const compileModularCSS = (props = {}) => {
  const { suppressStdout, callback } = props;
 
  if (!suppressStdout) {
    console.log('=> Clearing out .generated/css');
  }
  fs.emptyDirSync('.generated/css');
 
  const moduleFiles = glob.sync('./ui/(components|utilities)/**/*_index.scss', {
    ignore: ['ui/components/_index.scss', 'ui/utilities/_index.scss'],
    sourceComments: false,
  });
  const moduleFileCount = moduleFiles.length;
 
  moduleFiles.forEach((filename, i) => {
    const pathBase = filename.replace(/\.\/ui\//, '').replace('/_index.scss', '');
    const outFile = `.generated/css/${pathBase}/index.css`;
 
    // console output
    if (!suppressStdout) {
      readline.clearLine(process.stdout, 0);
      readline.cursorTo(process.stdout, 0, -1);
      process.stdout.write(`=> Processing ${i + 1}/${moduleFileCount} - ${filename}`);
    }
 
    const css = sass
      .renderSync({
        data: `
        @import 'ui/_init.scss';
        @import '${filename}';
      `,
      })
      .css.toString();
 
    fs.ensureFileSync(outFile);
    fs.writeFileSync(outFile, css, 'utf8');
  });
 
  if (!suppressStdout) {
    process.stdout.write(`\n=> Generation Complete\n`);
  }
 
  if (callback) callback();
};
 
module.exports = {
  compileModularCSS,
};