UNPKG

2.18 kBJavaScriptView Raw
1#!/usr/bin/env node
2const OctoDash = require("octodash")
3const path = require("path")
4const ora = require("ora")
5const packageJSON = require("./package.json")
6const { MeshbluConnectorInstaller } = require("./src/installer")
7
8const CLI_OPTIONS = [
9 {
10 names: ["connector-path"],
11 type: "string",
12 required: true,
13 env: "MESHBLU_CONNECTOR_PATH",
14 help: "Path to connector package.json and assets",
15 helpArg: "PATH",
16 default: ".",
17 completionType: "file",
18 },
19 {
20 names: ["destination-path"],
21 type: "string",
22 env: "MESHBLU_CONNECTOR_DESTINATION_PATH",
23 help: "Path for bin files to be placed in installer",
24 helpArg: "PATH",
25 completionType: "file",
26 },
27 {
28 names: ["cert-password"],
29 type: "string",
30 required: true,
31 env: "MESHBLU_CONNECTOR_CERT_PASSWORD",
32 help: "Password to unlock .p12 certificate",
33 helpArg: "PASSWORD",
34 },
35 {
36 names: ["user-install"],
37 type: "bool",
38 env: "MESHBLU_CONNECTOR_USER_INSTALL",
39 help: "Creates a per-user installer",
40 default: false,
41 },
42]
43
44class MeshbluConnectorInstallerWindowsMSICommand {
45 constructor({ argv, cliOptions = CLI_OPTIONS } = {}) {
46 this.octoDash = new OctoDash({
47 argv,
48 cliOptions,
49 name: packageJSON.name,
50 version: packageJSON.version,
51 })
52 }
53
54 async run() {
55 const { connectorPath, certPassword, destinationPath, userInstall } = this.octoDash.parseOptions()
56 const spinner = ora("Building package").start()
57 const installer = new MeshbluConnectorInstaller({
58 connectorPath: path.resolve(connectorPath),
59 destinationPath,
60 userInstall,
61 certPassword,
62 spinner,
63 })
64 return installer.build().then(() => spinner.succeed("Ship it!")).catch(error => {
65 spinner.fail(error.message)
66 return Promise.reject(error)
67 })
68 }
69}
70
71const command = new MeshbluConnectorInstallerWindowsMSICommand({ argv: process.argv })
72command
73 .run()
74 .then(() => {
75 process.exit(0)
76 })
77 .catch(error => {
78 if (error) {
79 if (error.stdout) console.error(error.stdout)
80 if (error.stderr) console.error(error.stderr)
81 console.error(error)
82 }
83 process.exit(1)
84 })