Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/__tests__/build-scss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ describe('buildScssCommand', () => {
});
});

it('should compile core and theme stylesheets', () => {
it('should compile core and theme stylesheets', async () => {
const args = [
'--corePath=styles/core.scss',
'--themesPath=styles/themes',
'--outDir=dist',
'--defaultThemeVariants=light',
];

buildScssCommand(args);
await buildScssCommand(args);

expect(sass.compile).toHaveBeenCalledWith(
expect.stringContaining('core.scss'),
Expand All @@ -135,17 +135,17 @@ describe('buildScssCommand', () => {
);
});

it('should use default arguments when none provided', () => {
buildScssCommand([]);
it('should use default arguments when none provided', async () => {
await buildScssCommand([]);

expect(sass.compile).toHaveBeenCalledWith(
expect.stringContaining('core.scss'),
expect.any(Object),
);
});

it('should exclude core properly', () => {
buildScssCommand(['--excludeCore']);
it('should exclude core properly', async () => {
await buildScssCommand(['--excludeCore']);

expect(sass.compile).not.toHaveBeenCalledWith(
expect.stringContaining('core.scss'),
Expand Down
38 changes: 26 additions & 12 deletions lib/build-scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,13 @@ const compileAndWriteStyleSheets = ({
*
* @param {Array<string>} commandArgs - Command line arguments for building SCSS stylesheets.
*/
function buildScssCommand(commandArgs) {
async function buildScssCommand(commandArgs) {
process.on('SIGINT', () => {
// eslint-disable-next-line no-console
console.log(chalk.yellow('\nBuild interrupted. Partial output may exist in the output directory.'));
process.exit(130);
});

const defaultArgs = {
corePath: path.resolve(process.cwd(), 'styles/scss/core/core.scss'),
excludeCore: false,
Expand All @@ -168,27 +174,35 @@ function buildScssCommand(commandArgs) {
defaultThemeVariants,
} = minimist(commandArgs, { default: defaultArgs, boolean: ['excludeCore'] });

// eslint-disable-next-line no-console
console.log(chalk.grey('Press Ctrl+C to interrupt the build (takes effect between compilations).\n'));

// Core CSS
if (!excludeCore) {
compileAndWriteStyleSheets({
name: 'core',
stylesPath: corePath,
outDir,
});
// Yield to the event loop so pending SIGINT can be processed
await new Promise(resolve => setTimeout(resolve, 0));
}

// Theme Variants CSS
fs.readdirSync(themesPath, { withFileTypes: true })
.filter((item) => item.isDirectory())
.forEach((themeDir) => {
compileAndWriteStyleSheets({
name: themeDir.name,
stylesPath: `${themesPath}/${themeDir.name}/index.css`,
outDir,
isThemeVariant: true,
isDefaultThemeVariant: defaultThemeVariants.includes(themeDir.name),
});
// Theme variants CSS (sequential so SIGINT can be handled between compilations)
const themeDirs = fs.readdirSync(themesPath, { withFileTypes: true })
.filter((item) => item.isDirectory());

for (const themeDir of themeDirs) {
compileAndWriteStyleSheets({
name: themeDir.name,
stylesPath: `${themesPath}/${themeDir.name}/index.css`,
outDir,
isThemeVariant: true,
isDefaultThemeVariant: defaultThemeVariants.includes(themeDir.name),
});
// Yield to the event loop so pending SIGINT can be processed
await new Promise(resolve => setTimeout(resolve, 0));
}
}

module.exports = buildScssCommand;
Expand Down