|
43 | 43 | Templates[name] = await metadata.template({__templates, name, plugins, logger}) |
44 | 44 | } |
45 | 45 | //Reorder keys |
46 | | - const {classic, repository, markdown, community, ...templates} = Templates |
47 | | - Templates = {classic, repository, ...templates, markdown, community} |
| 46 | + const {community, ...templates} = Templates |
| 47 | + Templates = {...Object.fromEntries(Object.entries(templates).sort(([_an, a], [_bn, b]) => (a.index ?? Infinity) - (b.index ?? Infinity))), community} |
48 | 48 |
|
49 | 49 | //Packaged metadata |
50 | 50 | const packaged = JSON.parse(`${await fs.promises.readFile(__package)}`) |
|
254 | 254 | metadata.template = async function({__templates, name, plugins, logger}) { |
255 | 255 | try { |
256 | 256 | //Load meta descriptor |
257 | | - const raw = `${await fs.promises.readFile(path.join(__templates, name, "README.md"), "utf-8")}` |
| 257 | + const raw = fs.existsSync(path.join(__templates, name, "metadata.yml")) ? `${await fs.promises.readFile(path.join(__templates, name, "metadata.yml"), "utf-8")}` : "" |
| 258 | + const readme = `${await fs.promises.readFile(path.join(__templates, name, "README.md"), "utf-8")}` |
| 259 | + const meta = yaml.load(raw) ?? {} |
258 | 260 |
|
259 | 261 | //Compatibility |
260 | 262 | const partials = path.join(__templates, name, "partials") |
|
269 | 271 |
|
270 | 272 | //Result |
271 | 273 | return { |
272 | | - name:raw.match(/^### (?<name>[\s\S]+?)\n/)?.groups?.name?.trim(), |
| 274 | + name:meta.name ?? readme.match(/^### (?<name>[\s\S]+?)\n/)?.groups?.name?.trim(), |
| 275 | + index:meta.index ?? null, |
| 276 | + formats:meta.formats ?? null, |
| 277 | + supports:meta.supports ?? null, |
273 | 278 | readme:{ |
274 | | - demo:raw.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? (name === "community" ? '<td align="center" colspan="2">See <a href="/source/templates/community/README.md">documentation</a> 🌍</td>' : "<td></td>"), |
| 279 | + demo:readme.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? (name === "community" ? '<td align="center" colspan="2">See <a href="/source/templates/community/README.md">documentation</a> 🌍</td>' : "<td></td>"), |
275 | 280 | compatibility:{...compatibility, base:true}, |
276 | 281 | }, |
| 282 | + check({q, account = "bypass", format = null}) { |
| 283 | + //Support check |
| 284 | + if (account !== "bypass") { |
| 285 | + const context = q.repo ? "repository" : account |
| 286 | + if ((Array.isArray(this.supports))&&(!this.supports.includes(context))) |
| 287 | + throw new Error(`not supported for: ${context}`) |
| 288 | + } |
| 289 | + //Format check |
| 290 | + if ((format)&&(Array.isArray(this.formats))&&(!this.formats.includes(format))) |
| 291 | + throw new Error(`not supported for: ${format}`) |
| 292 | + }, |
277 | 293 | } |
278 | 294 | } |
279 | 295 | catch (error) { |
|
0 commit comments