create-jsc-vite-react-ts 1.0.2 ā 1.1.0
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/bin/cli.js +72 -64
- package/package.json +1 -1
- package/template/.prettierrc +7 -0
- package/template/package.json +4 -1
package/bin/cli.js
CHANGED
|
@@ -1,113 +1,121 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { execSync } from
|
|
4
|
-
import fs from
|
|
5
|
-
import path from
|
|
6
|
-
import { fileURLToPath } from
|
|
7
|
-
import prompts from
|
|
8
|
-
import chalk from
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import fs from "fs-extra";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import prompts from "prompts";
|
|
8
|
+
import chalk from "chalk";
|
|
9
9
|
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
11
|
-
const __dirname = path.dirname(__filename)
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
12
|
|
|
13
13
|
const run = async () => {
|
|
14
|
-
console.log(chalk.bold.cyan(
|
|
14
|
+
console.log(chalk.bold.cyan("\nš Create React + TypeScript + Vite App\n"));
|
|
15
15
|
|
|
16
|
-
const args = process.argv.slice(2)
|
|
17
|
-
let projectName = args[0]
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
let projectName = args[0];
|
|
18
18
|
|
|
19
19
|
if (!projectName) {
|
|
20
20
|
const response = await prompts({
|
|
21
|
-
type:
|
|
22
|
-
name:
|
|
23
|
-
message:
|
|
24
|
-
initial:
|
|
21
|
+
type: "text",
|
|
22
|
+
name: "projectName",
|
|
23
|
+
message: "What is your project named?",
|
|
24
|
+
initial: "my-app",
|
|
25
25
|
validate: (value) => {
|
|
26
|
-
if (!value) return
|
|
26
|
+
if (!value) return "Project name is required";
|
|
27
27
|
if (!/^[a-z0-9-_]+$/.test(value)) {
|
|
28
|
-
return
|
|
28
|
+
return "Project name can only contain lowercase letters, numbers, hyphens, and underscores";
|
|
29
29
|
}
|
|
30
|
-
return true
|
|
30
|
+
return true;
|
|
31
31
|
},
|
|
32
|
-
})
|
|
32
|
+
});
|
|
33
33
|
|
|
34
34
|
if (!response.projectName) {
|
|
35
|
-
console.log(chalk.red(
|
|
36
|
-
process.exit(1)
|
|
35
|
+
console.log(chalk.red("\nā Project creation cancelled\n"));
|
|
36
|
+
process.exit(1);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
projectName = response.projectName
|
|
39
|
+
projectName = response.projectName;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const targetDir = path.resolve(process.cwd(), projectName)
|
|
42
|
+
const targetDir = path.resolve(process.cwd(), projectName);
|
|
43
43
|
|
|
44
44
|
if (fs.existsSync(targetDir)) {
|
|
45
|
-
console.log(chalk.red(`\nā Directory ${projectName} already exists\n`))
|
|
46
|
-
process.exit(1)
|
|
45
|
+
console.log(chalk.red(`\nā Directory ${projectName} already exists\n`));
|
|
46
|
+
process.exit(1);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
console.log(chalk.blue(`\nš Creating project in ${targetDir}...\n`))
|
|
49
|
+
console.log(chalk.blue(`\nš Creating project in ${targetDir}...\n`));
|
|
50
50
|
|
|
51
|
-
const templateDir = path.resolve(__dirname,
|
|
51
|
+
const templateDir = path.resolve(__dirname, "../template");
|
|
52
52
|
fs.copySync(templateDir, targetDir, {
|
|
53
53
|
filter: (src) => {
|
|
54
|
-
const basename = path.basename(src)
|
|
55
|
-
return ![
|
|
54
|
+
const basename = path.basename(src);
|
|
55
|
+
return !["node_modules", "dist", "coverage", "yarn.lock"].includes(
|
|
56
|
+
basename
|
|
57
|
+
);
|
|
56
58
|
},
|
|
57
|
-
})
|
|
59
|
+
});
|
|
58
60
|
|
|
59
|
-
const packageJsonPath = path.join(targetDir,
|
|
60
|
-
const packageJson = fs.readJsonSync(packageJsonPath)
|
|
61
|
-
packageJson.name = projectName
|
|
62
|
-
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 })
|
|
61
|
+
const packageJsonPath = path.join(targetDir, "package.json");
|
|
62
|
+
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
63
|
+
packageJson.name = projectName;
|
|
64
|
+
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
|
|
63
65
|
|
|
64
|
-
console.log(chalk.green(
|
|
66
|
+
console.log(chalk.green("ā Project files created"));
|
|
65
67
|
|
|
66
|
-
const packageManager = await detectPackageManager()
|
|
68
|
+
const packageManager = await detectPackageManager();
|
|
67
69
|
|
|
68
|
-
console.log(
|
|
70
|
+
console.log(
|
|
71
|
+
chalk.blue(`\nš¦ Installing dependencies with ${packageManager}...\n`)
|
|
72
|
+
);
|
|
69
73
|
|
|
70
74
|
try {
|
|
71
75
|
execSync(`${packageManager} install`, {
|
|
72
76
|
cwd: targetDir,
|
|
73
|
-
stdio:
|
|
74
|
-
})
|
|
75
|
-
console.log(chalk.green(
|
|
77
|
+
stdio: "inherit",
|
|
78
|
+
});
|
|
79
|
+
console.log(chalk.green("\nā Dependencies installed"));
|
|
76
80
|
} catch (error) {
|
|
77
|
-
console.log(
|
|
78
|
-
|
|
81
|
+
console.log(
|
|
82
|
+
chalk.yellow("\nā Failed to install dependencies automatically")
|
|
83
|
+
);
|
|
84
|
+
console.log(
|
|
85
|
+
chalk.yellow(` Please run "${packageManager} install" manually\n`)
|
|
86
|
+
);
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
console.log(chalk.bold.green(
|
|
82
|
-
console.log(chalk.bold(
|
|
83
|
-
console.log(chalk.cyan(` cd ${projectName}`))
|
|
84
|
-
console.log(chalk.cyan(` ${packageManager} dev`))
|
|
85
|
-
console.log()
|
|
86
|
-
}
|
|
89
|
+
console.log(chalk.bold.green("\n⨠Success! Your project is ready.\n"));
|
|
90
|
+
console.log(chalk.bold("Next steps:\n"));
|
|
91
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
92
|
+
console.log(chalk.cyan(` ${packageManager} dev`));
|
|
93
|
+
console.log();
|
|
94
|
+
};
|
|
87
95
|
|
|
88
96
|
const detectPackageManager = async () => {
|
|
89
|
-
const userAgent = process.env.npm_config_user_agent ||
|
|
97
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
90
98
|
|
|
91
|
-
if (userAgent.startsWith(
|
|
92
|
-
if (userAgent.startsWith(
|
|
99
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
100
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
93
101
|
|
|
94
102
|
const response = await prompts({
|
|
95
|
-
type:
|
|
96
|
-
name:
|
|
97
|
-
message:
|
|
103
|
+
type: "select",
|
|
104
|
+
name: "packageManager",
|
|
105
|
+
message: "Which package manager do you want to use?",
|
|
98
106
|
choices: [
|
|
99
|
-
{ title:
|
|
100
|
-
{ title:
|
|
101
|
-
{ title:
|
|
107
|
+
{ title: "npm", value: "npm" },
|
|
108
|
+
{ title: "yarn", value: "yarn" },
|
|
109
|
+
{ title: "pnpm", value: "pnpm" },
|
|
102
110
|
],
|
|
103
111
|
initial: 0,
|
|
104
|
-
})
|
|
112
|
+
});
|
|
105
113
|
|
|
106
|
-
return response.packageManager ||
|
|
107
|
-
}
|
|
114
|
+
return response.packageManager || "npm";
|
|
115
|
+
};
|
|
108
116
|
|
|
109
117
|
run().catch((error) => {
|
|
110
|
-
console.error(chalk.red(
|
|
111
|
-
console.error(error)
|
|
112
|
-
process.exit(1)
|
|
113
|
-
})
|
|
118
|
+
console.error(chalk.red("\nā An error occurred:\n"));
|
|
119
|
+
console.error(error);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
});
|
package/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"preview": "vite preview",
|
|
11
11
|
"test": "vitest",
|
|
12
12
|
"test:ui": "vitest --ui",
|
|
13
|
-
"test:coverage": "vitest --coverage"
|
|
13
|
+
"test:coverage": "vitest --coverage",
|
|
14
|
+
"format": "prettier --write ."
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"react": "^19.2.0",
|
|
@@ -34,6 +35,8 @@
|
|
|
34
35
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
35
36
|
"globals": "^16.5.0",
|
|
36
37
|
"jsdom": "^27.3.0",
|
|
38
|
+
"prettier": "^3.7.4",
|
|
39
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
37
40
|
"tailwindcss": "^4.0.0",
|
|
38
41
|
"typescript": "~5.9.3",
|
|
39
42
|
"typescript-eslint": "^8.46.4",
|