mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-08 01:10:03 +02:00
✨ Log output of init function when being called manually
This commit is contained in:
parent
fd65317719
commit
43f8f1eed6
6 changed files with 48 additions and 31 deletions
|
@ -79,7 +79,7 @@ export const download = async (): Promise<void> => {
|
|||
{
|
||||
title: 'Init firefox',
|
||||
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
|
||||
.map((addon) => includeAddon(addon.name, addon.url, addon.id))
|
||||
|
@ -242,18 +242,6 @@ async function unpackFirefoxSource(
|
|||
name: string,
|
||||
task: Listr.ListrTaskWrapper<any>
|
||||
): 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)
|
||||
|
||||
if (process.platform == 'win32') {
|
||||
|
|
|
@ -17,7 +17,7 @@ export const execute = async (_: any, cmd: any[]) => {
|
|||
' '
|
||||
)}\` in \`src\`...`
|
||||
)
|
||||
dispatch(bin, args, ENGINE_DIR, true)
|
||||
dispatch(bin, args, ENGINE_DIR)
|
||||
} else {
|
||||
log.error(`Unable to locate src directory.`)
|
||||
}
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
import { Command } from 'commander'
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import Listr from 'listr'
|
||||
import { resolve } from 'path'
|
||||
import { bin_name, log } from '..'
|
||||
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') {
|
||||
// Because Windows cannot handle paths correctly, we're just calling a script as the workaround.
|
||||
log.info(
|
||||
|
@ -41,14 +53,28 @@ export const init = async (directory: Command | string): Promise<void> => {
|
|||
|
||||
version = version.trim().replace(/\\n/g, '')
|
||||
|
||||
log.info('Initializing git, this may take some time')
|
||||
await dispatch('git', ['init'], dir as string)
|
||||
await dispatch('git', ['checkout', '--orphan', version], dir as string)
|
||||
await dispatch('git', ['add', '-f', '.'], dir as string)
|
||||
logInfo('Initializing git, this may take some time')
|
||||
await dispatch('git', ['init'], dir as string, false, logInfo)
|
||||
await dispatch(
|
||||
'git',
|
||||
['checkout', '--orphan', version],
|
||||
dir as string,
|
||||
false,
|
||||
logInfo
|
||||
)
|
||||
await dispatch('git', ['add', '-f', '.'], dir as string, false, logInfo)
|
||||
await dispatch(
|
||||
'git',
|
||||
['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)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ export const run = async (chrome?: string) => {
|
|||
'./mach',
|
||||
['run'].concat(chrome ? ['-chrome', chrome] : []),
|
||||
ENGINE_DIR,
|
||||
true,
|
||||
true
|
||||
)
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,7 @@ export const status = async (): Promise<void> => {
|
|||
|
||||
if (engineExists) {
|
||||
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
|
||||
} else {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
import execa from 'execa'
|
||||
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()
|
||||
|
||||
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) {
|
||||
|
@ -18,8 +22,8 @@ export const dispatch = (
|
|||
cmd: string,
|
||||
args?: string[],
|
||||
cwd?: string,
|
||||
noLog?: boolean,
|
||||
killOnError?: boolean
|
||||
killOnError?: boolean,
|
||||
logger = (data: string) => log.info(data)
|
||||
): Promise<boolean> =>
|
||||
new Promise((resolve) => {
|
||||
process.env.MACH_USE_SYSTEM_PYTHON = 'true'
|
||||
|
@ -29,11 +33,11 @@ export const dispatch = (
|
|||
env: process.env,
|
||||
})
|
||||
|
||||
proc.stdout?.on('data', (d) => handle(d))
|
||||
proc.stderr?.on('data', (d) => handle(d))
|
||||
proc.stdout?.on('data', (d) => handle(d, logger))
|
||||
proc.stderr?.on('data', (d) => handle(d, logger))
|
||||
|
||||
proc.stdout?.on('error', (d) => handle(d, killOnError))
|
||||
proc.stderr?.on('error', (d) => handle(d, killOnError))
|
||||
proc.stdout?.on('error', (d) => handle(d, logger, killOnError))
|
||||
proc.stderr?.on('error', (d) => handle(d, logger, killOnError))
|
||||
|
||||
proc.on('exit', () => {
|
||||
resolve(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue