Skip to content

Commit

Permalink
feat(rn-runner): support onBuildFinish hook
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqingchen authored and Chen-jj committed May 7, 2021
1 parent 64a216d commit 9d7169d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/taro-rn-runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export default async function build (appPath: string, config: any): Promise<any>
metroConfig.resetCache = config.resetCache
}
metroConfig.reporter = new TerminalReporter(entry, sourceRoot, metroConfig.cacheStores[0])

const onFinish = function (error?) {
if (typeof config.onBuildFinish !== 'function') return
config.onBuildFinish({
error,
isWatch: config.isWatch
})
}

if (config.isWatch) {
if (!metroConfig.server || (metroConfig.server.useGlobalHotkey === undefined)) {
if (!metroConfig.server) {
Expand Down Expand Up @@ -105,7 +114,7 @@ export default async function build (appPath: string, config: any): Promise<any>
hmrEnabled: true
}).then(server => {
console.log(`React-Native Dev server is running on port: ${metroConfig.server.port}`)
console.log('\n\nTo reload the app press "r"\nTo open developer menu press "d"')
console.log('\n\nTo reload the app press "r"\nTo open developer menu press "d"\n')

const { messageSocket } = attachToServer(server)

Expand All @@ -123,7 +132,10 @@ export default async function build (appPath: string, config: any): Promise<any>
process.exit()
}
})
onFinish(null)
return server
}).catch(e => {
onFinish(e)
})
} else {
const options = {
Expand Down Expand Up @@ -159,7 +171,11 @@ export default async function build (appPath: string, config: any): Promise<any>
...Server.DEFAULT_BUNDLE_OPTIONS,
...requestOptions
})
return await saveAssets(outputAssets, options.platform, concatOutputAssetsDest(config))
return await saveAssets(outputAssets, options.platform, concatOutputAssetsDest(config)).then(() => {
onFinish(null)
})
} catch (e) {
onFinish(e)
} finally {
server.end()
}
Expand Down

0 comments on commit 9d7169d

Please sign in to comment.