@trayio/generator 2.11.0 → 2.12.0
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.
|
@@ -3,6 +3,7 @@ import { Generator } from './Generator';
|
|
|
3
3
|
export declare class NodeFsGenerator implements Generator {
|
|
4
4
|
generate(templatePath: string, targetPath: string, values: Record<string, string>): TE.TaskEither<Error, undefined>;
|
|
5
5
|
private replacePlaceholdersInDir;
|
|
6
|
+
private renameParentDir;
|
|
6
7
|
private replacePlaceholdersInFile;
|
|
7
8
|
private replacePlaceholdersInContent;
|
|
8
9
|
private readStats;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeFsGenerator.d.ts","sourceRoot":"","sources":["../../src/generator/NodeFsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAOvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,eAAgB,YAAW,SAAS;IAChD,QAAQ,CACP,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"NodeFsGenerator.d.ts","sourceRoot":"","sources":["../../src/generator/NodeFsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAOvC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,qBAAa,eAAgB,YAAW,SAAS;IAChD,QAAQ,CACP,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC;IAyBlC,OAAO,CAAC,wBAAwB,CA0B9B;IAEF,OAAO,CAAC,eAAe,CAsCrB;IAEF,OAAO,CAAC,yBAAyB,CAa/B;IAEF,OAAO,CAAC,4BAA4B,CAUlC;IAEF,OAAO,CAAC,SAAS,CACiD;IAElE,OAAO,CAAC,OAAO,CAGZ;IAEH,OAAO,CAAC,QAAQ,CAGb;IAEH,OAAO,CAAC,SAAS,CASd;IAEH,OAAO,CAAC,MAAM,CASX;IAEH,OAAO,CAAC,IAAI,CAST;IAEH,OAAO,CAAC,KAAK,CAYV;CACH"}
|
|
@@ -47,6 +47,21 @@ class NodeFsGenerator {
|
|
|
47
47
|
return TE.left(new Error('Unknown file type. Template directory should contain either folders or files'));
|
|
48
48
|
})(direntList)), TE.map(() => undefined));
|
|
49
49
|
};
|
|
50
|
+
this.renameParentDir = (targetPath, values) => {
|
|
51
|
+
const regex = /\$(.*?)\$/g;
|
|
52
|
+
return (0, function_1.pipe)(this.readDir(targetPath), TE.chain((direntList) => TE.right(direntList.filter((dirent) => regex.test(dirent.name)))), TE.chain((direntList) => {
|
|
53
|
+
if (direntList.length === 0) {
|
|
54
|
+
return TE.right(targetPath);
|
|
55
|
+
}
|
|
56
|
+
if (direntList.length > 1) {
|
|
57
|
+
return TE.left(new Error('More than one parent directory found. This is not allowed'));
|
|
58
|
+
}
|
|
59
|
+
return TE.right(`${targetPath}/${direntList[0].name}`);
|
|
60
|
+
}), TE.chain((parentDirName) => {
|
|
61
|
+
const replacedParentDirName = this.replacePlaceholdersInContent(parentDirName, values);
|
|
62
|
+
return (0, function_1.pipe)(this.rename(parentDirName, replacedParentDirName), TE.map(() => replacedParentDirName));
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
50
65
|
this.replacePlaceholdersInFile = (filePath, values) => {
|
|
51
66
|
const targetPath = this.replacePlaceholdersInContent(filePath, values);
|
|
52
67
|
return (0, function_1.pipe)(this.rename(filePath, targetPath), TE.chain(() => this.readFile(targetPath)), TE.map((fileContent) => this.replacePlaceholdersInContent(fileContent, values)), TE.chain((replacedContent) => this.writeFile(targetPath, replacedContent)));
|
|
@@ -82,7 +97,7 @@ class NodeFsGenerator {
|
|
|
82
97
|
return unzip;
|
|
83
98
|
}
|
|
84
99
|
return TE.left(new Error('Unknown file type. Template path needs to be either a directory or a zip file'));
|
|
85
|
-
}), TE.chain(() => this.
|
|
100
|
+
}), TE.chain(() => this.renameParentDir(targetPath, values)), TE.chain((parentDirName) => this.replacePlaceholdersInDir(parentDirName, values)), TE.map(() => undefined));
|
|
86
101
|
}
|
|
87
102
|
}
|
|
88
103
|
exports.NodeFsGenerator = NodeFsGenerator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/generator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "Template based generator",
|
|
5
5
|
"author": "Tray.io",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@trayio/commons": "2.
|
|
14
|
+
"@trayio/commons": "2.12.0",
|
|
15
15
|
"extract-zip": "2.0.1",
|
|
16
16
|
"fs-extra": "11.1.0"
|
|
17
17
|
},
|