@mux/cli 0.8.0 → 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.
- package/LICENSE +13 -0
- package/README.md +1216 -259
- package/bin/mux +31 -0
- package/package.json +64 -103
- package/bin/run +0 -6
- package/bin/run.cmd +0 -3
- package/lib/command-bases/asset-base.d.ts +0 -11
- package/lib/command-bases/asset-base.js +0 -41
- package/lib/command-bases/base.d.ts +0 -14
- package/lib/command-bases/base.js +0 -62
- package/lib/command-bases/live-base.d.ts +0 -11
- package/lib/command-bases/live-base.js +0 -31
- package/lib/commands/assets/create.d.ts +0 -10
- package/lib/commands/assets/create.js +0 -64
- package/lib/commands/assets/upload.d.ts +0 -20
- package/lib/commands/assets/upload.js +0 -148
- package/lib/commands/init.d.ts +0 -20
- package/lib/commands/init.js +0 -115
- package/lib/commands/live/complete.d.ts +0 -12
- package/lib/commands/live/complete.js +0 -54
- package/lib/commands/live/disable.d.ts +0 -13
- package/lib/commands/live/disable.js +0 -40
- package/lib/commands/live/enable.d.ts +0 -13
- package/lib/commands/live/enable.js +0 -40
- package/lib/commands/sign.d.ts +0 -11
- package/lib/commands/sign.js +0 -68
- package/lib/commands/spaces/sign.d.ts +0 -11
- package/lib/commands/spaces/sign.js +0 -79
- package/lib/config.d.ts +0 -10
- package/lib/config.js +0 -12
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -7
- package/oclif.manifest.json +0 -1
- package/src/command-bases/asset-base.ts +0 -52
- package/src/command-bases/base.ts +0 -72
- package/src/command-bases/live-base.ts +0 -35
- package/src/commands/assets/create.ts +0 -74
- package/src/commands/assets/upload.ts +0 -192
- package/src/commands/init.ts +0 -150
- package/src/commands/live/complete.ts +0 -63
- package/src/commands/live/disable.ts +0 -47
- package/src/commands/live/enable.ts +0 -47
- package/src/commands/sign.ts +0 -76
- package/src/commands/spaces/sign.ts +0 -90
- package/src/config.ts +0 -13
- package/src/index.ts +0 -3
- package/yarn.lock +0 -7350
package/bin/mux
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { platform, arch, env } = process;
|
|
3
|
+
|
|
4
|
+
const PLATFORMS = {
|
|
5
|
+
darwin: {
|
|
6
|
+
x64: "@mux/cli-darwin-x64/mux",
|
|
7
|
+
arm64: "@mux/cli-darwin-arm64/mux",
|
|
8
|
+
},
|
|
9
|
+
linux: {
|
|
10
|
+
x64: "@mux/cli-linux-x64/mux",
|
|
11
|
+
arm64: "@mux/cli-linux-arm64/mux",
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const binPath = env.MUX_BINARY || PLATFORMS?.[platform]?.[arch];
|
|
16
|
+
|
|
17
|
+
if (binPath) {
|
|
18
|
+
const result = require("child_process").spawnSync(
|
|
19
|
+
require.resolve(binPath),
|
|
20
|
+
process.argv.slice(2),
|
|
21
|
+
{ shell: false, stdio: "inherit" },
|
|
22
|
+
);
|
|
23
|
+
if (result.error) throw result.error;
|
|
24
|
+
process.exitCode = result.status;
|
|
25
|
+
} else {
|
|
26
|
+
console.error(
|
|
27
|
+
`The Mux CLI doesn't ship prebuilt binaries for your platform (${platform}/${arch}) yet.\n` +
|
|
28
|
+
"You can build from source: https://github.com/muxinc/cli"
|
|
29
|
+
);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,116 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mux/cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"author":
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "Official Mux CLI for interacting with Mux APIs",
|
|
5
|
+
"author": "Mux",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"homepage": "https://github.com/muxinc/cli#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/muxinc/cli.git"
|
|
9
12
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"Ed Ropple <ed@mux.com>"
|
|
13
|
-
],
|
|
14
|
-
"bin": {
|
|
15
|
-
"mux": "./bin/run"
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/muxinc/cli/issues"
|
|
16
15
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"
|
|
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
|
-
"clipboardy": "^2.3.0",
|
|
31
|
-
"dotenv": "^8.2.0",
|
|
32
|
-
"fs-extra": "^10.0.0",
|
|
33
|
-
"inquirer": "^8.2.0",
|
|
34
|
-
"jsonwebtoken": "^8.5.1",
|
|
35
|
-
"listr": "^0.14.3",
|
|
36
|
-
"request": "^2.88.2",
|
|
37
|
-
"runtypes": "^6.5.0",
|
|
38
|
-
"rxjs": "^7.5.2"
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
19
|
},
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"globby": "11.0.4",
|
|
54
|
-
"mocha": "6.2.3",
|
|
55
|
-
"nyc": "^15.1.0",
|
|
56
|
-
"oclif": "^2.4.0",
|
|
57
|
-
"ts-node": "^10.4.0",
|
|
58
|
-
"tslint": "^6.1.3",
|
|
59
|
-
"tslint-config-prettier": "^1.18.0",
|
|
60
|
-
"typescript": "^4.5.5"
|
|
61
|
-
},
|
|
62
|
-
"engines": {
|
|
63
|
-
"node": ">=14.0.0"
|
|
20
|
+
"keywords": [
|
|
21
|
+
"mux",
|
|
22
|
+
"video",
|
|
23
|
+
"cli",
|
|
24
|
+
"streaming",
|
|
25
|
+
"live",
|
|
26
|
+
"assets",
|
|
27
|
+
"playback",
|
|
28
|
+
"signing",
|
|
29
|
+
"typescript"
|
|
30
|
+
],
|
|
31
|
+
"bin": {
|
|
32
|
+
"mux": "bin/mux"
|
|
64
33
|
},
|
|
65
34
|
"files": [
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"/yarn.lock",
|
|
70
|
-
"/oclif.manifest.json"
|
|
71
|
-
],
|
|
72
|
-
"homepage": "https://github.com/muxinc/cli",
|
|
73
|
-
"keywords": [
|
|
74
|
-
"oclif"
|
|
35
|
+
"bin",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
75
38
|
],
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"plugins": [
|
|
82
|
-
"@oclif/plugin-help",
|
|
83
|
-
"@oclif/plugin-not-found",
|
|
84
|
-
"@oclif/plugin-autocomplete",
|
|
85
|
-
"@oclif/plugin-commands",
|
|
86
|
-
"@oclif/plugin-update",
|
|
87
|
-
"@oclif/plugin-warn-if-update-available",
|
|
88
|
-
"@oclif/plugin-plugins"
|
|
89
|
-
],
|
|
90
|
-
"macos": {
|
|
91
|
-
"identifier": "com.mux.cli"
|
|
92
|
-
},
|
|
93
|
-
"topics": {
|
|
94
|
-
"assets": {
|
|
95
|
-
"description": "tools for managing Mux assets"
|
|
96
|
-
},
|
|
97
|
-
"live": {
|
|
98
|
-
"description": "tools for managing Mux live streams"
|
|
99
|
-
}
|
|
100
|
-
}
|
|
39
|
+
"optionalDependencies": {
|
|
40
|
+
"@mux/cli-darwin-arm64": "1.0.0-beta.1",
|
|
41
|
+
"@mux/cli-darwin-x64": "1.0.0-beta.1",
|
|
42
|
+
"@mux/cli-linux-x64": "1.0.0-beta.1",
|
|
43
|
+
"@mux/cli-linux-arm64": "1.0.0-beta.1"
|
|
101
44
|
},
|
|
102
|
-
"repository": "muxinc/cli",
|
|
103
45
|
"scripts": {
|
|
104
|
-
"
|
|
105
|
-
"build": "
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
46
|
+
"build": "bun build src/index.ts --outdir ./dist --target bun --format esm",
|
|
47
|
+
"build:binary": "bun build --compile --minify --sourcemap ./src/index.ts --outfile ./dist/mux",
|
|
48
|
+
"dev": "bun run src/index.ts",
|
|
49
|
+
"format": "pnpm exec biome format --write",
|
|
50
|
+
"lint": "pnpm exec biome format",
|
|
51
|
+
"check": "pnpm exec biome check",
|
|
52
|
+
"check:write": "pnpm exec biome check --write",
|
|
53
|
+
"typecheck": "bun --bun tsc --noEmit",
|
|
54
|
+
"test": "bun test",
|
|
55
|
+
"test:watch": "bun test --watch"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@cliffy/ansi": "jsr:1.0.0-rc.8",
|
|
59
|
+
"@cliffy/command": "jsr:1.0.0-rc.8",
|
|
60
|
+
"@cliffy/prompt": "npm:@jsr/cliffy__prompt@1.0.0-rc.8",
|
|
61
|
+
"@mux/mux-node": "^12.8.1",
|
|
62
|
+
"@opentui/core": "^0.1.50",
|
|
63
|
+
"@opentui/react": "^0.1.50",
|
|
64
|
+
"@std/path": "npm:@jsr/std__path@^1.1.3",
|
|
65
|
+
"glob": "^13.0.0",
|
|
66
|
+
"react": "^19.2.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@biomejs/biome": "2.3.7",
|
|
70
|
+
"@types/bun": "latest",
|
|
71
|
+
"@types/react": "^19.2.7",
|
|
72
|
+
"typescript": "^5.0.0"
|
|
111
73
|
},
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
"node": "14.16.1"
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"typescript": "^5.0.0"
|
|
115
76
|
}
|
|
116
77
|
}
|
package/bin/run
DELETED
package/bin/run.cmd
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Asset } from '@mux/mux-node';
|
|
2
|
-
import * as Parser from '@oclif/parser';
|
|
3
|
-
import CommandBase from './base';
|
|
4
|
-
export declare type AssetBaseFlags = {
|
|
5
|
-
private: Parser.flags.IBooleanFlag<boolean>;
|
|
6
|
-
};
|
|
7
|
-
export default abstract class AssetCommandBase extends CommandBase {
|
|
8
|
-
static flags: AssetBaseFlags;
|
|
9
|
-
playbackUrl(asset: Asset): string;
|
|
10
|
-
pollAsset(assetId: string): Promise<Asset>;
|
|
11
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const base_1 = require("./base");
|
|
5
|
-
class AssetCommandBase extends base_1.default {
|
|
6
|
-
playbackUrl(asset) {
|
|
7
|
-
var _a;
|
|
8
|
-
const publicPlaybackId = ((_a = asset.playback_ids) !== null && _a !== void 0 ? _a : []).find(p => p.policy === 'public');
|
|
9
|
-
if (!publicPlaybackId) {
|
|
10
|
-
return 'No public playback policies found!';
|
|
11
|
-
}
|
|
12
|
-
return `https://mux-playground.now.sh/videojs?playback_id=${publicPlaybackId.id}`;
|
|
13
|
-
}
|
|
14
|
-
pollAsset(assetId) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const poll = () => setTimeout(async () => {
|
|
17
|
-
try {
|
|
18
|
-
const asset = await this.Video.Assets.get(assetId);
|
|
19
|
-
if (asset.status === 'ready') {
|
|
20
|
-
return resolve(asset);
|
|
21
|
-
}
|
|
22
|
-
else if (asset.status === 'errored') {
|
|
23
|
-
return reject(asset);
|
|
24
|
-
}
|
|
25
|
-
poll();
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
reject(err);
|
|
29
|
-
}
|
|
30
|
-
}, 500);
|
|
31
|
-
poll();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.default = AssetCommandBase;
|
|
36
|
-
AssetCommandBase.flags = {
|
|
37
|
-
private: command_1.flags.boolean({
|
|
38
|
-
char: 'p',
|
|
39
|
-
description: 'add a private playback policy to the created asset',
|
|
40
|
-
}),
|
|
41
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Mux, { Video as MuxVideo, Data as MuxData, JWT as MuxJWT } from '@mux/mux-node';
|
|
2
|
-
import Command from '@oclif/command';
|
|
3
|
-
import { MuxCliConfigV1 } from '../config';
|
|
4
|
-
export declare const MUX_API_BASE_URL = "https://api.mux.com";
|
|
5
|
-
export default abstract class CommandBase extends Command {
|
|
6
|
-
configFile: string;
|
|
7
|
-
MuxConfig: MuxCliConfigV1;
|
|
8
|
-
Mux: Mux;
|
|
9
|
-
Video: MuxVideo;
|
|
10
|
-
Data: MuxData;
|
|
11
|
-
JWT: typeof MuxJWT;
|
|
12
|
-
readConfigV1(): Promise<MuxCliConfigV1>;
|
|
13
|
-
init(): Promise<void>;
|
|
14
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MUX_API_BASE_URL = void 0;
|
|
4
|
-
const mux_node_1 = require("@mux/mux-node");
|
|
5
|
-
const command_1 = require("@oclif/command");
|
|
6
|
-
const chalk = require("chalk");
|
|
7
|
-
const fs = require("fs-extra");
|
|
8
|
-
const path = require("path");
|
|
9
|
-
const config_1 = require("../config");
|
|
10
|
-
exports.MUX_API_BASE_URL = "https://api.mux.com";
|
|
11
|
-
class CommandBase extends command_1.default {
|
|
12
|
-
constructor() {
|
|
13
|
-
super(...arguments);
|
|
14
|
-
this.configFile = path.join(this.config.configDir, 'config.json');
|
|
15
|
-
}
|
|
16
|
-
async readConfigV1() {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
|
-
const configAlreadyExists = await fs.pathExists(this.configFile);
|
|
19
|
-
try {
|
|
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);
|
|
32
|
-
}
|
|
33
|
-
catch (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.`);
|
|
39
|
-
}
|
|
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);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async init() {
|
|
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.MuxConfig = config;
|
|
57
|
-
this.Video = this.Mux.Video;
|
|
58
|
-
this.Data = this.Mux.Data;
|
|
59
|
-
this.JWT = mux_node_1.default.JWT;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.default = CommandBase;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IFlag } from '@oclif/command/lib/flags';
|
|
2
|
-
import CommandBase from './base';
|
|
3
|
-
export default abstract class LiveCommandBase extends CommandBase {
|
|
4
|
-
static argsForSingleLiveStream: {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
required: boolean;
|
|
8
|
-
}[];
|
|
9
|
-
static flagsForSingleLiveStream: Record<string, IFlag<any>>;
|
|
10
|
-
protected getStreamId(flags: Record<string, any>, streamName: string): string;
|
|
11
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
|
-
const base_1 = require("./base");
|
|
5
|
-
class LiveCommandBase extends base_1.default {
|
|
6
|
-
getStreamId(flags, streamName) {
|
|
7
|
-
switch (flags.streamId) {
|
|
8
|
-
case 'stream-id':
|
|
9
|
-
// just a pass-through
|
|
10
|
-
return streamName;
|
|
11
|
-
}
|
|
12
|
-
throw new Error("Could not derive a stream ID. Please pass one with --stream-id.");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.default = LiveCommandBase;
|
|
16
|
-
LiveCommandBase.argsForSingleLiveStream = [
|
|
17
|
-
{
|
|
18
|
-
name: 'streamName',
|
|
19
|
-
description: "the name (coupled with --reference-type) to look up in Mux to yield this livestream",
|
|
20
|
-
required: true,
|
|
21
|
-
},
|
|
22
|
-
];
|
|
23
|
-
LiveCommandBase.flagsForSingleLiveStream = {
|
|
24
|
-
streamId: command_1.flags.string({
|
|
25
|
-
name: 'reference-type',
|
|
26
|
-
char: 't',
|
|
27
|
-
description: 'the type of the provided reference name',
|
|
28
|
-
options: ['stream-id'],
|
|
29
|
-
default: 'stream-id',
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import AssetCommandBase from '../../command-bases/asset-base';
|
|
2
|
-
export default class AssetsCreate extends AssetCommandBase {
|
|
3
|
-
static description: string;
|
|
4
|
-
static args: {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
required: boolean;
|
|
8
|
-
}[];
|
|
9
|
-
run(): Promise<void>;
|
|
10
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chalk = require("chalk");
|
|
4
|
-
const clipboard = require("clipboardy");
|
|
5
|
-
const Listr = require("listr");
|
|
6
|
-
const asset_base_1 = require("../../command-bases/asset-base");
|
|
7
|
-
class AssetsCreate extends asset_base_1.default {
|
|
8
|
-
async run() {
|
|
9
|
-
const { args, flags } = this.parse(AssetsCreate);
|
|
10
|
-
let assetBodyParams = {
|
|
11
|
-
input: args.input,
|
|
12
|
-
playback_policies: flags.private ? ['signed'] : ['public'],
|
|
13
|
-
};
|
|
14
|
-
const tasks = new Listr([
|
|
15
|
-
{
|
|
16
|
-
title: 'Creating Mux Asset',
|
|
17
|
-
task: async (ctx) => {
|
|
18
|
-
const asset = await this.Video.Assets.create(assetBodyParams);
|
|
19
|
-
ctx.asset = asset;
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
title: 'Waiting for asset to be playable',
|
|
24
|
-
task: async (ctx) => {
|
|
25
|
-
const asset = await this.pollAsset(ctx.asset.id);
|
|
26
|
-
ctx.asset = asset;
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
try {
|
|
31
|
-
const ctx = await tasks.run();
|
|
32
|
-
const playbackUrl = this.playbackUrl(ctx.asset);
|
|
33
|
-
if (!process.env.WSL_DISTRO_NAME) {
|
|
34
|
-
await clipboard.write(playbackUrl);
|
|
35
|
-
}
|
|
36
|
-
this.log(chalk `
|
|
37
|
-
💫 {bold.blue Asset ready for your enjoyment!}
|
|
38
|
-
|
|
39
|
-
{bold.underline Playback URL}
|
|
40
|
-
${playbackUrl}
|
|
41
|
-
`);
|
|
42
|
-
}
|
|
43
|
-
catch (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
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.default = AssetsCreate;
|
|
57
|
-
AssetsCreate.description = "Create a new asset in Mux using a file that's already available online";
|
|
58
|
-
AssetsCreate.args = [
|
|
59
|
-
{
|
|
60
|
-
name: 'input',
|
|
61
|
-
description: "input URL for the file you'd like to create this asset from",
|
|
62
|
-
required: true,
|
|
63
|
-
},
|
|
64
|
-
];
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Upload } from '@mux/mux-node';
|
|
2
|
-
import { flags } from '@oclif/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 {
|
|
9
|
-
static description: string;
|
|
10
|
-
static args: {
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
required: boolean;
|
|
14
|
-
}[];
|
|
15
|
-
static flags: AssetCreateFlags;
|
|
16
|
-
getFilePaths(filePath: string, filter?: string): string[];
|
|
17
|
-
uploadFile(filePath: string, url: string): Promise<unknown>;
|
|
18
|
-
pollUpload(uploadId: string): Promise<Upload>;
|
|
19
|
-
run(): Promise<void>;
|
|
20
|
-
}
|
|
@@ -1,148 +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 fs = require("fs-extra");
|
|
7
|
-
const inquirer = require("inquirer");
|
|
8
|
-
const Listr = require("listr");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const request = require("request");
|
|
11
|
-
const asset_base_1 = require("../../command-bases/asset-base");
|
|
12
|
-
class AssetsCreate extends asset_base_1.default {
|
|
13
|
-
getFilePaths(filePath, filter = '') {
|
|
14
|
-
if (fs.lstatSync(filePath).isDirectory()) {
|
|
15
|
-
return fs.readdirSync(filePath).filter(file => file.match(filter));
|
|
16
|
-
}
|
|
17
|
-
return [filePath];
|
|
18
|
-
}
|
|
19
|
-
uploadFile(filePath, url) {
|
|
20
|
-
return new Promise((resolve, reject) => {
|
|
21
|
-
fs.createReadStream(path.resolve(process.cwd(), filePath)).pipe(request
|
|
22
|
-
.put(url)
|
|
23
|
-
.on('response', resolve)
|
|
24
|
-
.on('error', reject));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
pollUpload(uploadId) {
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
const poll = () => setTimeout(async () => {
|
|
30
|
-
try {
|
|
31
|
-
const upload = await this.Video.Uploads.get(uploadId);
|
|
32
|
-
if (upload.status === 'asset_created') {
|
|
33
|
-
return resolve(upload);
|
|
34
|
-
}
|
|
35
|
-
else if (upload.status === 'errored') {
|
|
36
|
-
return reject(upload);
|
|
37
|
-
}
|
|
38
|
-
poll();
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
reject(err);
|
|
42
|
-
}
|
|
43
|
-
}, 500);
|
|
44
|
-
poll();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
async run() {
|
|
48
|
-
const { args, flags } = this.parse(AssetsCreate);
|
|
49
|
-
let assetBodyParams = {
|
|
50
|
-
new_asset_settings: {
|
|
51
|
-
playback_policy: flags.private ? ['signed'] : ['public'],
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
const regex = new RegExp(flags.filter || '', 'ig');
|
|
55
|
-
const files = this.getFilePaths(path.resolve(process.cwd(), args.path)).filter(file => file.match(regex));
|
|
56
|
-
let prompt = { files };
|
|
57
|
-
if (files.length === 0) {
|
|
58
|
-
return this.log(`We were unable to find any files. You might want to double check your path or make sure your filter isn't too strict`);
|
|
59
|
-
}
|
|
60
|
-
else if (files.length > 1) {
|
|
61
|
-
prompt = await inquirer.prompt([
|
|
62
|
-
{
|
|
63
|
-
type: 'checkbox',
|
|
64
|
-
name: 'files',
|
|
65
|
-
message: 'We found a few files! Do all of these look good?',
|
|
66
|
-
choices: files,
|
|
67
|
-
default: files,
|
|
68
|
-
},
|
|
69
|
-
]);
|
|
70
|
-
}
|
|
71
|
-
const tasks = prompt.files.map((file) => ({
|
|
72
|
-
title: `${file}: getting direct upload URL`,
|
|
73
|
-
task: async (ctx, task) => {
|
|
74
|
-
const upload = await this.Video.Uploads.create(assetBodyParams);
|
|
75
|
-
task.title = `${file}: uploading`;
|
|
76
|
-
await this.uploadFile(path.resolve(process.cwd(), args.path, file), upload.url);
|
|
77
|
-
task.title = `${file}: waiting for asset to be playable`;
|
|
78
|
-
const { asset_id: assetId } = await this.pollUpload(upload.id);
|
|
79
|
-
if (!assetId) {
|
|
80
|
-
throw new Error(`Asset for upload '${upload.id}' failed to resolve.`);
|
|
81
|
-
}
|
|
82
|
-
const asset = await this.pollAsset(assetId);
|
|
83
|
-
const playbackUrl = this.playbackUrl(asset);
|
|
84
|
-
task.title = `${file}: ${playbackUrl}`;
|
|
85
|
-
ctx.assets = [
|
|
86
|
-
...(ctx.assets || [['Filename', 'Asset ID', 'PlaybackURL']]),
|
|
87
|
-
[file, asset.id, playbackUrl],
|
|
88
|
-
];
|
|
89
|
-
},
|
|
90
|
-
}));
|
|
91
|
-
// I hate this `any` here, but I'm running into a weird issue casting
|
|
92
|
-
// the `tasks` above to an array of `ListrTasks[]`.
|
|
93
|
-
try {
|
|
94
|
-
const finalCtx = await new Listr(tasks, {
|
|
95
|
-
concurrent: flags.concurrent,
|
|
96
|
-
}).run();
|
|
97
|
-
const tsv = finalCtx.assets
|
|
98
|
-
.map((row) => row.join('\t'))
|
|
99
|
-
.join('\n');
|
|
100
|
-
if (prompt.files.length > 1 && !process.env.WSL_DISTRO_NAME) {
|
|
101
|
-
await clipboard.write(tsv);
|
|
102
|
-
return this.log(chalk `
|
|
103
|
-
📹 {bold.underline Assets ready for your enjoyment:}
|
|
104
|
-
${tsv}
|
|
105
|
-
|
|
106
|
-
{blue (copied to your clipboard)}`);
|
|
107
|
-
}
|
|
108
|
-
await clipboard.write(finalCtx.assets[1][2]);
|
|
109
|
-
return this.log(chalk `
|
|
110
|
-
📹 {bold.underline Asset ready for your enjoyment:}
|
|
111
|
-
${tsv}
|
|
112
|
-
|
|
113
|
-
{blue (since you only uploaded one asset, we just added the playback URL to your clipboard.)}`);
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
// TODO: make this clearer / separate it out per video for more obvious debugging.
|
|
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
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.default = AssetsCreate;
|
|
130
|
-
AssetsCreate.description = 'Create a new asset in Mux via a local file';
|
|
131
|
-
AssetsCreate.args = [
|
|
132
|
-
{
|
|
133
|
-
name: 'path',
|
|
134
|
-
description: "local path for the file (or folder) you'd like to upload",
|
|
135
|
-
required: true,
|
|
136
|
-
},
|
|
137
|
-
];
|
|
138
|
-
AssetsCreate.flags = Object.assign(Object.assign({}, asset_base_1.default.flags), { filter: command_1.flags.string({
|
|
139
|
-
char: 'f',
|
|
140
|
-
description: 'regex that filters the selected destination if the provided path is a folder',
|
|
141
|
-
}), concurrent: command_1.flags.integer({
|
|
142
|
-
char: 'c',
|
|
143
|
-
description: 'max number of files to upload at once',
|
|
144
|
-
default: 3,
|
|
145
|
-
}), private: command_1.flags.boolean({
|
|
146
|
-
char: 'p',
|
|
147
|
-
default: false,
|
|
148
|
-
}) });
|
package/lib/commands/init.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as Parser from '@oclif/parser';
|
|
2
|
-
import MuxBase from '../command-bases/base';
|
|
3
|
-
import { MuxCliConfigV1 } from '../config';
|
|
4
|
-
export declare type InitFlags = {
|
|
5
|
-
force: Parser.flags.IBooleanFlag<boolean>;
|
|
6
|
-
};
|
|
7
|
-
export default class Init extends MuxBase {
|
|
8
|
-
static description: string;
|
|
9
|
-
static args: {
|
|
10
|
-
name: string;
|
|
11
|
-
required: boolean;
|
|
12
|
-
description: string;
|
|
13
|
-
parse: (input: string) => string;
|
|
14
|
-
}[];
|
|
15
|
-
static flags: InitFlags;
|
|
16
|
-
Video: any;
|
|
17
|
-
JWT: any;
|
|
18
|
-
muxConfig: Partial<MuxCliConfigV1>;
|
|
19
|
-
run(): Promise<void>;
|
|
20
|
-
}
|