diff --git a/lib/build-watch.mjs b/lib/build-watch.mjs index ee598d68..4df55884 100644 --- a/lib/build-watch.mjs +++ b/lib/build-watch.mjs @@ -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({ @@ -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) { diff --git a/lib/package.json b/lib/package.json index e165b3bf..875e0d7c 100644 --- a/lib/package.json +++ b/lib/package.json @@ -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" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index daf0e870..f84e9f86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,7 +69,6 @@ importers: postcss-cli: ^10.1.0 sass: ^1.58.0 typescript: ^4.9.5 - yargs: ^17.6.2 devDependencies: autoprefixer: 10.4.13_postcss@8.4.21 copyfiles: 2.4.1 @@ -81,7 +80,6 @@ importers: postcss-cli: 10.1.0_postcss@8.4.21 sass: 1.58.0 typescript: 4.9.5 - yargs: 17.6.2 packages: