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

Build system refactor #8140

Merged
merged 59 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f1be8af
build - start static asset task cleanup
kumavis Feb 27, 2020
9f5ee68
build - simplify manifest tasks
kumavis Feb 27, 2020
b3c336b
build - refactor + rename some tasks
kumavis Feb 27, 2020
2bae542
build - various cleanups
kumavis Feb 27, 2020
51895b8
manifest - fix ref from controller
kumavis Feb 27, 2020
04a934d
build - drop gulp for simple async tasks
kumavis Feb 28, 2020
e575c98
build - breakout gulpfile into multiple files
kumavis Feb 28, 2020
0328465
build - rename some tasks
kumavis Feb 28, 2020
fddb209
build - use task fn refs instead of string names
kumavis Feb 28, 2020
7fce940
build - bundle all scripts first, except for contentscript
kumavis Feb 28, 2020
4a042a3
build - improve task timeline
kumavis Feb 28, 2020
d242e0a
deps - update lock
kumavis Feb 28, 2020
41b44f0
build - improve task time printout
kumavis Mar 2, 2020
cd39d38
build/scripts - remove intermediate named task
kumavis Mar 2, 2020
5f82b00
build - use 'yarn build' for task entry points
kumavis Mar 2, 2020
e3fb072
build - properly run tasks via runTask for timeline display
kumavis Mar 2, 2020
36bd9a5
development/announcer - fix manifest path + clean
kumavis Mar 2, 2020
78c8141
build - lint fix
kumavis Mar 2, 2020
83f5098
build - make all defined tasks possible entry points
kumavis Mar 2, 2020
393263d
build/task - properly report errors during task
kumavis Mar 2, 2020
4ff258e
ci - fix sesify/lavamoat-viz build command
kumavis Mar 2, 2020
32c399a
build/scripts - run each bundle in separate processes
kumavis Mar 2, 2020
609203d
lint fix
kumavis Mar 2, 2020
0ad3dc6
build - forward childProcess logs to console
kumavis Mar 2, 2020
08e2eee
build/task - fix parallel/series stream end event
kumavis Mar 3, 2020
3d22591
build/scripts refactor contentscript+inpage into a single task
kumavis Mar 3, 2020
cbed1ef
build/static - use the fs for 150x speedup zomg
kumavis Mar 3, 2020
2989988
lint fix
kumavis Mar 3, 2020
c75cd66
build/static - fix css copy
kumavis Mar 3, 2020
ec58397
Update development/build/scripts.js
kumavis Mar 6, 2020
634c66f
Update development/build/scripts.js
kumavis Mar 6, 2020
eabacc0
Update development/build/index.js
kumavis Mar 6, 2020
6d27b3c
deps - remove redundant mkdirp
kumavis Mar 7, 2020
ada046d
deps - remove unused pumpify
kumavis Mar 7, 2020
26b621d
deps - remove redundant merge-deep
kumavis Mar 7, 2020
05c4985
deps - prefer is-stream of isstream
kumavis Mar 7, 2020
1c06fab
deps - remove clone for lodash.cloneDeep
kumavis Mar 7, 2020
625322f
clean - remove commented code
kumavis Mar 7, 2020
e0cadf9
build/static - use fs.copy + fast-glob instead of linux cp for better…
kumavis Mar 7, 2020
1b50959
build/manifest - standardize task naming
kumavis Mar 7, 2020
24e9188
build/display - clean - remove unused code
kumavis Mar 7, 2020
2a4b770
bugfix - fix fs.promises import
kumavis Mar 7, 2020
e039d21
build - create "clean" as named task for use as entrypoint
kumavis Mar 7, 2020
673af20
build/static - fix for copying dirs
kumavis Mar 7, 2020
f2351e2
Update development/build/task.js
kumavis Mar 7, 2020
d72d52c
Update development/build/display.js
kumavis Mar 7, 2020
4062a55
Update development/build/display.js
kumavis Mar 7, 2020
08bdcf0
Update development/build/display.js
kumavis Mar 7, 2020
6bfa71a
build - use task refs, tasks only return promises not streams, etc
kumavis Mar 7, 2020
da7f3e6
Merge branch 'build-sys-1' of github.com:MetaMask/metamask-extension …
kumavis Mar 7, 2020
b5d6a34
lint fi bad merge + lint
kumavis Mar 7, 2020
dcee622
build - one last cleanup + refactor
kumavis Mar 7, 2020
987ebe3
build - add comments introducing file
kumavis Mar 7, 2020
562005f
build/manifest - fix bug + subtasks dont beed to be named
kumavis Mar 7, 2020
bfa086f
Update package.json
kumavis Mar 8, 2020
a1bdc8a
build/task - remove unused fn
kumavis Mar 8, 2020
a9dd12e
Update package.json
kumavis Mar 8, 2020
9de374f
Update development/build/styles.js
kumavis Mar 8, 2020
132758f
Update development/build/styles.js
kumavis Mar 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/scripts/create-sesify-viz
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ set -o pipefail
mkdir -p ./build-artifacts/deps-viz/

