create-jsc-vite-react-ts 1.0.2 ā 1.2.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
CHANGED
|
@@ -1,113 +1,131 @@
|
|
|
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
|
+
});
|
|
60
|
+
|
|
61
|
+
// Make files fromthe "scripts" folder executable
|
|
62
|
+
const scriptsDir = path.join(targetDir, "scripts");
|
|
63
|
+
if (fs.existsSync(scriptsDir)) {
|
|
64
|
+
const scriptFiles = fs.readdirSync(scriptsDir);
|
|
65
|
+
scriptFiles.forEach((file) => {
|
|
66
|
+
const filePath = path.join(scriptsDir, file);
|
|
67
|
+
fs.chmodSync(filePath, 0o755);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
58
70
|
|
|
59
|
-
const packageJsonPath = path.join(targetDir,
|
|
60
|
-
const packageJson = fs.readJsonSync(packageJsonPath)
|
|
61
|
-
packageJson.name = projectName
|
|
62
|
-
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 })
|
|
71
|
+
const packageJsonPath = path.join(targetDir, "package.json");
|
|
72
|
+
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
73
|
+
packageJson.name = projectName;
|
|
74
|
+
fs.writeJsonSync(packageJsonPath, packageJson, { spaces: 2 });
|
|
63
75
|
|
|
64
|
-
console.log(chalk.green(
|
|
76
|
+
console.log(chalk.green("ā Project files created"));
|
|
65
77
|
|
|
66
|
-
const packageManager = await detectPackageManager()
|
|
78
|
+
const packageManager = await detectPackageManager();
|
|
67
79
|
|
|
68
|
-
console.log(
|
|
80
|
+
console.log(
|
|
81
|
+
chalk.blue(`\nš¦ Installing dependencies with ${packageManager}...\n`),
|
|
82
|
+
);
|
|
69
83
|
|
|
70
84
|
try {
|
|
71
85
|
execSync(`${packageManager} install`, {
|
|
72
86
|
cwd: targetDir,
|
|
73
|
-
stdio:
|
|
74
|
-
})
|
|
75
|
-
console.log(chalk.green(
|
|
87
|
+
stdio: "inherit",
|
|
88
|
+
});
|
|
89
|
+
console.log(chalk.green("\nā Dependencies installed"));
|
|
76
90
|
} catch (error) {
|
|
77
|
-
console.log(
|
|
78
|
-
|
|
91
|
+
console.log(
|
|
92
|
+
chalk.yellow("\nā Failed to install dependencies automatically"),
|
|
93
|
+
);
|
|
94
|
+
console.log(
|
|
95
|
+
chalk.yellow(` Please run "${packageManager} install" manually\n`),
|
|
96
|
+
);
|
|
79
97
|
}
|
|
80
98
|
|
|
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
|
-
}
|
|
99
|
+
console.log(chalk.bold.green("\n⨠Success! Your project is ready.\n"));
|
|
100
|
+
console.log(chalk.bold("Next steps:\n"));
|
|
101
|
+
console.log(chalk.cyan(` cd ${projectName}`));
|
|
102
|
+
console.log(chalk.cyan(` ${packageManager} dev`));
|
|
103
|
+
console.log();
|
|
104
|
+
};
|
|
87
105
|
|
|
88
106
|
const detectPackageManager = async () => {
|
|
89
|
-
const userAgent = process.env.npm_config_user_agent ||
|
|
107
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
90
108
|
|
|
91
|
-
if (userAgent.startsWith(
|
|
92
|
-
if (userAgent.startsWith(
|
|
109
|
+
if (userAgent.startsWith("yarn")) return "yarn";
|
|
110
|
+
if (userAgent.startsWith("pnpm")) return "pnpm";
|
|
93
111
|
|
|
94
112
|
const response = await prompts({
|
|
95
|
-
type:
|
|
96
|
-
name:
|
|
97
|
-
message:
|
|
113
|
+
type: "select",
|
|
114
|
+
name: "packageManager",
|
|
115
|
+
message: "Which package manager do you want to use?",
|
|
98
116
|
choices: [
|
|
99
|
-
{ title:
|
|
100
|
-
{ title:
|
|
101
|
-
{ title:
|
|
117
|
+
{ title: "npm", value: "npm" },
|
|
118
|
+
{ title: "yarn", value: "yarn" },
|
|
119
|
+
{ title: "pnpm", value: "pnpm" },
|
|
102
120
|
],
|
|
103
121
|
initial: 0,
|
|
104
|
-
})
|
|
122
|
+
});
|
|
105
123
|
|
|
106
|
-
return response.packageManager ||
|
|
107
|
-
}
|
|
124
|
+
return response.packageManager || "npm";
|
|
125
|
+
};
|
|
108
126
|
|
|
109
127
|
run().catch((error) => {
|
|
110
|
-
console.error(chalk.red(
|
|
111
|
-
console.error(error)
|
|
112
|
-
process.exit(1)
|
|
113
|
-
})
|
|
128
|
+
console.error(chalk.red("\nā An error occurred:\n"));
|
|
129
|
+
console.error(error);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
package/package.json
CHANGED
package/template/package.json
CHANGED
|
@@ -10,7 +10,11 @@
|
|
|
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 .",
|
|
15
|
+
"update-version": "./update-version.sh",
|
|
16
|
+
"create-tag": "./create-tag.sh",
|
|
17
|
+
"full-tag": "yarn update-version && yarn create-tag"
|
|
14
18
|
},
|
|
15
19
|
"dependencies": {
|
|
16
20
|
"react": "^19.2.0",
|
|
@@ -34,6 +38,8 @@
|
|
|
34
38
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
35
39
|
"globals": "^16.5.0",
|
|
36
40
|
"jsdom": "^27.3.0",
|
|
41
|
+
"prettier": "^3.7.4",
|
|
42
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
37
43
|
"tailwindcss": "^4.0.0",
|
|
38
44
|
"typescript": "~5.9.3",
|
|
39
45
|
"typescript-eslint": "^8.46.4",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Get the latest git tag that starts with 'v'
|
|
4
|
+
LATEST_TAG=$(git tag -l --sort=version:refname | grep "^v" | tail -1)
|
|
5
|
+
|
|
6
|
+
# Increment the patch version of the latest tag
|
|
7
|
+
if [ -z "$LATEST_TAG" ]; then
|
|
8
|
+
NEW_TAG="0.0.1"
|
|
9
|
+
else
|
|
10
|
+
MAJOR=$(echo "$LATEST_TAG" | sed 's/^v//' | awk -F"." '{print $1}')
|
|
11
|
+
MINOR=$(echo "$LATEST_TAG" | sed 's/^v//' | awk -F"." '{print $2}')
|
|
12
|
+
PATCH=$(echo "$LATEST_TAG" | sed 's/^v//' | awk -F"." '{print $3}')
|
|
13
|
+
PATCH=$((PATCH + 1))
|
|
14
|
+
NEW_TAG="$MAJOR.$MINOR.$PATCH"
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
export NEW_TAG
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# !/bin/bash
|
|
2
|
+
|
|
3
|
+
echo "š Updating version"
|
|
4
|
+
|
|
5
|
+
. "$(dirname "$0")/get-tag.sh"
|
|
6
|
+
|
|
7
|
+
# Echo the new tag version
|
|
8
|
+
echo "š New tag version will be: $NEW_TAG"
|
|
9
|
+
|
|
10
|
+
# Update the version field in package.json
|
|
11
|
+
PACKAGE_JSON_PATH="package.json"
|
|
12
|
+
if [ -f "$PACKAGE_JSON_PATH" ]; then
|
|
13
|
+
# Use jq to update the version field
|
|
14
|
+
jq --arg new_version "$NEW_TAG" '.version = $new_version' "$PACKAGE_JSON_PATH" > "${PACKAGE_JSON_PATH}.tmp" && mv "${PACKAGE_JSON_PATH}.tmp" "$PACKAGE_JSON_PATH"
|
|
15
|
+
echo "š¦ Updated package.json version to $NEW_TAG"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
git add "$PACKAGE_JSON_PATH"
|
|
19
|
+
git commit -m "chore: bump version to $NEW_TAG"
|
|
20
|
+
|
|
21
|
+
# Echo a message indicating the pre-push hook is running with emoji
|
|
22
|
+
echo "š Version updated."
|
|
23
|
+
|
|
24
|
+
exit 0
|