Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: provide metalsmith.on('built') #392

Open
Tracked by #405
webketje opened this issue Aug 31, 2023 · 0 comments
Open
Tracked by #405

Feature: provide metalsmith.on('built') #392

webketje opened this issue Aug 31, 2023 · 0 comments

Comments

@webketje
Copy link
Member

Currently only the end-user of a metalsmith build can choose to do post-processing on the build.

Use cases:

  • Plugins like metalsmith-debug-ui add dynamically generated files to the build that are not intended for plugin processing. Providing such an event would allow them to do this safely without requiring user tweaks with pattern-matching in subsequent plugins
  • This event would also allow plugins to encapsulate command-line tools (like exiftool or 7zip) to run on metalsmith.destination() with the guarantee that files have already been written

Given that plugins have access to the files object and it is passed by reference, care should be taken in the docs to discourage altering or overwriting user files in these event listeners (or Object.freez'ing it?). The listeners should be executed sequentially, and should properly handle async (maybe use another Ware instance?)

Sample usage:

// adding a dynamically generated file not intended for processing
metalsmith.use((files, metalsmith, done) => {
  metalsmith.on('built', async files => {
    const file = { contents: await fsPromises.readFile('dynamically-generated.html', 'utf-8') }
    files['dynamically-generated.html']  = file
  })
})

// running a command after completion
metalsmith.use((files, metalsmith, done) => {
  metalsmith.on('built', () => {
    execSync('ls -la', { cwd: metalsmith.destination() })
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant