MCPcopy Index your code
hub / github.com/resend/react-email / init

Function init

packages/create-email/src/index.js:38–90  ·  view source on GitHub ↗
(name, { tag })

Source from the content-addressed store, hash-verified

36};
37
38const init = async (name, { tag }) => {
39 let projectPath = name;
40
41 if (!projectPath) {
42 projectPath = path.join(process.cwd(), 'react-email-starter');
43 }
44
45 if (typeof projectPath === 'string') {
46 projectPath = projectPath.trim();
47 }
48
49 const templatePath = path.resolve(dirname, '../template');
50 const resolvedProjectPath = path.resolve(projectPath);
51
52 if (fse.existsSync(resolvedProjectPath)) {
53 console.error(`Project called ${projectPath} already exists!`);
54 process.exit(1);
55 }
56
57 const spinner = ora({
58 text: 'Preparing files...\n',
59 }).start();
60
61 fse.copySync(templatePath, resolvedProjectPath, {
62 recursive: true,
63 });
64 const templatePackageJsonPath = path.resolve(
65 resolvedProjectPath,
66 './package.json',
67 );
68 const templatePackageJson = fse.readFileSync(templatePackageJsonPath, 'utf8');
69 fse.writeFileSync(
70 templatePackageJsonPath,
71 templatePackageJson.replaceAll(
72 'INSERT_REACT_EMAIL_VERSION',
73 await getLatestVersionOfTag('react-email', tag),
74 ),
75 'utf8',
76 );
77
78 spinner.stopAndPersist({
79 symbol: logSymbols.success,
80 text: 'React Email Starter files ready',
81 });
82
83 console.info(
84 await tree(resolvedProjectPath, 4, (dirent) => {
85 return !path
86 .join(dirent.parentPath, dirent.name)
87 .includes('node_modules');
88 }),
89 );
90};
91
92new Command()
93 .name(packageJson.name)

Callers

nothing calls this directly

Calls 4

treeFunction · 0.90
getLatestVersionOfTagFunction · 0.85
startMethod · 0.65
errorMethod · 0.45

Tested by

no test coverage detected