@mux/cli 0.6.2 → 0.8.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 +93 -38
- package/lib/command-bases/asset-base.d.ts +5 -3
- package/lib/command-bases/base.d.ts +4 -3
- package/lib/command-bases/base.js +26 -18
- 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.d.ts +1 -5
- package/lib/commands/sign.js +29 -12
- package/lib/commands/spaces/sign.d.ts +11 -0
- package/lib/commands/spaces/sign.js +79 -0
- package/lib/config.d.ts +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +34 -32
- package/src/command-bases/asset-base.ts +6 -1
- package/src/command-bases/base.ts +35 -24
- 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 +34 -15
- package/src/commands/spaces/sign.ts +90 -0
- package/yarn.lock +2452 -1301
package/lib/commands/sign.js
CHANGED
|
@@ -6,24 +6,36 @@ const clipboard = require("clipboardy");
|
|
|
6
6
|
const base_1 = require("../command-bases/base");
|
|
7
7
|
class Sign extends base_1.default {
|
|
8
8
|
async run() {
|
|
9
|
-
const
|
|
9
|
+
const parsed = this.parse(Sign);
|
|
10
|
+
const args = parsed.args;
|
|
11
|
+
const flags = parsed.flags;
|
|
10
12
|
const playbackId = args['playback-id'];
|
|
11
|
-
const options = {
|
|
13
|
+
const options = {
|
|
14
|
+
expiration: flags.expiresIn,
|
|
15
|
+
type: flags.type,
|
|
16
|
+
keyId: this.MuxConfig.signingKeyId,
|
|
17
|
+
keySecret: this.MuxConfig.signingKeySecret,
|
|
18
|
+
};
|
|
12
19
|
const key = this.JWT.sign(playbackId, options);
|
|
13
20
|
const url = `https://stream.mux.com/${playbackId}.m3u8?token=${key}`;
|
|
14
|
-
|
|
21
|
+
if (flags.raw) {
|
|
22
|
+
console.log(url);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.log(chalk `
|
|
15
26
|
🔑 {bold.underline Your Mux Signed Token}
|
|
16
27
|
{blue ${key}}
|
|
17
28
|
|
|
18
29
|
🌏 {bold.underline Full URL}
|
|
19
30
|
{green ${url}}
|
|
20
|
-
`);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
`);
|
|
32
|
+
try {
|
|
33
|
+
await clipboard.write(url);
|
|
34
|
+
this.log(`👉 Copied Full URL to your system clipboard`);
|
|
35
|
+
}
|
|
36
|
+
catch (_a) {
|
|
37
|
+
this.error('Unable to copy full url automatically');
|
|
38
|
+
}
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
}
|
|
@@ -46,6 +58,11 @@ Sign.flags = {
|
|
|
46
58
|
char: 't',
|
|
47
59
|
description: 'What type of token this signature is for.',
|
|
48
60
|
default: 'video',
|
|
49
|
-
options: ['video', 'thumbnail', 'gif'],
|
|
50
|
-
})
|
|
61
|
+
options: ['video', 'thumbnail', 'gif', 'storyboard'],
|
|
62
|
+
}),
|
|
63
|
+
raw: command_1.flags.boolean({
|
|
64
|
+
char: 'r',
|
|
65
|
+
description: 'If set, emits only the URL+JWT. Defaults to true for non-TTY.',
|
|
66
|
+
default: !process.stdin.isTTY,
|
|
67
|
+
}),
|
|
51
68
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import MuxBase from '../../command-bases/base';
|
|
2
|
+
export default class SignSpace extends MuxBase {
|
|
3
|
+
static description: string;
|
|
4
|
+
static args: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
}[];
|
|
9
|
+
static flags: any;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const JWT = require("jsonwebtoken");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const clipboard = require("clipboardy");
|
|
7
|
+
const base_1 = require("../../command-bases/base");
|
|
8
|
+
class SignSpace extends base_1.default {
|
|
9
|
+
async run() {
|
|
10
|
+
const parsed = this.parse(SignSpace);
|
|
11
|
+
const args = parsed.args;
|
|
12
|
+
const flags = parsed.flags;
|
|
13
|
+
const signingKeySecret = this.MuxConfig.signingKeySecret;
|
|
14
|
+
if (!signingKeySecret) {
|
|
15
|
+
throw new Error("No signing key found. Re-run `mux init` and generate one!");
|
|
16
|
+
}
|
|
17
|
+
// TODO: replace with mux-node-sdk signing when available
|
|
18
|
+
const payload = {
|
|
19
|
+
role: flags.role,
|
|
20
|
+
participant_id: flags.participantId,
|
|
21
|
+
kid: this.MuxConfig.signingKeyId,
|
|
22
|
+
};
|
|
23
|
+
const jwtOptions = {
|
|
24
|
+
audience: 'rt',
|
|
25
|
+
subject: args['space-id'],
|
|
26
|
+
algorithm: 'RS256',
|
|
27
|
+
noTimestamp: true,
|
|
28
|
+
expiresIn: flags.expiresIn,
|
|
29
|
+
};
|
|
30
|
+
const key = Buffer.from(signingKeySecret, 'base64');
|
|
31
|
+
const jwt = JWT.sign(payload, key, jwtOptions);
|
|
32
|
+
if (flags.raw) {
|
|
33
|
+
console.log(jwt);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.log(chalk `
|
|
37
|
+
🔑 Your JWT for Mux Spaces
|
|
38
|
+
{cyan ${jwt}}
|
|
39
|
+
`);
|
|
40
|
+
try {
|
|
41
|
+
await clipboard.write(jwt);
|
|
42
|
+
this.log(`👉 Copied your JWT to your system clipboard`);
|
|
43
|
+
}
|
|
44
|
+
catch (_a) {
|
|
45
|
+
this.error('Unable to copy JWT automatically');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = SignSpace;
|
|
51
|
+
SignSpace.description = 'Creates a new signed token for a Mux Space';
|
|
52
|
+
SignSpace.args = [
|
|
53
|
+
{
|
|
54
|
+
name: 'space-id',
|
|
55
|
+
description: 'Space ID for which a token shall be generated.',
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
SignSpace.flags = {
|
|
60
|
+
raw: command_1.flags.boolean({
|
|
61
|
+
char: 'r',
|
|
62
|
+
description: "prints a raw JWT to stdout (default if not tty)",
|
|
63
|
+
default: !process.stdin.isTTY,
|
|
64
|
+
}),
|
|
65
|
+
participantId: command_1.flags.string({
|
|
66
|
+
char: 'p',
|
|
67
|
+
description: 'Optional, user-specified participant ID.',
|
|
68
|
+
}),
|
|
69
|
+
role: command_1.flags.string({
|
|
70
|
+
char: 'R',
|
|
71
|
+
description: 'One of \'publisher\' or \'subscriber\'.',
|
|
72
|
+
default: 'publisher',
|
|
73
|
+
}),
|
|
74
|
+
expiresIn: command_1.flags.string({
|
|
75
|
+
char: 'e',
|
|
76
|
+
description: 'How long the signature is valid for. If no unit is specified, milliseconds is assumed.',
|
|
77
|
+
default: '7d',
|
|
78
|
+
}),
|
|
79
|
+
};
|
package/lib/config.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export declare const MuxCliConfigV1: RT.Record<{
|
|
|
3
3
|
configVersion: RT.Literal<1>;
|
|
4
4
|
tokenId: RT.String;
|
|
5
5
|
tokenSecret: RT.String;
|
|
6
|
-
signingKeyId: RT.
|
|
7
|
-
signingKeySecret: RT.
|
|
6
|
+
signingKeyId: RT.Union<[RT.String, RT.Literal<undefined>]>;
|
|
7
|
+
signingKeySecret: RT.Union<[RT.String, RT.Literal<undefined>]>;
|
|
8
8
|
baseUrl: RT.String;
|
|
9
9
|
}, false>;
|
|
10
10
|
export declare type MuxCliConfigV1 = RT.Static<typeof MuxCliConfigV1>;
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.8.0","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"},"raw":{"name":"raw","type":"boolean","char":"r","description":"If set, emits only the URL+JWT. Defaults to true for non-TTY.","allowNo":false}},"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}]},"spaces:sign":{"id":"spaces:sign","description":"Creates a new signed token for a Mux Space","pluginName":"@mux/cli","pluginType":"core","aliases":[],"flags":{"raw":{"name":"raw","type":"boolean","char":"r","description":"prints a raw JWT to stdout (default if not tty)","allowNo":false},"participantId":{"name":"participantId","type":"option","char":"p","description":"Optional, user-specified participant ID."},"role":{"name":"role","type":"option","char":"R","description":"One of 'publisher' or 'subscriber'.","default":"publisher"},"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"}},"args":[{"name":"space-id","description":"Space ID for which a token shall be generated.","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.8.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mux",
|
|
7
7
|
"email": "devex@mux.com",
|
|
@@ -16,49 +16,51 @@
|
|
|
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
|
+
"jsonwebtoken": "^8.5.1",
|
|
34
35
|
"listr": "^0.14.3",
|
|
35
36
|
"request": "^2.88.2",
|
|
36
|
-
"runtypes": "^5.0
|
|
37
|
-
"rxjs": "^
|
|
37
|
+
"runtypes": "^6.5.0",
|
|
38
|
+
"rxjs": "^7.5.2"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@oclif/dev-cli": "^1.
|
|
41
|
-
"@oclif/test": "^
|
|
41
|
+
"@oclif/dev-cli": "^1.26.10",
|
|
42
|
+
"@oclif/test": "^2.0.3",
|
|
42
43
|
"@oclif/tslint": "^3",
|
|
43
|
-
"@types/chai": "^4.
|
|
44
|
-
"@types/fs-extra": "^9.0.
|
|
45
|
-
"@types/inquirer": "^
|
|
46
|
-
"@types/
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
44
|
+
"@types/chai": "^4.3.0",
|
|
45
|
+
"@types/fs-extra": "^9.0.13",
|
|
46
|
+
"@types/inquirer": "^8.1.3",
|
|
47
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
48
|
+
"@types/listr": "^0.14.4",
|
|
49
|
+
"@types/mocha": "^9.1.0",
|
|
50
|
+
"@types/node": "^17.0.12",
|
|
51
|
+
"@types/request": "^2.48.8",
|
|
52
|
+
"chai": "^4.3.6",
|
|
53
|
+
"globby": "11.0.4",
|
|
54
|
+
"mocha": "6.2.3",
|
|
53
55
|
"nyc": "^15.1.0",
|
|
54
|
-
"oclif": "^
|
|
55
|
-
"ts-node": "^
|
|
56
|
+
"oclif": "^2.4.0",
|
|
57
|
+
"ts-node": "^10.4.0",
|
|
56
58
|
"tslint": "^6.1.3",
|
|
57
59
|
"tslint-config-prettier": "^1.18.0",
|
|
58
|
-
"typescript": "^4.
|
|
60
|
+
"typescript": "^4.5.5"
|
|
59
61
|
},
|
|
60
62
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
63
|
+
"node": ">=14.0.0"
|
|
62
64
|
},
|
|
63
65
|
"files": [
|
|
64
66
|
"/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',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Mux, { Video as MuxVideo, Data as MuxData } from '@mux/mux-node';
|
|
1
|
+
import Mux, { Video as MuxVideo, Data as MuxData, JWT as MuxJWT } from '@mux/mux-node';
|
|
2
2
|
import Command from '@oclif/command';
|
|
3
3
|
import * as chalk from 'chalk';
|
|
4
4
|
import * as fs from 'fs-extra';
|
|
@@ -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
|
-
JWT
|
|
18
|
+
JWT!: typeof MuxJWT;
|
|
18
19
|
|
|
19
|
-
async readConfigV1(): Promise<MuxCliConfigV1
|
|
20
|
+
async readConfigV1(): Promise<MuxCliConfigV1> {
|
|
21
|
+
const configAlreadyExists = await fs.pathExists(this.configFile);
|
|
20
22
|
try {
|
|
21
|
-
const configRaw =
|
|
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,39 @@ 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 (
|
|
36
|
-
|
|
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
|
-
|
|
54
|
+
process.exit(1);
|
|
40
55
|
}
|
|
41
56
|
}
|
|
42
57
|
|
|
43
58
|
async init() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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.MuxConfig = config;
|
|
68
|
+
this.Video = this.Mux.Video;
|
|
69
|
+
this.Data = this.Mux.Data;
|
|
70
|
+
this.JWT = Mux.JWT;
|
|
60
71
|
}
|
|
61
72
|
}
|
|
@@ -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(
|