Skip to content

Commit

Permalink
Fix problem with project path resolution on *nix machines
Browse files Browse the repository at this point in the history
Use both expansion path as well as project path avoiding APEX file load errors (if project path is correctly configured)
  • Loading branch information
Codeneos committed Sep 24, 2019
1 parent 2dc5d0d commit 23f749f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog Vlocode

## [0.11.5] - 2019-09-23
- Fix problem with project path resolution on *nix machines
- Use both expansion path as well as project path avoiding APEX file load errors (if project path is correctly configured)

## [0.11.4] - 2019-08-16
- Update clone and rename Datapack features
- Now correctly regenerate all Global Keys for the parent and the child records during Datapack cloning
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vlocode",
"displayName": "Vlocode",
"description": "Vlocity datapack development and deployment extension",
"version": "0.11.4",
"version": "0.11.5",
"license": "MIT",
"icon": "resources/icon.png",
"author": {
Expand Down
13 changes: 1 addition & 12 deletions src/datapackUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,7 @@ export function getDatapackManifestKey(datapackHeaderPath: string) : { datapackT
*/
export function getExportProjectFolder(datapackHeaderPath: string) : string {
const dirname = path.dirname(datapackHeaderPath);
const lastPathParts = dirname.split(/\/|\\/gm);
return path.join(...lastPathParts.slice(0, lastPathParts.length - 2));
}

/**
* Resolve the project folder of the datapack assuming the standard 2-level structure
* @param file Datapack header file path
*/
export function getDatapackDependencies(datapackHeaderPath: string) : string {
const dirname = path.dirname(datapackHeaderPath);
const lastPathParts = dirname.split(/\/|\\/gm);
return path.join(...lastPathParts.slice(0, lastPathParts.length - 2));
return path.join(dirname, '..', '..');
}

/**
Expand Down
16 changes: 12 additions & 4 deletions src/services/vlocityDatapackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from 'path';
import * as yaml from 'js-yaml';
import * as fs from 'fs-extra';
import ServiceContainer, { default as s, container } from 'serviceContainer';
import { existsAsync, groupBy, mapAsync, stringEquals } from '../util';
import { existsAsync, groupBy, mapAsync, stringEquals, getObjectValues } from '../util';
import { LogManager } from 'loggers';
import { VlocityDatapack } from 'models/datapack';
import VlocodeConfiguration from 'models/vlocodeConfiguration';
Expand Down Expand Up @@ -211,6 +211,10 @@ export default class VlocityDatapackService implements vscode.Disposable {
public async isVlocityPackageInstalled() : Promise<boolean> {
return (await this.salesforceService.isPackageInstalled(/^vlocity/i)) !== undefined;
}

private resolvedProjectPath() {
return path.resolve(this.config.projectPath || '.');
}

/**
* @deprecated Use `container.get(DatapackLoader).loadFrom(...)` instead
Expand Down Expand Up @@ -240,12 +244,14 @@ export default class VlocityDatapackService implements vscode.Disposable {

public async deploy(...datapackHeaders: string[]) : Promise<DatapackResultCollection> {
const headersByProject = groupBy(datapackHeaders, header => getExportProjectFolder(header));
const projectPath = this.resolvedProjectPath();

const results = await mapAsync(Object.keys(headersByProject), projectFolder => {
const deployManifest = headersByProject[projectFolder].map(header => getDatapackManifestKey(header).key);
return this.runCommand('Deploy', {
manifest: deployManifest,
projectPath: projectFolder,
projectPath: projectPath,
expansionPath: path.relative(projectPath, projectFolder),
activate: this.config.autoActivate,
delete: true,
compileOnBuild: this.config.compileOnBuild
Expand All @@ -271,9 +277,11 @@ export default class VlocityDatapackService implements vscode.Disposable {
public async export(entries: ObjectEntry[], exportFolder: string, maxDepth: number = 0) : Promise<DatapackResultCollection> {
const exportQueries = await this.createExportQueries(entries.filter(e => !e.id));
const exportManifest = this.createExportManifest(<ObjectEntryWithId[]>entries.filter(e => !!e.id));
const projectPath = this.resolvedProjectPath();
return this.runCommand('Export',{
queries: exportQueries,
projectPath: exportFolder,
projectPath: projectPath,
expansionPath: path.relative(projectPath, exportFolder),
fullManifest: exportManifest,
skipQueries: exportQueries.length == 0,
maxDepth: maxDepth,
Expand Down Expand Up @@ -318,7 +326,7 @@ export default class VlocityDatapackService implements vscode.Disposable {

private async datapacksJobAsync(command: vlocity.actionType, jobInfo : vlocity.JobInfo) : Promise<vlocity.VlocityJobResult> {
// collect and create job optipns
const localOptions = { projectPath: this.config.projectPath || '.' };
const localOptions = { projectPath: this.resolvedProjectPath() };
const customOptions = await this.getCustomJobOptions();
const jobOptions = Object.assign({}, customOptions, this.config, localOptions, jobInfo);

Expand Down
22 changes: 21 additions & 1 deletion src/test/core/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'mocha';

import * as vscode from 'vscode';
import vlocityDatapackService, * as vds from '../../services/vlocityDatapackService';
import { sanitizePath, formatString, groupBy, evalExpr, filterAsyncParallel } from '../../util';
import { sanitizePath, formatString, groupBy, evalExpr, filterAsyncParallel, getObjectValues } from '../../util';

describe('util', () => {

Expand Down Expand Up @@ -70,4 +70,24 @@ describe('util', () => {
expect(result['3']).to.deep.equal([list[4]]);
});
});

describe('#getObjectValues', () => {
it("should get values from array", function() {
const obj = [ 'foo', ['bar'] ];
const result = getObjectValues(obj);
expect(result).to.deep.equal(['foo', 'bar']);
});
it("should get values from object", function() {
const obj = { a: 'foo', bar: { b: 'bar' } };
const result = getObjectValues(obj);
expect(result).to.deep.equal(['foo', 'bar']);
});
it("should not get values beyond max depth", function() {
const obj = { a: 'foo', bar: { b: 'bar' }};
const result = getObjectValues(obj, 0);
expect(result).to.deep.equal(['foo']);
});
});

//getObjectValues
});
19 changes: 18 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,21 @@ export function stringEquals(a : string, b: string, insensitive?: boolean) : boo
return false;
}


/**
* Get all primitive non-object values in the specified object hiearchy up to the specified depth.
* @param obj Object from which to get the values
* @param depth Max object depth to go down the tree
*/
export function getObjectValues(obj: Object, depth = -1) : any[] {
let properties = [];
Object.keys(obj).forEach(key => {
if (typeof obj[key] === 'object') {
if (depth != 0) {
properties.push(...getObjectValues(obj[key], depth-1));
}
} else {
properties.push(obj[key]);
}
});
return properties;
}
2 changes: 2 additions & 0 deletions types/vlocity/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ declare module 'vlocity' {
printJobStatus(jobInfo: JobInfo) : void;
overrideExpandedDefinition(overrides : any) : void;
isGuaranteedParentKey(parentKey : any) : boolean;
loadApex(projectPath: string, filePath: string) : string;
runApex(projectPath: string, filePaths: string, currentContextData: any) : Promise<void>
}

export class UtilityService {
Expand Down

0 comments on commit 23f749f

Please sign in to comment.