MCPcopy
hub / github.com/QwikDev/qwik / loadTemplates

Function loadTemplates

packages/qwik/src/cli/utils/templates.ts:8–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6let templates: TemplateSet[] | null = null;
7
8export 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
41export async function readTemplates(rootDir: string) {
42 const componentDir = join(rootDir, 'component');

Callers 3

runNewCommandFunction · 0.90
selectTemplateFunction · 0.90
printNewHelpFunction · 0.90

Calls 2

joinFunction · 0.85
readTemplatesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…