Skip to content

Commit 1d9b26c

Browse files
authored
Merge pull request #6 from ghiscoding/chore/select-all-outside-ul-list
chore: use lerna env variable to get file changes
2 parents f9bf76c + bdd975d commit 1d9b26c

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

lib/build-watch.mjs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import { exec } from 'child_process';
1+
import { exec, execSync } from 'child_process';
22
import { buildSync } from 'esbuild';
33
import copyfiles from 'copyfiles';
44
import fs from 'fs-extra';
55
import path from 'path';
66
import sass from 'sass';
7-
import yargs from 'yargs';
8-
import { hideBin } from 'yargs/helpers';
97

108
const env = process.env.NODE_ENV;
11-
const argv = yargs(hideBin(process.argv)).argv;
129

1310
// Start the compilation process
14-
runCompilation(argv.files.split(','));
11+
runCompilation(process.env.LERNA_FILE_CHANGES.split(','));
1512

1613
function runBuild() {
1714
buildSync({
@@ -27,23 +24,29 @@ function runBuild() {
2724

2825
async function runCompilation(changedFiles) {
2926
for (const changedFile of changedFiles) {
27+
const fileWithExtension = path.basename(changedFile);
28+
const filename = path.basename(changedFile, '.scss');
3029
const extension = path.extname(changedFile);
30+
3131
if (extension === '.ts') {
3232
console.log('TypeScript file change detected');
3333
runBuild();
34-
exec('npm run build:types', () => console.log('tsc incremental completed'));
34+
exec('pnpm run build:types', () => {});
3535
} else if (extension === '.scss') {
36-
console.log('SASS file changed');
37-
const basePath = path.join(process.cwd(), '/src/styles');
38-
const absoluteFilePath = path.relative(basePath, changedFile);
39-
const posixPath = absoluteFilePath.replaceAll('\\', '/');
36+
console.log('SASS file change detected');
37+
if (filename.startsWith('_')) {
38+
// when _variables changes, let's rebuild all SASS files instead of just one
39+
execSync('pnpm run sass:build');
40+
} else {
41+
const basePath = path.join(process.cwd(), '/src/styles');
42+
const absoluteFilePath = path.relative(basePath, changedFile);
43+
const posixPath = absoluteFilePath.replaceAll('\\', '/');
4044

41-
const fileWithExtension = path.basename(changedFile);
42-
const filename = path.basename(changedFile, '.scss');
43-
fs.outputFileSync(
44-
`dist/styles/css/${posixPath.replace('.scss', '')}.css`,
45-
sass.compile(`src/styles/${posixPath}`, { style: 'compressed', quietDeps: true, noSourceMap: true }).css
46-
);
45+
fs.outputFileSync(
46+
`dist/styles/css/${posixPath.replace('.scss', '')}.css`,
47+
sass.compile(`src/styles/${posixPath}`, { style: 'compressed', quietDeps: true, noSourceMap: true }).css
48+
);
49+
}
4750

4851
copyfiles([`src/styles/**/${filename}.scss`, 'dist/styles/sass'], { up: 2 }, (err) => {
4952
if (err) {

lib/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"postcss": "^8.4.21",
6262
"postcss-cli": "^10.1.0",
6363
"sass": "^1.58.0",
64-
"typescript": "^4.9.5",
65-
"yargs": "^17.6.2"
64+
"typescript": "^4.9.5"
6665
}
6766
}

pnpm-lock.yaml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)