@@ -20,8 +20,11 @@ const devCompileLog = require('./utils/raxDevCompileLog');
2020const buildCompileLog = require ( './utils/raxBuildCompileLog' ) ;
2121const modifyPkgHomePage = require ( './utils/modifyPkgHomePage' ) ;
2222const getDemoConfig = require ( './configs/rax/getDemoConfig' ) ;
23+ const getReadme = require ( './utils/getReadme' ) ;
24+ const generateRaxDemo = require ( './utils/generateRaxDemo' ) ;
25+ const { setModulesInfo } = require ( './utils/getPortalModules' ) ;
2326
24- module . exports = ( { registerTask, registerUserConfig, context, onHook, registerCliOption, onGetWebpackConfig, onGetJestConfig, modifyUserConfig, log } ) => {
27+ module . exports = ( { registerTask, registerUserConfig, context, onHook, registerCliOption, onGetWebpackConfig, onGetJestConfig, modifyUserConfig, log, registerMethod , setValue } ) => {
2528 const { rootDir, userConfig, command, pkg, commandArgs } = context ;
2629 const { plugins, targets, disableUMD, inlineStyle = true , ...compileOptions } = userConfig ;
2730 if ( ! ( targets && targets . length ) ) {
@@ -37,6 +40,12 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
3740 registerUserConfig ( defaultUserConfig . concat ( raxUserConfig ) ) ;
3841 // disable demo when watch dist
3942
43+ registerMethod ( 'pluginComponentGetDemoDir' , getDemoDir ) ;
44+ registerMethod ( 'pluginComponentGetDemos' , getDemos ) ;
45+ registerMethod ( 'pluginComponentGetReadme' , getReadme ) ;
46+ registerMethod ( 'pluginComponentSetPortalModules' , setModulesInfo ) ;
47+ setValue ( 'pluginComponentDir' , __dirname ) ;
48+
4049 let entries = { } ;
4150 let serverBundles = { } ;
4251 let demos = [ ] ;
@@ -76,7 +85,7 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
7685 if ( raxBundles ) {
7786 entries = raxBundles . entries ;
7887 serverBundles = raxBundles . serverBundles ;
79- const demoConfig = getDemoConfig ( context , { ...compileOptions , entries, demos } ) ;
88+ const demoConfig = getDemoConfig ( context , { ...compileOptions , entries, demos, inlineStyle } ) ;
8089 registerTask ( 'component-demo' , demoConfig ) ;
8190 }
8291 }
@@ -108,7 +117,7 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
108117 fse . removeSync ( path . join ( rootDir , 'build' ) ) ;
109118 fse . removeSync ( path . join ( rootDir , 'es' ) ) ;
110119
111- targets . forEach ( target => {
120+ targets . forEach ( ( target ) => {
112121 const options = { ...userConfig , target, inlineStyle } ;
113122 if ( target === WEB ) {
114123 registerTask ( `component-build-${ target } ` , getDistConfig ( context , options ) ) ;
@@ -140,16 +149,22 @@ module.exports = ({ registerTask, registerUserConfig, context, onHook, registerC
140149 } ) ;
141150 }
142151
152+ onHook ( `before.${ command } .run` , async ( ) => {
153+ await generateRaxDemo ( demos , context ) ;
154+ } ) ;
155+
143156 onHook ( 'after.build.compile' , async ( args ) => {
144157 buildCompileLog ( args , targets , rootDir , userConfig ) ;
145158 if ( ! skipDemo ) {
146159 await modifyPkgHomePage ( pkg , rootDir ) ;
147160 }
148161 } ) ;
162+
149163 onHook ( 'after.start.compile' , async ( args ) => {
150164 const devUrl = args . url ;
151165 devCompileLog ( args , devUrl , targets , entries , rootDir , { ...userConfig , watchDist } ) ;
152166 } ) ;
167+
153168 if ( command === 'test' ) {
154169 // jest config
155170 onGetJestConfig ( ( jestConfig ) => {
@@ -177,4 +192,4 @@ function addMiniappTargetParam(target, originalConfig = {}) {
177192 break ;
178193 }
179194 originalConfig . mode = 'watch' ;
180- }
195+ }
0 commit comments