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 all 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
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 @@ -16,13 +16,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
15 changes: 15 additions & 0 deletions packages/cli/src/__test__/fsUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Dirent} from 'fs';

export const getFile = (name: string) => getDirent(name, 'file');
export const getDirectory = (name: string) => getDirent(name, 'dir');

const getDirent = (name: string, type: 'file' | 'dir') => {
const dirent = new Dirent();
const isFile = type === 'file';
dirent.isDirectory = isFile ? () => false : () => true;
dirent.isFile = isFile ? () => true : () => false;
if (name) {
dirent.name = name;
}
return dirent;
};
2 changes: 1 addition & 1 deletion packages/cli/src/commands/org/config/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
IsAuthenticated,
Preconditions,
} from '../../../lib/decorators/preconditions';
import {ReportViewerStyles} from '../../../lib/snapshot/reportViewer/reportViewerStyles';
import {ReportViewerStyles} from '../../../lib/snapshot/reportPreviewer/reportPreviewerStyles';
import {Snapshot, waitUntilDoneOptions} from '../../../lib/snapshot/snapshot';
import {
getTargetOrg,
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/commands/org/config/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IsAuthenticated,
Preconditions,
} from '../../../lib/decorators/preconditions';
import {IsGitInstalled} from '../../../lib/decorators/preconditions/git';
import {SnapshotOperationTimeoutError} from '../../../lib/errors';
import {Snapshot} from '../../../lib/snapshot/snapshot';
import {
Expand All @@ -36,7 +37,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 @@ -50,7 +51,7 @@ export default class Preview extends Command {

public static hidden = true;

@Preconditions(IsAuthenticated())
@Preconditions(IsAuthenticated(), IsGitInstalled())
public async run() {
const {flags} = this.parse(Preview);
const target = await getTargetOrg(this.configuration, flags.target);
Expand All @@ -64,7 +65,7 @@ export default class Preview extends Command {
options
);

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

if (reporter.isSuccessReport()) {
await snapshot.delete();
Expand Down
4 changes: 2 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,7 @@ export default class Push extends Command {
);

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

if (reporter.isSuccessReport()) {
Expand Down
32 changes: 17 additions & 15 deletions packages/cli/src/lib/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {DotFolder, DotFolderConfig} from './dotFolder';

export class Project {
private static readonly resourceFolderName = 'resources';
public constructor(private pathToProject: string) {
public constructor(private _pathToProject: string) {
if (!this.isCoveoProject) {
this.makeCoveoProject();
}
Expand All @@ -17,25 +17,25 @@ export class Project {
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() {
if (!this.isResourcesProject) {
throw new InvalidProjectError(
this.pathToProject,
this._pathToProject,
'Does not contain any resources folder'
);
}
if (!this.isCoveoProject) {
throw new InvalidProjectError(
this.pathToProject,
this._pathToProject,
'Does not contain any .coveo folder'
);
}
Expand All @@ -45,8 +45,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 @@ -56,22 +55,25 @@ export class Project {
archive.directory(this.resourcePath, false);
archive.finalize();
});
return this.pathToTemporaryZip;
return this.temporaryZipPath;
} catch (error) {
cli.error(error);
}
}

public contains(fileName: string) {
return existsSync(join(this.pathToProject, fileName));
public get pathToProject() {
return this._pathToProject;
}

private get pathToTemporaryZip() {
return join(this.pathToProject, 'snapshot.zip');
private get temporaryZipPath() {
return join(this._pathToProject, 'snapshot.zip');
}

private get resourcePath() {
return join(this.pathToProject, Project.resourceFolderName);
public get resourcePath() {
return join(this._pathToProject, Project.resourceFolderName);
}
public contains(fileName: string) {
return existsSync(join(this.pathToProject, fileName));
}

private get isCoveoProject() {
Expand Down
Loading