Skip to content

Commit

Permalink
fix: datapack filenames should not contain path seperators
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeneos committed Aug 21, 2024
1 parent ca9c483 commit ec7b6d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/vlocity-deploy/src/export/datapackExpander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ export class DatapackExpander {
scope: context?.scope
};

const baseSourceKey = substringAfter(datapack.VlocityRecordSourceKey, '/').replace(/\/+/g, '_');
const baseSourceKey = substringAfter(datapack.VlocityRecordSourceKey, '/');
const fileNameFormat = this.definitions.getFileName(itemRef) ?? baseSourceKey;
const baseName = this.evalPathFormat(fileNameFormat, { context: datapack });

const folderFormat = this.definitions.getFolder(itemRef) ?? baseSourceKey;
const folder = path.join(
this.normalizePath(datapack.VlocityRecordSObjectType),
this.normalizeFileName(datapack.VlocityRecordSObjectType),
this.evalPathFormat(folderFormat, { context: datapack })
);

Expand Down Expand Up @@ -163,13 +163,13 @@ export class DatapackExpander {
const name = Array.isArray(format)
? format.map(f => f.startsWith('_') ? f.substring(1) : options?.context?.[f] ?? '').join('_')
: (options?.context ? formatString(format, options?.context) : format);
return this.normalizePath(name, options?.defaultExt);
return this.normalizeFileName(name, options?.defaultExt);
}

private normalizePath(path: string, extension?: string) {
private normalizeFileName(path: string, extension?: string) {
const normalized = path.trim()
.replace(/[\s\\/]+/g, '-')
.replace(/[^\s\w.\\/-]+/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-');
if (extension) {
return `${normalized}.${extension}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/vlocity-deploy/src/export/exportDefinitionStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { injectable } from "@vlocode/core";
import { merge, withDefaults } from "@vlocode/util";
import { merge } from "@vlocode/util";
import { ObjectRef } from "./datapackExporter";
import { DatapackExportDefinition, ExportFieldDefinition, ObjectFilter, ObjectRelationship } from "./exportDefinitions";

Expand Down Expand Up @@ -189,7 +189,7 @@ export class DatapackExportDefinitionStore {
}

public getFolder(item: ObjectRef) {
return this.get(item, 'folder');
return this.get(item, 'folderName');
}

public isAutoGeneratedMatchingKey(item: ObjectRef) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vlocity-deploy/src/export/exportDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface DatapackExportDefinition extends ExpandFileDefinition {
* ```
* All exported fields are written to this file in JSON format and '.json' is appended to the file name if no extension is provided.
*/
folder?: string | string[];
folderName?: string | string[];
/**
* Type of SObject to export
*/
Expand Down

0 comments on commit ec7b6d2

Please sign in to comment.