xref: /expo/tools/src/ProjectTemplates.ts (revision bb5069cd)
1import JsonFile from '@expo/json-file';
2import fs from 'fs-extra';
3import path from 'path';
4
5import { TEMPLATES_DIR } from './Constants';
6
7export type Template = {
8  name: string;
9  version: string;
10  path: string;
11};
12
13export async function getAvailableProjectTemplatesAsync(): Promise<Template[]> {
14  const templates = await fs.readdir(TEMPLATES_DIR);
15
16  return Promise.all<Template>(
17    templates.map(async (template) => {
18      const packageJson = await JsonFile.readAsync<Template>(
19        path.join(TEMPLATES_DIR, template, 'package.json')
20      );
21
22      return {
23        name: packageJson.name,
24        version: packageJson.version,
25        path: path.join(TEMPLATES_DIR, template),
26      };
27    })
28  );
29}
30