1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const Config = require("@oclif/config");
|
4 | const path = require("path");
|
5 | const qq = require("qqjs");
|
6 | const util_1 = require("../util");
|
7 | const TARGETS = [
|
8 | 'linux-x64',
|
9 | 'linux-arm',
|
10 | 'win32-x64',
|
11 | 'win32-x86',
|
12 | 'darwin-x64',
|
13 | ];
|
14 | function gitSha(cwd, options = {}) {
|
15 | const args = options.short ? ['rev-parse', '--short', 'HEAD'] : ['rev-parse', 'HEAD'];
|
16 | return qq.x.stdout('git', args, { cwd });
|
17 | }
|
18 | exports.gitSha = gitSha;
|
19 | async function Tmp(config) {
|
20 | const tmp = path.join(config.root, 'tmp');
|
21 | await qq.mkdirp(tmp);
|
22 | return tmp;
|
23 | }
|
24 | async function buildConfig(root, options = {}) {
|
25 | const config = await Config.load({ root: path.resolve(root), devPlugins: false, userPlugins: false });
|
26 | const channel = config.channel;
|
27 | root = config.root;
|
28 | const _gitSha = await gitSha(root, { short: true });
|
29 | const version = config.version.includes('-') ? `${config.version}.${_gitSha}` : config.version;
|
30 |
|
31 | const tmp = await Tmp(config);
|
32 | const updateConfig = config.pjson.oclif.update || {};
|
33 | updateConfig.s3 = updateConfig.s3 || {};
|
34 | return {
|
35 | root,
|
36 | gitSha: _gitSha,
|
37 | config,
|
38 | tmp,
|
39 | updateConfig,
|
40 | version,
|
41 | channel,
|
42 | xz: typeof options.xz === 'boolean' ? options.xz : Boolean(updateConfig.s3.xz),
|
43 | dist: (...args) => path.join(config.root, 'dist', ...args),
|
44 | s3Config: updateConfig.s3,
|
45 | nodeVersion: updateConfig.node.version || process.versions.node,
|
46 | workspace(target) {
|
47 | const base = qq.join(config.root, 'tmp');
|
48 | if (target && target.platform)
|
49 | return qq.join(base, [target.platform, target.arch].join('-'), config.s3Key('baseDir', target));
|
50 | return qq.join(base, config.s3Key('baseDir', target));
|
51 | },
|
52 | targets: util_1.compact(options.targets || updateConfig.node.targets || TARGETS).map(t => {
|
53 | const [platform, arch] = t.split('-');
|
54 | return { platform, arch };
|
55 | }),
|
56 | };
|
57 | }
|
58 | exports.buildConfig = buildConfig;
|