Skip to content

Commit 49726c1

Browse files
committed
chore: misc CLI fixes
1 parent bcbfb9a commit 49726c1

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

packages/schema/src/cli/actions/generate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export async function generate(projectPath: string, options: Options) {
3737

3838
// check for multiple versions of Zenstack packages
3939
const packages = getZenStackPackages(projectPath);
40-
if (packages) {
41-
const versions = new Set<string>(packages.map((p) => p.version));
40+
if (packages.length > 0) {
41+
const versions = new Set<string>(packages.map((p) => p.version).filter((v): v is string => !!v));
4242
if (versions.size > 1) {
4343
console.warn(
4444
colors.yellow(

packages/schema/src/cli/actions/info.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export async function info(projectPath: string) {
1616
console.log('Installed ZenStack Packages:');
1717
const versions = new Set<string>();
1818
for (const { pkg, version } of packages) {
19-
versions.add(version);
19+
if (version) {
20+
versions.add(version);
21+
}
2022
console.log(` ${colors.green(pkg.padEnd(20))}\t${version}`);
2123
}
2224

packages/schema/src/cli/actions/init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ export async function init(projectPath: string, options: Options) {
6363
if (sampleModelGenerated) {
6464
console.log(`Sample model generated at: ${colors.blue(zmodelFile)}
6565
66-
Please check the following guide on how to model your app:
67-
https://zenstack.dev/#/modeling-your-app.`);
66+
Learn how to use ZenStack: https://zenstack.dev/docs.`);
6867
} else if (prismaSchema) {
6968
console.log(
7069
`Your current Prisma schema "${prismaSchema}" has been copied to "${zmodelFile}".

packages/schema/src/cli/cli-util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ export async function getPluginDocuments(services: ZModelServices, fileName: str
227227
return result;
228228
}
229229

230-
export function getZenStackPackages(projectPath: string) {
230+
export function getZenStackPackages(projectPath: string): Array<{ pkg: string; version: string | undefined }> {
231231
let pkgJson: { dependencies: Record<string, unknown>; devDependencies: Record<string, unknown> };
232232
const resolvedPath = path.resolve(projectPath);
233233
try {
234234
pkgJson = require(path.join(resolvedPath, 'package.json'));
235235
} catch {
236-
return undefined;
236+
return [];
237237
}
238238

239239
const packages = [
@@ -245,7 +245,7 @@ export function getZenStackPackages(projectPath: string) {
245245
try {
246246
const resolved = require.resolve(`${pkg}/package.json`, { paths: [resolvedPath] });
247247
// eslint-disable-next-line @typescript-eslint/no-var-requires
248-
return { pkg, version: require(resolved).version };
248+
return { pkg, version: require(resolved).version as string };
249249
} catch {
250250
return { pkg, version: undefined };
251251
}
@@ -286,7 +286,7 @@ export async function checkNewVersion() {
286286
return;
287287
}
288288

289-
if (latestVersion && semver.gt(latestVersion, currVersion)) {
289+
if (latestVersion && currVersion && semver.gt(latestVersion, currVersion)) {
290290
console.log(`A newer version ${colors.cyan(latestVersion)} is available.`);
291291
}
292292
}

packages/schema/src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const checkAction = async (options: Parameters<typeof actions.check>[1]):
7373
export function createProgram() {
7474
const program = new Command('zenstack');
7575

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

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

packages/schema/src/utils/version-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
2-
export function getVersion() {
2+
export function getVersion(): string | undefined {
33
try {
44
return require('../package.json').version;
55
} catch {

0 commit comments

Comments
 (0)