forked from brave/brave-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.js
More file actions
92 lines (76 loc) · 3.17 KB
/
sync.js
File metadata and controls
92 lines (76 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (c) 2019 The Brave Authors. All rights reserved.
// 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/.
const program = require('commander')
const config = require('../lib/config')
const util = require('../lib/util')
const Log = require('../lib/sync/logging')
const projectNames = config.projectNames.filter((project) => config.projects[project].ref)
program
.version(process.env.npm_package_version)
.arguments('[ref]')
.option('--gclient_file <file>', 'gclient config file location')
.option('--gclient_verbose', 'verbose output for gclient')
.option('--run_hooks', 'This flag is deprecated and no longer has any effect')
.option('--run_sync', 'This flag is deprecated and no longer has any effect')
.option('--target_os <target_os>', 'target OS')
.option('--target_arch <target_arch>', 'target architecture')
.option('--target_apk_base <target_apk_base>', 'target Android OS apk (classic, modern, mono)')
.option('--submodule_sync', 'run submodule sync')
.option('--init', 'initialize all dependencies')
.option('--all', 'This flag is deprecated and no longer has any effect')
.option('--force', 'force reset all projects to origin/ref')
.option('--create', 'create a new branch if needed for [ref]')
async function RunCommand () {
program.parse(process.argv)
config.update(program)
if (program.all || program.run_hooks || program.run_sync) {
Log.warn('--all, --run_hooks and --run_sync are deprecated. Will behave as if flag was not passed. Please update your command to `npm run sync` in the future.')
}
// Perform initial brave-core clone and checkout
if (program.init) {
Log.progress('Performing initial checkout of brave-core')
util.checkoutBraveCore()
}
if (program.init || program.submodule_sync) {
util.submoduleSync()
}
if (program.init) {
util.buildGClientConfig()
}
let braveCoreRef = program.args[0]
if (!braveCoreRef) {
braveCoreRef = program.init ? config.getProjectVersion('brave-core') : null
}
if (braveCoreRef || program.init || program.force) {
// we're doing a reset of brave-core so try to stash any changes
Log.progress('Stashing any local changes')
util.runGit(config.braveCoreDir, ['stash'], true)
}
if (braveCoreRef) {
// try to checkout to the right ref if possible
util.runGit(config.braveCoreDir, ['reset', '--hard', 'HEAD'], true)
result = util.runGit(config.braveCoreDir, ['checkout', braveCoreRef], true)
if (result === null && program.create) {
result = util.runGit(config.braveCoreDir, ['checkout', '-b', braveCoreRef], true)
}
if (result === null) {
Log.error('Could not checkout: ' + braveCoreRef)
Log.error(prog.stdout.toString())
}
}
util.gclientSync(program.init || program.force, program.init, braveCoreRef)
await util.applyPatches()
util.gclientRunhooks()
}
Log.progress('Brave Browser Sync starting')
RunCommand()
.then(() => {
Log.progress('Brave Browser Sync complete')
})
.catch((err) => {
Log.error('Brave Browser Sync ERROR:')
console.error(err)
process.exit(1)
})