Skip to content

Commit c324cfd

Browse files
committed
feat: support .stpl parse
Signed-off-by: zxypro1 <1018995004@qq.com>
1 parent 9e3151e commit c324cfd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

packages/load-application/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@serverless-devs/load-application",
3-
"version": "0.0.15",
3+
"version": "0.0.16-beta.1",
44
"description": "load application for serverless-devs",
55
"main": "lib/index.js",
66
"scripts": {

packages/load-application/src/v3.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,35 @@ class LoadApplication {
9595
* 7. 解析 s.yaml里的 name 字段
9696
*/
9797
this.parseAppName(templateData as string);
98+
/**
99+
* 8. 解析目录下所有后缀为.stpl的文件
100+
*/
101+
await this.parseStpl(this.filePath);
98102
/**
99-
* 8. 最后的动作, 比如:删除临时文件夹
103+
* 9. 最后的动作, 比如:删除临时文件夹
100104
*/
101105
await this.final();
102106
return this.filePath;
103107
}
104108

109+
// art-template解析目录下所有后缀为.stpl的文件
110+
private async parseStpl(dirPath: string) {
111+
const allFiles = fs.readdirSync(dirPath);
112+
for (const file of allFiles) {
113+
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
114+
await this.parseStpl(path.join(dirPath, file));
115+
continue;
116+
}
117+
if (file.endsWith('.stpl')) {
118+
const filePath = path.join(dirPath, file);
119+
const newData = this.doArtTemplate(filePath);
120+
fs.writeFileSync(filePath, newData, 'utf-8');
121+
// 删除.stpl后缀
122+
fs.renameSync(filePath, filePath.replace('.stpl', ''));
123+
}
124+
}
125+
}
126+
105127
private async check() {
106128
if (this.options.y) return true;
107129
if (isCiCdEnvironment()) return true;

0 commit comments

Comments
 (0)