@mux/cli 0.6.1 → 0.7.1
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 +69 -41
- package/lib/command-bases/asset-base.d.ts +5 -3
- package/lib/command-bases/base.d.ts +3 -1
- package/lib/command-bases/base.js +34 -24
- package/lib/commands/assets/create.js +6 -1
- package/lib/commands/assets/upload.d.ts +7 -7
- package/lib/commands/assets/upload.js +9 -1
- package/lib/commands/init.d.ts +7 -6
- package/lib/commands/init.js +22 -3
- package/lib/commands/live/complete.js +6 -1
- package/lib/commands/live/disable.js +6 -1
- package/lib/commands/live/enable.js +6 -1
- package/lib/commands/sign.js +1 -1
- package/lib/config.d.ts +3 -3
- package/lib/config.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +32 -32
- package/src/command-bases/asset-base.ts +6 -1
- package/src/command-bases/base.ts +39 -27
- package/src/commands/assets/create.ts +6 -1
- package/src/commands/assets/upload.ts +19 -5
- package/src/commands/init.ts +31 -9
- package/src/commands/live/complete.ts +6 -1
- package/src/commands/live/disable.ts +6 -1
- package/src/commands/live/enable.ts +6 -1
- package/src/commands/sign.ts +1 -1
- package/src/config.ts +1 -1
- package/yarn.lock +2445 -1301
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.7.1","commands":{"init":{"id":"init","description":"set up a user-level config","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"f","description":"Will initialize a new file even if one already exists.","allowNo":false}},"args":[{"name":"envFile","description":"path to a Mux access token .env file","required":false}]},"sign":{"id":"sign","description":"Creates a new signed URL token for a playback ID","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"expiresIn":{"name":"expiresIn","type":"option","char":"e","description":"How long the signature is valid for. If no unit is specified, milliseconds is assumed.","default":"7d"},"type":{"name":"type","type":"option","char":"t","description":"What type of token this signature is for.","options":["video","thumbnail","gif","storyboard"],"default":"video"}},"args":[{"name":"playback-id","description":"Playback ID to create a signed URL token for.","required":true}]},"assets:create":{"id":"assets:create","description":"Create a new asset in Mux using a file that's already available online","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"private":{"name":"private","type":"boolean","char":"p","description":"add a private playback policy to the created asset","allowNo":false}},"args":[{"name":"input","description":"input URL for the file you'd like to create this asset from","required":true}]},"assets:upload":{"id":"assets:upload","description":"Create a new asset in Mux via a local file","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"private":{"name":"private","type":"boolean","char":"p","allowNo":false},"filter":{"name":"filter","type":"option","char":"f","description":"regex that filters the selected destination if the provided path is a folder"},"concurrent":{"name":"concurrent","type":"option","char":"c","description":"max number of files to upload at once","default":3}},"args":[{"name":"path","description":"local path for the file (or folder) you'd like to upload","required":true}]},"live:complete":{"id":"live:complete","description":"Signal to Mux that a live stream has concluded and should be closed.","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"streamId":{"name":"streamId","type":"option","char":"t","description":"the type of the provided reference name","options":["stream-id"],"default":"stream-id"},"disableAfterCompletion":{"name":"disableAfterCompletion","type":"boolean","char":"d","description":"If set, disables the stream upon completion.","allowNo":false}},"args":[{"name":"streamName","description":"the name (coupled with --reference-type) to look up in Mux to yield this livestream","required":true}]},"live:disable":{"id":"live:disable","description":"Disables a live stream and prevents encoders from streaming to it.","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"streamId":{"name":"streamId","type":"option","char":"t","description":"the type of the provided reference name","options":["stream-id"],"default":"stream-id"}},"args":[{"name":"streamName","description":"the name (coupled with --reference-type) to look up in Mux to yield this livestream","required":true}]},"live:enable":{"id":"live:enable","description":"Enables a live stream, allowing encoders to streaming to it.","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"streamId":{"name":"streamId","type":"option","char":"t","description":"the type of the provided reference name","options":["stream-id"],"default":"stream-id"}},"args":[{"name":"streamName","description":"the name (coupled with --reference-type) to look up in Mux to yield this livestream","required":true}]}}}
|
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.
|
|
4
|
+
"version": "0.7.1",
|
|
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": "^
|
|
20
|
-
"@oclif/command": "^1.8.
|
|
21
|
-
"@oclif/config": "^1.
|
|
22
|
-
"@oclif/plugin-autocomplete": "^
|
|
23
|
-
"@oclif/plugin-commands": "^
|
|
24
|
-
"@oclif/plugin-help": "^
|
|
25
|
-
"@oclif/plugin-not-found": "^
|
|
26
|
-
"@oclif/plugin-plugins": "^
|
|
27
|
-
"@oclif/plugin-update": "^1.
|
|
28
|
-
"@oclif/plugin-warn-if-update-available": "^
|
|
29
|
-
"chalk": "
|
|
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": "^
|
|
33
|
-
"inquirer": "^
|
|
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
|
|
37
|
-
"rxjs": "^
|
|
36
|
+
"runtypes": "^6.5.0",
|
|
37
|
+
"rxjs": "^7.5.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@oclif/dev-cli": "^1.
|
|
41
|
-
"@oclif/test": "^
|
|
40
|
+
"@oclif/dev-cli": "^1.26.10",
|
|
41
|
+
"@oclif/test": "^2.0.3",
|
|
42
42
|
"@oclif/tslint": "^3",
|
|
43
|
-
"@types/chai": "^4.
|
|
44
|
-
"@types/fs-extra": "^9.0.
|
|
45
|
-
"@types/inquirer": "^
|
|
46
|
-
"@types/listr": "^0.14.
|
|
47
|
-
"@types/mocha": "^
|
|
48
|
-
"@types/node": "^
|
|
49
|
-
"@types/request": "^2.48.
|
|
50
|
-
"chai": "^4",
|
|
51
|
-
"globby": "
|
|
52
|
-
"mocha": "
|
|
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": "^
|
|
55
|
-
"ts-node": "^
|
|
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.
|
|
58
|
+
"typescript": "^4.5.5"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
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',
|
|
@@ -6,54 +6,66 @@ import * as path from 'path';
|
|
|
6
6
|
|
|
7
7
|
import { MuxCliConfigV1 } from '../config';
|
|
8
8
|
|
|
9
|
+
export const MUX_API_BASE_URL = "https://api.mux.com";
|
|
10
|
+
|
|
9
11
|
export default abstract class CommandBase extends Command {
|
|
10
12
|
configFile = path.join(this.config.configDir, 'config.json');
|
|
11
13
|
|
|
12
14
|
MuxConfig!: MuxCliConfigV1;
|
|
15
|
+
Mux!: Mux;
|
|
13
16
|
Video!: MuxVideo;
|
|
14
17
|
Data!: MuxData;
|
|
15
18
|
JWT: any;
|
|
16
19
|
|
|
17
20
|
async readConfigV1(): Promise<MuxCliConfigV1 | null> {
|
|
21
|
+
const configAlreadyExists = await fs.pathExists(this.configFile);
|
|
18
22
|
try {
|
|
19
|
-
const configRaw =
|
|
23
|
+
const configRaw =
|
|
24
|
+
configAlreadyExists
|
|
25
|
+
? await fs.readJSON(this.configFile)
|
|
26
|
+
: {};
|
|
20
27
|
|
|
21
28
|
// Mux SDK configuration options
|
|
22
|
-
configRaw.tokenId = process.env.MUX_TOKEN_ID
|
|
23
|
-
configRaw.tokenSecret = process.env.MUX_TOKEN_SECRET
|
|
24
|
-
configRaw.signingKeyId = process.env.MUX_SIGNING_KEY
|
|
25
|
-
configRaw.signingKeySecret = process.env.MUX_PRIVATE_KEY
|
|
29
|
+
configRaw.tokenId = process.env.MUX_TOKEN_ID ?? configRaw.tokenId;
|
|
30
|
+
configRaw.tokenSecret = process.env.MUX_TOKEN_SECRET ?? configRaw.tokenSecret;
|
|
31
|
+
configRaw.signingKeyId = process.env.MUX_SIGNING_KEY ?? configRaw.signingKeyId;
|
|
32
|
+
configRaw.signingKeySecret = process.env.MUX_PRIVATE_KEY ?? configRaw.signingKeySecret;
|
|
26
33
|
|
|
27
34
|
// Mux CLI specific configuration options
|
|
28
|
-
configRaw.configVersion = configRaw.configVersion
|
|
29
|
-
configRaw.baseUrl = process.env.MUX_CLI_BASE_URL
|
|
30
|
-
|
|
35
|
+
configRaw.configVersion = configRaw.configVersion ?? 1;
|
|
36
|
+
configRaw.baseUrl = process.env.MUX_CLI_BASE_URL ?? configRaw.baseUrl ?? MUX_API_BASE_URL;
|
|
31
37
|
return MuxCliConfigV1.check(configRaw);
|
|
32
38
|
} catch (err) {
|
|
33
|
-
if (
|
|
34
|
-
|
|
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
|
+
);
|
|
35
52
|
}
|
|
36
53
|
|
|
37
|
-
|
|
54
|
+
process.exit(1);
|
|
38
55
|
}
|
|
39
56
|
}
|
|
40
57
|
|
|
41
58
|
async init() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.log(
|
|
55
|
-
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. 👋`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
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;
|
|
58
70
|
}
|
|
59
71
|
}
|
|
@@ -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
|
|
11
|
+
import AssetCommandBase, { AssetBaseFlags } from '../../command-bases/asset-base';
|
|
12
12
|
|
|
13
|
-
export
|
|
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
|
-
...
|
|
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
|
-
|
|
184
|
+
|
|
185
|
+
if (err instanceof Error) {
|
|
186
|
+
this.error(err);
|
|
187
|
+
} else {
|
|
188
|
+
throw err;
|
|
189
|
+
}
|
|
176
190
|
}
|
|
177
191
|
}
|
|
178
192
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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(
|
package/src/commands/sign.ts
CHANGED
package/src/config.ts
CHANGED
|
@@ -8,6 +8,6 @@ export const MuxCliConfigV1 = RT.Record({
|
|
|
8
8
|
signingKeyId: RT.String.Or(RT.Undefined),
|
|
9
9
|
signingKeySecret: RT.String.Or(RT.Undefined),
|
|
10
10
|
|
|
11
|
-
baseUrl: RT.String
|
|
11
|
+
baseUrl: RT.String,
|
|
12
12
|
});
|
|
13
13
|
export type MuxCliConfigV1 = RT.Static<typeof MuxCliConfigV1>;
|