@ds-sfdc/sfparty 1.4.8 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/fileUtils.js +23 -0
- package/src/party/combine.js +15 -0
package/package.json
CHANGED
package/src/lib/fileUtils.js
CHANGED
|
@@ -4,21 +4,36 @@ import * as path from 'path'
|
|
|
4
4
|
import * as yaml from 'js-yaml'
|
|
5
5
|
import { Parser } from 'xml2js'
|
|
6
6
|
|
|
7
|
+
String.prototype.replaceSpecialChars = function () {
|
|
8
|
+
return this.replace(/\*/g, '\u002a')
|
|
9
|
+
.replace(/\?/g, '\u003f')
|
|
10
|
+
.replace(/</g, '\u003c')
|
|
11
|
+
.replace(/>/g, '\u003e')
|
|
12
|
+
.replace(/"/g, '\u0022')
|
|
13
|
+
.replace(/\|/g, '\u007c')
|
|
14
|
+
.replace(/\\/g, '\u005c')
|
|
15
|
+
.replace(/:/g, '\u003a')
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
export function directoryExists({ dirPath, fs }) {
|
|
19
|
+
dirPath = dirPath.replaceSpecialChars()
|
|
8
20
|
return fs.existsSync(dirPath) && fs.statSync(dirPath).isDirectory()
|
|
9
21
|
}
|
|
10
22
|
|
|
11
23
|
export function fileExists({ filePath, fs }) {
|
|
24
|
+
filePath = filePath.replaceSpecialChars()
|
|
12
25
|
return fs.existsSync(filePath) && fs.statSync(filePath).isFile()
|
|
13
26
|
}
|
|
14
27
|
|
|
15
28
|
export function createDirectory(dirPath, fsTmp = fs) {
|
|
29
|
+
dirPath = dirPath.replaceSpecialChars()
|
|
16
30
|
if (!fsTmp.existsSync(dirPath)) {
|
|
17
31
|
fsTmp.mkdirSync(dirPath, { recursive: true })
|
|
18
32
|
}
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
export function deleteDirectory(dirPath, recursive = false, fsTmp = fs) {
|
|
36
|
+
dirPath = dirPath.replaceSpecialChars()
|
|
22
37
|
if (!directoryExists({ dirPath, fs: fsTmp })) {
|
|
23
38
|
return false
|
|
24
39
|
} else {
|
|
@@ -39,6 +54,7 @@ export function deleteDirectory(dirPath, recursive = false, fsTmp = fs) {
|
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
export function getFiles(dirPath, filter = undefined, fsTmp = fs) {
|
|
57
|
+
dirPath = dirPath.replaceSpecialChars()
|
|
42
58
|
const filesList = []
|
|
43
59
|
if (directoryExists({ dirPath, fs: fsTmp })) {
|
|
44
60
|
fsTmp.readdirSync(dirPath).forEach((file) => {
|
|
@@ -62,6 +78,7 @@ export function getFiles(dirPath, filter = undefined, fsTmp = fs) {
|
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
export function getDirectories(dirPath, fsTmp = fs) {
|
|
81
|
+
dirPath = dirPath.replaceSpecialChars()
|
|
65
82
|
if (directoryExists({ dirPath, fs: fsTmp })) {
|
|
66
83
|
return fsTmp
|
|
67
84
|
.readdirSync(dirPath, { withFileTypes: true })
|
|
@@ -73,6 +90,7 @@ export function getDirectories(dirPath, fsTmp = fs) {
|
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
export function deleteFile(filePath, fsTmp = fs) {
|
|
93
|
+
filePath = filePath.replaceSpecialChars()
|
|
76
94
|
if (!fileExists({ filePath, fs: fsTmp })) {
|
|
77
95
|
return false
|
|
78
96
|
} else {
|
|
@@ -81,6 +99,7 @@ export function deleteFile(filePath, fsTmp = fs) {
|
|
|
81
99
|
}
|
|
82
100
|
|
|
83
101
|
export function fileInfo(filePath, fsTmp = fs) {
|
|
102
|
+
filePath = filePath.replaceSpecialChars()
|
|
84
103
|
return {
|
|
85
104
|
dirname: path.join(path.dirname(filePath)), //something/folder/example
|
|
86
105
|
basename: path.basename(filePath, path.extname(filePath)), //example
|
|
@@ -100,6 +119,7 @@ export function saveFile(
|
|
|
100
119
|
fsTmp = fs,
|
|
101
120
|
) {
|
|
102
121
|
try {
|
|
122
|
+
fileName = fileName.replaceSpecialChars()
|
|
103
123
|
switch (format) {
|
|
104
124
|
case 'json':
|
|
105
125
|
let jsonString = JSON.stringify(json, null, '\t')
|
|
@@ -119,6 +139,7 @@ export function saveFile(
|
|
|
119
139
|
|
|
120
140
|
export function readFile(filePath, convert = true, fsTmp = fs) {
|
|
121
141
|
try {
|
|
142
|
+
filePath = filePath.replaceSpecialChars()
|
|
122
143
|
let result = undefined
|
|
123
144
|
if (fileExists({ filePath, fs: fsTmp })) {
|
|
124
145
|
const data = fsTmp.readFileSync(filePath, {
|
|
@@ -167,6 +188,7 @@ export function writeFile(
|
|
|
167
188
|
fsTmp = fs,
|
|
168
189
|
) {
|
|
169
190
|
try {
|
|
191
|
+
fileName = fileName.replaceSpecialChars()
|
|
170
192
|
// write data to the file
|
|
171
193
|
fsTmp.writeFileSync(fileName, data)
|
|
172
194
|
|
|
@@ -188,6 +210,7 @@ export function find(filename, root, fsTmp = fs) {
|
|
|
188
210
|
root = root || process.cwd()
|
|
189
211
|
|
|
190
212
|
if (!filename) throw new Error('filename is required')
|
|
213
|
+
filename = filename.replaceSpecialChars()
|
|
191
214
|
|
|
192
215
|
if (filename.indexOf('/') !== -1 || filename === '..') {
|
|
193
216
|
throw new Error('filename must be just a filename and not a path')
|
package/src/party/combine.js
CHANGED
|
@@ -22,6 +22,7 @@ export class Combine {
|
|
|
22
22
|
#fileName = {
|
|
23
23
|
fullName: undefined,
|
|
24
24
|
shortName: undefined,
|
|
25
|
+
profileName: undefined,
|
|
25
26
|
}
|
|
26
27
|
#errorMessage = ''
|
|
27
28
|
#frameIndex = 0
|
|
@@ -469,6 +470,20 @@ export class Combine {
|
|
|
469
470
|
return true
|
|
470
471
|
}
|
|
471
472
|
let result = fileUtils.readFile(fileObj.fullName)
|
|
473
|
+
if (
|
|
474
|
+
fileObj.fullName ==
|
|
475
|
+
path.join(
|
|
476
|
+
that.sourceDir,
|
|
477
|
+
that.metaDir,
|
|
478
|
+
`main.${global.format}`,
|
|
479
|
+
) &&
|
|
480
|
+
that.#type == 'profile'
|
|
481
|
+
) {
|
|
482
|
+
that.#fileName.profileName = path.join(
|
|
483
|
+
that.targetDir,
|
|
484
|
+
result.main.fullName + `.${that.#type}-meta.xml`,
|
|
485
|
+
)
|
|
486
|
+
}
|
|
472
487
|
|
|
473
488
|
// if split by object we need to add object back to values
|
|
474
489
|
if (
|