1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/development/build/manifest.js
kumavis 7686edadb0
Build system refactor (#8140)
* build - start static asset task cleanup

* build - simplify manifest tasks

* build - refactor + rename some tasks

* build - various cleanups

* manifest - fix ref from controller

* build - drop gulp for simple async tasks

* build - breakout gulpfile into multiple files

* build - rename some tasks

* build - use task fn refs instead of string names

* build - bundle all scripts first, except for contentscript

* build - improve task timeline

* deps - update lock

* build - improve task time printout

* build/scripts - remove intermediate named task

* build - use 'yarn build' for task entry points

* build - properly run tasks via runTask for timeline display

* development/announcer - fix manifest path + clean

* build - lint fix

* build - make all defined tasks possible entry points

* build/task - properly report errors during task

* ci - fix sesify/lavamoat-viz build command

* build/scripts - run each bundle in separate processes

* lint fix

* build - forward childProcess logs to console

* build/task - fix parallel/series stream end event

* build/scripts refactor contentscript+inpage into a single task

* build/static - use the fs for 150x speedup zomg

* lint fix

* build/static - fix css copy

* Update development/build/scripts.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/scripts.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/index.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* deps - remove redundant mkdirp

* deps - remove unused pumpify

* deps - remove redundant merge-deep

* deps - prefer is-stream of isstream

* deps - remove clone for lodash.cloneDeep

* clean - remove commented code

* build/static - use fs.copy + fast-glob instead of linux cp for better platform support

* build/manifest - standardize task naming

* build/display - clean - remove unused code

* bugfix - fix fs.promises import

* build - create "clean" as named task for use as entrypoint

* build/static - fix for copying dirs

* Update development/build/task.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/display.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/display.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/display.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* build - use task refs, tasks only return promises not streams, etc

* lint fi bad merge + lint

* build - one last cleanup + refactor

* build - add comments introducing file

* build/manifest - fix bug + subtasks dont beed to be named

* Update package.json

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* build/task - remove unused fn

* Update package.json

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/styles.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

* Update development/build/styles.js

Co-Authored-By: Mark Stacey <markjstacey@gmail.com>

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-03-09 08:55:02 +08:00

98 lines
3.0 KiB
JavaScript

const { promises: fs } = require('fs')
const { merge, cloneDeep } = require('lodash')
const baseManifest = require('../../app/manifest/_base.json')
const { createTask, composeSeries } = require('./task')
module.exports = createManifestTasks
const scriptsToExcludeFromBackgroundDevBuild = {
'bg-libs.js': true,
}
function createManifestTasks ({ browserPlatforms }) {
// merge base manifest with per-platform manifests
const prepPlatforms = async () => {
return Promise.all(browserPlatforms.map(async (platform) => {
const platformModifications = await readJson(`${__dirname}/../../app/manifest/${platform}.json`)
const result = merge(cloneDeep(baseManifest), platformModifications)
const dir = `./dist/${platform}`
await fs.mkdir(dir, { recursive: true })
await writeJson(result, `${dir}/manifest.json`)
}))
}
// dev: remove bg-libs, add chromereload, add perms
const envDev = createTaskForModifyManifestForEnvironment((manifest) => {
const scripts = manifest.background.scripts.filter((scriptName) => !scriptsToExcludeFromBackgroundDevBuild[scriptName])
scripts.push('chromereload.js')
manifest.background = {
...manifest.background,
scripts,
}
manifest.permissions = [...manifest.permissions, 'webRequestBlocking']
})
// testDev: remove bg-libs, add perms
const envTestDev = createTaskForModifyManifestForEnvironment((manifest) => {
const scripts = manifest.background.scripts.filter((scriptName) => !scriptsToExcludeFromBackgroundDevBuild[scriptName])
scripts.push('chromereload.js')
manifest.background = {
...manifest.background,
scripts,
}
manifest.permissions = [...manifest.permissions, 'webRequestBlocking', 'http://localhost/*']
})
// test: add permissions
const envTest = createTaskForModifyManifestForEnvironment((manifest) => {
manifest.permissions = [...manifest.permissions, 'webRequestBlocking', 'http://localhost/*']
})
// high level manifest tasks
const dev = createTask('manifest:dev', composeSeries(
prepPlatforms,
envDev,
))
const testDev = createTask('manifest:testDev', composeSeries(
prepPlatforms,
envTestDev,
))
const test = createTask('manifest:test', composeSeries(
prepPlatforms,
envTest,
))
const prod = createTask('manifest:prod', prepPlatforms)
return { prod, dev, testDev, test }
// helper for modifying each platform's manifest.json in place
function createTaskForModifyManifestForEnvironment (transformFn) {
return () => {
return Promise.all(browserPlatforms.map(async (platform) => {
const path = `./dist/${platform}/manifest.json`
const manifest = await readJson(path)
transformFn(manifest)
await writeJson(manifest, path)
}))
}
}
}
// helper for reading and deserializing json from fs
async function readJson (path) {
return JSON.parse(await fs.readFile(path, 'utf8'))
}
// helper for serializing and writing json to fs
async function writeJson (obj, path) {
return fs.writeFile(path, JSON.stringify(obj, null, 2))
}