Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions script/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ const options: SpawnSyncOptions = {
stdio: 'inherit',
}

/** Check if the caller has set the OFFLINe environment variable */
function isOffline() {
return process.env.OFFLINE === '1'
}

/** Format the arguments to ensure these work offline */
function getYarnArgs(baseArgs: Array<string>): Array<string> {
const args = baseArgs

if (isOffline()) {
args.splice(1, 0, '--offline')
}

return args
}

function findYarnVersion(callback: (path: string) => void) {
glob('vendor/yarn-*.js', (error, files) => {
if (error != null) {
Expand All @@ -29,33 +45,33 @@ function findYarnVersion(callback: (path: string) => void) {
}

findYarnVersion(path => {
let result = spawnSync(
'node',
[path, '--cwd', 'app', 'install', '--force'],
options
)
const installArgs = getYarnArgs([path, '--cwd', 'app', 'install', '--force'])

let result = spawnSync('node', installArgs, options)

if (result.status !== 0) {
process.exit(result.status || 1)
}

result = spawnSync(
'git',
['submodule', 'update', '--recursive', '--init'],
options
)
if (isOffline()) {
result = spawnSync(
'git',
['submodule', 'update', '--recursive', '--init'],
options
)

if (result.status !== 0) {
process.exit(result.status || 1)
if (result.status !== 0) {
process.exit(result.status || 1)
}
}

result = spawnSync('node', [path, 'compile:tslint'], options)
result = spawnSync('node', getYarnArgs([path, 'compile:tslint']), options)

if (result.status !== 0) {
process.exit(result.status || 1)
}

result = spawnSync('node', [path, 'compile:script'], options)
result = spawnSync('node', getYarnArgs([path, 'compile:script']), options)

if (result.status !== 0) {
process.exit(result.status || 1)
Expand Down