@@ -38,12 +38,11 @@ async function main() {
38
38
const srcDir = path . join ( packageRoot , 'src' ) ;
39
39
const distDir = path . join ( packageRoot , 'dist' ) ;
40
40
41
-
42
41
if ( ! fs . existsSync ( srcDir ) ) {
43
42
console . error ( `The package directory "${ packageRoot } " does not contain a "src" directory.` ) ;
44
43
process . exit ( 1 ) ;
45
44
}
46
-
45
+
47
46
if ( fs . existsSync ( distDir ) ) {
48
47
console . log ( `Cleaning up the "${ distDir } " directory...` ) ;
49
48
await fs . promises . rm ( distDir , { recursive : true } ) ;
@@ -53,41 +52,42 @@ async function main() {
53
52
const inputScriptFiles = [
54
53
...glob . sync ( path . join ( srcDir , '*controller.ts' ) ) ,
55
54
...( [ '@symfony/ux-react' , '@symfony/ux-vue' , '@symfony/ux-svelte' ] . includes ( packageName )
56
- ? [
57
- path . join ( srcDir , 'loader.ts' ) ,
58
- path . join ( srcDir , 'components.ts' ) ,
59
- ]
55
+ ? [ path . join ( srcDir , 'loader.ts' ) , path . join ( srcDir , 'components.ts' ) ]
60
56
: [ ] ) ,
61
57
...( packageName === '@symfony/stimulus-bundle'
62
- ? [
63
- path . join ( srcDir , 'loader.ts' ) ,
64
- path . join ( srcDir , 'controllers.ts' ) ,
65
- ] : [ ] ) ,
58
+ ? [ path . join ( srcDir , 'loader.ts' ) , path . join ( srcDir , 'controllers.ts' ) ]
59
+ : [ ] ) ,
66
60
] ;
67
-
68
- const inputStyleFile = packageData . config && packageData . config . css_source ;
61
+
62
+ const inputStyleFile = packageData . config ? .css_source ;
69
63
const buildCss = async ( ) => {
70
- const inputStyleFileDist = inputStyleFile ? path . resolve ( distDir , `${ path . basename ( inputStyleFile , '.css' ) } .min.css` ) : undefined ;
64
+ const inputStyleFileDist = inputStyleFile
65
+ ? path . resolve ( distDir , `${ path . basename ( inputStyleFile , '.css' ) } .min.css` )
66
+ : undefined ;
71
67
if ( ! inputStyleFile ) {
72
68
return ;
73
69
}
74
-
70
+
75
71
console . log ( 'Minifying CSS...' ) ;
76
72
const css = await fs . promises . readFile ( inputStyleFile , 'utf-8' ) ;
77
73
const minified = new CleanCSS ( ) . minify ( css ) . styles ;
78
74
await fs . promises . writeFile ( inputStyleFileDist , minified ) ;
79
- }
75
+ } ;
80
76
81
77
if ( inputScriptFiles . length === 0 ) {
82
- console . error ( `No input files found for package "${ packageName } " (directory "${ packageRoot } ").\nEnsure you have at least a file matching the pattern "src/*_controller.ts", or manually specify input files in "${ __filename } " file.` ) ;
78
+ console . error (
79
+ `No input files found for package "${ packageName } " (directory "${ packageRoot } ").\nEnsure you have at least a file matching the pattern "src/*_controller.ts", or manually specify input files in "${ __filename } " file.`
80
+ ) ;
83
81
process . exit ( 1 ) ;
84
82
}
85
83
86
84
const rollupConfig = getRollupConfiguration ( { packageRoot, inputFiles : inputScriptFiles } ) ;
87
85
88
86
if ( args . values . watch ) {
89
- console . log ( `Watching for JavaScript${ inputStyleFile ? ' and CSS' : '' } files modifications in "${ srcDir } " directory...` ) ;
90
-
87
+ console . log (
88
+ `Watching for JavaScript${ inputStyleFile ? ' and CSS' : '' } files modifications in "${ srcDir } " directory...`
89
+ ) ;
90
+
91
91
if ( inputStyleFile ) {
92
92
rollupConfig . plugins = ( rollupConfig . plugins || [ ] ) . concat ( {
93
93
name : 'watcher' ,
@@ -96,7 +96,7 @@ async function main() {
96
96
} ,
97
97
} ) ;
98
98
}
99
-
99
+
100
100
const watcher = rollup . watch ( rollupConfig ) ;
101
101
watcher . on ( 'event' , ( { result } ) => {
102
102
if ( result ) {
@@ -105,7 +105,7 @@ async function main() {
105
105
} ) ;
106
106
watcher . on ( 'change' , async ( id , { event } ) => {
107
107
if ( event === 'update' ) {
108
- console . log ( ` Files were modified, rebuilding...` ) ;
108
+ console . log ( ' Files were modified, rebuilding...' ) ;
109
109
}
110
110
111
111
if ( inputStyleFile && id === inputStyleFile ) {
@@ -115,12 +115,12 @@ async function main() {
115
115
} else {
116
116
console . log ( `Building JavaScript files from ${ packageName } package...` ) ;
117
117
const start = Date . now ( ) ;
118
-
118
+
119
119
const bundle = await rollup . rollup ( rollupConfig ) ;
120
120
await bundle . write ( rollupConfig . output ) ;
121
-
121
+
122
122
await buildCss ( ) ;
123
-
123
+
124
124
console . log ( `Done in ${ ( ( Date . now ( ) - start ) / 1000 ) . toFixed ( 3 ) } seconds.` ) ;
125
125
}
126
126
}
0 commit comments