1
- import { exec } from 'child_process' ;
1
+ import { exec , execSync } from 'child_process' ;
2
2
import { buildSync } from 'esbuild' ;
3
3
import copyfiles from 'copyfiles' ;
4
4
import fs from 'fs-extra' ;
5
5
import path from 'path' ;
6
6
import sass from 'sass' ;
7
- import yargs from 'yargs' ;
8
- import { hideBin } from 'yargs/helpers' ;
9
7
10
8
const env = process . env . NODE_ENV ;
11
- const argv = yargs ( hideBin ( process . argv ) ) . argv ;
12
9
13
10
// Start the compilation process
14
- runCompilation ( argv . files . split ( ',' ) ) ;
11
+ runCompilation ( process . env . LERNA_FILE_CHANGES . split ( ',' ) ) ;
15
12
16
13
function runBuild ( ) {
17
14
buildSync ( {
@@ -27,23 +24,29 @@ function runBuild() {
27
24
28
25
async function runCompilation ( changedFiles ) {
29
26
for ( const changedFile of changedFiles ) {
27
+ const fileWithExtension = path . basename ( changedFile ) ;
28
+ const filename = path . basename ( changedFile , '.scss' ) ;
30
29
const extension = path . extname ( changedFile ) ;
30
+
31
31
if ( extension === '.ts' ) {
32
32
console . log ( 'TypeScript file change detected' ) ;
33
33
runBuild ( ) ;
34
- exec ( 'npm run build:types' , ( ) => console . log ( 'tsc incremental completed' ) ) ;
34
+ exec ( 'pnpm run build:types' , ( ) => { } ) ;
35
35
} 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 ( '\\' , '/' ) ;
40
44
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
+ }
47
50
48
51
copyfiles ( [ `src/styles/**/${ filename } .scss` , 'dist/styles/sass' ] , { up : 2 } , ( err ) => {
49
52
if ( err ) {
0 commit comments