# generate viz
SESIFY_AUTOGEN=1 npx gulp build:extension:js:background
SESIFY_AUTOGEN=1 yarn build scripts:core:prod:background
npx sesify-viz --deps sesify/deps-background.json --config sesify/background.json --dest ./build-artifacts/deps-viz/background
7 changes: 0 additions & 7 deletions app/manifest.json → app/manifest/_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@
"128": "images/icon-128.png",
"512": "images/icon-512.png"
},
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "56.0"
}
},
"default_locale": "en",
"background": {
"scripts": [
"chromereload.js",
"bg-libs.js",
"background.js"
],
Expand Down
1 change: 1 addition & 0 deletions app/manifest/brave.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions app/manifest/chrome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"minimum_chrome_version": "58"
}
8 changes: 8 additions & 0 deletions app/manifest/firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "56.0"
}
}
}
9 changes: 9 additions & 0 deletions app/manifest/opera.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"permissions": [
"storage",
"tabs",
"clipboardWrite",
"clipboardRead",
"http://localhost:8545/"
]
}
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import accountImporter from './account-import-strategies'
import getBuyEthUrl from './lib/buy-eth-url'
import selectChainId from './lib/select-chain-id'
import { Mutex } from 'await-semaphore'
import { version } from '../manifest.json'
import { version } from '../manifest/_base.json'
import ethUtil, { BN } from 'ethereumjs-util'

const GWEI_BN = new BN('1000000000')
Expand Down
8 changes: 2 additions & 6 deletions development/announcer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
const manifest = require('../app/manifest.json')

const version = manifest.version

const fs = require('fs')
const path = require('path')
const { version } = require('../app/manifest/_base.json')

const changelog = fs.readFileSync(path.join(__dirname, '..', 'CHANGELOG.md')).toString()
const changelog = fs.readFileSync(path.join(__dirname, '..', 'CHANGELOG.md'), 'utf8')

const log = changelog.split(version)[1].split('##')[0].trim()

const msg = `*MetaMask ${version}* now published! It should auto-update soon!\n${log}`

console.log(msg)
150 changes: 150 additions & 0 deletions development/build/display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const randomColor = require('randomcolor')
const chalk = require('chalk')

module.exports = { setupTaskDisplay, displayChart }

const SYMBOLS = {
Empty: '',
Space: ' ',
Full: '█',
SevenEighths: '▉',
ThreeQuarters: '▊',
FiveEighths: '▋',
Half: '▌',
ThreeEighths: '▍',
Quarter: '▎',
Eighth: '▏',
RightHalf: '▐',
RightEigth: '▕',
}

function setupTaskDisplay (taskEvents) {
const taskData = []
taskEvents.on('start', ([name]) => {
console.log(`Starting '${name}'...`)
})
taskEvents.on('end', ([name, start, end]) => {
taskData.push([name, start, end])
console.log(`Finished '${name}'`)
})
taskEvents.on('complete', () => {
displayChart(taskData)
})
}

function displayChart (data) {
// sort tasks by start time
data.sort((a, b,) => a[1] - b[1])

// get bounds
const first = Math.min(...data.map((entry) => entry[1]))
const last = Math.max(...data.map((entry) => entry[2]))

// get colors
const colors = randomColor({ count: data.length })

// some heading before the bars
console.log(`\nbuild completed. task timeline:`)

// build bars for bounds
data.map((entry, index) => {
const [label, start, end] = entry
const [start2, end2] = [start, end].map((value) => adjust(value, first, last, 40))
const barString = barBuilder(start2, end2)
const color = colors[index]
const coloredBarString = colorize(color, barString)
const duration = ((end - start) / 1e3).toFixed(1)
console.log(coloredBarString, `${label} ${duration}s`)
})

}

function colorize (color, string) {
const colorizer = (typeof chalk[color] === 'function') ? chalk[color] : chalk.hex(color)
return colorizer(string)
}

// scale number within bounds
function adjust (value, first, last, size) {
const length = last - first
const result = (value - first) / length * size
return result
}

// draw bars
function barBuilder (start, end) {
const [spaceInt, spaceRest] = splitNumber(start)
const barBodyLength = end - spaceInt
let [barInt, barRest] = splitNumber(barBodyLength)
// We are handling zero value as a special case
// to print at least something on the screen
if (barInt === 0 && barRest === 0) {
barInt = 0
barRest = 0.001
}

const spaceFull = SYMBOLS.Space.repeat(spaceInt)
const spacePartial = getSymbolNormalRight(spaceRest)
const barFull = SYMBOLS.Full.repeat(barInt)
const barPartial = getSymbolNormal(barRest)

return `${spaceFull}${spacePartial}${barFull}${barPartial}`
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
}

