Log output of init function when being called manually

This commit is contained in:
trickypr 2021-12-03 17:55:37 +11:00
parent fd65317719
commit 43f8f1eed6
6 changed files with 48 additions and 31 deletions

View file

@ -79,7 +79,7 @@ export const download = async (): Promise<void> => {
{ {
title: 'Init firefox', title: 'Init firefox',
enabled: (ctx) => ctx.firefoxSourceTar && !process.env.CI_SKIP_INIT, enabled: (ctx) => ctx.firefoxSourceTar && !process.env.CI_SKIP_INIT,
task: async () => await init(ENGINE_DIR), task: async (_ctx, task) => await init(ENGINE_DIR, task),
}, },
...addons ...addons
.map((addon) => includeAddon(addon.name, addon.url, addon.id)) .map((addon) => includeAddon(addon.name, addon.url, addon.id))
@ -242,18 +242,6 @@ async function unpackFirefoxSource(
name: string, name: string,
task: Listr.ListrTaskWrapper<any> task: Listr.ListrTaskWrapper<any>
): Promise<void> { ): Promise<void> {
const onData = (data: any) => {
const d = data.toString()
d.split('\n').forEach((line: any) => {
if (line.trim().length !== 0) {
const t = line.split(' ')
t.shift()
task.output = t.join(' ')
}
})
}
let cwd = process.cwd().split(sep).join(posix.sep) let cwd = process.cwd().split(sep).join(posix.sep)
if (process.platform == 'win32') { if (process.platform == 'win32') {

View file

@ -17,7 +17,7 @@ export const execute = async (_: any, cmd: any[]) => {
' ' ' '
)}\` in \`src\`...` )}\` in \`src\`...`
) )
dispatch(bin, args, ENGINE_DIR, true) dispatch(bin, args, ENGINE_DIR)
} else { } else {
log.error(`Unable to locate src directory.`) log.error(`Unable to locate src directory.`)
} }

View file

@ -1,10 +1,22 @@
import { Command } from 'commander' import { Command } from 'commander'
import { existsSync, readFileSync } from 'fs' import { existsSync, readFileSync } from 'fs'
import Listr from 'listr'
import { resolve } from 'path' import { resolve } from 'path'
import { bin_name, log } from '..' import { bin_name, log } from '..'
import { dispatch } from '../utils' import { dispatch } from '../utils'
export const init = async (directory: Command | string): Promise<void> => { export const init = async (
directory: Command | string,
task?: Listr.ListrTaskWrapper<any>
): Promise<void> => {
function logInfo(data: string) {
if (task) {
task.output = data
} else {
log.info(data)
}
}
if (process.platform == 'win32') { if (process.platform == 'win32') {
// Because Windows cannot handle paths correctly, we're just calling a script as the workaround. // Because Windows cannot handle paths correctly, we're just calling a script as the workaround.
log.info( log.info(
@ -41,14 +53,28 @@ export const init = async (directory: Command | string): Promise<void> => {
version = version.trim().replace(/\\n/g, '') version = version.trim().replace(/\\n/g, '')
log.info('Initializing git, this may take some time') logInfo('Initializing git, this may take some time')
await dispatch('git', ['init'], dir as string) await dispatch('git', ['init'], dir as string, false, logInfo)
await dispatch('git', ['checkout', '--orphan', version], dir as string) await dispatch(
await dispatch('git', ['add', '-f', '.'], dir as string) 'git',
['checkout', '--orphan', version],
dir as string,
false,
logInfo
)
await dispatch('git', ['add', '-f', '.'], dir as string, false, logInfo)
await dispatch( await dispatch(
'git', 'git',
['commit', '-am', `"Firefox ${version}"`], ['commit', '-am', `"Firefox ${version}"`],
dir as string dir as string,
false,
logInfo
)
await dispatch(
'git',
['checkout', '-b', 'dot'],
dir as string,
false,
logInfo
) )
await dispatch('git', ['checkout', '-b', 'dot'], dir as string)
} }

View file

@ -19,7 +19,6 @@ export const run = async (chrome?: string) => {
'./mach', './mach',
['run'].concat(chrome ? ['-chrome', chrome] : []), ['run'].concat(chrome ? ['-chrome', chrome] : []),
ENGINE_DIR, ENGINE_DIR,
true,
true true
) )
} else { } else {

View file

@ -17,7 +17,7 @@ export const status = async (): Promise<void> => {
if (engineExists) { if (engineExists) {
log.info("The following changes have been made to firefox's source code") log.info("The following changes have been made to firefox's source code")
await dispatch('git', ['diff'], ENGINE_DIR, true) await dispatch('git', ['diff'], ENGINE_DIR)
return return
} else { } else {

View file

@ -1,11 +1,15 @@
import execa from 'execa' import execa from 'execa'
import { log } from '..' import { log } from '..'
const handle = (data: string | Error, killOnError?: boolean) => { const handle = (
data: string | Error,
logger: (data: string) => void,
killOnError?: boolean
) => {
const d = data.toString() const d = data.toString()
d.split('\n').forEach((line: string) => { d.split('\n').forEach((line: string) => {
if (line.length !== 0) log.info(line.replace(/\s\d{1,5}:\d\d\.\d\d /g, '')) if (line.length !== 0) logger(line.replace(/\s\d{1,5}:\d\d\.\d\d /g, ''))
}) })
if (killOnError) { if (killOnError) {
@ -18,8 +22,8 @@ export const dispatch = (
cmd: string, cmd: string,
args?: string[], args?: string[],
cwd?: string, cwd?: string,
noLog?: boolean, killOnError?: boolean,
killOnError?: boolean logger = (data: string) => log.info(data)
): Promise<boolean> => ): Promise<boolean> =>
new Promise((resolve) => { new Promise((resolve) => {
process.env.MACH_USE_SYSTEM_PYTHON = 'true' process.env.MACH_USE_SYSTEM_PYTHON = 'true'
@ -29,11 +33,11 @@ export const dispatch = (
env: process.env, env: process.env,
}) })
proc.stdout?.on('data', (d) => handle(d)) proc.stdout?.on('data', (d) => handle(d, logger))
proc.stderr?.on('data', (d) => handle(d)) proc.stderr?.on('data', (d) => handle(d, logger))
proc.stdout?.on('error', (d) => handle(d, killOnError)) proc.stdout?.on('error', (d) => handle(d, logger, killOnError))
proc.stderr?.on('error', (d) => handle(d, killOnError)) proc.stderr?.on('error', (d) => handle(d, logger, killOnError))
proc.on('exit', () => { proc.on('exit', () => {
resolve(true) resolve(true)