@mux/cli 0.7.1 → 1.0.0-beta.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.
Files changed (44) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +1228 -244
  3. package/bin/mux +31 -0
  4. package/package.json +64 -101
  5. package/bin/run +0 -6
  6. package/bin/run.cmd +0 -3
  7. package/lib/command-bases/asset-base.d.ts +0 -11
  8. package/lib/command-bases/asset-base.js +0 -41
  9. package/lib/command-bases/base.d.ts +0 -14
  10. package/lib/command-bases/base.js +0 -61
  11. package/lib/command-bases/live-base.d.ts +0 -11
  12. package/lib/command-bases/live-base.js +0 -31
  13. package/lib/commands/assets/create.d.ts +0 -10
  14. package/lib/commands/assets/create.js +0 -64
  15. package/lib/commands/assets/upload.d.ts +0 -20
  16. package/lib/commands/assets/upload.js +0 -148
  17. package/lib/commands/init.d.ts +0 -20
  18. package/lib/commands/init.js +0 -115
  19. package/lib/commands/live/complete.d.ts +0 -12
  20. package/lib/commands/live/complete.js +0 -54
  21. package/lib/commands/live/disable.d.ts +0 -13
  22. package/lib/commands/live/disable.js +0 -40
  23. package/lib/commands/live/enable.d.ts +0 -13
  24. package/lib/commands/live/enable.js +0 -40
  25. package/lib/commands/sign.d.ts +0 -15
  26. package/lib/commands/sign.js +0 -51
  27. package/lib/config.d.ts +0 -10
  28. package/lib/config.js +0 -12
  29. package/lib/index.d.ts +0 -2
  30. package/lib/index.js +0 -7
  31. package/oclif.manifest.json +0 -1
  32. package/src/command-bases/asset-base.ts +0 -52
  33. package/src/command-bases/base.ts +0 -71
  34. package/src/command-bases/live-base.ts +0 -35
  35. package/src/commands/assets/create.ts +0 -74
  36. package/src/commands/assets/upload.ts +0 -192
  37. package/src/commands/init.ts +0 -150
  38. package/src/commands/live/complete.ts +0 -63
  39. package/src/commands/live/disable.ts +0 -47
  40. package/src/commands/live/enable.ts +0 -47
  41. package/src/commands/sign.ts +0 -57
  42. package/src/config.ts +0 -13
  43. package/src/index.ts +0 -3
  44. package/yarn.lock +0 -7343
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const mux_node_1 = require("@mux/mux-node");
4
- const command_1 = require("@oclif/command");
5
- const chalk = require("chalk");
6
- const dotenv = require("dotenv");
7
- const fs = require("fs-extra");
8
- const inquirer = require("inquirer");
9
- const path = require("path");
10
- const base_1 = require("../command-bases/base");
11
- class Init extends base_1.default {
12
- constructor() {
13
- super(...arguments);
14
- this.muxConfig = {};
15
- }
16
- async run() {
17
- const { args, flags } = this.parse(Init);
18
- let prompts = [];
19
- if (args.envFile) {
20
- const envFile = path.resolve(args.envFile);
21
- const env = dotenv.config({ path: envFile });
22
- if (env.error) {
23
- this.error(`Unable to load env file: ${envFile}`);
24
- }
25
- else if (env.parsed) {
26
- this.log(chalk `Loaded your Mux .env file! Using token with id: {blue ${env.parsed.MUX_TOKEN_ID}}`);
27
- process.env.MUX_TOKEN_ID = env.parsed.MUX_TOKEN_ID;
28
- process.env.MUX_TOKEN_SECRET = env.parsed.MUX_TOKEN_SECRET;
29
- }
30
- }
31
- else {
32
- prompts = [
33
- {
34
- name: 'tokenId',
35
- message: "What's your token ID?",
36
- type: 'string',
37
- default: process.env.MUX_TOKEN_ID,
38
- },
39
- {
40
- name: 'tokenSecret',
41
- message: "What's your token secret?",
42
- type: 'password',
43
- default: process.env.MUX_TOKEN_SECRET,
44
- },
45
- ];
46
- }
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
- }
51
- const signingKeyPrompt = {
52
- name: 'createSigningKey',
53
- message: 'Do you want to go ahead and set up a Signing Key? This is used to create tokens for signed playback policies.',
54
- type: 'confirm',
55
- };
56
- if (process.env.MUX_SIGNING_KEY || process.env.MUX_PRIVATE_KEY) {
57
- signingKeyPrompt.message =
58
- 'Looks like you already have a signing key configured. Would you like to create a new one?';
59
- }
60
- prompts = [...prompts, signingKeyPrompt];
61
- const answers = await inquirer.prompt(prompts);
62
- let { createSigningKey, tokenId, tokenSecret } = answers;
63
- // If the token was loaded from an env file they'll already be set in the appropriate environment variables and
64
- // the prompts themselves will be null.
65
- this.muxConfig.configVersion = 1;
66
- this.muxConfig.tokenId = process.env.MUX_TOKEN_ID = tokenId || process.env.MUX_TOKEN_ID;
67
- this.muxConfig.tokenSecret = process.env.MUX_TOKEN_SECRET = tokenSecret || process.env.MUX_TOKEN_SECRET;
68
- if (createSigningKey) {
69
- const { Video } = new mux_node_1.default();
70
- try {
71
- // this is not great; we need to also update mux-node for this call
72
- // but that's a bigger can of worms. We'll come back to this one.
73
- // @ts-ignore
74
- const { id, private_key } = await Video.SigningKeys.create();
75
- this.muxConfig.signingKeyId = process.env.MUX_SIGNING_KEY = id;
76
- this.muxConfig.signingKeySecret = process.env.MUX_PRIVATE_KEY = private_key;
77
- }
78
- catch (_a) {
79
- this.error("Couldn't create a signing key pair! Are you sure your token credentials were right?");
80
- }
81
- }
82
- try {
83
- await fs.ensureDir(this.config.configDir);
84
- await fs.writeFile(this.configFile, JSON.stringify(this.muxConfig), 'utf8');
85
- }
86
- catch (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
- }
94
- }
95
- this.log(chalk `{bold.underline Configuration written to:} ${this.configFile}`);
96
- }
97
- }
98
- exports.default = Init;
99
- Init.description = 'set up a user-level config';
100
- Init.args = [
101
- {
102
- name: 'envFile',
103
- required: false,
104
- description: 'path to a Mux access token .env file',
105
- parse: (input) => path.resolve(input),
106
- },
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
- };
@@ -1,12 +0,0 @@
1
- import { IFlag } from '@oclif/command/lib/flags';
2
- import LiveCommandBase from '../../command-bases/live-base';
3
- export default class LiveComplete extends LiveCommandBase {
4
- static description: string;
5
- static args: {
6
- name: string;
7
- description: string;
8
- required: boolean;
9
- }[];
10
- static flags: Record<string, IFlag<any>>;
11
- run(): Promise<void>;
12
- }
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Listr = require("listr");
4
- const command_1 = require("@oclif/command");
5
- const live_base_1 = require("../../command-bases/live-base");
6
- const chalk = require("chalk");
7
- class LiveComplete extends live_base_1.default {
8
- async run() {
9
- const { args, flags } = this.parse(LiveComplete);
10
- const streamId = this.getStreamId(flags, args.streamName);
11
- try {
12
- await (new Listr([
13
- {
14
- title: `Signaling completion of '${streamId}'`,
15
- task: async (ctx, task) => {
16
- await this.Video.LiveStreams.signalComplete(streamId),
17
- task.title = `${task.title} (OK)`;
18
- },
19
- },
20
- {
21
- title: `Disabling '${streamId}'`,
22
- enabled: () => flags.disableAfterCompletion,
23
- task: async (ctx, task) => {
24
- await this.Video.LiveStreams.disable(streamId);
25
- task.title = `${task.title} (OK)`;
26
- },
27
- },
28
- ], {}).run());
29
- }
30
- catch (err) {
31
- // TODO: make this clearer
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
- }
41
- }
42
- }
43
- }
44
- exports.default = LiveComplete;
45
- LiveComplete.description = "Signal to Mux that a live stream has concluded and should be closed.";
46
- LiveComplete.args = [
47
- ...live_base_1.default.argsForSingleLiveStream,
48
- ];
49
- LiveComplete.flags = Object.assign(Object.assign({}, live_base_1.default.flagsForSingleLiveStream), { disableAfterCompletion: command_1.flags.boolean({
50
- name: 'disable-after-completion',
51
- char: 'd',
52
- description: 'If set, disables the stream upon completion.',
53
- default: false,
54
- }) });
@@ -1,13 +0,0 @@
1
- import LiveCommandBase from '../../command-bases/live-base';
2
- export default class LiveDisable extends LiveCommandBase {
3
- static description: string;
4
- static args: {
5
- name: string;
6
- description: string;
7
- required: boolean;
8
- }[];
9
- static flags: {
10
- [x: string]: import("@oclif/command/lib/flags").IFlag<any>;
11
- };
12
- run(): Promise<void>;
13
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Listr = require("listr");
4
- const live_base_1 = require("../../command-bases/live-base");
5
- const chalk = require("chalk");
6
- class LiveDisable extends live_base_1.default {
7
- async run() {
8
- const { args, flags } = this.parse(LiveDisable);
9
- const streamId = this.getStreamId(flags, args.streamName);
10
- try {
11
- await (new Listr([
12
- {
13
- title: `Disabling '${streamId}'`,
14
- task: async (ctx, task) => {
15
- await this.Video.LiveStreams.disable(streamId);
16
- task.title = `${task.title} (OK)`;
17
- },
18
- },
19
- ], {}).run());
20
- }
21
- catch (err) {
22
- // TODO: make this clearer
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
- }
32
- }
33
- }
34
- }
35
- exports.default = LiveDisable;
36
- LiveDisable.description = "Disables a live stream and prevents encoders from streaming to it.";
37
- LiveDisable.args = [
38
- ...live_base_1.default.argsForSingleLiveStream,
39
- ];
40
- LiveDisable.flags = Object.assign({}, live_base_1.default.flagsForSingleLiveStream);
@@ -1,13 +0,0 @@
1
- import LiveCommandBase from '../../command-bases/live-base';
2
- export default class LiveEnable extends LiveCommandBase {
3
- static description: string;
4
- static args: {
5
- name: string;
6
- description: string;
7
- required: boolean;
8
- }[];
9
- static flags: {
10
- [x: string]: import("@oclif/command/lib/flags").IFlag<any>;
11
- };
12
- run(): Promise<void>;
13
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const Listr = require("listr");
4
- const live_base_1 = require("../../command-bases/live-base");
5
- const chalk = require("chalk");
6
- class LiveEnable extends live_base_1.default {
7
- async run() {
8
- const { args, flags } = this.parse(LiveEnable);
9
- const streamId = this.getStreamId(flags, args.streamName);
10
- try {
11
- await (new Listr([
12
- {
13
- title: `Enabling '${streamId}'`,
14
- task: async (ctx, task) => {
15
- await this.Video.LiveStreams.enable(streamId);
16
- task.title = `${task.title} (OK)`;
17
- },
18
- },
19
- ], {}).run());
20
- }
21
- catch (err) {
22
- // TODO: make this clearer
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
- }
32
- }
33
- }
34
- }
35
- exports.default = LiveEnable;
36
- LiveEnable.description = "Enables a live stream, allowing encoders to streaming to it.";
37
- LiveEnable.args = [
38
- ...live_base_1.default.argsForSingleLiveStream,
39
- ];
40
- LiveEnable.flags = Object.assign({}, live_base_1.default.flagsForSingleLiveStream);
@@ -1,15 +0,0 @@
1
- import { flags } from '@oclif/command';
2
- import MuxBase from '../command-bases/base';
3
- export default class Sign extends MuxBase {
4
- static description: string;
5
- static args: {
6
- name: string;
7
- description: string;
8
- required: boolean;
9
- }[];
10
- static flags: {
11
- expiresIn: flags.IOptionFlag<string>;
12
- type: flags.IOptionFlag<string>;
13
- };
14
- run(): Promise<void>;
15
- }
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- const chalk = require("chalk");
5
- const clipboard = require("clipboardy");
6
- const base_1 = require("../command-bases/base");
7
- class Sign extends base_1.default {
8
- async run() {
9
- const { args, flags } = this.parse(Sign);
10
- const playbackId = args['playback-id'];
11
- const options = { expiration: flags.expiresIn, type: flags.type };
12
- const key = this.JWT.sign(playbackId, options);
13
- const url = `https://stream.mux.com/${playbackId}.m3u8?token=${key}`;
14
- this.log(chalk `
15
- 🔑 {bold.underline Your Mux Signed Token}
16
- {blue ${key}}
17
-
18
- 🌏 {bold.underline Full URL}
19
- {green ${url}}
20
- `);
21
- try {
22
- await clipboard.write(url);
23
- this.log(`👉 Copied Full URL to your system clipboard`);
24
- }
25
- catch (_a) {
26
- this.error('Unable to copy full url automatically');
27
- }
28
- }
29
- }
30
- exports.default = Sign;
31
- Sign.description = 'Creates a new signed URL token for a playback ID';
32
- Sign.args = [
33
- {
34
- name: 'playback-id',
35
- description: 'Playback ID to create a signed URL token for.',
36
- required: true,
37
- },
38
- ];
39
- Sign.flags = {
40
- expiresIn: command_1.flags.string({
41
- char: 'e',
42
- description: 'How long the signature is valid for. If no unit is specified, milliseconds is assumed.',
43
- default: '7d',
44
- }),
45
- type: command_1.flags.string({
46
- char: 't',
47
- description: 'What type of token this signature is for.',
48
- default: 'video',
49
- options: ['video', 'thumbnail', 'gif', 'storyboard'],
50
- })
51
- };
package/lib/config.d.ts DELETED
@@ -1,10 +0,0 @@
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 DELETED
@@ -1,12 +0,0 @@
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
- });
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { run } from '@oclif/command';
2
- export { default as CommandBase } from './command-bases/base';
package/lib/index.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandBase = exports.run = void 0;
4
- var command_1 = require("@oclif/command");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
6
- var base_1 = require("./command-bases/base");
7
- Object.defineProperty(exports, "CommandBase", { enumerable: true, get: function () { return base_1.default; } });
@@ -1 +0,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}]}}}
@@ -1,52 +0,0 @@
1
- import { Asset } from '@mux/mux-node';
2
- import { flags } from '@oclif/command';
3
- import * as Parser from '@oclif/parser';
4
- import CommandBase from './base';
5
-
6
- export type AssetBaseFlags = {
7
- private: Parser.flags.IBooleanFlag<boolean>;
8
- };
9
-
10
- export default abstract class AssetCommandBase extends CommandBase {
11
- static flags: AssetBaseFlags = {
12
- private: flags.boolean({
13
- char: 'p',
14
- description: 'add a private playback policy to the created asset',
15
- }),
16
- };
17
-
18
- playbackUrl(asset: Asset) {
19
- const publicPlaybackId = (asset.playback_ids ?? []).find(
20
- p => p.policy === 'public'
21
- );
22
- if (!publicPlaybackId) {
23
- return 'No public playback policies found!';
24
- }
25
-
26
- return `https://mux-playground.now.sh/videojs?playback_id=${
27
- publicPlaybackId.id
28
- }`;
29
- }
30
-
31
- pollAsset(assetId: string): Promise<Asset> {
32
- return new Promise((resolve, reject) => {
33
- const poll = () =>
34
- setTimeout(async () => {
35
- try {
36
- const asset = await this.Video.Assets.get(assetId);
37
- if (asset.status === 'ready') {
38
- return resolve(asset);
39
- } else if (asset.status === 'errored') {
40
- return reject(asset);
41
- }
42
-
43
- poll();
44
- } catch (err) {
45
- reject(err);
46
- }
47
- }, 500);
48
-
49
- poll();
50
- });
51
- }
52
- }
@@ -1,71 +0,0 @@
1
- import Mux, { Video as MuxVideo, Data as MuxData } from '@mux/mux-node';
2
- import Command from '@oclif/command';
3
- import * as chalk from 'chalk';
4
- import * as fs from 'fs-extra';
5
- import * as path from 'path';
6
-
7
- import { MuxCliConfigV1 } from '../config';
8
-
9
- export const MUX_API_BASE_URL = "https://api.mux.com";
10
-
11
- export default abstract class CommandBase extends Command {
12
- configFile = path.join(this.config.configDir, 'config.json');
13
-
14
- MuxConfig!: MuxCliConfigV1;
15
- Mux!: Mux;
16
- Video!: MuxVideo;
17
- Data!: MuxData;
18
- JWT: any;
19
-
20
- async readConfigV1(): Promise<MuxCliConfigV1 | null> {
21
- const configAlreadyExists = await fs.pathExists(this.configFile);
22
- try {
23
- const configRaw =
24
- configAlreadyExists
25
- ? await fs.readJSON(this.configFile)
26
- : {};
27
-
28
- // Mux SDK configuration options
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;
33
-
34
- // Mux CLI specific configuration options
35
- configRaw.configVersion = configRaw.configVersion ?? 1;
36
- configRaw.baseUrl = process.env.MUX_CLI_BASE_URL ?? configRaw.baseUrl ?? MUX_API_BASE_URL;
37
- return MuxCliConfigV1.check(configRaw);
38
- } catch (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
- );
52
- }
53
-
54
- process.exit(1);
55
- }
56
- }
57
-
58
- async init() {
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;
70
- }
71
- }
@@ -1,35 +0,0 @@
1
- import { flags } from '@oclif/command';
2
- import { IFlag } from '@oclif/command/lib/flags';
3
-
4
- import CommandBase from './base';
5
-
6
- export default abstract class LiveCommandBase extends CommandBase {
7
- static argsForSingleLiveStream = [
8
- {
9
- name: 'streamName',
10
- description:
11
- "the name (coupled with --reference-type) to look up in Mux to yield this livestream",
12
- required: true,
13
- },
14
- ];
15
-
16
- static flagsForSingleLiveStream: Record<string, IFlag<any>> = {
17
- streamId: flags.string({
18
- name: 'reference-type',
19
- char: 't',
20
- description: 'the type of the provided reference name',
21
- options: ['stream-id'],
22
- default: 'stream-id',
23
- }),
24
- }
25
-
26
- protected getStreamId(flags: Record<string, any>, streamName: string): string {
27
- switch (flags.streamId) {
28
- case 'stream-id':
29
- // just a pass-through
30
- return streamName;
31
- }
32
-
33
- throw new Error("Could not derive a stream ID. Please pass one with --stream-id.");
34
- }
35
- }
@@ -1,74 +0,0 @@
1
- import * as chalk from 'chalk';
2
- import * as clipboard from 'clipboardy';
3
- import * as Listr from 'listr';
4
-
5
- import AssetCommandBase from '../../command-bases/asset-base';
6
-
7
- export default class AssetsCreate extends AssetCommandBase {
8
- static description =
9
- "Create a new asset in Mux using a file that's already available online";
10
-
11
- static args = [
12
- {
13
- name: 'input',
14
- description:
15
- "input URL for the file you'd like to create this asset from",
16
- required: true,
17
- },
18
- ];
19
-
20
- async run() {
21
- const { args, flags } = this.parse(AssetsCreate);
22
- let assetBodyParams = {
23
- input: args.input,
24
- playback_policies: flags.private ? ['signed'] : ['public'],
25
- };
26
-
27
- const tasks = new Listr([
28
- {
29
- title: 'Creating Mux Asset',
30
- task: async ctx => {
31
- const asset = await this.Video.Assets.create(assetBodyParams);
32
- ctx.asset = asset;
33
- },
34
- },
35
- {
36
- title: 'Waiting for asset to be playable',
37
- task: async ctx => {
38
- const asset = await this.pollAsset(ctx.asset.id);
39
- ctx.asset = asset;
40
- },
41
- },
42
- ]);
43
-
44
- try {
45
- const ctx = await tasks.run();
46
- const playbackUrl = this.playbackUrl(ctx.asset);
47
-
48
- if (!process.env.WSL_DISTRO_NAME) {
49
- await clipboard.write(playbackUrl);
50
- }
51
-
52
- this.log(
53
- chalk`
54
- 💫 {bold.blue Asset ready for your enjoyment!}
55
-
56
- {bold.underline Playback URL}
57
- ${playbackUrl}
58
- `
59
- );
60
- } catch (err) {
61
- console.log(
62
- chalk.redBright('Error:') +
63
- "\n\n" +
64
- err
65
- );
66
-
67
- if (err instanceof Error) {
68
- this.error(err);
69
- } else {
70
- throw err;
71
- }
72
- }
73
- }
74
- }