mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-23 02:10:12 +01:00
7686edadb0
* 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>
75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
const { promises: fs } = require('fs')
|
|
const Koa = require('koa')
|
|
const path = require('path')
|
|
|
|
const CURRENT_STATE_KEY = '__CURRENT__'
|
|
const DEFAULT_STATE_KEY = '__DEFAULT__'
|
|
|
|
const FIXTURE_SERVER_HOST = 'localhost'
|
|
const FIXTURE_SERVER_PORT = 12345
|
|
|
|
class FixtureServer {
|
|
constructor () {
|
|
this._app = new Koa()
|
|
this._stateMap = new Map([
|
|
[DEFAULT_STATE_KEY, Object.create(null)],
|
|
])
|
|
this._initialStateCache = new Map()
|
|
|
|
this._app.use(async (ctx) => {
|
|
// Firefox is _super_ strict about needing CORS headers
|
|
ctx.set('Access-Control-Allow-Origin', '*')
|
|
if (this._isStateRequest(ctx)) {
|
|
ctx.body = this._stateMap.get(CURRENT_STATE_KEY)
|
|
}
|
|
})
|
|
}
|
|
|
|
async start () {
|
|
const options = {
|
|
host: FIXTURE_SERVER_HOST,
|
|
port: FIXTURE_SERVER_PORT,
|
|
exclusive: true,
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
this._server = this._app.listen(options)
|
|
this._server.once('error', reject)
|
|
this._server.once('listening', resolve)
|
|
})
|
|
}
|
|
|
|
async stop () {
|
|
if (!this._server) {
|
|
return
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
this._server.close()
|
|
this._server.once('error', reject)
|
|
this._server.once('close', resolve)
|
|
})
|
|
}
|
|
|
|
async loadState (directory) {
|
|
const statePath = path.resolve(__dirname, directory, 'state.json')
|
|
|
|
let state
|
|
if (this._initialStateCache.has(statePath)) {
|
|
state = this._initialStateCache.get(statePath)
|
|
} else {
|
|
const data = await fs.readFile(statePath)
|
|
state = JSON.parse(data.toString('utf-8'))
|
|
this._initialStateCache.set(statePath, state)
|
|
}
|
|
|
|
this._stateMap.set(CURRENT_STATE_KEY, state)
|
|
}
|
|
|
|
_isStateRequest (ctx) {
|
|
return ctx.method === 'GET' && ctx.path === '/state.json'
|
|
}
|
|
}
|
|
|
|
module.exports = FixtureServer
|