@capawesome/cli 0.0.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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/commands/apps/bundles/create.js +104 -0
- package/dist/commands/apps/bundles/delete.js +79 -0
- package/dist/commands/apps/channels/create.js +71 -0
- package/dist/commands/apps/channels/delete.js +83 -0
- package/dist/commands/apps/create.js +55 -0
- package/dist/commands/apps/delete.js +65 -0
- package/dist/commands/apps/devices/delete.js +79 -0
- package/dist/commands/login.js +54 -0
- package/dist/commands/logout.js +31 -0
- package/dist/commands/whoami.js +32 -0
- package/dist/config/consts.js +5 -0
- package/dist/config/index.js +17 -0
- package/dist/index.js +50 -0
- package/dist/service/app-bundle.js +45 -0
- package/dist/service/app-channel.js +50 -0
- package/dist/service/app-device.js +35 -0
- package/dist/service/apps.js +61 -0
- package/dist/service/authorization-service.js +23 -0
- package/dist/types/app-bundle.js +2 -0
- package/dist/types/app-channel.js +2 -0
- package/dist/types/app-device.js +2 -0
- package/dist/types/app.js +2 -0
- package/dist/types/index.js +20 -0
- package/dist/utils/ci.js +7 -0
- package/dist/utils/http-client.js +77 -0
- package/dist/utils/prompt.js +43 -0
- package/dist/utils/userConfig.js +16 -0
- package/dist/utils/zip.js +35 -0
- package/package.json +61 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# cli
|
|
2
|
+
|
|
3
|
+
💻 The Capawesome Cloud Command Line Interface (CLI) can be used to manage [Live Updates](https://capawesome.io/cloud/) from the command line.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
The Capawesome Cloud CLI can be installed globally via npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @capawesome/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Help
|
|
14
|
+
|
|
15
|
+
The Capawesome Cloud CLI ships with command documentation that is accessible with the `--help` flag.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx capawesome --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Changelog
|
|
22
|
+
|
|
23
|
+
See [CHANGELOG](./CHANGELOG.md).
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
See [LICENSE](./LICENSE.md).
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const consola_1 = __importDefault(require("consola"));
|
|
17
|
+
const prompt_1 = require("../../../utils/prompt");
|
|
18
|
+
const axios_1 = require("axios");
|
|
19
|
+
const zip_1 = __importDefault(require("../../../utils/zip"));
|
|
20
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
21
|
+
const node_fs_1 = require("node:fs");
|
|
22
|
+
const authorization_service_1 = __importDefault(require("../../../service/authorization-service"));
|
|
23
|
+
const apps_1 = __importDefault(require("../../../service/apps"));
|
|
24
|
+
const app_bundle_1 = __importDefault(require("../../../service/app-bundle"));
|
|
25
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
26
|
+
meta: {
|
|
27
|
+
description: 'Create a new app bundle.',
|
|
28
|
+
},
|
|
29
|
+
args: {
|
|
30
|
+
path: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Path to the bundle to upload. Must be a folder or zip file',
|
|
33
|
+
},
|
|
34
|
+
appId: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
description: 'App ID to deploy to.',
|
|
37
|
+
},
|
|
38
|
+
channel: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
description: 'Channel to associate the bundle with.',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!authorization_service_1.default.hasAuthorizationToken()) {
|
|
46
|
+
consola_1.default.error('You must be logged in to run this command.');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let path = ctx.args.path;
|
|
50
|
+
let appId = ctx.args.appId;
|
|
51
|
+
let channelName = ctx.args.channel;
|
|
52
|
+
if (!path) {
|
|
53
|
+
path = yield (0, prompt_1.prompt)('Enter the path to the app bundle:', {
|
|
54
|
+
type: 'text',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (!appId) {
|
|
58
|
+
const apps = yield apps_1.default.findAll();
|
|
59
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
60
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to deploy to:', {
|
|
61
|
+
type: 'select',
|
|
62
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
63
|
+
});
|
|
64
|
+
if (!channelName) {
|
|
65
|
+
const promptChannel = yield (0, prompt_1.prompt)('Do you want to deploy to a specific channel?', {
|
|
66
|
+
type: 'select',
|
|
67
|
+
options: ['Yes', 'No'],
|
|
68
|
+
});
|
|
69
|
+
if (promptChannel === 'Yes') {
|
|
70
|
+
channelName = yield (0, prompt_1.prompt)('Enter the channel name:', {
|
|
71
|
+
type: 'text',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Create form data
|
|
77
|
+
const formData = new form_data_1.default();
|
|
78
|
+
if (zip_1.default.isZipped(path)) {
|
|
79
|
+
formData.append('file', (0, node_fs_1.createReadStream)(path));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
consola_1.default.start('Zipping folder...');
|
|
83
|
+
const zipBuffer = yield zip_1.default.zipFolder(path);
|
|
84
|
+
formData.append('file', zipBuffer, { filename: 'bundle.zip' });
|
|
85
|
+
}
|
|
86
|
+
consola_1.default.start('Uploading...');
|
|
87
|
+
if (channelName) {
|
|
88
|
+
formData.append('channelName', channelName);
|
|
89
|
+
}
|
|
90
|
+
// Upload the bundle
|
|
91
|
+
try {
|
|
92
|
+
yield app_bundle_1.default.create({ appId: appId, formData: formData });
|
|
93
|
+
consola_1.default.success('Bundle successfully created.');
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
97
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
consola_1.default.error('Failed to create bundle.');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const consola_1 = __importDefault(require("consola"));
|
|
17
|
+
const axios_1 = require("axios");
|
|
18
|
+
const ci_1 = require("../../../utils/ci");
|
|
19
|
+
const apps_1 = __importDefault(require("../../../service/apps"));
|
|
20
|
+
const prompt_1 = require("../../../utils/prompt");
|
|
21
|
+
const app_bundle_1 = __importDefault(require("../../../service/app-bundle"));
|
|
22
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
23
|
+
meta: {
|
|
24
|
+
description: 'Delete an app bundle.',
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
appId: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'ID of the app.',
|
|
30
|
+
},
|
|
31
|
+
bundleId: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'ID of the bundle.',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
+
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let appId = ctx.args.appId;
|
|
43
|
+
if (!appId) {
|
|
44
|
+
const apps = yield apps_1.default.findAll();
|
|
45
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
46
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the bundle from?', {
|
|
47
|
+
type: 'select',
|
|
48
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
let bundleId = ctx.args.bundleId;
|
|
52
|
+
if (!bundleId) {
|
|
53
|
+
bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
|
|
54
|
+
type: 'text',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this bundle?', {
|
|
58
|
+
type: 'confirm',
|
|
59
|
+
});
|
|
60
|
+
if (!confirmed) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
yield app_bundle_1.default.delete({
|
|
65
|
+
appId,
|
|
66
|
+
bundleId,
|
|
67
|
+
});
|
|
68
|
+
consola_1.default.success('Bundle deleted successfully.');
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
72
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
consola_1.default.error('Failed to delete bundle.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const ci_1 = require("../../../utils/ci");
|
|
17
|
+
const consola_1 = __importDefault(require("consola"));
|
|
18
|
+
const prompt_1 = require("../../../utils/prompt");
|
|
19
|
+
const apps_1 = __importDefault(require("../../../service/apps"));
|
|
20
|
+
const axios_1 = require("axios");
|
|
21
|
+
const app_channel_1 = __importDefault(require("../../../service/app-channel"));
|
|
22
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
23
|
+
meta: {
|
|
24
|
+
description: 'Create a new app channel.',
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
appId: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'ID of the app.',
|
|
30
|
+
},
|
|
31
|
+
name: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'Name of the channel.',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
+
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let appId = ctx.args.appId;
|
|
43
|
+
if (!appId) {
|
|
44
|
+
const apps = yield apps_1.default.findAll();
|
|
45
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
46
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the channel from?', {
|
|
47
|
+
type: 'select',
|
|
48
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
let name = ctx.args.name;
|
|
52
|
+
if (!name) {
|
|
53
|
+
name = yield (0, prompt_1.prompt)('Enter the name of the channel:', { type: 'text' });
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
yield app_channel_1.default.create({
|
|
57
|
+
appId,
|
|
58
|
+
name,
|
|
59
|
+
});
|
|
60
|
+
consola_1.default.success('Channel created successfully.');
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
64
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
consola_1.default.error('Failed to create channel.');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const consola_1 = __importDefault(require("consola"));
|
|
17
|
+
const axios_1 = require("axios");
|
|
18
|
+
const ci_1 = require("../../../utils/ci");
|
|
19
|
+
const apps_1 = __importDefault(require("../../../service/apps"));
|
|
20
|
+
const prompt_1 = require("../../../utils/prompt");
|
|
21
|
+
const app_channel_1 = __importDefault(require("../../../service/app-channel"));
|
|
22
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
23
|
+
meta: {
|
|
24
|
+
description: 'Delete an app channel.',
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
appId: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'ID of the app.',
|
|
30
|
+
},
|
|
31
|
+
channelId: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'ID of the channel.',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
+
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let appId = ctx.args.appId;
|
|
43
|
+
if (!appId) {
|
|
44
|
+
const apps = yield apps_1.default.findAll();
|
|
45
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
46
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the channel from?', {
|
|
47
|
+
type: 'select',
|
|
48
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
let channel = ctx.args.channel;
|
|
52
|
+
if (!channel) {
|
|
53
|
+
channel = yield (0, prompt_1.prompt)('Enter the channel name:', {
|
|
54
|
+
type: 'text',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (typeof channel !== 'string') {
|
|
58
|
+
consola_1.default.error('Channel name must be a string.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this channel?', {
|
|
62
|
+
type: 'confirm',
|
|
63
|
+
});
|
|
64
|
+
if (!confirmed) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
yield app_channel_1.default.delete({
|
|
69
|
+
appId,
|
|
70
|
+
name: channel,
|
|
71
|
+
});
|
|
72
|
+
consola_1.default.success('Channel deleted successfully.');
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
76
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
consola_1.default.error('Failed to delete channel.');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const ci_1 = require("../../utils/ci");
|
|
17
|
+
const consola_1 = __importDefault(require("consola"));
|
|
18
|
+
const prompt_1 = require("../../utils/prompt");
|
|
19
|
+
const apps_1 = __importDefault(require("../../service/apps"));
|
|
20
|
+
const axios_1 = require("axios");
|
|
21
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
22
|
+
meta: {
|
|
23
|
+
description: 'Create a new app.',
|
|
24
|
+
},
|
|
25
|
+
args: {
|
|
26
|
+
name: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description: 'Name of the app.',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
var _a;
|
|
33
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
34
|
+
consola_1.default.error('This command is not supported in CI environments.');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let name = ctx.args.name;
|
|
38
|
+
if (!name) {
|
|
39
|
+
name = yield (0, prompt_1.prompt)('Enter the name of the app:', { type: 'text' });
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const response = yield apps_1.default.create({ name });
|
|
43
|
+
consola_1.default.success('App created successfully.');
|
|
44
|
+
consola_1.default.info(`App ID: ${response.id}`);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
48
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
consola_1.default.error('Failed to create app.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const ci_1 = require("../../utils/ci");
|
|
17
|
+
const consola_1 = __importDefault(require("consola"));
|
|
18
|
+
const prompt_1 = require("../../utils/prompt");
|
|
19
|
+
const apps_1 = __importDefault(require("../../service/apps"));
|
|
20
|
+
const axios_1 = require("axios");
|
|
21
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
22
|
+
meta: {
|
|
23
|
+
description: 'Delete an app.',
|
|
24
|
+
},
|
|
25
|
+
args: {
|
|
26
|
+
appId: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
description: 'ID of the app.',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
var _a;
|
|
33
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
34
|
+
consola_1.default.error('This command is not supported in CI environments.');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let appId = ctx.args.appId;
|
|
38
|
+
if (!appId) {
|
|
39
|
+
const apps = yield apps_1.default.findAll();
|
|
40
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
41
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to delete?', {
|
|
42
|
+
type: 'select',
|
|
43
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this app?', {
|
|
47
|
+
type: 'confirm',
|
|
48
|
+
});
|
|
49
|
+
if (!confirmed) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
yield apps_1.default.delete({ id: appId });
|
|
54
|
+
consola_1.default.success('App deleted successfully.');
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
58
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
consola_1.default.error('Failed to delete app.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const consola_1 = __importDefault(require("consola"));
|
|
17
|
+
const axios_1 = require("axios");
|
|
18
|
+
const ci_1 = require("../../../utils/ci");
|
|
19
|
+
const apps_1 = __importDefault(require("../../../service/apps"));
|
|
20
|
+
const prompt_1 = require("../../../utils/prompt");
|
|
21
|
+
const app_device_1 = __importDefault(require("../../../service/app-device"));
|
|
22
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
23
|
+
meta: {
|
|
24
|
+
description: 'Delete an app device.',
|
|
25
|
+
},
|
|
26
|
+
args: {
|
|
27
|
+
appId: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
description: 'ID of the app.',
|
|
30
|
+
},
|
|
31
|
+
deviceId: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
description: 'ID of the device.',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
39
|
+
consola_1.default.error('This command is not supported in CI environments.');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
let appId = ctx.args.appId;
|
|
43
|
+
if (!appId) {
|
|
44
|
+
const apps = yield apps_1.default.findAll();
|
|
45
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
46
|
+
appId = yield (0, prompt_1.prompt)('Which app do you want to delete the device from?', {
|
|
47
|
+
type: 'select',
|
|
48
|
+
options: apps.map((app) => ({ label: app.name, value: app.id })),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
let deviceId = ctx.args.deviceId;
|
|
52
|
+
if (!deviceId) {
|
|
53
|
+
deviceId = yield (0, prompt_1.prompt)('Enter the device ID:', {
|
|
54
|
+
type: 'text',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this device?', {
|
|
58
|
+
type: 'confirm',
|
|
59
|
+
});
|
|
60
|
+
if (!confirmed) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
yield app_device_1.default.delete({
|
|
65
|
+
appId,
|
|
66
|
+
deviceId,
|
|
67
|
+
});
|
|
68
|
+
consola_1.default.success('Device deleted successfully.');
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error instanceof axios_1.AxiosError && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
72
|
+
consola_1.default.error('Your token is no longer valid. Please sign in again.');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
consola_1.default.error('Failed to delete device.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const citty_1 = require("citty");
|
|
16
|
+
const consola_1 = __importDefault(require("consola"));
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const userConfig_1 = __importDefault(require("../utils/userConfig"));
|
|
19
|
+
const config_1 = require("../config");
|
|
20
|
+
const prompt_1 = require("../utils/prompt");
|
|
21
|
+
const ci_1 = require("../utils/ci");
|
|
22
|
+
exports.default = (0, citty_1.defineCommand)({
|
|
23
|
+
meta: {
|
|
24
|
+
name: 'login',
|
|
25
|
+
description: 'Sign in to the Capawesome Cloud Console.',
|
|
26
|
+
},
|
|
27
|
+
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
if ((0, ci_1.isRunningInCi)()) {
|
|
29
|
+
consola_1.default.error('Sign in is not supported in CI environments. Please use the CAPAWESOME_TOKEN environment variable.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const email = yield (0, prompt_1.prompt)('Enter your email:', { type: 'text' });
|
|
33
|
+
const password = yield (0, prompt_1.passwordPrompt)('Enter your password:');
|
|
34
|
+
consola_1.default.start('Logging in...');
|
|
35
|
+
let sessionId;
|
|
36
|
+
try {
|
|
37
|
+
const sessionResponse = yield axios_1.default.post(`${config_1.API_URL}/sessions`, {
|
|
38
|
+
email: email,
|
|
39
|
+
password: password,
|
|
40
|
+
});
|
|
41
|
+
sessionId = sessionResponse.data.id;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
consola_1.default.error('Invalid email or password.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const tokenResponse = yield axios_1.default.post(`${config_1.API_URL}/tokens`, { name: 'Capawesome CLI' }, { headers: { Authorization: `Bearer ${sessionId}` } });
|
|
48
|
+
userConfig_1.default.write({
|
|
49
|
+
username: email,
|
|
50
|
+
token: tokenResponse.data.token,
|
|
51
|
+
});
|
|
52
|
+
consola_1.default.success(`Successfully signed in.`);
|
|
53
|
+
}),
|
|
54
|
+
});
|