@inglorious/create-game 1.0.0 → 1.0.1
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/index.js +53 -43
- package/package.json +2 -1
package/bin/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { execSync } from "child_process"
|
|
4
4
|
import fs from "fs"
|
|
5
|
+
import ora from "ora"
|
|
5
6
|
import { EOL } from "os"
|
|
6
7
|
import path from "path"
|
|
7
8
|
import prompts from "prompts"
|
|
@@ -71,59 +72,56 @@ async function main() {
|
|
|
71
72
|
return
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
const
|
|
75
|
-
const templateDir = path.join(templatesRoot, template)
|
|
75
|
+
const spinner = ora(`Creating project "${projectName}"...`).start()
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
try {
|
|
78
|
+
const targetDir = path.join(process.cwd(), projectName)
|
|
79
|
+
const templateDir = path.join(templatesRoot, template)
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (fs.existsSync(readmePath)) {
|
|
83
|
-
let readme = fs.readFileSync(readmePath, "utf-8")
|
|
84
|
-
readme = readme.replace(/# my-game/, `# ${projectName}`)
|
|
85
|
-
fs.writeFileSync(readmePath, readme)
|
|
86
|
-
}
|
|
81
|
+
// Create project directory and copy template files
|
|
82
|
+
copyDir(templateDir, targetDir)
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// Update package.json with project name
|
|
95
|
-
const pkgPath = path.join(targetDir, "package.json")
|
|
96
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
|
97
|
-
pkg.name = projectName
|
|
98
|
-
|
|
99
|
-
function getLatestVersion(packageName) {
|
|
100
|
-
try {
|
|
101
|
-
const version = execSync(`npm view ${packageName} version`, {
|
|
102
|
-
encoding: "utf-8",
|
|
103
|
-
}).trim()
|
|
104
|
-
return `^${version}`
|
|
105
|
-
} catch {
|
|
106
|
-
return "latest" // fallback
|
|
107
|
-
}
|
|
84
|
+
// Update README.md with project name
|
|
85
|
+
const readmePath = path.join(targetDir, "README.md")
|
|
86
|
+
if (fs.existsSync(readmePath)) {
|
|
87
|
+
let readme = fs.readFileSync(readmePath, "utf-8")
|
|
88
|
+
readme = readme.replace(/# my-game/, `# ${projectName}`)
|
|
89
|
+
fs.writeFileSync(readmePath, readme)
|
|
108
90
|
}
|
|
109
91
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
92
|
+
if (template === "minimal") {
|
|
93
|
+
spinner.succeed(`Created ${projectName} at ${targetDir}`)
|
|
94
|
+
console.log(`\nNext steps:`)
|
|
95
|
+
console.log(` cd ${projectName}`)
|
|
96
|
+
console.log(` Open index.html in your browser`)
|
|
97
|
+
} else {
|
|
98
|
+
// Update package.json with project name
|
|
99
|
+
const pkgPath = path.join(targetDir, "package.json")
|
|
100
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
|
101
|
+
pkg.name = projectName
|
|
102
|
+
|
|
103
|
+
for (const depType of ["dependencies", "devDependencies"]) {
|
|
104
|
+
if (pkg[depType]) {
|
|
105
|
+
for (const [name, version] of Object.entries(pkg[depType])) {
|
|
106
|
+
if (version.startsWith("workspace:")) {
|
|
107
|
+
spinner.text = `Fetching latest version of ${name}...`
|
|
108
|
+
pkg[depType][name] = getLatestVersion(name)
|
|
109
|
+
}
|
|
115
110
|
}
|
|
116
111
|
}
|
|
117
112
|
}
|
|
118
|
-
}
|
|
119
113
|
|
|
120
|
-
|
|
114
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, INDENTATION) + EOL)
|
|
121
115
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
spinner.succeed(`Created ${projectName} at ${targetDir}`)
|
|
117
|
+
console.log(`\nNext steps:`)
|
|
118
|
+
console.log(` cd ${projectName}`)
|
|
119
|
+
console.log(` pnpm install`)
|
|
120
|
+
console.log(` pnpm dev`)
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
spinner.fail("Operation failed.")
|
|
124
|
+
console.error(error)
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
function copyDir(src, dest) {
|
|
@@ -148,6 +146,18 @@ async function main() {
|
|
|
148
146
|
}
|
|
149
147
|
}
|
|
150
148
|
}
|
|
149
|
+
|
|
150
|
+
function getLatestVersion(packageName) {
|
|
151
|
+
try {
|
|
152
|
+
const version = execSync(`npm view ${packageName} version`, {
|
|
153
|
+
encoding: "utf-8",
|
|
154
|
+
stdio: "pipe", // Prevent npm view output from cluttering the console
|
|
155
|
+
}).trim()
|
|
156
|
+
return `^${version}`
|
|
157
|
+
} catch {
|
|
158
|
+
return "latest" // fallback
|
|
159
|
+
}
|
|
160
|
+
}
|
|
151
161
|
}
|
|
152
162
|
|
|
153
163
|
main().catch((e) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/create-game",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A scaffolding tool to quickly create a new game with the Inglorious Engine.",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"ora": "^9.0.0",
|
|
38
39
|
"prompts": "^2.4.2"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|