// get integer and remainder
function splitNumber (value = 0) {
const [int, rest = '0'] = value.toString().split('.')
const int2 = parseInt(int, 10)
const rest2 = parseInt(rest, 10) / Math.pow(10, rest.length)
return [int2, rest2]
}

// get partial block char for value (left-adjusted)
function getSymbolNormal (value) {
// round to closest supported value
const possibleValues = [0, 1 / 8, 1 / 4, 3 / 8, 1 / 2, 5 / 8, 3 / 4, 7 / 8, 1]
const rounded = possibleValues.reduce((prev, curr) => {
return (Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev)
})

if (rounded === 0) {
return SYMBOLS.Empty
} else if (rounded === 1 / 8) {
return SYMBOLS.Eighth
} else if (rounded === 1 / 4) {
return SYMBOLS.Quarter
} else if (rounded === 3 / 8) {
return SYMBOLS.ThreeEighths
} else if (rounded === 1 / 2) {
return SYMBOLS.Half
} else if (rounded === 5 / 8) {
return SYMBOLS.FiveEighths
} else if (rounded === 3 / 4) {
return SYMBOLS.ThreeQuarters
} else if (rounded === 7 / 8) {
return SYMBOLS.SevenEighths
} else {
return SYMBOLS.Full
}
}

// get partial block char for value (right-adjusted)
function getSymbolNormalRight (value) {
// round to closest supported value (not much :/)
const possibleValues = [0, 1 / 2, 7 / 8, 1]
const rounded = possibleValues.reduce((prev, curr) => {
return (Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev)
})

if (rounded === 0) {
return SYMBOLS.Full
} else if (rounded === 1 / 2) {
return SYMBOLS.RightHalf
} else if (rounded === 7 / 8) {
return SYMBOLS.RightEigth
} else if (rounded === 1) {
return SYMBOLS.Space
} else {
throw new Error('getSymbolNormalRight got unexpected result')
}
}
42 changes: 42 additions & 0 deletions development/build/etc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const gulp = require('gulp')
const gulpZip = require('gulp-zip')
const del = require('del')
const { promises: fs } = require('fs')
const pify = require('pify')
const pump = pify(require('pump'))
const baseManifest = require('../../app/manifest/_base.json')
const { createTask, composeParallel } = require('./task')

module.exports = createEtcTasks


function createEtcTasks ({ browserPlatforms, livereload }) {

const clean = createTask('clean', async function clean () {
await del(['./dist/*'])
await Promise.all(browserPlatforms.map(async (platform) => {
await fs.mkdir(`./dist/${platform}`, { recursive: true })
}))
})

const reload = createTask('reload', function devReload () {
livereload.listen({ port: 35729 })
})

// zip tasks for distribution
const zip = createTask('zip', composeParallel(
...browserPlatforms.map((platform) => createZipTask(platform))
))

return { clean, reload, zip }
}

function createZipTask (target) {
return async () => {
await pump(
gulp.src(`dist/${target}/**`),
gulpZip(`metamask-${target}-${baseManifest.version}.zip`),
gulp.dest('builds'),
)
}
}
91 changes: 91 additions & 0 deletions development/build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// build task definitions
//
// run any task with "yarn build ${taskName}"
//

const livereload = require('gulp-livereload')
const { createTask, composeSeries, composeParallel, detectAndRunEntryTask } = require('./task')
const createManifestTasks = require('./manifest')
const createScriptTasks = require('./scripts')
const createStyleTasks = require('./styles')
const createStaticAssetTasks = require('./static')
const createEtcTasks = require('./etc')

const browserPlatforms = [
'firefox',
'chrome',
'brave',
'opera',
]

defineAllTasks()
detectAndRunEntryTask()

function defineAllTasks () {

const staticTasks = createStaticAssetTasks({ livereload, browserPlatforms })
const manifestTasks = createManifestTasks({ browserPlatforms })
const styleTasks = createStyleTasks({ livereload })
const scriptTasks = createScriptTasks({ livereload, browserPlatforms })
const { clean, reload, zip } = createEtcTasks({ livereload, browserPlatforms })

// build for development (livereload)
createTask('dev',
composeSeries(
clean,
styleTasks.dev,
composeParallel(
scriptTasks.dev,
staticTasks.dev,
manifestTasks.dev,
reload
)
)
)

// build for test development (livereload)
createTask('testDev',
composeSeries(
clean,
styleTasks.dev,
composeParallel(
scriptTasks.testDev,
staticTasks.dev,
manifestTasks.testDev,
reload
)
)
)

// build for prod release
createTask('prod',
composeSeries(
clean,
styleTasks.prod,
composeParallel(
scriptTasks.prod,
staticTasks.prod,
manifestTasks.prod,
),
zip,
)
)

// build for CI testing
createTask('test',
composeSeries(
clean,
styleTasks.prod,
composeParallel(
scriptTasks.test,
staticTasks.prod,
manifestTasks.test,
),
)
)

// special build for minimal CI testing
createTask('styles', styleTasks.prod)

}
Loading