Skip to content

Commit

Permalink
Fix showing latitude -v version outside a latitude app (#506)
Browse files Browse the repository at this point in the history
* Fix showing latitude -v version outside a latitude app

We did a refactor of Latitude --version command and we broke the use
case of just showing CLI version when user is not in a latitude project.
Now we check if there is a latitude.json file in the folder before
showing latitude.json app version and installed version.

* Avoid showing deprecation warnings to users in production
  • Loading branch information
andresgutgon committed Jun 11, 2024
1 parent 55b2808 commit 9891a4f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-bottles-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latitude-data/cli": patch
---

Fix show Latitude CLI version outside a latitude project
9 changes: 9 additions & 0 deletions packages/cli/core/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/usr/bin/env node
import process from 'process'

/*
* Avoid shwing deprecation warnings to users
* for internal packages
*/
if (process.env.NODE_ENV === 'production') {
process.removeAllListeners('warning')
}

import buildCommand from './commands/build'
import cancelCommand from './commands/cloud/cancel'
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/core/src/commands/start/cloneTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { TemplateUrl } from './questions'

const TEMPLATE_URL: Record<TemplateUrl, string> = {
[TemplateUrl.default]: `${LATITUDE_GITHUB_SLUG}/template`,
// TODO: restore duckdb repo
//
// We don't have write permissions to this repo. Only Gerard has.
// [TemplateUrl.duckdb]: `${LATITUDE_GITHUB_SLUG}/sample-duckdb`,
[TemplateUrl.duckdb]: `${LATITUDE_GITHUB_SLUG}/sample-netflix`,
[TemplateUrl.duckdb]: `${LATITUDE_GITHUB_SLUG}/sample-duckdb`,
}

export default async function cloneTemplate({
Expand Down
30 changes: 23 additions & 7 deletions packages/cli/core/src/commands/version/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fsExtra from 'fs-extra'
import colors from 'picocolors'
import setRootDir from '$src/lib/decorators/setRootDir'
import boxedMessage from '$src/lib/boxedMessage'
import findOrCreateConfigFile from '$src/lib/latitudeConfig/findOrCreate'
import { getInstalledVersion } from '$src/lib/versionManagement/appVersion'
Expand All @@ -8,18 +8,20 @@ import config from '$src/config'
function versionLine({ name, version }: { name: string; version: string }) {
return `${colors.blue(`${name} version: `)} ${colors.green(version)}`
}
async function showVersions() {

function cliVersion() {
return process.env.PACKAGE_VERSION ?? 'development'
}

async function showVersionsInApp() {
const latitudeJson = await findOrCreateConfigFile()
const appVersion = latitudeJson.data.version
const installed = getInstalledVersion(config.rootDir)
boxedMessage({
color: 'green',
title: 'Latitude versions',
text: `
${versionLine({
name: 'CLI',
version: process.env.PACKAGE_VERSION ?? 'development',
})}
${versionLine({ name: 'CLI', version: cliVersion() })}
${versionLine({ name: 'App (latitude.json)', version: appVersion! })}
${
installed
Expand All @@ -35,4 +37,18 @@ async function showVersions() {
})
}

export default setRootDir(showVersions)
function showVersions() {
if (!fsExtra.existsSync(config.latitudeJsonPath)) {
return boxedMessage({
color: 'green',
title: 'Latitude CLI version',
text: `
${versionLine({ name: 'CLI', version: cliVersion() })}
`,
})
}

showVersionsInApp()
}

export default showVersions

0 comments on commit 9891a4f

Please sign in to comment.