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 14 commits
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
6 changes: 3 additions & 3 deletions .github/workflows/renovate-config-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: 'Renovate Config Validator'

on:
push:
branches: [ master ]
branches: [master]
paths:
- 'renovate.json'
pull_request:
branches: [ master ]
branches: [master]
paths:
- 'renovate.json'

Expand All @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: Check Renovate config
- name: Check Renovate config
run: |
npm i renovate
node_modules/.bin/renovate-config-validator
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Coveo CLI

<!-- removefromdocs -->

[![Build](https://github.com/coveo/cli/actions/workflows/build.yml/badge.svg)](https://github.com/coveo/cli/actions/workflows/build.yml)

<!-- endremovefromdocs -->

## About
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/package-lock.json

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

3 changes: 3 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,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",
"extract-zip": "^2.0.1",
"fs-extra": "^10.0.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/commands/org/config/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Preview extends Command {
}),
showMissingResources: flags.boolean({
char: 'd',
description: 'Whether or not preview missing resources',
description: 'Preview resources deletion when enabled',
default: false,
required: false,
}),
Expand All @@ -53,7 +53,10 @@ export default class Preview extends Command {
options
);

await snapshot.preview();
await snapshot.preview(
project.resourcePath,
options.deleteMissingResources
);

if (reporter.isSuccessReport()) {
await snapshot.delete();
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/commands/org/config/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Push extends Command {
}),
deleteMissingResources: flags.boolean({
char: 'd',
description: 'Whether or not to delete missing resources',
description: 'Delete missing resources when enabled',
default: false,
required: false,
}),
Expand Down Expand Up @@ -65,7 +65,10 @@ export default class Push extends Command {
);

if (!flags.skipPreview) {
await snapshot.preview();
await snapshot.preview(
project.resourcePath,
options.deleteMissingResources
);
}

if (reporter.isSuccessReport()) {
Expand Down
21 changes: 12 additions & 9 deletions packages/cli/src/lib/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import {InvalidProjectError} from '../errors';
import extract from 'extract-zip';

export class Project {
public constructor(private pathToProject: string) {}
public constructor(private _pathToProject: string) {}
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved

public async refresh(projectContent: Blob) {
const buffer = await projectContent.arrayBuffer();
const view = new DataView(buffer);
writeFileSync(this.pathToTemporaryZip, view);
await extract(this.pathToTemporaryZip, {dir: this.resourcePath});
writeFileSync(this.temporaryZipPath, view);
await extract(this.temporaryZipPath, {dir: this.resourcePath});
this.deleteTemporaryZipFile();
}

public deleteTemporaryZipFile() {
unlinkSync(this.pathToTemporaryZip);
unlinkSync(this.temporaryZipPath);
}

private ensureProjectCompliance() {
Expand All @@ -36,8 +36,7 @@ export class Project {
try {
this.ensureProjectCompliance();
await new Promise<void>((resolve, reject) => {
const pathToTemporaryZip = this.pathToTemporaryZip;
const outputStream = createWriteStream(pathToTemporaryZip);
const outputStream = createWriteStream(this.temporaryZipPath);
const archive = archiver('zip');

outputStream.on('close', () => resolve());
Expand All @@ -47,17 +46,21 @@ export class Project {
archive.directory(this.resourcePath, false);
archive.finalize();
});
return this.pathToTemporaryZip;
return this.temporaryZipPath;
} catch (error) {
cli.error(error);
}
}

private get pathToTemporaryZip() {
public get pathToProject() {
return this._pathToProject;
}

public get temporaryZipPath() {
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
return join(this.pathToProject, 'snapshot.zip');
}

private get resourcePath() {
public get resourcePath() {
return join(this.pathToProject, 'resources');
}
}
74 changes: 74 additions & 0 deletions packages/cli/src/lib/snapshot/expandedPreviewer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
jest.mock('fs');
import {ResourceSnapshotsReportType} from '@coveord/platform-client';
import {Dirent, readdirSync, rmSync} from 'fs';
import {join} from 'path';

import {mocked} from 'ts-jest/utils';
import {getSuccessReport} from '../../__stub__/resourceSnapshotsReportModel';
import {ExpandedPreviewer} from './expandedPreviewer';

describe('ExpandedPreviewer', () => {
const getDirectory = (name?: string) => {
const dirent = new Dirent();
dirent.isDirectory = () => true;
if (name) {
dirent.name = name;
}
return dirent;
};
describe('when there are more than 5 expanded preview stored', () => {
const mockedReaddirSync = mocked(readdirSync);
const mockedRmSync = mocked(rmSync);

beforeAll(() => {
const dirs = new Array<Dirent>();
for (let i = 0; i < 8; i++) {
dirs.push(getDirectory(`someOrgId-${i}`));
}
mockedReaddirSync.mockReturnValue(dirs);
});

afterAll(() => {
mockedReaddirSync.mockRestore();
mockedRmSync.mockRestore();
});

it('should delete the exceeding preview directories', async () => {
const expandedPreviewer = new ExpandedPreviewer(
getSuccessReport('some-id', ResourceSnapshotsReportType.DryRun),
'someorg',
'my/awesome/path',
false
);
await expandedPreviewer.preview();

expect(mockedReaddirSync).toBeCalledWith('.coveo/preview', {
withFileTypes: true,
});
expect(mockedRmSync).toHaveBeenCalledTimes(4);
for (let index = 0; index < 4; index++) {
expect(mockedRmSync).toHaveBeenNthCalledWith(
index + 1,
join('.coveo/preview', `someOrgId-${index}`),
expect.anything()
);
}
});
});

describe('when shouldDelete is false', () => {
it.todo('should not delete missing resources');
it.todo('should not delete missing resourceType/file');
});

describe('when shouldDelete is true', () => {
it.todo('should not delete missing resources');
it.todo('should not delete missing resourceType/file');
});

it.todo('should download the before snapshot');
it.todo('should do two commits');
it.todo(
"should replace the value of the 'before' snapshot with the one of the applied snapshot"
);
});
Loading