Skip to content

Commit

Permalink
ADD post-build hook
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oelmekki committed Jun 6, 2024
1 parent 5b983c2 commit 3c3c094
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/plasmo/src/features/manifest-factory/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ export abstract class PlasmoManifest<T extends ExtensionManifest = any> {
}
})
)

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() {
Expand Down

0 comments on commit 3c3c094

Please sign in to comment.