-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.js
274 lines (238 loc) · 8.36 KB
/
doc.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
const fs = require("fs");
const path = require("path");
const camelCasedMap = new Map();
function getFileWithTypeFromFolder(path, fileTypes){
const results = [];
const files = fs.readdirSync(path);
files.forEach((file) => {
const ext = getFileExtension(file);
if(fileTypes.includes(ext)){
results.push(file);
};
});
return results;
}
function getFileExtension(filename) {
return filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);
}
function getCoverImage() {
const exampleFolderPath = path.join(__dirname, "examples");
const images = getFileWithTypeFromFolder(exampleFolderPath, ["png", "gif", "jpeg"]);
for(let i = 0; i < images.length; i++) {
const imageName = images[i].split(".")[0];
if(imageName === "cover") {
return `<img src="./examples/${images[i]}" width="150" /><br>`;
}
}
return "<img src=\"./src/icon.svg\" width=\"100\" /><br>";
}
const config = require("./src/pluginConfig.js");
const readme = [];
readme.push(getCoverImage());
readme.push(`# ${config.name} <br>`);
readme.push(`${config.description} <br>`);
readme.push("<br>");
readme.push(`Author: ${config.author} <br>`);
if (config.website && config.website !== "" && config.website !== "https://www.construct.net") {
readme.push(`Website: ${config.website} <br>`)
}
if (config.addonUrl && config.addonUrl !== "") {
readme.push(`Addon Url: ${config.addonUrl} <br>`);
}
if(config.githubUrl && config.githubUrl !== "") {
readme.push(`Download Latest Version : [Version: ${config.version}](${config.githubUrl}/releases/latest) <br>`);
}
//add link to c3ide2-framework
readme.push(`<sub>Made using [c3ide2-framework](https://github.com/ConstructFund/c3ide2-framework) </sub><br>`);
readme.push(``);
readme.push(`## Table of Contents`);
readme.push(`- [Usage](#usage)`);
readme.push(`- [Examples Files](#examples-files)`);
readme.push(`- [Properties](#properties)`);
readme.push(`- [Actions](#actions)`);
readme.push(`- [Conditions](#conditions)`);
readme.push(`- [Expressions](#expressions)`);
readme.push(`---`);
readme.push(`## Usage`);
readme.push(`To build the addon, run the following commands:`);
readme.push(``);
readme.push(`\`\`\``);
readme.push(`npm i`);
readme.push(`node ./build.js`);
readme.push(`\`\`\``);
readme.push(``);
readme.push(`To run the dev server, run`);
readme.push(``);
readme.push(`\`\`\``);
readme.push(`npm i`);
readme.push(`node ./dev.js`);
readme.push(`\`\`\``);
readme.push(``);
readme.push(`The build uses the pluginConfig file to generate everything else.`);
readme.push(
`The main files you may want to look at would be instance.js and scriptInterface.js`
);
readme.push(``);
readme.push(`## Examples Files`);
const exampleFolderPath = path.join(__dirname, "examples");
if(fs.existsSync(exampleFolderPath)) {
//get all files in examples folder
const exampleFiles = getFileWithTypeFromFolder(exampleFolderPath, ["c3p"]);
const images = getFileWithTypeFromFolder(exampleFolderPath, ["png", "gif", "jpeg"]);
exampleFiles.forEach((file) => {
const fileName = file.split(".")[0];
readme.push(`- [${fileName}](./examples/${file})`);
//add images
images.forEach((image) => {
const imageName = image.split(".")[0];
readme.push(`</br>`);
//check if image contains the name of the example file
if (imageName.includes(fileName)) {
// display the a small version of the image on a new line
readme.push(`<img src="./examples/${image}" width="200" />`);
}
});
readme.push(`</br>`);
});
}
readme.push(``);
readme.push(`---`);
readme.push(`## Properties`);
readme.push(`| Property Name | Description | Type |`);
readme.push(`| --- | --- | --- |`);
config.properties.forEach((property) => {
readme.push(
`| ${property.name} | ${property.desc} | ${property.type} |`
);
});
readme.push(``);
// config.properties.forEach((property) => {
// readme.push(`### ${property.name}`);
// readme.push(`**Description:** <br> ${property.desc} </br>`);
// readme.push(`**Type:** <br> ${property.type}`);
// if (property.type === "combo") {
// readme.push(`**Options:**`);
// property.options.items.forEach((item) => {
// const key = Object.keys(item)[0];
// readme.push(`- ${key}: ${item[key]}`);
// });
// } else if (property.type === "link") {
// readme.push(`**Link Text:** ${property.linkText}`);
// }
// });
readme.push(``);
readme.push(`---`);
readme.push(`## Actions`);
readme.push(`| Action | Description | Params`);
readme.push(`| --- | --- | --- |`);
Object.keys(config.Acts).forEach((key) => {
const action = config.Acts[key];
let paramString = "";
if (action.params.length > 0) {
action.params.forEach((param) => {
paramString += `${param.name} *(${param.type})* <br>`;
});
}
readme.push(
`| ${action.listName} | ${action.description} | ${paramString} |`
);
});
readme.push(``);
// Object.keys(config.Acts).forEach((key) => {
// const action = config.Acts[key];
// readme.push(`### ${action.listName}`);
// readme.push(`**Description:** <br> ${action.description} </br>`);
// if (action.isAsync) {
// readme.push(`**Is Async:** <br> ${action.isAsync} </br>`);
// }
// if(action.params.length > 0){
// readme.push(`#### Parameters:`);
// // write parameters to indented table, with three columns (name, type, description)
// readme.push(`| Name | Type | Description |`);
// readme.push(`| --- | --- | --- |`);
// action.params.forEach((param) => {
// readme.push(
// `| ${param.name} | ${param.type} | ${param.desc} |`
// );
// });
// }
// });
readme.push(``);
readme.push(`---`);
readme.push(`## Conditions`);
readme.push(`| Condition | Description | Params`);
readme.push(`| --- | --- | --- |`);
Object.keys(config.Cnds).forEach((key) => {
const condition = config.Cnds[key];
let paramString = "";
if (condition.params.length > 0) {
condition.params.forEach((param) => {
paramString += `${param.name} *(${param.type})* <br>`;
});
}
readme.push(
`| ${condition.listName} | ${condition.description} | ${paramString} |`
);
});
readme.push(``);
// Object.keys(config.Cnds).forEach((key) => {
// const condition = config.Cnds[key];
// readme.push(`### ${condition.listName}`);
// readme.push(`**Description:** <br> ${condition.description} </br>`);
// if (condition.isTrigger) {
// readme.push(`**Is Trigger:** <br> ${condition.isTrigger} </br>`);
// }
// if(condition.islooping) {
// readme.push(`**Is Looping:** <br> ${condition.islooping} </br>`);
// }
// if(condition.params.length > 0) {
// readme.push(`#### Parameters:`);
// // write parameters to indented table, with three columns (name, type, description)
// readme.push(`| Name | Type | Description |`);
// readme.push(`| --- | --- | --- |`);
// condition.params.forEach((param) => {
// readme.push(
// `| ${param.name} | ${param.type} | ${param.desc} |`
// );
// });
// }
// });
readme.push(``);
readme.push(`---`);
readme.push(`## Expressions`);
readme.push(`| Expression | Description | Return Type | Params`);
readme.push(`| --- | --- | --- | --- |`);
Object.keys(config.Exps).forEach((key) => {
const expression = config.Exps[key];
let paramString = "";
if (expression.params.length > 0) {
expression.params.forEach((param) => {
paramString += `${param.name} *(${param.type})* <br>`;
});
}
readme.push(
`| ${key} | ${expression.description} | ${expression.returnType} | ${paramString} | `
);
});
readme.push(``);
// Object.keys(config.Exps).forEach((key) => {
// const expression = config.Exps[key];
// readme.push(`### ${key}`);
// readme.push(`**Description:** <br> ${expression.description} </br>`);
// readme.push(`**Return Type:** <br> ${expression.returnType} </br>`);
// if(expression.isVariadicParam) {
// readme.push(`**Is Variadic Param:** ${expression.isVariadicParam} </br>`);
// }
// if(expression.params.length > 0) {
// readme.push(`#### Parameters:`);
// // write parameters to indented table, with three columns (name, type, description)
// readme.push(`| Name | Type | Description |`);
// readme.push(`| --- | --- | --- |`);
// expression.params.forEach((param) => {
// readme.push(
// `| ${param.name} | ${param.type} | ${param.desc} |`
// );
// });
// }
// });
fs.writeFileSync(path.join(__dirname, "README.md"), readme.join("\n"));