UNPKG

2.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const command_1 = require("@oclif/command");
4const path = require("path");
5const qq = require("qqjs");
6const Tarballs = require("../../tarballs");
7class PackMacos extends command_1.Command {
8 async run() {
9 if (process.platform !== 'darwin')
10 this.error('must be run from macos');
11 const { flags } = this.parse(PackMacos);
12 const buildConfig = await Tarballs.buildConfig(flags.root);
13 const { config } = buildConfig;
14 const c = config.pjson.oclif;
15 if (!c.macos || !c.macos.identifier)
16 this.error('package.json must have oclif.macos.identifier set');
17 await Tarballs.build(buildConfig, { platform: 'darwin', pack: false });
18 const dist = buildConfig.dist(`macos/${config.bin}-v${buildConfig.version}.pkg`);
19 await qq.emptyDir(path.dirname(dist));
20 const scriptsDir = qq.join(buildConfig.tmp, 'macos/scripts');
21 const writeScript = async (script) => {
22 const path = [scriptsDir, script];
23 await qq.write(path, scripts[script](config));
24 await qq.chmod(path, 0o755);
25 };
26 await writeScript('preinstall');
27 await writeScript('postinstall');
28 const args = [
29 '--root', buildConfig.workspace({ platform: 'darwin', arch: 'x64' }),
30 '--identifier', c.macos.identifier,
31 '--version', buildConfig.version,
32 '--install-location', `/usr/local/lib/${config.dirname}`,
33 '--scripts', scriptsDir,
34 ];
35 if (c.macos.sign)
36 args.push('--sign', c.macos.sign);
37 if (process.env.OSX_KEYCHAIN)
38 args.push('--keychain', process.env.OSX_KEYCHAIN);
39 args.push(dist);
40 await qq.x('pkgbuild', args);
41 }
42}
43PackMacos.description = 'pack CLI into MacOS .pkg';
44PackMacos.flags = {
45 root: command_1.flags.string({ char: 'r', description: 'path to oclif CLI root', default: '.', required: true }),
46};
47exports.default = PackMacos;
48const scripts = {
49 preinstall: (config) => `#!/usr/bin/env bash
50sudo rm -rf /usr/local/lib/${config.bin}
51sudo rm -rf /usr/local/${config.bin}
52sudo rm -rf /usr/local/bin/${config.bin}
53`,
54 postinstall: (config) => `#!/usr/bin/env bash
55set -x
56sudo mkdir -p /usr/local/bin
57sudo ln -sf /usr/local/lib/${config.dirname}/bin/${config.dirname} /usr/local/bin/${config.dirname}
58`,
59};