@mux/cli 0.6.2 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mux/cli",
3
3
  "description": "Your friendly neighborhood Mux CLI tool!",
4
- "version": "0.6.2",
4
+ "version": "0.7.0",
5
5
  "author": {
6
6
  "name": "Mux",
7
7
  "email": "devex@mux.com",
@@ -16,49 +16,49 @@
16
16
  },
17
17
  "bugs": "https://github.com/muxinc/cli/issues",
18
18
  "dependencies": {
19
- "@mux/mux-node": "^3.1.0",
20
- "@oclif/command": "^1.8.0",
21
- "@oclif/config": "^1.17.0",
22
- "@oclif/plugin-autocomplete": "^0.2.0",
23
- "@oclif/plugin-commands": "^1.3.0",
24
- "@oclif/plugin-help": "^3.2.0",
25
- "@oclif/plugin-not-found": "^1.2.4",
26
- "@oclif/plugin-plugins": "^1.9.4",
27
- "@oclif/plugin-update": "^1.3.10",
28
- "@oclif/plugin-warn-if-update-available": "^1.7.0",
29
- "chalk": "^4.1.0",
19
+ "@mux/mux-node": "^4.0.0",
20
+ "@oclif/command": "^1.8.16",
21
+ "@oclif/config": "^1.18.2",
22
+ "@oclif/plugin-autocomplete": "^1.1.1",
23
+ "@oclif/plugin-commands": "^2.0.2",
24
+ "@oclif/plugin-help": "^5.1.10",
25
+ "@oclif/plugin-not-found": "^2.2.4",
26
+ "@oclif/plugin-plugins": "^2.0.12",
27
+ "@oclif/plugin-update": "^2.1.5",
28
+ "@oclif/plugin-warn-if-update-available": "^2.0.4",
29
+ "chalk": "4.1.2",
30
30
  "clipboardy": "^2.3.0",
31
31
  "dotenv": "^8.2.0",
32
- "fs-extra": "^9.0.1",
33
- "inquirer": "^7.3.3",
32
+ "fs-extra": "^10.0.0",
33
+ "inquirer": "^8.2.0",
34
34
  "listr": "^0.14.3",
35
35
  "request": "^2.88.2",
36
- "runtypes": "^5.0.1",
37
- "rxjs": "^6.6.3"
36
+ "runtypes": "^6.5.0",
37
+ "rxjs": "^7.5.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@oclif/dev-cli": "^1.24.3",
41
- "@oclif/test": "^1.2.8",
40
+ "@oclif/dev-cli": "^1.26.10",
41
+ "@oclif/test": "^2.0.3",
42
42
  "@oclif/tslint": "^3",
43
- "@types/chai": "^4.2.14",
44
- "@types/fs-extra": "^9.0.4",
45
- "@types/inquirer": "^7.3.1",
46
- "@types/listr": "^0.14.2",
47
- "@types/mocha": "^8.0.4",
48
- "@types/node": "^14.14.37",
49
- "@types/request": "^2.48.5",
50
- "chai": "^4",
51
- "globby": "^11.0.1",
52
- "mocha": "^8.2.1",
43
+ "@types/chai": "^4.3.0",
44
+ "@types/fs-extra": "^9.0.13",
45
+ "@types/inquirer": "^8.1.3",
46
+ "@types/listr": "^0.14.4",
47
+ "@types/mocha": "^9.1.0",
48
+ "@types/node": "^17.0.12",
49
+ "@types/request": "^2.48.8",
50
+ "chai": "^4.3.6",
51
+ "globby": "11.0.4",
52
+ "mocha": "6.2.3",
53
53
  "nyc": "^15.1.0",
54
- "oclif": "^1.16.1",
55
- "ts-node": "^9.0.0",
54
+ "oclif": "^2.4.0",
55
+ "ts-node": "^10.4.0",
56
56
  "tslint": "^6.1.3",
57
57
  "tslint-config-prettier": "^1.18.0",
58
- "typescript": "^4.1.2"
58
+ "typescript": "^4.5.5"
59
59
  },
60
60
  "engines": {
61
- "node": ">=8.0.0"
61
+ "node": ">=14.0.0"
62
62
  },
