-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.js
More file actions
140 lines (113 loc) · 4.53 KB
/
Copy pathbuild.js
File metadata and controls
140 lines (113 loc) · 4.53 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
const ADDON_PATH = 'addons/hexagon_tilemaplayer';
const REPO_URL = 'https://github.com/Zehir/godot-hexagon-tile-map-layer';
const category_ids = {
"2D Tools": "1",
"3D Tools": "2",
"Shaders": "3",
"Materials": "4",
"Tools": "5",
"Scripts": "6",
"Misc": "7",
}
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
// Remove dist directory if it exists and create it
const DIST_PATH = 'dist';
if (fs.existsSync(DIST_PATH)) {
fs.rmSync(DIST_PATH, { recursive: true });
console.log(`Removed existing ${DIST_PATH} directory`);
}
fs.mkdirSync(DIST_PATH);
console.log(`Created ${DIST_PATH} directory`);
// Create .gdignore file in dist directory
fs.writeFileSync(path.join(DIST_PATH, '.gdignore'), '');
console.log('Created .gdignore file in dist directory');
// Function to add files recursively to zip
function addFilesToZip(zip, sourceDir, zipPath = '', excludes = []) {
const files = fs.readdirSync(sourceDir);
files.forEach(file => {
const filePath = path.join(sourceDir, file);
const zipFilePath = path.join(zipPath, file);
// Skip if path matches any exclude pattern
if (excludes.some(pattern => filePath.includes(pattern))) {
return;
}
if (fs.statSync(filePath).isDirectory()) {
addFilesToZip(zip, filePath, zipFilePath, excludes);
} else {
zip.addLocalFile(filePath, path.dirname(zipFilePath));
}
});
}
// Create archives
const addonArchiveName = `${packageJson.name}-${packageJson.version}`;
// Create addon archive
const addonZip = new AdmZip();
addFilesToZip(addonZip, ADDON_PATH, path.join(addonArchiveName, ADDON_PATH));
addonZip.writeZip(path.join(DIST_PATH, `${addonArchiveName}.zip`));
console.log(`Created archives in ${DIST_PATH}:`);
console.log(`- ${addonArchiveName}.zip`);
const download_url = `${REPO_URL}/releases/download/v${packageJson.version}/${addonArchiveName}.zip`;
// Function to parse README and extract description
function getDescriptionFromReadme() {
const readmeContent = fs.readFileSync('README.md', 'utf8');
let description = '';
let searchStart = 0;
// Find all text blocks between description markers
while (true) {
const descriptionStart = readmeContent.indexOf('<!-- description_start -->', searchStart);
if (descriptionStart === -1) break;
const contentStart = descriptionStart + '<!-- description_start -->'.length;
const descriptionEnd = readmeContent.indexOf('<!-- description_end -->', contentStart);
if (descriptionEnd === -1) break;
// Extract the text between the markers
let blockText = readmeContent.substring(contentStart, descriptionEnd).trim();
blockText = blockText.replaceAll("A\\*", 'A*');
// Remove Markdown links - format [text](url) - keep only the text part
blockText = blockText.replaceAll(/\[([^\]]+)\]\([^)]+\)/g, '$1');
// Remove HTML links - format <url>
blockText = blockText.replaceAll(/<https?:\/\/[^>]+>/g, '');
// Add this block to the combined description
if (description && blockText) {
description += '\n\n';
}
description += blockText;
// Move search position to continue looking for more blocks
searchStart = descriptionEnd + '<!-- description_end -->'.length;
}
// If we found description blocks, return them
if (description) {
return description;
}
}
const image_url = (name) => `${REPO_URL.replace('github.com', 'raw.githubusercontent.com')}/main/images/${name}.png`;
// Create asset template
const assetTemplate = {
"title": packageJson.displayName,
"description": getDescriptionFromReadme(),
"category_id": category_ids[packageJson.category],
"godot_version": packageJson.godotVersion,
"version_string": packageJson.version,
"cost": packageJson.license,
"download_provider": "Custom",
"download_commit": download_url,
"download_url": download_url,
"browse_url": REPO_URL,
"issues_url": `${REPO_URL}/issues`,
"icon_url": image_url("hexagon_tilemaplayer"),
"previews": [
{
"preview_id": "1",
"type": "image",
"link": image_url("cube_linedraw"),
},
],
};
// Write asset template to dist
fs.writeFileSync(
path.join(DIST_PATH, 'asset-template.json.hb'),
JSON.stringify(assetTemplate, null, 2)
);
console.log('Created asset template file in dist directory');