()
| 6 | let templates: TemplateSet[] | null = null; |
| 7 | |
| 8 | export async function loadTemplates() { |
| 9 | if (!templates) { |
| 10 | const allTemplates: TemplateSet[] = []; |
| 11 | |
| 12 | const templatesDir = join(__dirname, 'templates'); |
| 13 | const templatesDirNames = await fs.promises.readdir(templatesDir); |
| 14 | |
| 15 | await Promise.all( |
| 16 | templatesDirNames.map(async (templatesDirName) => { |
| 17 | const dir = join(templatesDir, templatesDirName); |
| 18 | const files = await readTemplates(dir); |
| 19 | const template = { id: templatesDirName, ...files }; |
| 20 | allTemplates.push(template); |
| 21 | }) |
| 22 | ); |
| 23 | |
| 24 | // Sort qwik templates first so they can be overridden, then alphabetical |
| 25 | allTemplates.sort((a, b) => { |
| 26 | if (a.id === 'qwik') { |
| 27 | return -1; |
| 28 | } else if (b.id === 'qwik') { |
| 29 | return 1; |
| 30 | } |
| 31 | |
| 32 | return a.id > b.id ? 1 : -1; |
| 33 | }); |
| 34 | |
| 35 | templates = allTemplates; |
| 36 | } |
| 37 | |
| 38 | return templates; |
| 39 | } |
| 40 | |
| 41 | export async function readTemplates(rootDir: string) { |
| 42 | const componentDir = join(rootDir, 'component'); |
no test coverage detected
searching dependent graphs…