Skip to content

Commit 52905f4

Browse files
Merge pull request #36 from contentstack/CL-1612
Cl 1612
2 parents 7de4bd9 + 5429310 commit 52905f4

File tree

8 files changed

+15634
-15808
lines changed

8 files changed

+15634
-15808
lines changed

package-lock.json

Lines changed: 15556 additions & 15710 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-launch",
3-
"version": "1.7.1",
3+
"version": "1.8.0",
44
"description": "Launch related operations",
55
"author": "Contentstack CLI",
66
"bin": {
@@ -21,10 +21,10 @@
2121
],
2222
"dependencies": {
2323
"@apollo/client": "^3.11.8",
24-
"@contentstack/cli-command": "~1.3.2",
25-
"@contentstack/cli-utilities": "~1.8.0",
26-
"@oclif/core": "^3.27.0",
27-
"@oclif/plugin-help": "^5.2.20",
24+
"@contentstack/cli-command": "^1.4.0",
25+
"@contentstack/cli-utilities": "^1.10.0",
26+
"@oclif/core":"^4.2.7",
27+
"@oclif/plugin-help": "^6.2.25",
2828
"@oclif/plugin-plugins": "^5.4.15",
2929
"@rollup/plugin-commonjs": "^28.0.2",
3030
"@rollup/plugin-json": "^6.1.0",
@@ -56,11 +56,11 @@
5656
"@types/sinon": "^17.0.3",
5757
"chai": "^4.5.0",
5858
"eslint": "^7.32.0",
59-
"eslint-config-oclif": "^4",
59+
"eslint-config-oclif": "^6.0.15",
6060
"eslint-config-oclif-typescript": "^3.1.13",
6161
"mocha": "^11.0.1",
6262
"nyc": "^17.1.0",
63-
"oclif": "^3.17.2",
63+
"oclif": "^4.17.30",
6464
"shx": "^0.3.4",
6565
"sinon": "^19.0.2",
6666
"ts-node": "^10.9.2",

src/adapters/base-class.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -633,25 +633,20 @@ export default class BaseClass {
633633
* @memberof BaseClass
634634
*/
635635
printAllVariables(): void {
636-
ux.table(
637-
[
638-
...(this.config.flags['show-variables']
639-
? this.envVariables
640-
: this.envVariables.map(({ key, value }) => ({
641-
key,
642-
value: replace(value, /./g, '*'),
643-
}))),
644-
{ key: '', value: '' },
645-
],
646-
{
647-
key: {
648-
minWidth: 7,
649-
},
650-
value: {
651-
minWidth: 7,
652-
},
653-
},
654-
);
636+
const envVariablesData = [
637+
...(this.config.flags['show-variables']
638+
? this.envVariables
639+
: this.envVariables.map(({ key, value }) => ({
640+
key,
641+
value: replace(value, /./g, '*'),
642+
}))),
643+
];
644+
645+
const headers = [
646+
{ value: 'key', },
647+
{ value: 'value',},
648+
]
649+
ux.table(headers, envVariablesData);
655650
}
656651

657652
/**

src/adapters/file-upload.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import filter from 'lodash/filter';
77
import includes from 'lodash/includes';
88
import isEmpty from 'lodash/isEmpty';
99
import { basename, resolve } from 'path';
10-
import { cliux, configHandler, HttpClient, ux } from '@contentstack/cli-utilities';
10+
import { cliux, configHandler, HttpClient } from '@contentstack/cli-utilities';
1111
import { createReadStream, existsSync, PathLike, statSync, readFileSync } from 'fs';
1212

1313
import { print } from '../util';
@@ -262,7 +262,7 @@ export default class FileUpload extends BaseClass {
262262
* @memberof FileUpload
263263
*/
264264
async archive() {
265-
ux.action.start('Preparing zip file');
265+
cliux.loader('Preparing zip file');
266266
const projectName = basename(this.config.projectBasePath);
267267
const zipName = `${Date.now()}_${projectName}.zip`;
268268
const zipPath = resolve(this.config.projectBasePath, zipName);
@@ -296,7 +296,7 @@ export default class FileUpload extends BaseClass {
296296
this.exit(1);
297297
}
298298

299-
ux.action.stop();
299+
cliux.loader();
300300
return { zipName, zipPath, projectName };
301301
}
302302

@@ -347,7 +347,7 @@ export default class FileUpload extends BaseClass {
347347
}
348348

349349
private async submitFormData(formData: FormData, uploadUrl: string): Promise<void> {
350-
ux.action.start('Starting file upload...');
350+
cliux.loader('Starting file upload...');
351351
try {
352352
await new Promise<void>((resolve, reject) => {
353353
formData.submit(uploadUrl, (error, res) => {
@@ -359,9 +359,9 @@ export default class FileUpload extends BaseClass {
359359
});
360360
});
361361

362-
ux.action.stop();
362+
cliux.loader();
363363
} catch (error) {
364-
ux.action.stop('File upload failed!');
364+
cliux.loader('File upload failed!');
365365
this.log('File upload failed. Please try again.', 'error');
366366
if (error instanceof Error) {
367367
this.log(error.message, 'error');
@@ -375,7 +375,7 @@ export default class FileUpload extends BaseClass {
375375
uploadUrl: string,
376376
headers: Array<{ key: string; value: string }>,
377377
): Promise<void> {
378-
ux.action.start('Starting file upload...');
378+
cliux.loader('Starting file upload...');
379379
const httpClient = new HttpClient();
380380
const file = readFileSync(filePath);
381381

@@ -392,15 +392,15 @@ export default class FileUpload extends BaseClass {
392392
const { status } = response;
393393

394394
if (status >= 200 && status < 300) {
395-
ux.action.stop();
395+
cliux.loader();
396396
} else {
397-
ux.action.stop('File upload failed!');
397+
cliux.loader('File upload failed!');
398398
this.log('File upload failed. Please try again.', 'error');
399399
this.log(`Error: ${status}, ${response?.statusText}`, 'error');
400400
this.exit(1);
401401
}
402402
} catch (error) {
403-
ux.action.stop('File upload failed!');
403+
cliux.loader('File upload failed!');
404404
this.log('File upload failed. Please try again.', 'error');
405405
if (error instanceof Error) {
406406
this.log(`Error: ${error.message}`, 'error');

src/adapters/pre-check.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,23 @@ export default class PreCheck extends BaseClass {
7474
})?.name || '',
7575
};
7676

77+
const headers = [
78+
{ value: 'Project Name'},
79+
{ value: 'Project Type'},
80+
{ value: 'Environment'},
81+
{ value: 'Framework Preset'},
82+
];
83+
7784
if (repository?.repositoryName) {
7885
detail['Repository'] = repository.repositoryName;
86+
headers.push({ value: 'Repository' });
87+
}
88+
89+
if(!detail){
90+
this.exit(1);
7991
}
8092

81-
ux.table([detail, {}], {
82-
'Project Name': {
83-
minWidth: 7,
84-
},
85-
'Project Type': {
86-
minWidth: 7,
87-
},
88-
Environment: {
89-
minWidth: 7,
90-
},
91-
Repository: {
92-
minWidth: 7,
93-
},
94-
'Framework Preset': {
95-
minWidth: 7,
96-
},
97-
});
93+
ux.table(headers, [detail]);
9894
}
9995
}
10096

src/commands/launch/deployments.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,13 @@ export default class Deployments extends BaseCommand<typeof Deployments> {
7373
async showDeployments() {
7474
const environments = await this.getEnvironments();
7575

76-
ux.table(environments, {
77-
environment: {
78-
minWidth: 7,
79-
},
80-
deploymentUrl: {
81-
minWidth: 7,
82-
header: 'Deployment Url',
83-
},
84-
commitMessage: {
85-
minWidth: 7,
86-
header: 'Commit Message',
87-
},
88-
createdAt: {
89-
minWidth: 7,
90-
header: 'Created At',
91-
},
92-
});
76+
const headers = [
77+
{ value: 'environment', },
78+
{ value: 'deploymentUrl',},
79+
{ value: 'commitMessage',},
80+
{ value: 'createdAt', },
81+
];
82+
ux.table(headers, environments);
9383
}
9484

9585
/**

src/commands/launch/environments.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ export default class Environments extends BaseCommand<typeof Environments> {
126126
process.exit(1);
127127
});
128128

129-
ux.table(
130-
map(environments, ({ uid, name, frameworkPreset }) => {
129+
const environmentsData = map(environments, ({ uid, name, frameworkPreset }) => {
131130
return {
132131
uid: chalk.green(uid),
133132
name: chalk.green(name),
@@ -137,21 +136,13 @@ export default class Environments extends BaseCommand<typeof Environments> {
137136
})?.name || '',
138137
),
139138
};
140-
}),
141-
{
142-
uid: {
143-
minWidth: 7,
144-
header: 'UID',
145-
},
146-
name: {
147-
minWidth: 7,
148-
header: 'Name',
149-
},
150-
frameworkPreset: {
151-
minWidth: 7,
152-
header: 'Framework',
153-
},
154-
},
155-
);
139+
});
140+
const headers = [
141+
{ value: 'uid', },
142+
{ value: 'name',},
143+
{ value: 'frameworkPreset',},
144+
];
145+
ux.table(headers, environmentsData);
146+
156147
}
157148
}

src/util/logs-polling-utilities.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import EventEmitter from 'events';
2-
import { ux } from '@contentstack/cli-utilities';
2+
import { cliux } from '@contentstack/cli-utilities';
33
import { ApolloClient, ObservableQuery } from '@apollo/client/core';
4+
import { Ora } from 'ora';
45

56
import { LogPollingInput, ConfigType } from '../types';
67
import { deploymentQuery, deploymentLogsQuery, serverlessLogsQuery } from '../graphql';
@@ -14,6 +15,7 @@ export default class LogPolling {
1415
public deploymentStatus!: string;
1516
public startTime!: number;
1617
public endTime!: number;
18+
public loader!: Ora | void;
1719

1820
constructor(params: LogPollingInput) {
1921
const { apolloLogsClient, apolloManageClient, config, $event } = params;
@@ -112,10 +114,11 @@ export default class LogPolling {
112114
): void {
113115
let timestamp: number = 0;
114116
logsWatchQuery.subscribe(async({ data, errors, error }) => {
115-
ux.action.start('Loading deployment logs...');
116-
117+
if(!this.loader){
118+
this.loader = cliux.loaderV2('Loading deployment logs...');
119+
}
117120
if (error) {
118-
ux.action.stop();
121+
this.loader=cliux.loaderV2('done', this.loader);
119122
this.$event.emit('deployment-logs', {
120123
message: error?.message,
121124
msgType: 'error',
@@ -127,7 +130,7 @@ export default class LogPolling {
127130
logsWatchQuery.stopPolling();
128131
}
129132
if (errors?.length && data === null) {
130-
ux.action.stop();
133+
this.loader=cliux.loaderV2('done', this.loader);
131134
this.$event.emit('deployment-logs', {
132135
message: errors,
133136
msgType: 'error',
@@ -141,7 +144,7 @@ export default class LogPolling {
141144
if (this.deploymentStatus) {
142145
let logsData = data?.getLogs;
143146
if (logsData?.length) {
144-
ux.action.stop();
147+
this.loader=cliux.loaderV2('done', this.loader);
145148
this.$event.emit('deployment-logs', {
146149
message: logsData,
147150
msgType: 'info',
@@ -160,8 +163,11 @@ export default class LogPolling {
160163
message: 'DONE',
161164
msgType: 'debug',
162165
});
166+
if(this.loader){
167+
this.loader=cliux.loaderV2('done', this.loader);
163168
}
164169
}
170+
}
165171
});
166172
}
167173

@@ -211,21 +217,23 @@ export default class LogPolling {
211217
>,
212218
): void {
213219
serverLogsWatchQuery.subscribe(({ data, errors, error }) => {
214-
ux.action.start('Loading server logs...');
220+
if(!this.loader){
221+
this.loader = cliux.loaderV2('Loading server logs...');
222+
}
215223
if (error) {
216-
ux.action.stop();
224+
this.loader=cliux.loaderV2('done', this.loader);
217225
this.$event.emit('server-logs', { message: error?.message, msgType: 'error' });
218226
}
219227
if (errors?.length && data === null) {
220-
ux.action.stop();
228+
this.loader=cliux.loaderV2('done', this.loader);
221229
this.$event.emit('server-logs', { message: errors, msgType: 'error' });
222230
serverLogsWatchQuery.stopPolling();
223231
}
224232

225233
let logsData = data?.getServerlessLogs?.logs;
226234
let logsLength = logsData?.length;
227235
if (logsLength > 0) {
228-
ux.action.stop();
236+
this.loader=cliux.loaderV2('done', this.loader);
229237
this.$event.emit('server-logs', { message: logsData, msgType: 'info' });
230238
this.startTime = new Date(logsData[logsLength - 1].timestamp).getTime() + 1;
231239
this.endTime = this.startTime + 10 * 1000;

0 commit comments

Comments
 (0)