Skip to content

Commit

Permalink
feat: add post-build hook (#992)
Browse files Browse the repository at this point in the history
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

The provided script must export a function, which will be executed:

```javascript
module.exports = function() {
  // do stuff after build is done
}
```

Co-authored-by: L <[email protected]>
  • Loading branch information
oelmekki and louisgv committed Jun 8, 2024
1 parent c01e039 commit 082f22d
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 082f22d

Please sign in to comment.