63
63
  "files": [
64
64
  "/bin",
@@ -1,9 +1,14 @@
1
1
  import { Asset } from '@mux/mux-node';
2
2
  import { flags } from '@oclif/command';
3
+ import * as Parser from '@oclif/parser';
3
4
  import CommandBase from './base';
4
5
 
6
+ export type AssetBaseFlags = {
7
+ private: Parser.flags.IBooleanFlag<boolean>;
8
+ };
9
+
5
10
  export default abstract class AssetCommandBase extends CommandBase {
6
- static flags = {
11
+ static flags: AssetBaseFlags = {
7
12
  private: flags.boolean({
8
13
  char: 'p',
9
14
  description: 'add a private playback policy to the created asset',
@@ -12,13 +12,18 @@ export default abstract class CommandBase extends Command {
12
12
  configFile = path.join(this.config.configDir, 'config.json');
13
13
 
14
14
  MuxConfig!: MuxCliConfigV1;
15
+ Mux!: Mux;
15
16
  Video!: MuxVideo;
16
17
  Data!: MuxData;
17
18
  JWT: any;
18
19
 
19
20
  async readConfigV1(): Promise<MuxCliConfigV1 | null> {
21
+ const configAlreadyExists = await fs.pathExists(this.configFile);
20
22
  try {
21
- const configRaw = await fs.readJSON(this.configFile);
23
+ const configRaw =
24
+ configAlreadyExists
25
+ ? await fs.readJSON(this.configFile)
26
+ : {};
22
27
 
23
28
  // Mux SDK configuration options
24
29
  configRaw.tokenId = process.env.MUX_TOKEN_ID ?? configRaw.tokenId;
@@ -29,33 +34,38 @@ export default abstract class CommandBase extends Command {
29
34
  // Mux CLI specific configuration options
30
35
  configRaw.configVersion = configRaw.configVersion ?? 1;
31
36
  configRaw.baseUrl = process.env.MUX_CLI_BASE_URL ?? configRaw.baseUrl ?? MUX_API_BASE_URL;
32
-
33
37
  return MuxCliConfigV1.check(configRaw);
34
38
  } catch (err) {
35
- if (err.errno !== -2) {
36
- this.error(err);
39
+ if (configAlreadyExists) {
40
+ // we have a bad config file, and should say so
41
+ this.log(
42
+ chalk`{bold.underline.red Invalid Mux configuration file found at {bold.underline.cyan ${this.configFile}}:}\n\n` +
43
+ Object.entries((err as any).details).map(tup => " - " + chalk`{cyan ${tup[0]}}` + `: ${tup[1]}`) +
44
+ chalk`\n\nPlease fix the file or run {bold.magenta mux init --force} to create a new one.`
45
+ )
46
+ } else {
47
+ this.log(
48
+ chalk`{bold.underline.red No Mux configuration file found!} If you'd like to create ` +
49
+ chalk`one, run the {bold.magenta init} command. Otherwise, make sure to have the ` +
50
+ chalk`{bold.yellow MUX_TOKEN_ID} and {bold.yellow MUX_TOKEN_SECRET} environment variables set. 👋`
51
+ );
37
52
  }
38
53
 
39
- return null;
54
+ process.exit(1);
40
55
  }
41
56
  }
42
57
 
43
58
  async init() {
44
- try {
45
- const config = await this.readConfigV1();
46
- const { Video, Data } = new Mux(config?.tokenId, config?.tokenSecret, {
47
- baseUrl: config?.baseUrl,
48
- });
49
-
50
- this.Video = Video;
51
- this.Data = Data;
52
- this.JWT = Mux.JWT;
53
- } catch {
54
- if (this.id === 'init') return; // If we're initing we're trying to fix this, so don't yell :)
55
-
56
- this.log(
57
- 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. 👋`
58
- );
59
- }
59
+ if (this.id === 'init') return; // If we're initing we don't want any of this!
60
+
61
+ const config = await this.readConfigV1();
62
+ const mux = new Mux(config?.tokenId, config?.tokenSecret, {
63
+ baseUrl: config?.baseUrl,
64
+ });
65
+
66
+ this.Mux = mux;
67
+ this.Video = this.Mux.Video;
68
+ this.Data = this.Mux.Data;
69
+ this.JWT = Mux.JWT;
60
70
  }
61
71
  }
@@ -63,7 +63,12 @@ export default class AssetsCreate extends AssetCommandBase {
63
63
  "\n\n" +
64
64
  err
65
65
  );
66
- this.error(err);
66
+
67
+ if (err instanceof Error) {
68
+ this.error(err);
69
+ } else {
70
+ throw err;
71
+ }
67
72
  }
68
73
  }
69
74
  }
@@ -8,9 +8,14 @@ import * as Listr from 'listr';
8
8
  import * as path from 'path';
9
9
  import * as request from 'request';
10
10
 
11
- import Command from '../../command-bases/asset-base';
11
+ import AssetCommandBase, { AssetBaseFlags } from '../../command-bases/asset-base';
12
12
 
13
- export default class AssetsCreate extends Command {
13
+ export type AssetCreateFlags = AssetBaseFlags & {
14
+ filter: flags.IOptionFlag<string | undefined>;
15
+ concurrent: flags.IOptionFlag<number>;
16
+ };
17
+
18
+ export default class AssetsCreate extends AssetCommandBase {
14
19
  static description = 'Create a new asset in Mux via a local file';
15
20
 
16
21
  static args = [
@@ -21,8 +26,8 @@ export default class AssetsCreate extends Command {
21
26
  },
22
27
  ];
23
28
 
24
- static flags = {
25
- ...Command.flags,
29
+ static flags: AssetCreateFlags = {
30
+ ...AssetCommandBase.flags,
26
31
  filter: flags.string({
27
32
  char: 'f',
28
33
  description:
@@ -33,6 +38,10 @@ export default class AssetsCreate extends Command {
33
38
  description: 'max number of files to upload at once',
34
39
  default: 3,
35
40
  }),
41
+ private: flags.boolean({
42
+ char: 'p',
43
+ default: false,
44
+ })
36
45
  };
37
46
 
38
47
  getFilePaths(filePath: string, filter = '') {
@@ -172,7 +181,12 @@ export default class AssetsCreate extends Command {
172
181
  "\n\n" +
173
182
  err
174
183
  );
175
- this.error(err);
184
+
185
+ if (err instanceof Error) {
186
+ this.error(err);
187
+ } else {
188
+ throw err;
189
+ }
176
190
  }
177
191
  }
178
192
  }
@@ -1,4 +1,6 @@
1
1
  import Mux from '@mux/mux-node';
2
+ import { flags } from '@oclif/command';
3
+ import * as Parser from '@oclif/parser';
2
4
  import * as chalk from 'chalk';
3
5
  import * as dotenv from 'dotenv';
4
6
  import * as fs from 'fs-extra';
@@ -6,6 +8,11 @@ import * as inquirer from 'inquirer';
6
8
  import * as path from 'path';
7
9
 
8
10
  import MuxBase from '../command-bases/base';
11
+ import { MuxCliConfigV1 } from '../config';
12
+
13
+ export type InitFlags = {
14
+ force: Parser.flags.IBooleanFlag<boolean>;
15
+ };
9
16
 
10
17
  export default class Init extends MuxBase {
11
18
  static description = 'set up a user-level config';
@@ -19,18 +26,22 @@ export default class Init extends MuxBase {
19
26
  },
20
27
  ];
21
28
 
29
+ static flags: InitFlags = {
30
+ force: flags.boolean({
31
+ name: 'force',
32
+ char: 'f',
33
+ description: 'Will initialize a new file even if one already exists.',
34
+ default: false,
35
+ }),
36
+ };
37
+
22
38
  Video: any;
23
39
  JWT: any;
24
40
 
25
- muxConfig: {
26
- tokenId?: string;
27
- tokenSecret?: string;
28
- signingKeyId?: string;
29
- signingKeySecret?: string;
30
- } = {};
41
+ muxConfig: Partial<MuxCliConfigV1> = {};
31
42
 
32
43
  async run() {
33
- const { args } = this.parse(Init);
44
+ const { args, flags } = this.parse(Init);
34
45
 
35
46
  let prompts: {
36
47
  name: string;
@@ -70,7 +81,12 @@ export default class Init extends MuxBase {
70
81
  ];
71
82
  }
72
83
 
73
- await this.readConfigV1();
84
+ if (!flags.force && (await fs.pathExists(this.configFile))) {
85
+ this.log(
86
+ chalk`{bold.underline.red You are attempting to initialize with an existing configuration file!} If this is intentional, please pass {bold.yellow --force}.`
87
+ );
88
+ process.exit(1);
89
+ }
74
90
 
75
91
  const signingKeyPrompt = {
76
92
  name: 'createSigningKey',
@@ -91,6 +107,7 @@ export default class Init extends MuxBase {
91
107
 
92
108
  // If the token was loaded from an env file they'll already be set in the appropriate environment variables and
93
109
  // the prompts themselves will be null.
110
+ this.muxConfig.configVersion = 1;
94
111
  this.muxConfig.tokenId = process.env.MUX_TOKEN_ID = tokenId || process.env.MUX_TOKEN_ID;
95
112
  this.muxConfig.tokenSecret = process.env.MUX_TOKEN_SECRET = tokenSecret || process.env.MUX_TOKEN_SECRET;
96
113
 
@@ -118,7 +135,12 @@ export default class Init extends MuxBase {
118
135
  'utf8'
119
136
  );
120
137
  } catch (err) {
121
- this.error(err);
138
+ // TODO: improve error handling type safety here
139
+ if (err instanceof Error) {
140
+ this.error(err);
141
+ } else {
142
+ throw err;
143
+ }
122
144
  }
123
145
 
124
146
  this.log(
@@ -52,7 +52,12 @@ export default class LiveComplete extends LiveCommandBase {
52
52
  "\n\n" +
53
53
  err
54
54
  );
55
- this.error(err);
55
+
56
+ if (err instanceof Error) {
57
+ this.error(err);
58
+ } else {
59
+ throw err;
60
+ }
56
61
  }
57
62
  }
58
63
  }
@@ -36,7 +36,12 @@ export default class LiveDisable extends LiveCommandBase {
36
36
  "\n\n" +
37
37
  err
38
38
  );
39
- this.error(err);
39
+
40
+ if (err instanceof Error) {
41
+ this.error(err);
42
+ } else {
43
+ throw err;
44
+ }
40
45
  }
41
46
  }
42
47
  }
@@ -36,7 +36,12 @@ export default class LiveEnable extends LiveCommandBase {
36
36
  "\n\n" +
37
37
  err
38
38
  );
39
- this.error(err);
39
+
40
+ if (err instanceof Error) {
41
+ this.error(err);
42
+ } else {
43
+ throw err;
44
+ }
40
45
  }
41
46
  }
42
47
  }