51 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-07-23 11:39:22 -07:00
// 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/.
2020-07-27 19:25:57 -07:00
const fs = require('fs')
2020-07-23 11:39:22 -07:00
const Log = require('../lib/logging')
const path = require('path')
const { spawnSync } = require('child_process')
const util = require('../lib/util')
Log.progress('Performing initial checkout of brave-core')
2020-07-27 14:28:31 -07:00
const braveCoreDir = path.resolve(__dirname, '..', 'src', 'brave')
2020-07-23 11:39:22 -07:00
const braveCoreRef = util.getProjectVersion('brave-core')
2020-07-27 11:24:49 -07:00
if (!fs.existsSync(path.join(braveCoreDir, '.git'))) {
Log.status(`Cloning brave-core [${braveCoreRef}] into ${braveCoreDir}...`)
fs.mkdirSync(braveCoreDir)
util.runGit(braveCoreDir, ['clone', util.getNPMConfig(['projects', 'brave-core', 'repository', 'url']), '.'])
util.runGit(braveCoreDir, ['checkout', braveCoreRef])
2020-07-23 11:39:22 -07:00
}
// re-checkout as the commit ref because otherwise gclient sync clobbers
// the branch for braveCoreRef and doesn't set it to the correct commit
// for some reason
const braveCoreSha = util.runGit(braveCoreDir, ['rev-parse', 'HEAD'])
Log.progress(`Resetting brave core to "${braveCoreSha}"...`)
util.runGit(braveCoreDir, ['reset', '--hard', 'HEAD'], true)
let checkoutResult = util.runGit(braveCoreDir, ['checkout', braveCoreSha], true)
// Handle checkout failure
if (checkoutResult === null) {
Log.error('Could not checkout: ' + braveCoreSha)
}
// Checkout was successful
Log.progress(`...brave core is now at commit ID ${braveCoreSha}`)
2020-07-28 08:24:49 -07:00
let npmCommand = 'npm'
2020-07-28 07:55:20 -07:00
if (process.platform === 'win32') {
2020-07-28 08:24:49 -07:00
npmCommand += '.cmd'
2020-07-28 07:55:20 -07:00
}
2020-07-28 08:24:49 -07:00
util.run(npmCommand, ['install'], { cwd: braveCoreDir })
util.run(npmCommand, ['run', 'sync' ,'--', '--init'].concat(process.argv.slice(2)), {
2020-07-27 11:24:49 -07:00
cwd: braveCoreDir,
2020-07-23 11:39:22 -07:00
env: process.env,
stdio: 'inherit',
shell: true,
git_cwd: '.', })