feat: Add version check to cli, check if package.json and jsr.json have different versions

This commit is contained in:
Huakun Shen 2025-01-19 02:18:03 -05:00
parent 090271bdb9
commit c260ca2fc2
No known key found for this signature in database
5 changed files with 52 additions and 3 deletions

View File

@ -14,6 +14,7 @@
"@kksh/utils", "@kksh/utils",
"@kksh/extension", "@kksh/extension",
"@kksh/schema", "@kksh/schema",
"@kksh/supabase" "@kksh/supabase",
"@kksh/ui"
] ]
} }

View File

@ -1,5 +1,11 @@
# kksh # kksh
## 0.0.30
### Patch Changes
- Add version check to cli, check if package.json and jsr.json have different versions
## 0.0.29 ## 0.0.29
### Patch Changes ### Patch Changes

Binary file not shown.

View File

@ -1,7 +1,7 @@
{ {
"name": "kksh", "name": "kksh",
"module": "dist/cli.js", "module": "dist/cli.js",
"version": "0.0.29", "version": "0.0.30",
"type": "module", "type": "module",
"bin": { "bin": {
"kksh": "./dist/cli.js", "kksh": "./dist/cli.js",

View File

@ -32,6 +32,45 @@ export function verifyTemplateUiCommand(projectRoot: string, cmd: TemplateUiCmd)
return true return true
} }
export function verifyVersion(projectPath: string): boolean {
const pkgJsonPath = path.join(projectPath, "package.json")
const jsrJsonPath = path.join(projectPath, "jsr.json")
const denoJsonPath = path.join(projectPath, "deno.json")
const versions = { npm: undefined, jsr: undefined, deno: undefined }
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"))
versions.npm = pkgJson.version
if (fs.existsSync(jsrJsonPath)) {
const jsrJson = JSON.parse(fs.readFileSync(jsrJsonPath, "utf-8"))
versions.jsr = jsrJson.version
}
if (fs.existsSync(denoJsonPath)) {
const denoJson = JSON.parse(fs.readFileSync(denoJsonPath, "utf-8"))
versions.deno = denoJson.version
}
if (!versions.npm) {
logger.error(`version is not set in package.json`)
return false
}
if (fs.existsSync(jsrJsonPath) && fs.existsSync(denoJsonPath)) {
logger.error(`Both jsr.json and deno.json are present, only one is allowed`)
return false
}
if (versions.jsr && versions.jsr !== versions.npm) {
logger.error(
`jsr.json version ${versions.jsr} does not match package.json version ${versions.npm}`
)
return false
}
if (versions.deno && versions.deno !== versions.npm) {
logger.error(
`deno.json version ${versions.deno} does not match package.json version ${versions.npm}`
)
return false
}
return true
}
export function verifySingleProject(projectPath: string): boolean { export function verifySingleProject(projectPath: string): boolean {
logger.info(`Verifying project at ${projectPath}`) logger.info(`Verifying project at ${projectPath}`)
const pkgJsonPath = path.join(projectPath, "package.json") const pkgJsonPath = path.join(projectPath, "package.json")
@ -52,7 +91,7 @@ export function verifySingleProject(projectPath: string): boolean {
logger.info(`name`, pkg.name) logger.info(`name`, pkg.name)
logger.info(`version`, pkg.version) logger.info(`version`, pkg.version)
logger.info(`identifier`, pkg.kunkun.identifier) logger.info(`identifier`, pkg.kunkun.identifier)
if (pkg.files.length === 0) { if (!pkg.files?.length) {
logger.warn( logger.warn(
`"files" field is empty, it is recommended to include only the necessary files, e.g. dist` `"files" field is empty, it is recommended to include only the necessary files, e.g. dist`
) )
@ -66,6 +105,9 @@ export function verifySingleProject(projectPath: string): boolean {
pkg.kunkun.identifier = folderName pkg.kunkun.identifier = folderName
// } // }
} }
if (!verifyVersion(projectPath)) {
return false
}
for (const cmd of pkg.kunkun.customUiCmds ?? []) { for (const cmd of pkg.kunkun.customUiCmds ?? []) {
if (!verifyCustomUiCommand(projectPath, cmd)) { if (!verifyCustomUiCommand(projectPath, cmd)) {
return false return false