@justinli/create-vite-template 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,42 @@
1
- # Create Vite Template
2
-
3
- This template provides a minimal setup for a static site using:
4
- - React
5
- - TypeScript
6
- - Vite
7
- - Oxlint
8
- - Oxfmt
9
-
10
- ## Usage
11
-
12
- ```
13
- pnpm create @justinli/vite-template my-app
14
- ```
1
+ # Create Vite Template
2
+
3
+ This template provides a minimal setup for a static site using:
4
+
5
+ - React
6
+ - TypeScript
7
+ - Vite
8
+ - Oxlint
9
+ - Oxfmt
10
+
11
+ ## Prerequisites
12
+ - Node.js
13
+ - pnpm
14
+
15
+ ## Usage
16
+
17
+ Create a project in a new directory:
18
+ ```
19
+ pnpm create @justinli/vite-template my-app
20
+ ```
21
+
22
+ Create a project in the current (empty) directory:
23
+ ```
24
+ pnpm create @justinli/vite-template .
25
+ ```
26
+
27
+ cd into the project directory, install dependencies, and start the development server:
28
+ ```
29
+ cd my-app
30
+ pnpm install
31
+ pnpm dev
32
+ ```
33
+
34
+ ## Scripts
35
+ - `pnpm dev`: Start the development server
36
+ - `pnpm build`: Build for production
37
+ - `pnpm preview`: Preview the production build locally
38
+ - `pnpm lint`: Run Oxlint to check for linting errors
39
+ - `pnpm lint:fix`: Run Oxlint to fix linting errors
40
+ - `pnpm fmt`: Run Oxfmt to format code
41
+ - `pnpm fmt:check`: Run Oxfmt to check if code is formatted
42
+ - `pnpm check`: Run TypeScript, Oxlint, and Oxfmt checks
package/index.js CHANGED
@@ -1,16 +1,38 @@
1
- #!/usr/bin/env node
2
- import { cpSync, existsSync } from "node:fs";
3
- import { resolve } from "node:path";
4
- import { fileURLToPath } from "node:url";
5
-
1
+ #!/usr/bin/env node
2
+ import { cp, readFile, writeFile, rename, access, readdir } from "node:fs/promises";
3
+ import { resolve, basename } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
6
  const target = process.argv[2] ?? "my-app";
7
+ const targetName = target === "." ? basename(process.cwd()) : target;
7
8
  const from = fileURLToPath(new URL("./template", import.meta.url));
8
9
  const to = resolve(process.cwd(), target);
9
-
10
- if (existsSync(to)) {
11
- console.error(`Target already exists: ${to}`);
12
- process.exit(1);
13
- }
14
-
15
- cpSync(from, to, { recursive: true });
16
- console.log(`Created ${target}`);
10
+
11
+ try {
12
+ await access(to);
13
+ const entries = await readdir(to);
14
+ if (entries.length > 0) {
15
+ console.error(`Failed to create. Target directory is not empty: ${to}`);
16
+ process.exit(1);
17
+ }
18
+ } catch (e) {
19
+ if (e.code !== "ENOENT") throw e;
20
+ }
21
+
22
+ await cp(from, to, { recursive: true });
23
+
24
+ const files = [
25
+ resolve(to, "package.json"),
26
+ resolve(to, "index.html"),
27
+ resolve(to, "src/App.tsx"),
28
+ ]
29
+
30
+ for (const file of files) {
31
+ const content = await readFile(file, "utf8");
32
+ await writeFile(file, content.replace(/vite-template/g, targetName));
33
+ }
34
+
35
+ const gitignore = resolve(to, "_gitignore");
36
+ await rename(gitignore, resolve(to, ".gitignore"));
37
+
38
+ console.log(`Created ${targetName}`);
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
- {
2
- "name": "@justinli/create-vite-template",
3
- "version": "0.1.1",
4
- "private": false,
5
- "type": "module",
6
- "bin": {
7
- "create-vite-template": "index.js"
8
- },
9
- "files": ["index.js", "template"],
10
- "publishConfig": { "access": "public" },
11
- "license": "MIT",
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/justinli34/create-vite-template.git"
15
- }
16
- }
1
+ {
2
+ "name": "@justinli/create-vite-template",
3
+ "version": "0.1.3",
4
+ "private": false,
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/justinli34/create-vite-template.git"
9
+ },
10
+ "bin": {
11
+ "create-vite-template": "index.js"
12
+ },
13
+ "files": [
14
+ "index.js",
15
+ "template"
16
+ ],
17
+ "type": "module",
18
+ "publishConfig": {
19
+ "access": "public"
20
+ }
21
+ }
@@ -0,0 +1,3 @@
1
+ node_modules/
2
+ dist/
3
+ .env
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite Template</title>
7
+ <title>vite-template</title>
8
8
  </head>
9
9
  <body>
10
10
  <div id="root"></div>
@@ -10,7 +10,8 @@
10
10
  "lint": "oxlint",
11
11
  "lint:fix": "oxlint --fix",
12
12
  "fmt": "oxfmt",
13
- "fmt:check": "oxfmt --check"
13
+ "fmt:check": "oxfmt --check",
14
+ "check": "tsc --noEmit && oxlint && oxfmt --check"
14
15
  },
15
16
  "dependencies": {
16
17
  "react": "^19.2.0",
@@ -3,7 +3,7 @@ import "./App.css";
3
3
  const App = () => {
4
4
  return (
5
5
  <div className="container">
6
- <h1>Vite Template</h1>
6
+ <h1>vite-template</h1>
7
7
  <p>Hello, world!</p>
8
8
  </div>
9
9
  );