-
Notifications
You must be signed in to change notification settings - Fork 309
/
config.ts
84 lines (76 loc) · 2.75 KB
/
config.ts
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
import {CliUx, Interfaces, Config} from '@oclif/core'
import * as path from 'path'
import * as qq from 'qqjs'
import * as semver from 'semver'
import {compact} from '../util'
import {templateShortKey} from '../upload-util'
export const TARGETS = [
'linux-x64',
'linux-arm',
'win32-x64',
'win32-x86',
'darwin-x64',
'darwin-arm64',
]
export interface BuildConfig {
root: string;
gitSha: string;
config: Interfaces.Config;
nodeVersion: string;
tmp: string;
updateConfig: BuildConfig['config']['pjson']['oclif']['update'];
s3Config: BuildConfig['updateConfig']['s3'] & { folder?: string; indexVersionLimit?: number};
xz: boolean;
targets: { platform: Interfaces.PlatformTypes; arch: Interfaces.ArchTypes}[];
workspace(target?: { platform: Interfaces.PlatformTypes; arch: Interfaces.ArchTypes}): string;
dist(input: string): string;
}
export async function gitSha(cwd: string, options: {short?: boolean} = {}): Promise<string> {
const args = options.short ? ['rev-parse', '--short', 'HEAD'] : ['rev-parse', 'HEAD']
return qq.x.stdout('git', args, {cwd})
}
async function Tmp(config: Interfaces.Config,
) {
const tmp = path.join(config.root, 'tmp')
await qq.mkdirp(tmp)
return tmp
}
export async function buildConfig(root: string, options: {xz?: boolean; targets?: string[]} = {}): Promise<BuildConfig> {
const config = await Config.load({root: path.resolve(root), devPlugins: false, userPlugins: false})
root = config.root
const _gitSha = await gitSha(root, {short: true})
// eslint-disable-next-line new-cap
const tmp = await Tmp(config)
const updateConfig = config.pjson.oclif.update || {}
updateConfig.s3 = updateConfig.s3 || {}
const nodeVersion = updateConfig.node.version || process.versions.node
const targets = compact(options.targets || updateConfig.node.targets || TARGETS)
.filter(t => {
if (t === 'darwin-arm64' && semver.lt(nodeVersion, '16.0.0')) {
CliUx.ux.warn('darwin-arm64 is only supported for node >=16.0.0. Skipping...')
return false
}
return true
})
.map(t => {
const [platform, arch] = t.split('-') as [Interfaces.PlatformTypes, Interfaces.ArchTypes]
return {platform, arch}
})
return {
root,
gitSha: _gitSha,
config,
tmp,
updateConfig,
xz: typeof options.xz === 'boolean' ? options.xz : Boolean(updateConfig.s3.xz),
dist: (...args: string[]) => path.join(config.root, 'dist', ...args),
s3Config: updateConfig.s3,
nodeVersion,
workspace(target) {
const base = qq.join(config.root, 'tmp')
if (target && target.platform) return qq.join(base, [target.platform, target.arch].join('-'), templateShortKey('baseDir', {bin: config.bin}))
return qq.join(base, templateShortKey('baseDir', {bin: config.bin}))
},
targets,
}
}