Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): expanded preview #267

Merged
merged 40 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
879f751
draft 01
louis-bompart Jun 17, 2021
e4023c3
better merging
louis-bompart Jun 17, 2021
36552f1
strong type
louis-bompart Jun 17, 2021
67da6e3
merge master
louis-bompart Jul 12, 2021
b29bd4c
refresh PR
louis-bompart Jul 12, 2021
ab06b57
Merge branch 'master' into CDX-347
louis-bompart Jul 20, 2021
03ff235
ironing merge
louis-bompart Jul 20, 2021
e59a412
Working (with #365)
louis-bompart Jul 21, 2021
835399d
Merge branch 'master' into CDX-347
louis-bompart Jul 22, 2021
d9767d1
smoothing up
louis-bompart Jul 22, 2021
ca1bf53
prettier
louis-bompart Jul 22, 2021
ba24983
lint
louis-bompart Jul 22, 2021
e1b9a3f
spec
louis-bompart Jul 22, 2021
e31ec7f
add epoch sort + ut on old preview deletion
louis-bompart Jul 23, 2021
5a7ecb6
Merge branch 'master' into CDX-347
louis-bompart Jul 26, 2021
e7d4f09
viewer->previewer
louis-bompart Jul 26, 2021
2fd57e9
jsdoc
louis-bompart Jul 26, 2021
598373a
UT progress
louis-bompart Jul 26, 2021
c1db556
refactor file diff processor
louis-bompart Jul 27, 2021
8e60f66
adapt test for refactor
louis-bompart Jul 27, 2021
75f5386
prepare UT for filesDiffProcessor
louis-bompart Jul 28, 2021
e0b7740
rework filesDiffProcessor
louis-bompart Jul 28, 2021
09eae21
UT complete
louis-bompart Jul 28, 2021
a8cf76c
Merge branch 'master' into CDX-347
louis-bompart Jul 28, 2021
6ed4033
merge master into CDX-347
louis-bompart Jul 29, 2021
505feb5
tweak code for project change
louis-bompart Jul 29, 2021
abb330a
Merge branch 'master' into CDX-347
louis-bompart Jul 29, 2021
b0aacd0
Update expandedPreviewer.spec.ts
louis-bompart Jul 29, 2021
3aff71f
Merge branch 'master' into CDX-347
louis-bompart Jul 29, 2021
4cc7203
Merge branch 'master' into CDX-347
louis-bompart Jul 30, 2021
050587a
Merge branch 'master' into CDX-347
louis-bompart Jul 30, 2021
859184a
Merge branch 'master' into CDX-347
y-lakhdar Aug 2, 2021
55cc774
Merge branch 'master' into CDX-347
louis-bompart Aug 2, 2021
babb3b4
handle project absolute path v. relative path in exp preview
louis-bompart Aug 3, 2021
491006f
skip delete if no preview dir
louis-bompart Aug 4, 2021
ef9126f
Merge branch 'master' into CDX-347
louis-bompart Aug 4, 2021
4685eed
Merge branch 'master' into CDX-347
louis-bompart Aug 4, 2021
5c26e46
Merge branch 'master' into CDX-347
y-lakhdar Aug 9, 2021
bf73fee
Merge branch 'master' into CDX-347
louis-bompart Aug 9, 2021
82277b9
Merge branch 'master' into CDX-347
louis-bompart Aug 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 23 additions & 127 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
"@oclif/plugin-help": "^3",
"@oclif/plugin-update": "^1.3.10",
"@openid/appauth": "^1.3.0",
"@types/decompress": "^4.2.3",
"@vue/cli": "^4.5.11",
"abortcontroller-polyfill": "^1.7.1",
"archiver": "^5.3.0",
"async-retry": "^1.3.1",
"chalk": "^4.1.1",
"cli-ux": "^5.5.1",
"coveo.analytics": "^2.18.4",
"create-react-app": "^4.0.3",
"decompress": "^4.2.1",
"exponential-backoff": "^3.1.0",
"fs-extra": "^9.1.0",
"isomorphic-fetch": "^3.0.0",
Expand All @@ -38,6 +41,7 @@
"@oclif/errors": "^1.3.4",
"@oclif/test": "^1",
"@types/archiver": "^5.1.0",
"@types/async-retry": "^1.4.2",
"@types/cli-progress": "^3.9.1",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.22",
Expand Down
85 changes: 85 additions & 0 deletions packages/cli/src/lib/snapshot/expandedPreviewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import {
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
ResourceSnapshotsReportModel,
ResourceType,
} from '@coveord/platform-client';
import decompress from 'decompress';
import {mkdirSync} from 'fs';
import {join, resolve} from 'path';
import {spawnProcess} from '../utils/process';
import {SnapshotFactory} from './snapshotFactory';

export class ExpandedPreviewer {
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
private static readonly temporaryDirectory: string = '.coveo/tmp';
private static readonly previewDirectory: string = '.coveo/preview';

private resourcesToPreview: ResourceType[];

public constructor(
private readonly report: ResourceSnapshotsReportModel,
private readonly orgId: string,
private readonly snapshotToPreviewZipPath: string
) {
this.resourcesToPreview = Object.keys(
report.resourceOperationResults
) as ResourceType[];
}

/**
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
* preview
*/
public async preview() {
const previewLocalSlug = `${this.orgId}-${Date.now()}`;
const dirPath = resolve(
join(ExpandedPreviewer.previewDirectory, previewLocalSlug)
);
await this.initPreviewDirectory(previewLocalSlug, dirPath);
await this.applySnapshotToPreview(dirPath);
}

private async initPreviewDirectory(
previewLocalSlug: string,
dirPath: string
) {
const zipPath = join(
ExpandedPreviewer.temporaryDirectory,
previewLocalSlug
);
mkdirSync(dirPath, {
recursive: true,
});
await this.getFreshSnapshot(zipPath);
await decompress(zipPath, dirPath);

await this.initialPreviewCommit(dirPath);
}

private async initialPreviewCommit(dirPath: string) {
await spawnProcess('git', ['init'], {cwd: dirPath});
await spawnProcess('git', ['add', '.'], {cwd: dirPath});
await spawnProcess('git', ['commit', '-m', `"${this.orgId} currently"`], {
cwd: dirPath,
});
}

private async applySnapshotToPreview(dirPath: string) {
await decompress(this.snapshotToPreviewZipPath, dirPath);
await spawnProcess('git', ['add', '.'], {cwd: dirPath});
await spawnProcess(
'git',
['commit', '-m', `"${this.orgId} after snapshot application"`],
{
cwd: dirPath,
}
);
}

private async getFreshSnapshot(zipPath: string) {
const snapshot = await SnapshotFactory.createFromOrg(
this.resourcesToPreview,
this.orgId
);

await snapshot.downloadZip(zipPath);
return;
}
}
11 changes: 5 additions & 6 deletions packages/cli/src/lib/snapshot/reportViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
import {cli} from 'cli-ux';
import {bgHex, green, yellow, red, bold, italic} from 'chalk';

// TODO SRC-4448: keys should be `ResourceType` from `@coveord/platform-client`.
type ResourceEntry = [string, ResourceSnapshotsReportOperationModel];

export class ReportViewer {
public static maximumNumberOfErrorsToPrint = 5;
public static styles = {
Expand Down Expand Up @@ -85,11 +88,7 @@ export class ReportViewer {
}

private get changedResources() {
type resourceEntries = [string, ResourceSnapshotsReportOperationModel];
const resourceHasAtLeastOneOperation = ([
_,
operations,
]: resourceEntries) => {
const resourceHasAtLeastOneOperation = ([_, operations]: ResourceEntry) => {
return (
operations.resourcesCreated +
operations.resourcesUpdated +
Expand All @@ -104,7 +103,7 @@ export class ReportViewer {
const convertArrayToObject = ([
resourceName,
operations,
]: resourceEntries) => ({
]: ResourceEntry) => ({
resourceName,
operations,
});
Expand Down
18 changes: 14 additions & 4 deletions packages/cli/src/lib/snapshot/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {ReportViewer} from './reportViewer';
import {ensureFileSync, writeJsonSync} from 'fs-extra';
import {join} from 'path';
import dedent from 'ts-dedent';
import {ExpandedPreviewer} from './expandedPreviewer';

export interface ISnapshotValidation {
isValid: boolean;
Expand Down Expand Up @@ -39,15 +40,19 @@ export class Snapshot {
return {isValid: this.isValid(), report: this.latestReport};
}

public async preview() {
public async preview(snapshotZipPath: string) {
this.displayLightPreview();
this.displayExpandedPreview();
await this.displayExpandedPreview(snapshotZipPath);
}

public async delete() {
await this.client.resourceSnapshot.delete(this.model.id);
}

public async downloadZip(downloadPath: string) {
throw new Error('Method not implemented.');
}

public requiresSynchronization() {
// TODO: backend should provide a specific result code for snapshots that are out of sync with the target org.
// Waiting for the JIRA number...
Expand Down Expand Up @@ -95,8 +100,13 @@ export class Snapshot {
report.display();
}

private displayExpandedPreview() {
// TODO: CDX-347 Display Expanded preview
private async displayExpandedPreview(snapshotZipPath: string) {
const previewer = new ExpandedPreviewer(
this.latestReport,
this.targetId!,
snapshotZipPath
);
await previewer.preview();
}

private isValid() {
Expand Down
Loading