@@ -11,7 +11,7 @@ import { onExit } from "signal-exit";
1111import { PACKAGE_FILES } from "./constants.js" ;
1212import { loadConfig } from "./rolldown.js" ;
1313import { blue , bold , dim , green , greenBright , inverse } from "./utils/colors.js" ;
14- import { isTypeScriptProject , readPackageJson } from "./utils/fs.js" ;
14+ import { deployToMxProject , isTypeScriptProject , readPackageJson } from "./utils/fs.js" ;
1515import { createLogger } from "./utils/logger.js" ;
1616import { createMPK } from "./utils/mpk.js" ;
1717import { ProjectConfig } from "./utils/project-config.js" ;
@@ -32,27 +32,28 @@ export async function build(root: string | undefined, options: BuildCommandOptio
3232
3333 const [ pkg , isTsProject ] = await Promise . all ( [ readPackageJson ( root ) , isTypeScriptProject ( root ) ] ) ;
3434
35- const project = new ProjectConfig ( {
35+ const config = new ProjectConfig ( {
3636 pkg,
3737 isTsProject
3838 } ) ;
3939
40- const projectPath = await project . getProjectPath ( ) ;
40+ const projectPath = await config . getProjectPath ( ) ;
4141 if ( projectPath ) {
4242 logger . info ( formatMsg . mxpath ( projectPath ) ) ;
4343 }
4444
45- const bundles = await loadConfig ( project ) ;
45+ const bundles = await loadConfig ( config ) ;
4646
47- await fs . rm ( project . outputDirs . dist , { recursive : true , force : true } ) ;
48- console . dir ( project . inputFiles ) ;
49- console . dir ( project . outputDirs ) ;
50- console . dir ( project . outputFiles ) ;
51- console . dir ( project . assetsPublicPath ) ;
47+ await fs . rm ( config . outputDirs . dist , { recursive : true , force : true } ) ;
48+ console . dir ( config . inputFiles ) ;
49+ console . dir ( config . outputDirs ) ;
50+ console . dir ( config . outputFiles ) ;
51+ console . dir ( config . assetsPublicPath ) ;
52+ console . dir ( config . relativeWidgetPath ) ;
5253 if ( options . watch ) {
53- await tasks . watch ( { project , bundles, logger, root } ) ;
54+ await tasks . watch ( { config , bundles, logger, root } ) ;
5455 } else {
55- await tasks . build ( { project , bundles, logger, root } ) ;
56+ await tasks . build ( { config , bundles, logger, root } ) ;
5657 }
5758 } catch ( error ) {
5859 logger . error ( error ) ;
@@ -63,13 +64,13 @@ export async function build(root: string | undefined, options: BuildCommandOptio
6364interface TaskParams {
6465 root : string ;
6566 bundles : BuildOptions [ ] ;
66- project : ProjectConfig ;
67+ config : ProjectConfig ;
6768 logger : ConsolaInstance ;
6869}
6970
7071const tasks = {
7172 async build ( params : TaskParams ) : Promise < void > {
72- const { project , bundles, logger } = params ;
73+ const { config , bundles, logger } = params ;
7374 buildMeasure . start ( ) ;
7475
7576 for ( const bundle of bundles ) {
@@ -82,6 +83,11 @@ const tasks = {
8283
8384 const buildInfo = buildMeasure . end ( ) ;
8485 logger . success ( "Done in" , green ( ms ( buildInfo . duration ) ) ) ;
86+
87+ const projectPath = await config . getProjectPath ( ) ;
88+ if ( projectPath ) {
89+ await deployToMxProject ( config , projectPath ) ;
90+ }
8591 } ,
8692 async watch ( params : TaskParams ) : Promise < void > {
8793 const { root, bundles, logger } = params ;
@@ -127,11 +133,11 @@ const tasks = {
127133 logger . log ( "Build watcher stopped" ) ;
128134 } ) ;
129135 } ,
130- async copyPackageFiles ( { project } : TaskParams ) : Promise < void > {
136+ async copyPackageFiles ( { config } : TaskParams ) : Promise < void > {
131137 const stream = fg . stream ( PACKAGE_FILES ) ;
132138 for await ( const src of stream ) {
133139 const f = path . parse ( src as string ) ;
134- const dst = path . join ( project . outputDirs . contentRoot , f . base ) ;
140+ const dst = path . join ( config . outputDirs . contentRoot , f . base ) ;
135141
136142 await fs . cp ( src as string , dst , {
137143 recursive : true
@@ -140,15 +146,15 @@ const tasks = {
140146 } ,
141147 /** Watch & copy static package files */
142148 async watchPackageFiles ( params : TaskParams ) : Promise < void > {
143- const { project , logger } = params ;
149+ const { config , logger } = params ;
144150
145151 await tasks . copyPackageFiles ( params ) ;
146152
147153 const watcher = chokidar . watch ( await fg ( PACKAGE_FILES ) ) ;
148154 watcher . on ( "change" , async file => {
149155 logger . info ( formatMsg . copy ( file ) ) ;
150156 const f = path . parse ( file ) ;
151- const dst = path . join ( project . outputDirs . contentRoot , f . base ) ;
157+ const dst = path . join ( config . outputDirs . contentRoot , f . base ) ;
152158 await fs . cp ( file , dst ) ;
153159 } ) ;
154160
@@ -158,9 +164,9 @@ const tasks = {
158164 } ,
159165 /** Setup package content watcher to build mpk whenever package files change */
160166 async watchPackageContent ( params : TaskParams ) : Promise < void > {
161- const { project } = params ;
167+ const { config } = params ;
162168 await tasks . buildMpk ( { ...params , quiet : true } ) ;
163- const watcher = chokidar . watch ( project . outputDirs . contentRoot ) ;
169+ const watcher = chokidar . watch ( config . outputDirs . contentRoot ) ;
164170
165171 let debounceTimer : NodeJS . Timeout | null = null ;
166172
@@ -179,7 +185,7 @@ const tasks = {
179185 watcher . close ( ) ;
180186 } ) ;
181187 } ,
182- async buildMpk ( { project, logger, quiet = false } : TaskParams & { quiet ?: boolean } ) : Promise < void > {
188+ async buildMpk ( { config : project , logger, quiet = false } : TaskParams & { quiet ?: boolean } ) : Promise < void > {
183189 await createMPK ( project . outputDirs . contentRoot , project . outputFiles . mpk ) ;
184190 const mpkStat = await fs . stat ( project . outputFiles . mpk ) ;
185191 if ( ! quiet ) {
0 commit comments