@@ -22,6 +22,12 @@ function saveCache(cache) {
2222 fs . writeFileSync ( CACHE_FILE , JSON . stringify ( cache , null , 2 ) )
2323}
2424
25+ function parseOptions ( argv = process . argv . slice ( 2 ) ) {
26+ return {
27+ force : argv . includes ( '--force' ) || argv . includes ( '-f' ) || argv . includes ( 'force' ) ,
28+ }
29+ }
30+
2531function isModified ( dirPath , lastCompileTime ) {
2632 const files = fs . readdirSync ( dirPath )
2733 for ( const file of files ) {
@@ -120,12 +126,13 @@ async function cleanUpOldApps(targetPath, appList) {
120126 }
121127}
122128
123- async function buildMiniApp ( ) {
129+ async function buildMiniApp ( options = { } ) {
130+ const { force = false } = options
124131 const currentDirectory = `${ process . cwd ( ) } /example`
125132 const cache = loadCache ( )
126133
127134 // 检查编译器是否被修改
128- const compilerModified = isCompilerModified ( cache . compilerLastModified )
135+ const compilerModified = force || isCompilerModified ( cache . compilerLastModified )
129136
130137 fs . readdir ( currentDirectory , async ( err , files ) => {
131138 if ( err ) {
@@ -148,7 +155,7 @@ async function buildMiniApp() {
148155 const lastCompileTime = cache . apps [ fileName ] ?. lastCompileTime || 0
149156
150157 // 检查是否需要重新编译
151- if ( compilerModified || isModified ( workPath , lastCompileTime ) ) {
158+ if ( force || compilerModified || isModified ( workPath , lastCompileTime ) ) {
152159 const appInfo = await build ( targetPath , workPath )
153160 if ( appInfo ) {
154161 appList . push ( appInfo )
@@ -206,4 +213,4 @@ function getLastCompileTime(data, appId) {
206213 return 0 // 如果找不到对应的 appId
207214}
208215
209- buildMiniApp ( )
216+ buildMiniApp ( parseOptions ( ) )
0 commit comments