mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-10 02:05:31 +02:00
✨ Add method for specifying the branding type
This commit is contained in:
parent
f5bf98d03a
commit
3d3eb547f7
7 changed files with 75 additions and 9 deletions
|
@ -102,6 +102,12 @@ export const commands: Cmd[] = [
|
|||
description: 'Run the browser.',
|
||||
requestController: async () => (await import('./commands/run')).run,
|
||||
},
|
||||
{
|
||||
cmd: 'config',
|
||||
aliases: ['set', 'get'],
|
||||
description: 'Get and set the dynamic config from this project',
|
||||
requestController: async () => (await import('./commands/set')).set,
|
||||
},
|
||||
{
|
||||
cmd: 'setup-project',
|
||||
description: 'Sets up a gluon project for the first time',
|
||||
|
|
|
@ -6,9 +6,10 @@ import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|||
import { join, resolve } from 'path'
|
||||
import { bin_name, config } from '..'
|
||||
import { BUILD_TARGETS, CONFIGS_DIR, ENGINE_DIR } from '../constants'
|
||||
import { internalMozconfg } from '../constants/mozconfig'
|
||||
import { log } from '../log'
|
||||
import { patchCheck } from '../middleware/patch-check'
|
||||
import { configDispatch, stringTemplate } from '../utils'
|
||||
import { configDispatch, dynamicConfig, stringTemplate } from '../utils'
|
||||
|
||||
const platform: Record<string, string> = {
|
||||
win32: 'windows',
|
||||
|
@ -67,8 +68,6 @@ const applyConfig = async (os: string) => {
|
|||
|
||||
customConfig = stringTemplate(customConfig, templateOptions)
|
||||
|
||||
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` +
|
||||
commonConfig +
|
||||
|
@ -76,8 +75,8 @@ const applyConfig = async (os: string) => {
|
|||
osConfig +
|
||||
'\n\n' +
|
||||
customConfig +
|
||||
'\n\n' +
|
||||
internalConfig
|
||||
'\n' +
|
||||
internalMozconfg(dynamicConfig.get('brand'))
|
||||
|
||||
writeFileSync(resolve(ENGINE_DIR, 'mozconfig'), mergedConfig)
|
||||
|
||||
|
|
21
src/commands/set.ts
Normal file
21
src/commands/set.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { log } from '../log'
|
||||
import { dynamicConfig } from '../utils'
|
||||
|
||||
export const set = (key: string, value?: string) => {
|
||||
if (key in dynamicConfig.defaultValues) {
|
||||
log.warning(`The key ${key} is not found within the dynamic config options`)
|
||||
return
|
||||
}
|
||||
|
||||
if (value) {
|
||||
dynamicConfig.set(key as dynamicConfig.DefaultValuesKeys, value)
|
||||
log.info(`Set ${key} to ${value}`)
|
||||
return
|
||||
}
|
||||
|
||||
log.info(
|
||||
`The key '${key}' has ${dynamicConfig.get(
|
||||
key as dynamicConfig.DefaultValuesKeys
|
||||
)}`
|
||||
)
|
||||
}
|
11
src/constants/mozconfig.ts
Normal file
11
src/constants/mozconfig.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export const internalMozconfg = (brand: string) => `
|
||||
# =====================
|
||||
# Internal gluon config
|
||||
# =====================
|
||||
|
||||
# Custom branding
|
||||
ac_add_options --with-branding=browser/branding/${brand}
|
||||
|
||||
# Config for updates
|
||||
ac_add_options --disable-verify-mar
|
||||
`
|
29
src/utils/dynamicConfig.ts
Normal file
29
src/utils/dynamicConfig.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
// Defines config that should be set dynamically on the users system. This allows
|
||||
// for interfacing between these values
|
||||
|
||||
import { readItem, writeItem } from './store'
|
||||
|
||||
export type ValidDynamicEntries = 'brand'
|
||||
export const defaultValues: {
|
||||
brand: string
|
||||
} = {
|
||||
brand: 'unofficial',
|
||||
}
|
||||
|
||||
export type DefaultValuesType = typeof defaultValues
|
||||
export type DefaultValuesKeys = keyof DefaultValuesType
|
||||
|
||||
type DynamicGetter<K extends keyof DefaultValuesType> = (
|
||||
key: K
|
||||
) => DefaultValuesType[K]
|
||||
type DynamicSetter<K extends keyof DefaultValuesType> = (
|
||||
key: K,
|
||||
value: DefaultValuesType[K]
|
||||
) => void
|
||||
|
||||
export const get: DynamicGetter<keyof DefaultValuesType> = (key) =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
readItem(`dynamicConfig.${key}`).unwrapOr(defaultValues[key]) as any
|
||||
|
||||
export const set: DynamicSetter<keyof DefaultValuesType> = (key, value) =>
|
||||
writeItem(key, value)
|
|
@ -11,3 +11,4 @@ export * from './config'
|
|||
export * from './stringTemplate'
|
||||
export * from './fs'
|
||||
export * from './versionFormatter'
|
||||
export * as dynamicConfig from './dynamicConfig'
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { equip, None, OptionEquipped } from 'rustic'
|
||||
|
||||
|
@ -20,7 +19,7 @@ export const readItem = <T>(key: string): OptionEquipped<T> => {
|
|||
return equip(JSON.parse(data))
|
||||
}
|
||||
|
||||
export const writeItem = async <T>(key: string, data: T): Promise<void> => {
|
||||
export const writeItem = <T>(key: string, data: T) => {
|
||||
const dir = join(MELON_DIR, `${key}.json`)
|
||||
await writeFile(dir, JSON.stringify(data, null, 2))
|
||||
writeFileSync(dir, JSON.stringify(data, null, 2))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue