♻️ Make the build more readable

This commit is contained in:
trickypr 2021-11-27 11:51:10 +11:00
parent 56d5f02bfd
commit 22eb1c0a39
3 changed files with 21 additions and 28 deletions

View file

@ -15,6 +15,9 @@ const platform: any = {
const applyConfig = async (os: string, arch: string) => {
log.info('Applying mozconfig...')
// Retrieve changeset
const { stdout: changeset } = await execa('git', ['rev-parse', 'HEAD'])
const templateOptions = {
name: config.name,
vendor: config.name,
@ -23,36 +26,26 @@ const applyConfig = async (os: string, arch: string) => {
? 'branding/melon'
: 'branding/unofficial',
binName: config.binaryName,
changeset,
}
let commonConfig = readFileSync(
resolve(CONFIGS_DIR, 'common', 'mozconfig'),
'utf-8'
const commonConfig = stringTemplate(
readFileSync(resolve(CONFIGS_DIR, 'common', 'mozconfig'), 'utf-8'),
templateOptions
)
commonConfig = stringTemplate(commonConfig, templateOptions)
const changesetPrefix = commonConfig
.split('\n')
.find((ln) => ln.startsWith('export MOZ_SOURCE_CHANGESET='))
const changeset = changesetPrefix?.replace(/export MOZ_SOURCE_CHANGESET=/, '')
const { stdout: gitSha } = await execa('git', ['rev-parse', 'HEAD'])
console.log(changeset, gitSha)
if (changeset) commonConfig = commonConfig.replace(changeset, gitSha)
writeFileSync(resolve(CONFIGS_DIR, 'common', 'mozconfig'), commonConfig)
let osConfig = readFileSync(
resolve(CONFIGS_DIR, os, arch === 'i686' ? 'mozconfig-i686' : 'mozconfig'),
'utf-8'
const osConfig = stringTemplate(
readFileSync(
resolve(
CONFIGS_DIR,
os,
arch === 'i686' ? 'mozconfig-i686' : 'mozconfig'
),
'utf-8'
),
templateOptions
)
osConfig = stringTemplate(osConfig, templateOptions)
// Allow a custom config to be placed in /mozconfig. This will not be committed
// to origin
let customConfig = existsSync(join(process.cwd(), 'mozconfig'))
@ -61,7 +54,7 @@ const applyConfig = async (os: string, arch: string) => {
customConfig = stringTemplate(customConfig, templateOptions)
const internalConfig = `# Internally defined by melon\n`
const internalConfig = `# Internally defined by melon`
const mergedConfig =
`# This file is automatically generated. You should only modify this if you know what you are doing!\n\n` +
@ -127,7 +120,7 @@ interface Options {
ui: boolean
}
export const build = async (tier: string, options: Options): Promise<void> => {
export const build = async (options: Options): Promise<void> => {
const d = Date.now()
// Host build