Skip to content

Commit 8efeed3

Browse files
committed
Added csvWriteFleDelimiter, csvReadFileDelimiter
1 parent c546b9d commit 8efeed3

3 files changed

Lines changed: 41 additions & 28 deletions

File tree

src/modules/commands_processors/runCommand.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import 'reflect-metadata';
9-
import 'es6-shim';
108

11-
import { plainToClass } from 'class-transformer';
129
import * as fs from 'fs';
10+
import * as models from '../models';
1311
import * as path from 'path';
14-
12+
import IPluginInfo from '../models/common_models/IPluginInfo';
1513
import { ADDON_EVENTS } from '../components/common_components/enumerations';
14+
import { CommandInitializationError } from '../models/common_models/errors';
15+
import { Common } from '../components/common_components/common';
16+
import { CONSTANTS } from '../components/common_components/statics';
17+
import { plainToClass } from 'class-transformer';
18+
import 'reflect-metadata';
19+
import 'es6-shim';
1620
import {
1721
Logger,
1822
RESOURCES,
1923
} from '../components/common_components/logger';
20-
import { CONSTANTS } from '../components/common_components/statics';
21-
import * as models from '../models';
2224
import {
2325
MigrationJob as Job,
2426
ScriptObjectSet,
2527
} from '../models';
26-
import { CommandInitializationError } from '../models/common_models/errors';
27-
import IPluginInfo from '../models/common_models/IPluginInfo';
2828

2929
/**
3030
* SFDMU:RUN CLI command
@@ -127,6 +127,8 @@ export class RunCommand {
127127
this.workingJson = JSON.stringify(jsonObject);
128128
jsonObject.objects = [];
129129
this.script = plainToClass(models.Script, jsonObject);
130+
this.setupGlobalParameters();
131+
130132
} catch (ex: any) {
131133
throw new CommandInitializationError(this.logger.getResourceString(RESOURCES.incorrectExportJsonFormat, ex.message));
132134
}
@@ -135,6 +137,11 @@ export class RunCommand {
135137

136138
}
137139

140+
setupGlobalParameters() {
141+
Common.csvReadFileDelimiter = this.script.csvReadFileDelimiter;
142+
Common.csvWriteFileDelimiter = this.script.csvWriteFileDelimiter;
143+
}
144+
138145

139146
/**
140147
* Setup the Command

src/modules/components/common_components/common.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const createCsvStringifier = require('csv-writer').createObjectCsvStringifier;
6161
export class Common {
6262

6363
static logger: Logger;
64+
static csvReadFileDelimiter: ',' | ';' = ",";
65+
static csvWriteFileDelimiter: ',' | ';' = ",";
6466

6567
/**
6668
* @static Splits array to multiple chunks by max chunk size
@@ -716,6 +718,7 @@ export class Common {
716718
input = input.replace(/^\uFEFF/, '');
717719
const records = parse(input, {
718720
columns: ___columns,
721+
delimiter: Common.csvReadFileDelimiter,
719722
skip_empty_lines: true,
720723
skip_lines_with_error: true,
721724
cast: ___csvCast
@@ -819,6 +822,7 @@ export class Common {
819822
return;
820823
}
821824
const csvWriter = createCsvWriter({
825+
fieldDelimiter: Common.csvWriteFileDelimiter,
822826
header: (columns || Object.keys(array[0])).map(x => {
823827
return {
824828
id: x,
@@ -1086,15 +1090,15 @@ export class Common {
10861090
return temp.map(el => el.trim()).filter(el => el.length > 0);
10871091
}
10881092

1089-
/**
1090-
* Extracts QHERE clause from the query string
1091-
*
1092-
* @static
1093-
* @param {string} query The query to process (SELECT Name, a__c FROM Account WHERE b__c = 'test')
1094-
* @return {*} {string} Dry WHERE clause string (b__c = 'test')
1095-
* @memberof Common
1096-
*/
1097-
public static extractWhereClause(query: string): string {
1093+
/**
1094+
* Extracts QHERE clause from the query string
1095+
*
1096+
* @static
1097+
* @param {string} query The query to process (SELECT Name, a__c FROM Account WHERE b__c = 'test')
1098+
* @return {*} {string} Dry WHERE clause string (b__c = 'test')
1099+
* @memberof Common
1100+
*/
1101+
public static extractWhereClause(query: string): string {
10981102
if ((query || '').match(/WHERE/i)) {
10991103
return query.match(/^.*?WHERE.*?(.+?(?=LIMIT|OFFSET|GROUP|ORDER|$))/i)[1].trim();
11001104
}
@@ -1758,17 +1762,17 @@ public static extractWhereClause(query: string): string {
17581762
return entryNames.map(name => enumType[name] as ValType);
17591763
}
17601764

1761-
/**
1762-
* Creates a time delay
1763-
*
1764-
* @static
1765-
* @param {number} time The delay length in ms
1766-
* @return {*} {Promise<void>}
1767-
* @memberof Utils
1768-
*/
1769-
static async delayAsync(time: number): Promise<void> {
1770-
return new Promise(resolve => setTimeout(resolve, time));
1771-
}
1765+
/**
1766+
* Creates a time delay
1767+
*
1768+
* @static
1769+
* @param {number} time The delay length in ms
1770+
* @return {*} {Promise<void>}
1771+
* @memberof Utils
1772+
*/
1773+
static async delayAsync(time: number): Promise<void> {
1774+
return new Promise(resolve => setTimeout(resolve, time));
1775+
}
17721776

17731777

17741778
}

src/modules/models/script_models/script.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export default class Script implements IAppScript, ISfdmuRunScript {
9696
simulationMode: boolean = false;
9797

9898
proxyUrl: string;
99+
csvReadFileDelimiter: ',' | ';' = ",";
100+
csvWriteFileDelimiter: ',' | ';' = ",";
99101

100102
binaryDataCache: DATA_CACHE_TYPES = DATA_CACHE_TYPES.InMemory;
101103
sourceRecordsCache: DATA_CACHE_TYPES = DATA_CACHE_TYPES.InMemory;

0 commit comments

Comments
 (0)