Skip to content

Commit d4565c7

Browse files
author
Murat Mehmet
committed
fix: update logging
fix #138
1 parent 5f16a9f commit d4565c7

File tree

6 files changed

+55
-33
lines changed

6 files changed

+55
-33
lines changed

src/__tests__/unit/upgrade.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ describe('upgrade', () => {
9595
didRun: true,
9696
completedTaskCount: 1,
9797
});
98-
mockPrompter.log.success.mockClear();
98+
mockPrompter.log.info.mockClear();
9999

100100
await upgrade();
101101

102-
expect(mockPrompter.log.success).toHaveBeenCalledWith(
102+
expect(mockPrompter.log.info).toHaveBeenCalledWith(
103103
expect.stringContaining('task(s) successfully')
104104
);
105105
});

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ program
2727
try {
2828
progress.setOptions({
2929
title: 'integrating',
30-
total: 8,
30+
total: 4,
3131
step: 0,
3232
});
3333
if (!args.verbose) progress.display();

src/integrate.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,12 @@ export async function integrate(packageName?: string): Promise<void> {
267267
packagesToIntegrate[i];
268268

269269
progress.setOptions({
270-
step: stage++,
270+
step: i + 1,
271+
total: packagesToIntegrate.length,
271272
stage: `integrating ${color.blue(packageName)}`,
272273
});
273-
logInfo(
274-
color.bold(color.bgBlue(' new package ')) +
274+
logSuccess(
275+
color.bold(color.bgBlue(' integration ')) +
275276
color.bold(color.blue(` ${packageName} `))
276277
);
277278
if (
@@ -347,18 +348,16 @@ export async function integrate(packageName?: string): Promise<void> {
347348

348349
if (failedTaskCount) {
349350
logWarning(
350-
color.inverse(
351-
color.bold(color.yellow(' integrated with errors '))
352-
) +
351+
color.inverse(color.bold(color.yellow(' done with errors '))) +
353352
color.bold(color.blue(` ${packageName} `)) +
354353
color.yellow(
355354
`failed to complete ${failedTaskCount} task(s) - please complete this integration manually`
356355
),
357356
true
358357
);
359358
} else {
360-
logSuccess(
361-
color.inverse(color.bold(color.green(' integrated '))) +
359+
logInfo(
360+
color.inverse(color.bold(color.green(' done '))) +
362361
color.black(color.bold(color.blue(` ${packageName} `))) +
363362
color.green(
364363
`completed ${completedTaskCount} task(s) successfully`
@@ -393,10 +392,6 @@ export async function integrate(packageName?: string): Promise<void> {
393392
});
394393
}
395394
updateIntegrationStatus(packageLockUpdates);
396-
397-
if (!options.get().verbose) {
398-
progress.hide();
399-
}
400395
}
401396

402397
function checkIfJustCreatedLockFile(analyzedPackages: AnalyzedPackages) {

src/progress.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class Progress {
2121
}
2222

2323
drawMessage() {
24-
const stepRate = this.options.step / this.options.total;
24+
const stepRate = !this.options.total
25+
? 0
26+
: Math.min(1, Math.max(0, this.options.step / this.options.total));
2527
const barSize = 20;
2628
const scaledStep = Math.floor(stepRate * barSize);
2729
const completeBars = new Array(scaledStep).fill('\u2588').join('');
@@ -45,7 +47,6 @@ class Progress {
4547
if (this.isActive) {
4648
this.isActive = false;
4749
this.spinner?.stop();
48-
process.stdout.cursorTo(0); // up one line
4950
process.stdout.moveCursor(0, -2); // up one line
5051
process.stdout.clearLine(1); // from cursor to end
5152
}

src/upgrade.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export async function upgrade(): Promise<void> {
6666

6767
const didCreate = await createNewProject();
6868
if (didCreate) {
69-
logSuccess(
69+
logInfo(
7070
color.inverse(color.bold(color.green(' created '))) +
7171
color.green(' new project created successfully')
7272
);
@@ -95,7 +95,7 @@ export async function upgrade(): Promise<void> {
9595
oldProjectPath = path.resolve(oldProjectPath);
9696
const didImport = await importFromOldProject(oldProjectPath);
9797
if (didImport) {
98-
logSuccess(
98+
logInfo(
9999
color.inverse(color.bold(color.green(' imported '))) +
100100
color.green(' imported project data successfully')
101101
);
@@ -131,7 +131,7 @@ export async function upgrade(): Promise<void> {
131131
true
132132
);
133133
} else {
134-
logSuccess(
134+
logInfo(
135135
color.inverse(color.bold(color.green(' executed '))) +
136136
color.black(color.bold(color.blue(' upgrade.yml pre_install '))) +
137137
color.green(
@@ -179,6 +179,9 @@ export async function upgrade(): Promise<void> {
179179
}[] = [];
180180
let packagesToIntegrate: PackageWithConfig[] = [];
181181

182+
progress.setOptions({
183+
stage: 'checking package configuration',
184+
});
182185
startSpinner('checking package configuration');
183186
for (let i = 0; i < integratedPackages.length; i++) {
184187
const [packageName] = integratedPackages[i];
@@ -312,8 +315,13 @@ export async function upgrade(): Promise<void> {
312315
const { packageName, version, configPath, config } =
313316
packagesToIntegrate[i];
314317

315-
logInfo(
316-
color.bold(color.bgBlue(' package ')) +
318+
progress.setOptions({
319+
step: i + 1,
320+
total: packagesToIntegrate.length,
321+
stage: `integrating ${color.blue(packageName)}`,
322+
});
323+
logSuccess(
324+
color.bold(color.bgBlue(' integration ')) +
317325
color.bold(color.blue(` ${packageName} `))
318326
);
319327

@@ -374,18 +382,16 @@ export async function upgrade(): Promise<void> {
374382

375383
if (failedTaskCount) {
376384
logWarning(
377-
color.inverse(
378-
color.bold(color.yellow(' re-integrated with errors '))
379-
) +
385+
color.inverse(color.bold(color.yellow(' done with errors '))) +
380386
color.bold(color.blue(` ${packageName} `)) +
381387
color.yellow(
382388
`failed to complete ${failedTaskCount} task(s) - please complete this integration manually`
383389
),
384390
true
385391
);
386392
} else {
387-
logSuccess(
388-
color.inverse(color.bold(color.green(' re-integrated '))) +
393+
logInfo(
394+
color.inverse(color.bold(color.green(' done '))) +
389395
color.black(color.bold(color.blue(` ${packageName} `))) +
390396
color.green(
391397
`completed ${completedTaskCount} task(s) successfully`
@@ -418,7 +424,7 @@ export async function upgrade(): Promise<void> {
418424
logWarning(e.message);
419425
});
420426
if (didRestore) {
421-
logSuccess(
427+
logInfo(
422428
color.inverse(color.bold(color.green(' imported '))) +
423429
color.green(' files were imported successfully')
424430
);
@@ -449,7 +455,7 @@ export async function upgrade(): Promise<void> {
449455
true
450456
);
451457
} else {
452-
logSuccess(
458+
logInfo(
453459
color.inverse(color.bold(color.green(' executed '))) +
454460
color.black(color.bold(color.blue(' upgrade.yml '))) +
455461
color.green(
@@ -526,6 +532,21 @@ export async function upgrade(): Promise<void> {
526532
return;
527533
}
528534

535+
// push changes
536+
const { exitCode: didFetchFail } = await runCommand('git fetch', {
537+
silent: false,
538+
progressText: 'fetching changes to current project',
539+
completeText: 'fetched changes to current project',
540+
cwd: variables.get('__OLD_PROJECT_DIR__'),
541+
});
542+
if (didFetchFail) {
543+
logWarning(
544+
'please fetch changes manually in ' +
545+
variables.get('__OLD_PROJECT_DIR__')
546+
);
547+
return;
548+
}
549+
529550
logSuccess(
530551
color.inverse(color.bold(color.green(' committed '))) +
531552
color.green(` saved changes to ${color.bold(branchName)}`)
@@ -543,9 +564,5 @@ export async function upgrade(): Promise<void> {
543564
)
544565
);
545566
stopSpinner('cleaned up');
546-
547-
if (!options.get().verbose) {
548-
progress.hide();
549-
}
550567
}
551568
}

src/utils/getPackageConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import color from 'picocolors';
34
import { Constants } from '../constants';
5+
import { progress } from '../progress';
46
import { updateSpinner } from '../prompter';
57
import { getMd5 } from './getMd5';
68
import { getProjectPath } from './getProjectPath';
@@ -9,6 +11,13 @@ export async function getPackageConfig(
911
packageName: string,
1012
pagination: { index: number; count: number } = { index: 0, count: 1 }
1113
): Promise<string | null> {
14+
progress.setOptions({
15+
step: pagination.index + 1,
16+
total: pagination.count,
17+
stage: `[${pagination.index + 1}/${
18+
pagination.count
19+
}] checking ${color.blue(packageName)}`,
20+
});
1221
updateSpinner(
1322
`[${pagination.index + 1}/${
1423
pagination.count

0 commit comments

Comments
 (0)