From 3c3c094b61d42a2ae82bc1d565090bf90c89ad19 Mon Sep 17 00:00:00 2001 From: Olivier El Mekki Date: Thu, 6 Jun 2024 13:47:13 +0200 Subject: [PATCH] ADD post-build hook Allow to configure a hook to be ran whenever a build is made, so that users can perform post-build tasks. This is especially useful for the `dev` task, as a build is ran each time the filetree changes. This is an opportunity for users to perform custom tasks that they may need on every builds. To do so, they just have to declare a POST_BUILD_SCRIPT environment variable containing the path to a script, like this: POST_BUILD_SCRIPT=./post-build.cjs plasmo dev --- cli/plasmo/src/features/manifest-factory/base.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cli/plasmo/src/features/manifest-factory/base.ts b/cli/plasmo/src/features/manifest-factory/base.ts index abc2390f7..a6b7cde3b 100644 --- a/cli/plasmo/src/features/manifest-factory/base.ts +++ b/cli/plasmo/src/features/manifest-factory/base.ts @@ -224,6 +224,19 @@ export abstract class PlasmoManifest { } }) ) + + if (!process.env.POST_BUILD_SCRIPT) + return + + const postBuildPath = resolve(process.env.POST_BUILD_SCRIPT) + + if (!existsSync(postBuildPath)) { + console.error("Post-build file does not exist or is not readable:", postBuildPath) + return + } + + const postBuild = require(postBuildPath) + postBuild() } async updateEnv() {