Skip to content

Commit b7e27f5

Browse files
committed
fix: Copy handlebars templates during build
1 parent 030d3e4 commit b7e27f5

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"bin",
1616
"README.md",
1717
"LICENSE",
18-
"package.json"
18+
"package.json",
19+
"CHANGELOG.md",
20+
"src/features/schema/templates"
1921
],
2022
"release": {
2123
"branches": [
@@ -55,7 +57,8 @@
5557
},
5658
"scripts": {
5759
"start": "node bin/parse-server-schema.js",
58-
"build": "rimraf ./dist && tsc --build --force"
60+
"build": "rimraf ./dist && tsc --build --force && node scripts/copy-templates.js",
61+
"copy-templates": "node scripts/copy-templates.js"
5962
},
6063
"bin": {
6164
"parse-server-schema": "bin/parse-server-schema.js"
@@ -80,4 +83,4 @@
8083
"@types/node": "^24.5.1",
8184
"semantic-release-export-data": "^1.1.1"
8285
}
83-
}
86+
}

scripts/copy-templates.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'fs';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
const projectRoot = path.resolve(__dirname, '..');
10+
11+
console.log('📁 Copying Handlebars templates to dist folder...');
12+
13+
const srcTemplatesDir = path.join(projectRoot, 'src', 'features', 'schema', 'templates');
14+
const distTemplatesDir = path.join(projectRoot, 'dist', 'features', 'schema', 'templates');
15+
16+
try {
17+
// Ensure destination directory exists
18+
fs.mkdirSync(distTemplatesDir, { recursive: true });
19+
20+
// Read all files in the templates directory
21+
const templateFiles = fs.readdirSync(srcTemplatesDir).filter(file => file.endsWith('.hbs'));
22+
23+
if (templateFiles.length === 0) {
24+
console.log('⚠️ No .hbs template files found in source directory');
25+
process.exit(0);
26+
}
27+
28+
// Copy each template file
29+
let copiedCount = 0;
30+
for (const file of templateFiles) {
31+
const srcPath = path.join(srcTemplatesDir, file);
32+
const distPath = path.join(distTemplatesDir, file);
33+
34+
fs.copyFileSync(srcPath, distPath);
35+
console.log(` ✅ Copied ${file}`);
36+
copiedCount++;
37+
}
38+
39+
console.log(`📋 Successfully copied ${copiedCount} Handlebars template(s) to dist folder`);
40+
} catch (error) {
41+
console.error('❌ Error copying templates:', error.message);
42+
process.exit(1);
43+
}

0 commit comments

Comments
 (0)