Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async resolveAssetContents(asset) {
let contents = asset.generated[this.bundle.type]
if (!contents || (contents && contents.path)) {
contents = await fs.readFile(contents ? contents.path : asset.name)
}
console.log(asset.generated)
// Create sub-directories if needed
if (this.bundle.name.includes(path.sep)) {
await fs.mkdirp(path.dirname(this.bundle.name))
}
// Add the hot-reload.js script to background scripts
const json = JSON.parse(contents)
json.background = json.background || {}
json.background.scripts = json.background.scripts || []
json.background.scripts.unshift('hot-reload.js')
contents = JSON.stringify(json)
return contents
}
async addAsset(asset) {
const artifactsDir = path.resolve(
asset.options.outDir,
'..',
'artifacts'
)
await fs.mkdirp(artifactsDir)
// Write the manifest.json
const bundlePath = path.parse(this.bundle.name)
const contents = await this.resolveAssetContents(asset)
const hotReloadScriptFilename = path.resolve(
bundlePath.dir,
'hot-reload.js'
)
await fs.writeFile(hotReloadScriptFilename, hotReloadScript, {
encoding: 'utf8'
})
const manifestJsonFilename = path.resolve(
bundlePath.dir,
bundlePath.name + '.json'
)
await fs.writeFile(manifestJsonFilename, contents, { encoding: 'utf8' })