Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit 251403e

Browse files
committed
✨ Finalise setup-project
1 parent cf31fa2 commit 251403e

File tree

22 files changed

+292
-30
lines changed

22 files changed

+292
-30
lines changed

β€Ž.npmignoreβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
src/
2+
testing/
3+
.gitignore/
4+
.prettierrc.json
5+
melon.json
6+
yarn.lock
7+
node_modules/

β€Žpackage.jsonβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
"version": "1.0.0",
44
"description": "πŸ‰ Build Firefox-based browsers with ease",
55
"main": "index.js",
6+
"bin": {
7+
"melon": "./dist/index.js"
8+
},
69
"scripts": {
710
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build": "tsc",
11+
"build": "tsc && echo \"#!/bin/node\"|cat - ./dist/index.js > /tmp/out && mv /tmp/out ./dist/index.js && chmod +x ./dist/index.js",
912
"format": "prettier . -w",
1013
"app": "ts-node ./src/index"
1114
},

β€Žsrc/commands/download.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const unpack = async (name: string, version: string) => {
6060

6161
let tarProc = execa('tar', [
6262
'--transform',
63-
's,firefox-89.0,engine,',
63+
`s,firefox-${gFFVersion},engine,`,
6464
`--show-transformed`,
6565
'-xf',
6666
resolve(cwd, '.dotbuild', 'engines', name),
@@ -72,7 +72,7 @@ const unpack = async (name: string, version: string) => {
7272
tarProc.on('exit', () => {
7373
if (process.env.CI_SKIP_INIT) return log.info('Skipping initialisation.')
7474

75-
const initProc = execa(`./${bin_name}`, ['init', 'engine'])
75+
const initProc = execa('npx', ['melon', 'init', 'engine'])
7676

7777
;(initProc.stdout as any).on('data', onData)
7878
;(initProc.stdout as any).on('error', onData)

β€Žsrc/commands/import-patches.tsβ€Ž

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ const importPatchFiles = async (minimal?: boolean, noIgnore?: boolean) => {
8585
}
8686

8787
console.log()
88-
await dispatch(
89-
`./${bin_name}`,
90-
['doctor', 'patches'],
91-
process.cwd(),
92-
true,
93-
true
94-
)
88+
// TODO: Setup a custom patch doctor
89+
// await dispatch(
90+
// `./${bin_name}`,
91+
// ['doctor', 'patches'],
92+
// process.cwd(),
93+
// true,
94+
// true
95+
// )
9596

9697
log.success(`Successfully imported ${patches.length} patch files!`)
9798
}

β€Žsrc/commands/setupProject.tsβ€Ž

Lines changed: 82 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFileSync, existsSync, mkdirSync } from 'fs'
1+
import { writeFileSync, existsSync, mkdirSync, readFileSync } from 'fs'
22
import { readdir, stat, copyFile } from 'fs/promises'
33
import { join, isAbsolute, dirname } from 'path'
44

@@ -23,6 +23,13 @@ export async function setupProject() {
2323
await sleep(1000)
2424
}
2525

26+
if (configPath.includes('.optional')) {
27+
log.error(
28+
'The text ".optional" cannot be in the path to your custom browser'
29+
)
30+
process.exit(1)
31+
}
32+
2633
// Ask user for assorted information
2734
const { product } = await prompts({
2835
type: 'select',
@@ -57,7 +64,7 @@ export async function setupProject() {
5764

5865
const productVersion = await getLatestFF(product)
5966

60-
const { version, name, appId, vendor } = await prompts([
67+
const { version, name, appId, vendor, ui } = await prompts([
6168
{
6269
type: 'text',
6370
name: 'version',
@@ -84,6 +91,25 @@ export async function setupProject() {
8491
// Horrible validation to make sure people don't chose something entirely wrong
8592
validate: (t: string) => t.includes('.'),
8693
},
94+
{
95+
type: 'select',
96+
name: 'ui',
97+
message: 'Select a ui mode template',
98+
choices: [
99+
{
100+
title: 'None',
101+
value: 'none',
102+
},
103+
{
104+
title: 'User Chrome (custom browser css, simplest)',
105+
value: 'uc',
106+
},
107+
{
108+
title: 'Custom html',
109+
value: 'html',
110+
},
111+
],
112+
},
87113
])
88114

89115
const config: Config = {
@@ -95,7 +121,29 @@ export async function setupProject() {
95121

96122
await copyRequired()
97123

124+
if (ui === 'html') {
125+
await copyOptional([
126+
'customui',
127+
'toolkit-mozbuild.patch',
128+
'confvars-sh.patch',
129+
])
130+
} else if (ui === 'uc') {
131+
await copyOptional(['browser/themes'])
132+
}
133+
98134
writeFileSync(configPath, JSON.stringify(config, null, 2))
135+
136+
// Append important stuff to gitignore
137+
const gitignore = join(projectDir, '.gitignore')
138+
let gitignoreContents = ''
139+
140+
if (existsSync(gitignore)) {
141+
gitignoreContents = readFileSync(gitignore, 'utf8')
142+
}
143+
144+
gitignoreContents += '\n.dotbuild/\nengine/\nfirefox-*/\nnode_modules/\n'
145+
146+
writeFileSync(gitignore, gitignoreContents)
99147
} catch (e) {
100148
console.log(e)
101149
}
@@ -106,24 +154,40 @@ export async function setupProject() {
106154

107155
const templateDir = join(__dirname, '../..', 'template')
108156

157+
async function copyOptional(files: string[]) {
158+
await Promise.all(
159+
(
160+
await walkDirectory(templateDir)
161+
)
162+
.filter((f) => f.includes('.optional'))
163+
.filter((f) => files.map((file) => f.includes(file)).some((b) => b))
164+
.map(async (file) => {
165+
const out = join(projectDir, file.replace(templateDir, '')).replace(
166+
'.optional',
167+
''
168+
)
169+
if (!existsSync(out)) {
170+
mkdirSync(dirname(out), { recursive: true })
171+
await copyFile(file, out)
172+
}
173+
})
174+
)
175+
}
176+
109177
async function copyRequired() {
110-
try {
111-
await Promise.all(
112-
(
113-
await walkDirectory(templateDir)
114-
)
115-
.filter((f) => !f.includes('.optional'))
116-
.map(async (file) => {
117-
const out = join(projectDir, file.replace(templateDir, ''))
118-
if (!existsSync(out)) {
119-
mkdirSync(dirname(out), { recursive: true })
120-
await copyFile(file, out)
121-
}
122-
})
178+
await Promise.all(
179+
(
180+
await walkDirectory(templateDir)
123181
)
124-
} catch (e) {
125-
console.log(e)
126-
}
182+
.filter((f) => !f.includes('.optional'))
183+
.map(async (file) => {
184+
const out = join(projectDir, file.replace(templateDir, ''))
185+
if (!existsSync(out)) {
186+
mkdirSync(dirname(out), { recursive: true })
187+
await copyFile(file, out)
188+
}
189+
})
190+
)
127191
}
128192

129193
// =============================================================================

β€Žtemplate/melonβ€Ž

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
start_node() {
4+
if test -f "node_modules";
5+
then
6+
if ! command -v yarn &> /dev/null
7+
then
8+
NODE_HELPER="npm"
9+
npx melon $@
10+
else
11+
yarn melon $@
12+
fi
13+
else
14+
if ! command -v yarn &> /dev/null
15+
then
16+
NODE_HELPER="npm"
17+
npm i
18+
npx melon $@
19+
else
20+
yarn
21+
yarn melon $@
22+
fi
23+
fi
24+
}
25+
26+
27+
28+
run() {
29+
if command -v "node" > /dev/null;
30+
then
31+
mkdir .dotbuild >/dev/null 2>&1
32+
echo "$@" > .dotbuild/command
33+
34+
case $1 in
35+
rebuild)
36+
echo Rebuilding...
37+
build
38+
;;
39+
40+
doctor)
41+
if [ -z $2 ]; then
42+
echo "You must specify the doctor name. See scripts/doctors for more information.";
43+
else
44+
run_doctor $2
45+
fi
46+
;;
47+
48+
*)
49+
start_node $@
50+
exit $?
51+
;;
52+
esac
53+
else
54+
if [ -n "$MOZILLABUILD" ]; then
55+
PATH="$PATH:/c/Program Files/nodejs"
56+
run $@
57+
else
58+
echo "This melon command requires node, which wasn't found on the system!"
59+
exit 1
60+
fi
61+
fi
62+
}
63+
64+
run $@
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/browser/confvars.sh b/browser/confvars.sh
2+
index 92871c9516f98e065c5240a4a1cc7ead1de8ef9d..1d9ac38b48d39049a88a5439025f5b4fc5e8623c 100755
3+
--- a/browser/confvars.sh
4+
+++ b/browser/confvars.sh
5+
@@ -1,4 +1,4 @@
6+
-#! /bin/sh
7+
+BROWSER_CHROME_URL=chrome://dot/content/browser.html#! /bin/sh
8+
# This Source Code Form is subject to the terms of the Mozilla Public
9+
# License, v. 2.0. If a copy of the MPL was not distributed with this
10+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
11+
@@ -26,7 +26,7 @@ if test "$OS_ARCH" = "WINNT"; then
12+
fi
13+
fi
14+
15+
-BROWSER_CHROME_URL=chrome://browser/content/browser.xhtml
16+
+BROWSER_CHROME_URL=chrome://customui/content/browser.html
17+
18+
# MOZ_APP_DISPLAYNAME will be set by branding/configure.sh
19+
# MOZ_BRANDING_DIRECTORY is the default branding directory used when none is

β€Žtemplate/src/browser/themes.optional/custom/linux/linux.inc.cssβ€Ž

Whitespace-only changes.

β€Žtemplate/src/browser/themes.optional/custom/macos/macos.inc.cssβ€Ž

Whitespace-only changes.

β€Žtemplate/src/browser/themes.optional/custom/shared/shared.inc.cssβ€Ž

Whitespace-only changes.

0 commit comments

Comments
Β (0)