@xrystal/core 3.7.7 ā 3.7.8
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/main-cli.js +28 -12
- package/package.json +1 -1
package/bin/main-cli.js
CHANGED
|
@@ -57,17 +57,27 @@ const setupCLI = async () => {
|
|
|
57
57
|
|
|
58
58
|
cli
|
|
59
59
|
.command("create <project-name> [target-path]")
|
|
60
|
-
.description("
|
|
60
|
+
.description("Project initializer with git setup")
|
|
61
61
|
.action(async (projectName, targetDir) => {
|
|
62
|
-
|
|
63
|
-
const
|
|
62
|
+
let targetPath = ""
|
|
63
|
+
const isCurrentDir = projectName === "."
|
|
64
|
+
|
|
65
|
+
if (targetDir) {
|
|
66
|
+
targetPath = path.resolve(process.cwd(), targetDir)
|
|
67
|
+
} else {
|
|
68
|
+
targetPath = isCurrentDir ? process.cwd() : path.resolve(process.cwd(), projectName)
|
|
69
|
+
}
|
|
64
70
|
|
|
65
71
|
if (fs.existsSync(targetPath) && fs.readdirSync(targetPath).length > 0) {
|
|
66
72
|
console.log(chalk.red(`ā Error: Target directory '${targetPath}' is not empty!`))
|
|
67
73
|
process.exit(1)
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
|
|
76
|
+
if (!fs.existsSync(targetPath)) {
|
|
77
|
+
fs.mkdirSync(targetPath, { recursive: true })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const spinner = ora("Cloning and initializing git...").start()
|
|
71
81
|
|
|
72
82
|
try {
|
|
73
83
|
execSync(`git clone --depth 1 ${templateRepoUri} "${targetPath}"`, { stdio: "ignore" })
|
|
@@ -77,24 +87,30 @@ const setupCLI = async () => {
|
|
|
77
87
|
fs.rmSync(gitFolder, { recursive: true, force: true })
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
try {
|
|
91
|
+
execSync(`git init`, { cwd: targetPath, stdio: "ignore" })
|
|
92
|
+
} catch (e) {
|
|
93
|
+
// Failed silently
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
spinner.succeed(chalk.green("Template cloned and git initialized!"))
|
|
97
|
+
console.log(chalk.blue(`\nš¦ Installing dependencies with ${packageManager}...`))
|
|
82
98
|
|
|
83
99
|
const installCmd = isBun ? "bun install" : "npm install"
|
|
84
100
|
execSync(installCmd, { cwd: targetPath, stdio: "inherit" })
|
|
85
101
|
|
|
86
|
-
console.log(chalk.green("\nā
|
|
87
|
-
console.log(chalk.white(`\nStart Project:\n`))
|
|
102
|
+
console.log(chalk.green("\nā
Done!"))
|
|
88
103
|
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
const relativePath = path.relative(process.cwd(), targetPath)
|
|
105
|
+
if (relativePath && relativePath !== ".") {
|
|
106
|
+
console.log(chalk.cyan(`\n cd ${relativePath}`))
|
|
91
107
|
}
|
|
92
108
|
|
|
93
109
|
console.log(chalk.cyan(` ${packageManager} run dev`))
|
|
94
110
|
|
|
95
111
|
} catch (err) {
|
|
96
|
-
spinner.fail(chalk.red("Failed
|
|
97
|
-
console.error(chalk.red(`\
|
|
112
|
+
spinner.fail(chalk.red("Failed!"))
|
|
113
|
+
console.error(chalk.red(`\nDetails: ${err.message}`))
|
|
98
114
|
|
|
99
115
|
if (fs.existsSync(targetPath) && targetPath !== process.cwd() && fs.readdirSync(targetPath).length === 0) {
|
|
100
116
|
fs.rmSync(targetPath, { recursive: true, force: true })
|