-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.config.js
64 lines (62 loc) · 1.98 KB
/
template.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* This file is a configuration file generated by the `Template` extension on `vscode`
* @see https://marketplace.visualstudio.com/items?itemName=yongwoo.template
*/
module.exports = {
// You can change the template path to another path
templateRootPath: "./.templates",
// After copying the template file the `replaceFileTextFn` function is executed
/**
*
* @param {string} fileText
* @param {string} templateName
* @param {any} utils
*/
replaceFileTextFn: (fileText, templateName, utils) => {
// @see https://www.npmjs.com/package/change-case
const { changeCase } = utils;
let templateNameWithoutSuffix = templateName;
if (templateName.lastIndexOf(".") > templateName.lastIndexOf("/")) {
templateNameWithoutSuffix = templateName.substring(
0,
templateName.lastIndexOf(".")
);
}
// You can change the text in the file
return fileText
.replace(/__templateName__/g, templateNameWithoutSuffix)
.replace(
/__templateNameToCamelCase__/g,
changeCase.camelCase(templateNameWithoutSuffix)
)
.replace(
/__templateNameToPascalCase__/g,
changeCase.pascalCase(templateNameWithoutSuffix)
)
.replace(
/__templateNameToParamCase__/g,
changeCase.paramCase(templateNameWithoutSuffix)
);
},
renameFileFn: (fileName, templateName, utils) => {
if (
!fileName
.split("/")
.at(-1)
.includes(".")
) {
const l = templateName.split("/").at(-1);
if (l.includes(".")) {
fileName += l.substring(l.lastIndexOf("."));
}
}
const { path } = utils;
const { base } = path.parse(fileName);
return base.replace(/__templateName__/gm, templateName);
},
renameSubDirectoriesFn: (directoryName, templateName, _utils) => {
const { changeCase } = _utils;
const newDirectoryName = changeCase.paramCase(templateName);
return directoryName.replace(/__templateName__/g, newDirectoryName);
},
};