diff --git a/.changeset/config.json b/.changeset/config.json index e3e1b7f..1a0bb03 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -14,6 +14,7 @@ "@kksh/utils", "@kksh/extension", "@kksh/schema", - "@kksh/supabase" + "@kksh/supabase", + "@kksh/ui" ] } diff --git a/apps/cli/CHANGELOG.md b/apps/cli/CHANGELOG.md index 68709f0..c1fada5 100644 --- a/apps/cli/CHANGELOG.md +++ b/apps/cli/CHANGELOG.md @@ -1,5 +1,11 @@ # kksh +## 0.0.30 + +### Patch Changes + +- Add version check to cli, check if package.json and jsr.json have different versions + ## 0.0.29 ### Patch Changes diff --git a/apps/cli/bun.lockb b/apps/cli/bun.lockb deleted file mode 100755 index 56bb31c..0000000 Binary files a/apps/cli/bun.lockb and /dev/null differ diff --git a/apps/cli/package.json b/apps/cli/package.json index b6b84c3..e4f8c3d 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,7 +1,7 @@ { "name": "kksh", "module": "dist/cli.js", - "version": "0.0.29", + "version": "0.0.30", "type": "module", "bin": { "kksh": "./dist/cli.js", diff --git a/apps/cli/src/commands/verify.ts b/apps/cli/src/commands/verify.ts index 9853018..7a98182 100644 --- a/apps/cli/src/commands/verify.ts +++ b/apps/cli/src/commands/verify.ts @@ -32,6 +32,45 @@ export function verifyTemplateUiCommand(projectRoot: string, cmd: TemplateUiCmd) 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 { logger.info(`Verifying project at ${projectPath}`) const pkgJsonPath = path.join(projectPath, "package.json") @@ -52,7 +91,7 @@ export function verifySingleProject(projectPath: string): boolean { logger.info(`name`, pkg.name) logger.info(`version`, pkg.version) logger.info(`identifier`, pkg.kunkun.identifier) - if (pkg.files.length === 0) { + if (!pkg.files?.length) { logger.warn( `"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 // } } + if (!verifyVersion(projectPath)) { + return false + } for (const cmd of pkg.kunkun.customUiCmds ?? []) { if (!verifyCustomUiCommand(projectPath, cmd)) { return false