Skip to content

Commit 53c200b

Browse files
committed
lint
1 parent b917277 commit 53c200b

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

packages/create-email/src/index.js

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
#!/usr/bin/env node
22

3-
import path from "node:path";
4-
import { fileURLToPath } from "node:url";
5-
import { Command } from "commander";
6-
import fse from "fs-extra";
7-
import logSymbols from "log-symbols";
8-
import ora from "ora";
9-
import { tree } from "./tree.js";
3+
import path from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
import { Command } from 'commander';
6+
import fse from 'fs-extra';
7+
import logSymbols from 'log-symbols';
8+
import ora from 'ora';
9+
import { tree } from './tree.js';
1010

1111
const filename = fileURLToPath(import.meta.url);
1212
const dirname = path.dirname(filename);
1313

1414
const packageJson = JSON.parse(
15-
fse.readFileSync(path.resolve(dirname, "../package.json"), "utf8"),
15+
fse.readFileSync(path.resolve(dirname, '../package.json'), 'utf8'),
1616
);
1717

1818
const getLatestVersionOfTag = async (packageName, tag) => {
19-
const cacheFilename = `${packageName.replaceAll("/", "-")}-${tag}.json`;
20-
21-
const cacheDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '.cache');
22-
19+
const cacheFilename = `${packageName.replaceAll('/', '-')}-${tag}.json`;
20+
21+
const cacheDir = path.join(
22+
path.dirname(fileURLToPath(import.meta.url)),
23+
'..',
24+
'.cache',
25+
);
26+
2327
if (!fse.existsSync(cacheDir)) {
2428
fse.mkdirSync(cacheDir, { recursive: true, mode: 0o700 });
2529
}
26-
30+
2731
const cachePath = path.join(cacheDir, cacheFilename);
28-
32+
2933
let data;
3034
try {
3135
const response = await fetch(
3236
`https://registry.npmjs.org/${packageName}/${tag}`,
3337
);
3438
data = await response.json();
35-
39+
3640
fse.writeFileSync(cachePath, JSON.stringify(data), { mode: 0o600 });
3741
} catch (exception) {
3842
if (fse.existsSync(cachePath)) {
@@ -45,32 +49,32 @@ const getLatestVersionOfTag = async (packageName, tag) => {
4549
}
4650
}
4751

48-
if (typeof data === "string" && data.startsWith("version not found")) {
52+
if (typeof data === 'string' && data.startsWith('version not found')) {
4953
console.error(`Tag ${tag} does not exist for ${packageName}.`);
5054
process.exit(1);
5155
}
5256

5357
const { version } = data;
5458

5559
if (!/^\d+\.\d+\.\d+.*$/.test(version)) {
56-
console.error("Invalid version received, something has gone very wrong.");
60+
console.error('Invalid version received, something has gone very wrong.');
5761
}
58-
62+
5963
return version;
6064
};
6165

6266
const init = async (name, { tag }) => {
6367
let projectPath = name;
6468

6569
if (!projectPath) {
66-
projectPath = path.join(process.cwd(), "react-email-starter");
70+
projectPath = path.join(process.cwd(), 'react-email-starter');
6771
}
6872

69-
if (typeof projectPath === "string") {
73+
if (typeof projectPath === 'string') {
7074
projectPath = projectPath.trim();
7175
}
7276

73-
const templatePath = path.resolve(dirname, "../template");
77+
const templatePath = path.resolve(dirname, '../template');
7478
const resolvedProjectPath = path.resolve(projectPath);
7579

7680
if (fse.existsSync(resolvedProjectPath)) {
@@ -79,51 +83,51 @@ const init = async (name, { tag }) => {
7983
}
8084

8185
const spinner = ora({
82-
text: "Preparing files...\n",
86+
text: 'Preparing files...\n',
8387
}).start();
8488

8589
fse.copySync(templatePath, resolvedProjectPath, {
8690
recursive: true,
8791
});
8892
const templatePackageJsonPath = path.resolve(
8993
resolvedProjectPath,
90-
"./package.json",
94+
'./package.json',
9195
);
92-
const templatePackageJson = fse.readFileSync(templatePackageJsonPath, "utf8");
96+
const templatePackageJson = fse.readFileSync(templatePackageJsonPath, 'utf8');
9397
fse.writeFileSync(
9498
templatePackageJsonPath,
9599
templatePackageJson
96100
.replace(
97-
"INSERT_COMPONENTS_VERSION",
98-
await getLatestVersionOfTag("@react-email/components", tag),
101+
'INSERT_COMPONENTS_VERSION',
102+
await getLatestVersionOfTag('@react-email/components', tag),
99103
)
100104
.replace(
101-
"INSERT_REACT_EMAIL_VERSION",
102-
await getLatestVersionOfTag("react-email", tag),
105+
'INSERT_REACT_EMAIL_VERSION',
106+
await getLatestVersionOfTag('react-email', tag),
103107
),
104-
"utf8",
108+
'utf8',
105109
);
106110

107111
spinner.stopAndPersist({
108112
symbol: logSymbols.success,
109-
text: "React Email Starter files ready",
113+
text: 'React Email Starter files ready',
110114
});
111115

112116
// eslint-disable-next-line no-console
113117
console.info(
114118
await tree(resolvedProjectPath, 4, (dirent) => {
115119
return !path
116120
.join(dirent.parentPath, dirent.name)
117-
.includes("node_modules");
121+
.includes('node_modules');
118122
}),
119123
);
120124
};
121125

122126
new Command()
123127
.name(packageJson.name)
124128
.version(packageJson.version)
125-
.description("The easiest way to get started with React Email")
126-
.arguments("[dir]", "Path to initialize the project")
127-
.option("-t, --tag <tag>", "Tag of React Email versions to use", "latest")
129+
.description('The easiest way to get started with React Email')
130+
.arguments('[dir]', 'Path to initialize the project')
131+
.option('-t, --tag <tag>', 'Tag of React Email versions to use', 'latest')
128132
.action(init)
129133
.parse(process.argv);

0 commit comments

Comments
 (0)