@mux/cli 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # mux-cli
2
2
 
3
- Your friendly neighborhood Mux CLI tool
3
+ Your friendly neighborhood Mux CLI tool. **Requires Node 14 or newer.**
4
4
 
5
5
  [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
6
6
  [![Version](https://img.shields.io/npm/v/@mux/cli.svg)](https://npmjs.org/package/@mux/cli)
@@ -21,7 +21,7 @@ $ npm install -g @mux/cli
21
21
  $ mux COMMAND
22
22
  running command...
23
23
  $ mux (-v|--version|version)
24
- @mux/cli/0.5.0 linux-x64 node-v13.9.0
24
+ @mux/cli/0.7.0 linux-x64 node-v14.18.3
25
25
  $ mux --help [COMMAND]
26
26
  USAGE
27
27
  $ mux COMMAND
@@ -41,6 +41,12 @@ USAGE
41
41
  * [`mux live:complete STREAMNAME`](#mux-livecomplete-streamname)
42
42
  * [`mux live:disable STREAMNAME`](#mux-livedisable-streamname)
43
43
  * [`mux live:enable STREAMNAME`](#mux-liveenable-streamname)
44
+ * [`mux plugins`](#mux-plugins)
45
+ * [`mux plugins:inspect PLUGIN...`](#mux-pluginsinspect-plugin)
46
+ * [`mux plugins:install PLUGIN...`](#mux-pluginsinstall-plugin)
47
+ * [`mux plugins:link PLUGIN`](#mux-pluginslink-plugin)
48
+ * [`mux plugins:uninstall PLUGIN...`](#mux-pluginsuninstall-plugin)
49
+ * [`mux plugins:update`](#mux-pluginsupdate)
44
50
  * [`mux sign PLAYBACK-ID`](#mux-sign-playback-id)
45
51
  * [`mux update [CHANNEL]`](#mux-update-channel)
46
52
 
@@ -59,7 +65,7 @@ OPTIONS
59
65
  -p, --private add a private playback policy to the created asset
60
66
  ```
61
67
 
62
- _See code: [src/commands/assets/create.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/assets/create.ts)_
68
+ _See code: [src/commands/assets/create.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/assets/create.ts)_
63
69
 
64
70
  ## `mux assets:upload PATH`
65
71
 
@@ -75,10 +81,10 @@ ARGUMENTS
75
81
  OPTIONS
76
82
  -c, --concurrent=concurrent [default: 3] max number of files to upload at once
77
83
  -f, --filter=filter regex that filters the selected destination if the provided path is a folder
78
- -p, --private add a private playback policy to the created asset
84
+ -p, --private
79
85
  ```
80
86
 
81
- _See code: [src/commands/assets/upload.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/assets/upload.ts)_
87
+ _See code: [src/commands/assets/upload.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/assets/upload.ts)_
82
88
 
83
89
  ## `mux autocomplete [SHELL]`
84
90
 
@@ -101,7 +107,7 @@ EXAMPLES
101
107
  $ mux autocomplete --refresh-cache
102
108
  ```
103
109
 
104
- _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.2.0/src/commands/autocomplete/index.ts)_
110
+ _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.1.1/src/commands/autocomplete/index.ts)_
105
111
 
106
112
  ## `mux commands`
107
113
 
@@ -112,20 +118,20 @@ USAGE
112
118
  $ mux commands
113
119
 
114
120
  OPTIONS
115
- -h, --help show CLI help
116
- -j, --json display unfiltered api data in json format
121
+ -h, --help Show CLI help.
117
122
  -x, --extended show extra columns
118
123
  --columns=columns only show provided columns (comma-separated)
119
124
  --csv output is csv format [alias: --output=csv]
120
125
  --filter=filter filter property by partial string matching, ex: name=foo
121
126
  --hidden show hidden commands
127
+ --json Format output as json.
122
128
  --no-header hide table header from output
123
129
  --no-truncate do not truncate output to fit screen
124
130
  --output=csv|json|yaml output in a more machine friendly format
125
131
  --sort=sort property to sort by (prepend '-' for descending)
126
132
  ```
127
133
 
128
- _See code: [@oclif/plugin-commands](https://github.com/oclif/plugin-commands/blob/v1.3.0/src/commands/commands.ts)_
134
+ _See code: [@oclif/plugin-commands](https://github.com/oclif/plugin-commands/blob/v2.0.2/src/commands/commands.ts)_
129
135
 
130
136
  ## `mux help [COMMAND]`
131
137
 
@@ -142,7 +148,7 @@ OPTIONS
142
148
  --all see all commands in CLI
143
149
  ```
144
150
 
145
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.0/src/commands/help.ts)_
151
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.18/src/commands/help.ts)_
146
152
 
147
153
  ## `mux init [ENVFILE]`
148
154
 
@@ -154,9 +160,12 @@ USAGE
154
160
 
155
161
  ARGUMENTS
156
162
  ENVFILE path to a Mux access token .env file
163
+
164
+ OPTIONS
165
+ -f, --force Will initialize a new file even if one already exists.
157
166
  ```
158
167
 
159
- _See code: [src/commands/init.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/init.ts)_
168
+ _See code: [src/commands/init.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/init.ts)_
160
169
 
161
170
  ## `mux live:complete STREAMNAME`
162
171
 
@@ -174,7 +183,7 @@ OPTIONS
174
183
  -t, --streamId=stream-id [default: stream-id] the type of the provided reference name
175
184
  ```
176
185
 
177
- _See code: [src/commands/live/complete.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/live/complete.ts)_
186
+ _See code: [src/commands/live/complete.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/live/complete.ts)_
178
187
 
179
188
  ## `mux live:disable STREAMNAME`
180
189
 
@@ -191,7 +200,7 @@ OPTIONS
191
200
  -t, --streamId=stream-id [default: stream-id] the type of the provided reference name
192
201
  ```
193
202
 
194
- _See code: [src/commands/live/disable.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/live/disable.ts)_
203
+ _See code: [src/commands/live/disable.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/live/disable.ts)_
195
204
 
196
205
  ## `mux live:enable STREAMNAME`
197
206
 
@@ -208,7 +217,145 @@ OPTIONS
208
217
  -t, --streamId=stream-id [default: stream-id] the type of the provided reference name
209
218
  ```
210
219
 
211
- _See code: [src/commands/live/enable.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/live/enable.ts)_
220
+ _See code: [src/commands/live/enable.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/live/enable.ts)_
221
+
222
+ ## `mux plugins`
223
+
224
+ List installed plugins.
225
+
226
+ ```
227
+ USAGE
228
+ $ mux plugins
229
+
230
+ OPTIONS
231
+ --core Show core plugins.
232
+
233
+ EXAMPLE
234
+ $ mux plugins
235
+ ```
236
+
237
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/index.ts)_
238
+
239
+ ## `mux plugins:inspect PLUGIN...`
240
+
241
+ Displays installation properties of a plugin.
242
+
243
+ ```
244
+ USAGE
245
+ $ mux plugins:inspect PLUGIN...
246
+
247
+ ARGUMENTS
248
+ PLUGIN [default: .] Plugin to inspect.
249
+
250
+ OPTIONS
251
+ -h, --help Show CLI help.
252
+ -v, --verbose
253
+
254
+ EXAMPLE
255
+ $ mux plugins:inspect myplugin
256
+ ```
257
+
258
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/inspect.ts)_
259
+
260
+ ## `mux plugins:install PLUGIN...`
261
+
262
+ Installs a plugin into the CLI.
263
+
264
+ ```
265
+ USAGE
266
+ $ mux plugins:install PLUGIN...
267
+
268
+ ARGUMENTS
269
+ PLUGIN Plugin to install.
270
+
271
+ OPTIONS
272
+ -f, --force Run yarn install with force flag.
273
+ -h, --help Show CLI help.
274
+ -v, --verbose
275
+
276
+ DESCRIPTION
277
+ Can be installed from npm or a git url.
278
+
279
+ Installation of a user-installed plugin will override a core plugin.
280
+
281
+ e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
282
+ will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
283
+ the CLI without the need to patch and update the whole CLI.
284
+
285
+ ALIASES
286
+ $ mux plugins:add
287
+
288
+ EXAMPLES
289
+ $ mux plugins:install myplugin
290
+ $ mux plugins:install https://github.com/someuser/someplugin
291
+ $ mux plugins:install someuser/someplugin
292
+ ```
293
+
294
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/install.ts)_
295
+
296
+ ## `mux plugins:link PLUGIN`
297
+
298
+ Links a plugin into the CLI for development.
299
+
300
+ ```
301
+ USAGE
302
+ $ mux plugins:link PLUGIN
303
+
304
+ ARGUMENTS
305
+ PATH [default: .] path to plugin
306
+
307
+ OPTIONS
308
+ -h, --help Show CLI help.
309
+ -v, --verbose
310
+
311
+ DESCRIPTION
312
+ Installation of a linked plugin will override a user-installed or core plugin.
313
+
314
+ e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
315
+ command will override the user-installed or core plugin implementation. This is useful for development work.
316
+
317
+ EXAMPLE
318
+ $ mux plugins:link myplugin
319
+ ```
320
+
321
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/link.ts)_
322
+
323
+ ## `mux plugins:uninstall PLUGIN...`
324
+
325
+ Removes a plugin from the CLI.
326
+
327
+ ```
328
+ USAGE
329
+ $ mux plugins:uninstall PLUGIN...
330
+
331
+ ARGUMENTS
332
+ PLUGIN plugin to uninstall
333
+
334
+ OPTIONS
335
+ -h, --help Show CLI help.
336
+ -v, --verbose
337
+
338
+ ALIASES
339
+ $ mux plugins:unlink
340
+ $ mux plugins:remove
341
+ ```
342
+
343
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/uninstall.ts)_
344
+
345
+ ## `mux plugins:update`
346
+
347
+ Update installed plugins.
348
+
349
+ ```
350
+ USAGE
351
+ $ mux plugins:update
352
+
353
+ OPTIONS
354
+ -h, --help Show CLI help.
355
+ -v, --verbose
356
+ ```
357
+
358
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.0.12/src/commands/plugins/update.ts)_
212
359
 
213
360
  ## `mux sign PLAYBACK-ID`
214
361
 
@@ -228,7 +375,7 @@ OPTIONS
228
375
  -t, --type=video|thumbnail|gif [default: video] What type of token this signature is for.
229
376
  ```
230
377
 
231
- _See code: [src/commands/sign.ts](https://github.com/muxinc/cli/blob/v0.5.0/src/commands/sign.ts)_
378
+ _See code: [src/commands/sign.ts](https://github.com/muxinc/cli/blob/v0.7.0/src/commands/sign.ts)_
232
379
 
233
380
  ## `mux update [CHANNEL]`
234
381
 
@@ -237,7 +384,10 @@ update the mux CLI
237
384
  ```
238
385
  USAGE
239
386
  $ mux update [CHANNEL]
387
+
388
+ OPTIONS
389
+ --from-local interactively choose an already installed version
240
390
  ```
241
391
 
242
- _See code: [@oclif/plugin-update](https://github.com/oclif/plugin-update/blob/v1.3.10/src/commands/update.ts)_
392
+ _See code: [@oclif/plugin-update](https://github.com/oclif/plugin-update/blob/v2.1.5/src/commands/update.ts)_
243
393
  <!-- commandsstop -->
@@ -1,9 +1,11 @@
1
1
  import { Asset } from '@mux/mux-node';
2
+ import * as Parser from '@oclif/parser';
2
3
  import CommandBase from './base';
4
+ export declare type AssetBaseFlags = {
5
+ private: Parser.flags.IBooleanFlag<boolean>;
6
+ };
3
7
  export default abstract class AssetCommandBase extends CommandBase {
4
- static flags: {
5
- private: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
6
- };
8
+ static flags: AssetBaseFlags;
7
9
  playbackUrl(asset: Asset): string;
8
10
  pollAsset(assetId: string): Promise<Asset>;
9
11
  }
@@ -1,9 +1,14 @@
1
- import { Video as MuxVideo } from '@mux/mux-node';
1
+ import Mux, { Video as MuxVideo, Data as MuxData } from '@mux/mux-node';
2
2
  import Command from '@oclif/command';
3
+ import { MuxCliConfigV1 } from '../config';
4
+ export declare const MUX_API_BASE_URL = "https://api.mux.com";
3
5
  export default abstract class CommandBase extends Command {
4
6
  configFile: string;
7
+ MuxConfig: MuxCliConfigV1;
8
+ Mux: Mux;
5
9
  Video: MuxVideo;
10
+ Data: MuxData;
6
11
  JWT: any;
7
- readConfig(): Promise<any>;
12
+ readConfigV1(): Promise<MuxCliConfigV1 | null>;
8
13
  init(): Promise<void>;
9
14
  }
@@ -1,46 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MUX_API_BASE_URL = void 0;
3
4
  const mux_node_1 = require("@mux/mux-node");
4
5
  const command_1 = require("@oclif/command");
5
6
  const chalk = require("chalk");
6
7
  const fs = require("fs-extra");
7
8
  const path = require("path");
9
+ const config_1 = require("../config");
10
+ exports.MUX_API_BASE_URL = "https://api.mux.com";
8
11
  class CommandBase extends command_1.default {
9
12
  constructor() {
10
13
  super(...arguments);
11
14
  this.configFile = path.join(this.config.configDir, 'config.json');
12
15
  }
13
- async readConfig() {
16
+ async readConfigV1() {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ const configAlreadyExists = await fs.pathExists(this.configFile);
14
19
  try {
15
- const config = await fs.readJSON(this.configFile);
16
- process.env.MUX_TOKEN_ID = process.env.MUX_TOKEN_ID || config.tokenId;
17
- process.env.MUX_TOKEN_SECRET =
18
- process.env.MUX_TOKEN_SECRET || config.tokenSecret;
19
- process.env.MUX_SIGNING_KEY =
20
- process.env.MUX_SIGNING_KEY || config.signingKeyId;
21
- process.env.MUX_PRIVATE_KEY =
22
- process.env.MUX_PRIVATE_KEY || config.signingKeySecret;
23
- return config;
20
+ const configRaw = configAlreadyExists
21
+ ? await fs.readJSON(this.configFile)
22
+ : {};
23
+ // Mux SDK configuration options
24
+ configRaw.tokenId = (_a = process.env.MUX_TOKEN_ID) !== null && _a !== void 0 ? _a : configRaw.tokenId;
25
+ configRaw.tokenSecret = (_b = process.env.MUX_TOKEN_SECRET) !== null && _b !== void 0 ? _b : configRaw.tokenSecret;
26
+ configRaw.signingKeyId = (_c = process.env.MUX_SIGNING_KEY) !== null && _c !== void 0 ? _c : configRaw.signingKeyId;
27
+ configRaw.signingKeySecret = (_d = process.env.MUX_PRIVATE_KEY) !== null && _d !== void 0 ? _d : configRaw.signingKeySecret;
28
+ // Mux CLI specific configuration options
29
+ configRaw.configVersion = (_e = configRaw.configVersion) !== null && _e !== void 0 ? _e : 1;
30
+ configRaw.baseUrl = (_g = (_f = process.env.MUX_CLI_BASE_URL) !== null && _f !== void 0 ? _f : configRaw.baseUrl) !== null && _g !== void 0 ? _g : exports.MUX_API_BASE_URL;
31
+ return config_1.MuxCliConfigV1.check(configRaw);
24
32
  }
25
33
  catch (err) {
26
- if (err.errno !== -2) {
27
- this.error(err);
34
+ if (configAlreadyExists) {
35
+ // we have a bad config file, and should say so
36
+ this.log(chalk `{bold.underline.red Invalid Mux configuration file found at {bold.underline.cyan ${this.configFile}}:}\n\n` +
37
+ Object.entries(err.details).map(tup => " - " + chalk `{cyan ${tup[0]}}` + `: ${tup[1]}`) +
38
+ chalk `\n\nPlease fix the file or run {bold.magenta mux init --force} to create a new one.`);
28
39
  }
29
- return null;
40
+ else {
41
+ this.log(chalk `{bold.underline.red No Mux configuration file found!} If you'd like to create ` +
42
+ chalk `one, run the {bold.magenta init} command. Otherwise, make sure to have the ` +
43
+ chalk `{bold.yellow MUX_TOKEN_ID} and {bold.yellow MUX_TOKEN_SECRET} environment variables set. 👋`);
44
+ }
45
+ process.exit(1);
30
46
  }
31
47
  }
32
48
  async init() {
33
- await this.readConfig();
34
- try {
35
- const { Video } = new mux_node_1.default();
36
- this.Video = Video;
37
- this.JWT = mux_node_1.default.JWT;
38
- }
39
- catch (_a) {
40
- if (this.id === 'init')
41
- return; // If we're initing we're trying to fix this, so don't yell :)
42
- this.log(chalk `{bold.underline.red No Mux config file found!} If you'd like to create one, run the {bold.magenta init} command. Otherwise, make sure to have the {bold.yellow MUX_TOKEN_ID} and {bold.yellow MUX_TOKEN_SECRET} environment variables set. 👋`);
43
- }
49
+ if (this.id === 'init')
50
+ return; // If we're initing we don't want any of this!
51
+ const config = await this.readConfigV1();
52
+ const mux = new mux_node_1.default(config === null || config === void 0 ? void 0 : config.tokenId, config === null || config === void 0 ? void 0 : config.tokenSecret, {
53
+ baseUrl: config === null || config === void 0 ? void 0 : config.baseUrl,
54
+ });
55
+ this.Mux = mux;
56
+ this.Video = this.Mux.Video;
57
+ this.Data = this.Mux.Data;
58
+ this.JWT = mux_node_1.default.JWT;
44
59
  }
45
60
  }
46
61
  exports.default = CommandBase;
@@ -41,7 +41,15 @@ class AssetsCreate extends asset_base_1.default {
41
41
  `);
42
42
  }
43
43
  catch (err) {
44
- console.log("Error during asset:create:", err);
44
+ console.log(chalk.redBright('Error:') +
45
+ "\n\n" +
46
+ err);
47
+ if (err instanceof Error) {
48
+ this.error(err);
49
+ }
50
+ else {
51
+ throw err;
52
+ }
45
53
  }
46
54
  }
47
55
  }
@@ -1,18 +1,18 @@
1
1
  import { Upload } from '@mux/mux-node';
2
2
  import { flags } from '@oclif/command';
3
- import Command from '../../command-bases/asset-base';
4
- export default class AssetsCreate extends Command {
3
+ import AssetCommandBase, { AssetBaseFlags } from '../../command-bases/asset-base';
4
+ export declare type AssetCreateFlags = AssetBaseFlags & {
5
+ filter: flags.IOptionFlag<string | undefined>;
6
+ concurrent: flags.IOptionFlag<number>;
7
+ };
8
+ export default class AssetsCreate extends AssetCommandBase {
5
9
  static description: string;
6
10
  static args: {
7
11
  name: string;
8
12
  description: string;
9
13
  required: boolean;
10
14
  }[];
11
- static flags: {
12
- filter: flags.IOptionFlag<string | undefined>;
13
- concurrent: import("@oclif/parser/lib/flags").IOptionFlag<number>;
14
- private: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
15
- };
15
+ static flags: AssetCreateFlags;
16
16
  getFilePaths(filePath: string, filter?: string): string[];
17
17
  uploadFile(filePath: string, url: string): Promise<unknown>;
18
18
  pollUpload(uploadId: string): Promise<Upload>;
@@ -114,8 +114,15 @@ class AssetsCreate extends asset_base_1.default {
114
114
  }
115
115
  catch (err) {
116
116
  // TODO: make this clearer / separate it out per video for more obvious debugging.
117
- console.log("Error during video processing: ", err);
118
- throw err;
117
+ console.log(chalk.redBright('Error:') +
118
+ "\n\n" +
119
+ err);
120
+ if (err instanceof Error) {
121
+ this.error(err);
122
+ }
123
+ else {
124
+ throw err;
125
+ }
119
126
  }
120
127
  }
121
128
  }
@@ -135,4 +142,7 @@ AssetsCreate.flags = Object.assign(Object.assign({}, asset_base_1.default.flags)
135
142
  char: 'c',
136
143
  description: 'max number of files to upload at once',
137
144
  default: 3,
145
+ }), private: command_1.flags.boolean({
146
+ char: 'p',
147
+ default: false,
138
148
  }) });
@@ -1,4 +1,9 @@
1
+ import * as Parser from '@oclif/parser';
1
2
  import MuxBase from '../command-bases/base';
3
+ import { MuxCliConfigV1 } from '../config';
4
+ export declare type InitFlags = {
5
+ force: Parser.flags.IBooleanFlag<boolean>;
6
+ };
2
7
  export default class Init extends MuxBase {
3
8
  static description: string;
4
9
  static args: {
@@ -7,13 +12,9 @@ export default class Init extends MuxBase {
7
12
  description: string;
8
13
  parse: (input: string) => string;
9
14
  }[];
15
+ static flags: InitFlags;
10
16
  Video: any;
11
17
  JWT: any;
12
- muxConfig: {
13
- tokenId?: string;
14
- tokenSecret?: string;
15
- signingKeyId?: string;
16
- signingKeySecret?: string;
17
- };
18
+ muxConfig: Partial<MuxCliConfigV1>;
18
19
  run(): Promise<void>;
19
20
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const mux_node_1 = require("@mux/mux-node");
4
+ const command_1 = require("@oclif/command");
4
5
  const chalk = require("chalk");
5
6
  const dotenv = require("dotenv");
6
7
  const fs = require("fs-extra");
@@ -13,7 +14,7 @@ class Init extends base_1.default {
13
14
  this.muxConfig = {};
14
15
  }
15
16
  async run() {
16
- const { args } = this.parse(Init);
17
+ const { args, flags } = this.parse(Init);
17
18
  let prompts = [];
18
19
  if (args.envFile) {
19
20
  const envFile = path.resolve(args.envFile);
@@ -43,7 +44,10 @@ class Init extends base_1.default {
43
44
  },
44
45
  ];
45
46
  }
46
- await this.readConfig();
47
+ if (!flags.force && (await fs.pathExists(this.configFile))) {
48
+ this.log(chalk `{bold.underline.red You are attempting to initialize with an existing configuration file!} If this is intentional, please pass {bold.yellow --force}.`);
49
+ process.exit(1);
50
+ }
47
51
  const signingKeyPrompt = {
48
52
  name: 'createSigningKey',
49
53
  message: 'Do you want to go ahead and set up a Signing Key? This is used to create tokens for signed playback policies.',
@@ -58,6 +62,7 @@ class Init extends base_1.default {
58
62
  let { createSigningKey, tokenId, tokenSecret } = answers;
59
63
  // If the token was loaded from an env file they'll already be set in the appropriate environment variables and
60
64
  // the prompts themselves will be null.
65
+ this.muxConfig.configVersion = 1;
61
66
  this.muxConfig.tokenId = process.env.MUX_TOKEN_ID = tokenId || process.env.MUX_TOKEN_ID;
62
67
  this.muxConfig.tokenSecret = process.env.MUX_TOKEN_SECRET = tokenSecret || process.env.MUX_TOKEN_SECRET;
63
68
  if (createSigningKey) {
@@ -79,7 +84,13 @@ class Init extends base_1.default {
79
84
  await fs.writeFile(this.configFile, JSON.stringify(this.muxConfig), 'utf8');
80
85
  }
81
86
  catch (err) {
82
- this.error(err);
87
+ // TODO: improve error handling type safety here
88
+ if (err instanceof Error) {
89
+ this.error(err);
90
+ }
91
+ else {
92
+ throw err;
93
+ }
83
94
  }
84
95
  this.log(chalk `{bold.underline Configuration written to:} ${this.configFile}`);
85
96
  }
@@ -94,3 +105,11 @@ Init.args = [
94
105
  parse: (input) => path.resolve(input),
95
106
  },
96
107
  ];
108
+ Init.flags = {
109
+ force: command_1.flags.boolean({
110
+ name: 'force',
111
+ char: 'f',
112
+ description: 'Will initialize a new file even if one already exists.',
113
+ default: false,
114
+ }),
115
+ };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Listr = require("listr");
4
4
  const command_1 = require("@oclif/command");
5
5
  const live_base_1 = require("../../command-bases/live-base");
6
+ const chalk = require("chalk");
6
7
  class LiveComplete extends live_base_1.default {
7
8
  async run() {
8
9
  const { args, flags } = this.parse(LiveComplete);
@@ -28,8 +29,15 @@ class LiveComplete extends live_base_1.default {
28
29
  }
29
30
  catch (err) {
30
31
  // TODO: make this clearer
31
- console.log("Error: ", err);
32
- throw err;
32
+ console.log(chalk.redBright('Error:') +
33
+ "\n\n" +
34
+ err);
35
+ if (err instanceof Error) {
36
+ this.error(err);
37
+ }
38
+ else {
39
+ throw err;
40
+ }
33
41
  }
34
42
  }
35
43
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Listr = require("listr");
4
4
  const live_base_1 = require("../../command-bases/live-base");
5
+ const chalk = require("chalk");
5
6
  class LiveDisable extends live_base_1.default {
6
7
  async run() {
7
8
  const { args, flags } = this.parse(LiveDisable);
@@ -19,8 +20,15 @@ class LiveDisable extends live_base_1.default {
19
20
  }
20
21
  catch (err) {
21
22
  // TODO: make this clearer
22
- console.log("Error: ", err);
23
- throw err;
23
+ console.log(chalk.redBright('Error:') +
24
+ "\n\n" +
25
+ err);
26
+ if (err instanceof Error) {
27
+ this.error(err);
28
+ }
29
+ else {
30
+ throw err;
31
+ }
24
32
  }
25
33
  }
26
34
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Listr = require("listr");
4
4
  const live_base_1 = require("../../command-bases/live-base");
5
+ const chalk = require("chalk");
5
6
  class LiveEnable extends live_base_1.default {
6
7
  async run() {
7
8
  const { args, flags } = this.parse(LiveEnable);
@@ -19,8 +20,15 @@ class LiveEnable extends live_base_1.default {
19
20
  }
20
21
  catch (err) {
21
22
  // TODO: make this clearer
22
- console.log("Error: ", err);
23
- throw err;
23
+ console.log(chalk.redBright('Error:') +
24
+ "\n\n" +
25
+ err);
26
+ if (err instanceof Error) {
27
+ this.error(err);
28
+ }
29
+ else {
30
+ throw err;
31
+ }
24
32
  }
25
33
  }
26
34
  }
@@ -0,0 +1,10 @@
1
+ import * as RT from 'runtypes';
2
+ export declare const MuxCliConfigV1: RT.Record<{
3
+ configVersion: RT.Literal<1>;
4
+ tokenId: RT.String;
5
+ tokenSecret: RT.String;
6
+ signingKeyId: RT.Union<[RT.String, RT.Literal<undefined>]>;
7
+ signingKeySecret: RT.Union<[RT.String, RT.Literal<undefined>]>;
8
+ baseUrl: RT.String;
9
+ }, false>;
10
+ export declare type MuxCliConfigV1 = RT.Static<typeof MuxCliConfigV1>;
package/lib/config.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MuxCliConfigV1 = void 0;
4
+ const RT = require("runtypes");
5
+ exports.MuxCliConfigV1 = RT.Record({
6
+ configVersion: RT.Literal(1),
7
+ tokenId: RT.String,
8
+ tokenSecret: RT.String,
9
+ signingKeyId: RT.String.Or(RT.Undefined),
10
+ signingKeySecret: RT.String.Or(RT.Undefined),
11
+ baseUrl: RT.String,
12
+ });