mirror of
https://github.com/zen-browser/surfer.git
synced 2025-07-10 10:15:31 +02:00
✨ Finalise setup-project
This commit is contained in:
parent
cf31fa28c0
commit
251403e2f2
22 changed files with 293 additions and 31 deletions
|
@ -1,4 +1,4 @@
|
|||
import { writeFileSync, existsSync, mkdirSync } from 'fs'
|
||||
import { writeFileSync, existsSync, mkdirSync, readFileSync } from 'fs'
|
||||
import { readdir, stat, copyFile } from 'fs/promises'
|
||||
import { join, isAbsolute, dirname } from 'path'
|
||||
|
||||
|
@ -23,6 +23,13 @@ export async function setupProject() {
|
|||
await sleep(1000)
|
||||
}
|
||||
|
||||
if (configPath.includes('.optional')) {
|
||||
log.error(
|
||||
'The text ".optional" cannot be in the path to your custom browser'
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Ask user for assorted information
|
||||
const { product } = await prompts({
|
||||
type: 'select',
|
||||
|
@ -57,7 +64,7 @@ export async function setupProject() {
|
|||
|
||||
const productVersion = await getLatestFF(product)
|
||||
|
||||
const { version, name, appId, vendor } = await prompts([
|
||||
const { version, name, appId, vendor, ui } = await prompts([
|
||||
{
|
||||
type: 'text',
|
||||
name: 'version',
|
||||
|
@ -84,6 +91,25 @@ export async function setupProject() {
|
|||
// Horrible validation to make sure people don't chose something entirely wrong
|
||||
validate: (t: string) => t.includes('.'),
|
||||
},
|
||||
{
|
||||
type: 'select',
|
||||
name: 'ui',
|
||||
message: 'Select a ui mode template',
|
||||
choices: [
|
||||
{
|
||||
title: 'None',
|
||||
value: 'none',
|
||||
},
|
||||
{
|
||||
title: 'User Chrome (custom browser css, simplest)',
|
||||
value: 'uc',
|
||||
},
|
||||
{
|
||||
title: 'Custom html',
|
||||
value: 'html',
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const config: Config = {
|
||||
|
@ -95,7 +121,29 @@ export async function setupProject() {
|
|||
|
||||
await copyRequired()
|
||||
|
||||
if (ui === 'html') {
|
||||
await copyOptional([
|
||||
'customui',
|
||||
'toolkit-mozbuild.patch',
|
||||
'confvars-sh.patch',
|
||||
])
|
||||
} else if (ui === 'uc') {
|
||||
await copyOptional(['browser/themes'])
|
||||
}
|
||||
|
||||
writeFileSync(configPath, JSON.stringify(config, null, 2))
|
||||
|
||||
// Append important stuff to gitignore
|
||||
const gitignore = join(projectDir, '.gitignore')
|
||||
let gitignoreContents = ''
|
||||
|
||||
if (existsSync(gitignore)) {
|
||||
gitignoreContents = readFileSync(gitignore, 'utf8')
|
||||
}
|
||||
|
||||
gitignoreContents += '\n.dotbuild/\nengine/\nfirefox-*/\nnode_modules/\n'
|
||||
|
||||
writeFileSync(gitignore, gitignoreContents)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
@ -106,24 +154,40 @@ export async function setupProject() {
|
|||
|
||||
const templateDir = join(__dirname, '../..', 'template')
|
||||
|
||||
async function copyRequired() {
|
||||
try {
|
||||
await Promise.all(
|
||||
(
|
||||
await walkDirectory(templateDir)
|
||||
)
|
||||
.filter((f) => !f.includes('.optional'))
|
||||
.map(async (file) => {
|
||||
const out = join(projectDir, file.replace(templateDir, ''))
|
||||
if (!existsSync(out)) {
|
||||
mkdirSync(dirname(out), { recursive: true })
|
||||
await copyFile(file, out)
|
||||
}
|
||||
})
|
||||
async function copyOptional(files: string[]) {
|
||||
await Promise.all(
|
||||
(
|
||||
await walkDirectory(templateDir)
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
.filter((f) => f.includes('.optional'))
|
||||
.filter((f) => files.map((file) => f.includes(file)).some((b) => b))
|
||||
.map(async (file) => {
|
||||
const out = join(projectDir, file.replace(templateDir, '')).replace(
|
||||
'.optional',
|
||||
''
|
||||
)
|
||||
if (!existsSync(out)) {
|
||||
mkdirSync(dirname(out), { recursive: true })
|
||||
await copyFile(file, out)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
async function copyRequired() {
|
||||
await Promise.all(
|
||||
(
|
||||
await walkDirectory(templateDir)
|
||||
)
|
||||
.filter((f) => !f.includes('.optional'))
|
||||
.map(async (file) => {
|
||||
const out = join(projectDir, file.replace(templateDir, ''))
|
||||
if (!existsSync(out)) {
|
||||
mkdirSync(dirname(out), { recursive: true })
|
||||
await copyFile(file, out)
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue