Skip to content

Commit 4fe6a12

Browse files
committed
addCategory for export with regex
1 parent c43e91d commit 4fe6a12

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@
475475
},
476476
"objectscript.export.category": {
477477
"description": "Specifies a category: CLS = classes; RTN = routines; CSP = csp files; OTH = other. Default is *",
478-
"type": "string",
478+
"type": ["string", "object"],
479479
"default": "*"
480480
},
481481
"objectscript.autoCompile": {

src/commands/export.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,37 @@ const filesFilter = (file: any) => {
1616
return true;
1717
};
1818

19+
const getCategory = (fileName: string, addCategory: {} | boolean): string => {
20+
const fileExt = fileName
21+
.split(".")
22+
.pop()
23+
.toLowerCase();
24+
if (typeof addCategory === "object") {
25+
for (const pattern of Object.keys(addCategory)) {
26+
if (new RegExp(`^${pattern}$`).test(fileName)) {
27+
return addCategory[pattern];
28+
}
29+
if (addCategory[fileExt]) return addCategory[fileExt];
30+
if (addCategory["*"]) return addCategory["*"];
31+
}
32+
return null;
33+
}
34+
switch (fileExt) {
35+
case "cls":
36+
return "CLS";
37+
case "int":
38+
case "inc":
39+
case "mac":
40+
return "RTN";
41+
default:
42+
return "OTH";
43+
}
44+
};
45+
1946
export const getFileName = (folder: string, name: string, split: boolean, addCategory: boolean): string => {
2047
const fileNameArray: string[] = name.split(".");
2148
const fileExt = fileNameArray.pop().toLowerCase();
22-
const cat =
23-
typeof addCategory === "object" && addCategory[fileExt]
24-
? addCategory[fileExt]
25-
: addCategory
26-
? fileExt === "cls"
27-
? "CLS"
28-
: ["int", "mac", "inc"].includes(fileExt)
29-
? "RTN"
30-
: "OTH"
31-
: null;
49+
const cat = addCategory ? getCategory(name, addCategory) : null;
3250
if (split) {
3351
const fileName = [folder, cat, ...fileNameArray].filter(notNull).join(path.sep);
3452
return [fileName, fileExt].join(".");

0 commit comments

Comments
 (0)