Skip to content

Commit bd33a97

Browse files
authored
Fix project generation issue on Windows (#5)
* Fix project generation issue on Windows Signed-off-by: Ryan Wang <[email protected]> * Add windows ci Signed-off-by: Ryan Wang <[email protected]> --------- Signed-off-by: Ryan Wang <[email protected]>
1 parent ff39189 commit bd33a97

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ on:
88
- main
99
jobs:
1010
ci:
11-
runs-on: ubuntu-24.04
11+
strategy:
12+
matrix:
13+
os: [ubuntu-24.04, windows-latest]
14+
runs-on: ${{ matrix.os }}
1215
steps:
1316
- uses: actions/checkout@v4
1417
- uses: halo-sigs/reusable-workflows/plugin-setup-env@v3

src/template-config.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
export const templateConfig = {
2-
templateFiles: [
3-
".gitignore.template",
4-
"build.gradle.template",
5-
"settings.gradle.template",
6-
"README.md.template",
7-
"src/main/resources/plugin.yaml.template",
8-
"src/main/java/Plugin.java.template",
9-
"src/test/java/PluginTest.java.template",
10-
11-
"ui/build.gradle.template",
12-
"ui/package.json.template",
13-
"ui/tsconfig.node.json.template",
14-
"ui/env.d.ts.template",
15-
],
16-
172
conditionalFiles: {
183
vite: ["ui/vite.config.ts"],
194
rsbuild: ["ui/rsbuild.config.ts"],

src/template-engine.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,18 @@ function getAllFiles(dir, basePath = "") {
5858
return files;
5959
}
6060

61-
/**
62-
* Check if file is a template file
63-
* @param {string} filePath - File path
64-
* @param {string[]} templateFiles - Template files list
65-
* @returns {boolean}
66-
*/
67-
function isTemplateFile(filePath, templateFiles) {
68-
return templateFiles.includes(filePath);
69-
}
70-
7161
/**
7262
* Check if file is a conditional file
7363
* @param {string} filePath - File path
7464
* @param {string[]} conditionalFiles - Conditional files list
7565
* @returns {boolean}
7666
*/
7767
function isConditionalFile(filePath, conditionalFiles) {
78-
return conditionalFiles.includes(filePath);
68+
const normalizedPath = filePath.replace(/\\/g, '/');
69+
return conditionalFiles.some(conditional => {
70+
const normalizedConditional = conditional.replace(/\\/g, '/');
71+
return normalizedPath === normalizedConditional;
72+
});
7973
}
8074

8175
/**
@@ -85,15 +79,21 @@ function isConditionalFile(filePath, conditionalFiles) {
8579
* @returns {boolean}
8680
*/
8781
function isExcludedConditionalFile(filePath, config) {
82+
const normalizedPath = filePath.replace(/\\/g, '/');
83+
8884
// Get all conditional files (including selected and unselected)
8985
const allConditionalFiles = Object.values(
9086
templateConfig.conditionalFiles,
91-
).flat();
87+
).flat().map(file => file.replace(/\\/g, '/'));
88+
89+
const selectedConditionalFiles = config.conditionalFiles.map(file =>
90+
file.replace(/\\/g, '/')
91+
);
9292

9393
// If it's a conditional file but not in current selected conditional files list, it should be excluded
9494
return (
95-
allConditionalFiles.includes(filePath) &&
96-
!config.conditionalFiles.includes(filePath)
95+
allConditionalFiles.includes(normalizedPath) &&
96+
!selectedConditionalFiles.includes(normalizedPath)
9797
);
9898
}
9999

@@ -137,8 +137,7 @@ async function processFile(filePath, projectPath, variables, config) {
137137
return;
138138
}
139139

140-
// Determine file type and process accordingly
141-
if (isTemplateFile(filePath, config.templateFiles)) {
140+
if (filePath.endsWith('.template')) {
142141
// Process template file
143142
await processTemplateFile(filePath, srcPath, projectPath, variables);
144143
} else if (isExcludedConditionalFile(filePath, config)) {

0 commit comments

Comments
 (0)