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
35 changes: 19 additions & 16 deletions lib/build-watch.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { exec } from 'child_process';
import { exec, execSync } from 'child_process';
import { buildSync } from 'esbuild';
import copyfiles from 'copyfiles';
import fs from 'fs-extra';
import path from 'path';
import sass from 'sass';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

const env = process.env.NODE_ENV;
const argv = yargs(hideBin(process.argv)).argv;

// Start the compilation process
runCompilation(argv.files.split(','));
runCompilation(process.env.LERNA_FILE_CHANGES.split(','));

function runBuild() {
buildSync({
Expand All @@ -27,23 +24,29 @@ function runBuild() {

async function runCompilation(changedFiles) {
for (const changedFile of changedFiles) {
const fileWithExtension = path.basename(changedFile);
const filename = path.basename(changedFile, '.scss');
const extension = path.extname(changedFile);

if (extension === '.ts') {
console.log('TypeScript file change detected');
runBuild();
exec('npm run build:types', () => console.log('tsc incremental completed'));
exec('pnpm run build:types', () => {});
} else if (extension === '.scss') {
console.log('SASS file changed');
const basePath = path.join(process.cwd(), '/src/styles');
const absoluteFilePath = path.relative(basePath, changedFile);
const posixPath = absoluteFilePath.replaceAll('\\', '/');
console.log('SASS file change detected');
if (filename.startsWith('_')) {
// when _variables changes, let's rebuild all SASS files instead of just one
execSync('pnpm run sass:build');
} else {
const basePath = path.join(process.cwd(), '/src/styles');
const absoluteFilePath = path.relative(basePath, changedFile);
const posixPath = absoluteFilePath.replaceAll('\\', '/');

const fileWithExtension = path.basename(changedFile);
const filename = path.basename(changedFile, '.scss');
fs.outputFileSync(
`dist/styles/css/${posixPath.replace('.scss', '')}.css`,
sass.compile(`src/styles/${posixPath}`, { style: 'compressed', quietDeps: true, noSourceMap: true }).css
);
fs.outputFileSync(
`dist/styles/css/${posixPath.replace('.scss', '')}.css`,
sass.compile(`src/styles/${posixPath}`, { style: 'compressed', quietDeps: true, noSourceMap: true }).css
);
}

copyfiles([`src/styles/**/${filename}.scss`, 'dist/styles/sass'], { up: 2 }, (err) => {
if (err) {
Expand Down
3 changes: 1 addition & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"postcss": "^8.4.21",
"postcss-cli": "^10.1.0",
"sass": "^1.58.0",
"typescript": "^4.9.5",
"yargs": "^17.6.2"
"typescript": "^4.9.5"
}
}
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.