Skip to content

chore: misc CLI fixes #1939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/schema/src/cli/actions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export async function generate(projectPath: string, options: Options) {

// check for multiple versions of Zenstack packages
const packages = getZenStackPackages(projectPath);
if (packages) {
const versions = new Set<string>(packages.map((p) => p.version));
if (packages.length > 0) {
const versions = new Set<string>(packages.map((p) => p.version).filter((v): v is string => !!v));
if (versions.size > 1) {
console.warn(
colors.yellow(
Expand Down
4 changes: 3 additions & 1 deletion packages/schema/src/cli/actions/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export async function info(projectPath: string) {
console.log('Installed ZenStack Packages:');
const versions = new Set<string>();
for (const { pkg, version } of packages) {
versions.add(version);
if (version) {
versions.add(version);
}
console.log(` ${colors.green(pkg.padEnd(20))}\t${version}`);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/schema/src/cli/actions/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export async function init(projectPath: string, options: Options) {
if (sampleModelGenerated) {
console.log(`Sample model generated at: ${colors.blue(zmodelFile)}

Please check the following guide on how to model your app:
https://zenstack.dev/#/modeling-your-app.`);
Learn how to use ZenStack: https://zenstack.dev/docs.`);
} else if (prismaSchema) {
console.log(
`Your current Prisma schema "${prismaSchema}" has been copied to "${zmodelFile}".
Expand Down
8 changes: 4 additions & 4 deletions packages/schema/src/cli/cli-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ export async function getPluginDocuments(services: ZModelServices, fileName: str
return result;
}

export function getZenStackPackages(projectPath: string) {
export function getZenStackPackages(projectPath: string): Array<{ pkg: string; version: string | undefined }> {
let pkgJson: { dependencies: Record<string, unknown>; devDependencies: Record<string, unknown> };
const resolvedPath = path.resolve(projectPath);
try {
pkgJson = require(path.join(resolvedPath, 'package.json'));
} catch {
return undefined;
return [];
}

const packages = [
Expand All @@ -245,7 +245,7 @@ export function getZenStackPackages(projectPath: string) {
try {
const resolved = require.resolve(`${pkg}/package.json`, { paths: [resolvedPath] });
// eslint-disable-next-line @typescript-eslint/no-var-requires
return { pkg, version: require(resolved).version };
return { pkg, version: require(resolved).version as string };
} catch {
return { pkg, version: undefined };
}
Expand Down Expand Up @@ -286,7 +286,7 @@ export async function checkNewVersion() {
return;
}

if (latestVersion && semver.gt(latestVersion, currVersion)) {
if (latestVersion && currVersion && semver.gt(latestVersion, currVersion)) {
console.log(`A newer version ${colors.cyan(latestVersion)} is available.`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const checkAction = async (options: Parameters<typeof actions.check>[1]):
export function createProgram() {
const program = new Command('zenstack');

program.version(getVersion(), '-v --version', 'display CLI version');
program.version(getVersion()!, '-v --version', 'display CLI version');

const schemaExtensions = ZModelLanguageMetaData.fileExtensions.join(', ');

Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/utils/version-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
export function getVersion() {
export function getVersion(): string | undefined {
try {
return require('../package.json').version;
} catch {
Expand Down
Loading