Skip to content

Commit f8a5d53

Browse files
committed
Changing to direct imports
1 parent b7097ff commit f8a5d53

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/index.ts

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

33
import { Command, InvalidArgumentError } from "commander";
4-
import * as fs from "node:fs/promises";
5-
import * as path from "node:path";
4+
import { mkdir, copyFile, readFile, writeFile } from "node:fs/promises";
5+
import { resolve } from "node:path";
66
import { fileURLToPath } from "node:url";
77
import { intro, outro, spinner } from "@clack/prompts";
88
import { execa } from "execa";
@@ -25,32 +25,32 @@ async function createApp(projectName: string, options: Required<Options>) {
2525
const templateDir = fileURLToPath(
2626
new URL("../project-template", import.meta.url)
2727
);
28-
const targetDir = path.join(process.cwd(), projectName);
28+
const targetDir = resolve(process.cwd(), projectName);
2929

3030
async function copyFiles(files: string[]) {
3131
for (const file of files) {
3232
const targetFileName = file.replace(".tw", "");
33-
await fs.copyFile(
34-
path.join(templateDir, file),
35-
path.join(targetDir, targetFileName)
33+
await copyFile(
34+
resolve(templateDir, file),
35+
resolve(targetDir, targetFileName)
3636
);
3737
}
3838
}
3939

4040
intro(`Creating a new TanStack app in ${targetDir}...`);
4141

4242
// Make the root directory
43-
await fs.mkdir(targetDir, { recursive: true });
43+
await mkdir(targetDir, { recursive: true });
4444

4545
// Setup the .vscode directory
46-
await fs.mkdir(path.join(targetDir, ".vscode"), { recursive: true });
47-
await fs.copyFile(
48-
path.join(templateDir, ".vscode/settings.json"),
49-
path.join(targetDir, ".vscode/settings.json")
46+
await mkdir(resolve(targetDir, ".vscode"), { recursive: true });
47+
await copyFile(
48+
resolve(templateDir, ".vscode/settings.json"),
49+
resolve(targetDir, ".vscode/settings.json")
5050
);
5151

5252
// Fill the public directory
53-
await fs.mkdir(path.join(targetDir, "public"), { recursive: true });
53+
await mkdir(resolve(targetDir, "public"), { recursive: true });
5454
copyFiles([
5555
"./public/robots.txt",
5656
"./public/favicon.ico",
@@ -60,7 +60,7 @@ async function createApp(projectName: string, options: Required<Options>) {
6060
]);
6161

6262
// Make the src directory
63-
await fs.mkdir(path.join(targetDir, "src"), { recursive: true });
63+
await mkdir(resolve(targetDir, "src"), { recursive: true });
6464

6565
// Copy in Vite and Tailwind config and CSS
6666
if (options.tailwind) {
@@ -73,8 +73,8 @@ async function createApp(projectName: string, options: Required<Options>) {
7373

7474
// Setup the app component. There are four variations, typescript/javascript and tailwind/non-tailwind.
7575
let appComponent = (
76-
await fs.readFile(
77-
path.join(
76+
await readFile(
77+
resolve(
7878
templateDir,
7979
options.tailwind ? "./src/App.tw.tsx" : "./src/App.tsx"
8080
),
@@ -84,17 +84,17 @@ async function createApp(projectName: string, options: Required<Options>) {
8484
if (!options.typescript) {
8585
appComponent = appComponent.replace("App.tsx", "App.jsx");
8686
}
87-
await fs.writeFile(
88-
path.join(targetDir, `./src/App${options.typescript ? ".tsx" : ".jsx"}`),
87+
await writeFile(
88+
resolve(targetDir, `./src/App${options.typescript ? ".tsx" : ".jsx"}`),
8989
appComponent
9090
);
9191

9292
// Setup the main, reportWebVitals and index.html files
9393
if (options.typescript) {
9494
await copyFiles(["./src/main.tsx", "./src/reportWebVitals.ts"]);
95-
await fs.copyFile(
96-
path.join(templateDir, `./index.ts.html`),
97-
path.join(targetDir, "./index.html")
95+
await copyFile(
96+
resolve(templateDir, `./index.ts.html`),
97+
resolve(targetDir, "./index.html")
9898
);
9999
} else {
100100
await copyFiles([
@@ -111,12 +111,12 @@ async function createApp(projectName: string, options: Required<Options>) {
111111

112112
// Setup the package.json file, optionally with typescript and tailwind
113113
let packageJSON = JSON.parse(
114-
await fs.readFile(path.join(templateDir, "package.json"), "utf8")
114+
await readFile(resolve(templateDir, "package.json"), "utf8")
115115
);
116116
packageJSON.name = projectName;
117117
if (options.typescript) {
118118
const tsPackageJSON = JSON.parse(
119-
await fs.readFile(path.join(templateDir, "package.ts.json"), "utf8")
119+
await readFile(resolve(templateDir, "package.ts.json"), "utf8")
120120
);
121121
packageJSON = {
122122
...packageJSON,
@@ -128,7 +128,7 @@ async function createApp(projectName: string, options: Required<Options>) {
128128
}
129129
if (options.tailwind) {
130130
const twPackageJSON = JSON.parse(
131-
await fs.readFile(path.join(templateDir, "package.tw.json"), "utf8")
131+
await readFile(resolve(templateDir, "package.tw.json"), "utf8")
132132
);
133133
packageJSON = {
134134
...packageJSON,
@@ -138,19 +138,19 @@ async function createApp(projectName: string, options: Required<Options>) {
138138
},
139139
};
140140
}
141-
await fs.writeFile(
142-
path.join(targetDir, "package.json"),
141+
await writeFile(
142+
resolve(targetDir, "package.json"),
143143
JSON.stringify(packageJSON, null, 2)
144144
);
145145

146146
// Add .gitignore and README.md
147-
await fs.copyFile(
148-
path.join(templateDir, "gitignore"),
149-
path.join(targetDir, ".gitignore")
147+
await copyFile(
148+
resolve(templateDir, "gitignore"),
149+
resolve(targetDir, ".gitignore")
150150
);
151-
await fs.copyFile(
152-
path.join(templateDir, "README.md"),
153-
path.join(targetDir, "README.md")
151+
await copyFile(
152+
resolve(templateDir, "README.md"),
153+
resolve(targetDir, "README.md")
154154
);
155155

156156
// Install dependencies

0 commit comments

Comments
 (0)