Skip to content
Merged
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
9 changes: 8 additions & 1 deletion bin/paragon-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ const COMMANDS = {
},
{
name: '--defaultThemeVariants',
description: `Specifies default theme variants. Defaults to a single 'light' theme variant.
description: `Specifies which theme variants are marked as defaults in the generated theme-urls.json.
Consuming applications (Open edX micro-frontends) use theme-urls.json to determine
which theme CSS files to load; variants listed here are loaded automatically without
requiring explicit configuration.
You can provide multiple default theme variants by passing multiple values, for
example: \`--defaultThemeVariants light dark\`
`,
Expand Down Expand Up @@ -262,6 +265,10 @@ const COMMANDS = {
* @function executeParagonCommand
*/
(async () => {
process.on('SIGINT', () => {
process.exit(130);
});

const [command, ...commandArgs] = process.argv.slice(2);
const resolvedCommand = commandAliases[command] || command;
const executor = COMMANDS[resolvedCommand];
Expand Down
33 changes: 29 additions & 4 deletions lib/__tests__/build-scss.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
const os = require('os');
const sass = require('sass');

const buildScssCommand = require('../build-scss');
Expand Down Expand Up @@ -135,17 +138,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 All @@ -158,3 +161,25 @@ describe('buildScssCommand', () => {
);
});
});

describe('SIGINT handling', () => {
it('should exit with code 130 when SIGINT is received during build', async () => {
const child = spawn(process.execPath, [
path.resolve(__dirname, '../../bin/paragon-scripts.js'),
'build-scss',
`--outDir=${path.join(os.tmpdir(), 'build-scss-sigint-test')}`,
], {
cwd: path.resolve(__dirname, '../..'),
stdio: 'ignore',
});

const { code, signal } = await new Promise((resolve) => {
child.on('exit', (exitCode, exitSignal) => resolve({ code: exitCode, signal: exitSignal }));
setTimeout(() => child.kill('SIGINT'), 500);
});

// Process was terminated by SIGINT — either our handler called process.exit(130)
// or default signal handling killed it before the handler was registered
expect(code === 130 || signal === 'SIGINT').toBe(true);
}, 30000);
});
10 changes: 9 additions & 1 deletion lib/__tests__/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,15 @@ describe('helpCommand', () => {
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining(`${chalk.yellow.bold('--defaultThemeVariants')} ${chalk.grey('Default: light')}`),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('Specifies default theme variants'));
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Specifies which theme variants are marked as defaults in the generated theme-urls.json.'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('Consuming applications (Open edX micro-frontends) use theme-urls.json'),
);
expect(console.log).toHaveBeenCalledWith(
expect.stringContaining('variants listed here are loaded automatically without'),
);
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('You can provide multiple default theme variants'));
expect(console.log).toHaveBeenCalledWith(expect.stringContaining('example: `--defaultThemeVariants light dark`'));
/* eslint-enable no-console */
Expand Down
23 changes: 12 additions & 11 deletions lib/build-scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,19 @@ function buildScssCommand(commandArgs) {
});
}

// 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
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),
});
}
}

module.exports = buildScssCommand;
Expand Down
Loading