Skip to content

Commit

Permalink
feat(deno): Fetch version from git in local context
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jun 10, 2024
1 parent 98360f6 commit a019092
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bids-validator/src/setup/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const validateCommand = new Command()
'This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about Brain Imaging Data Structure visit http:https://bids.neuroimaging.io',
)
.arguments('<dataset_directory>')
.version(getVersion())
.version(await getVersion())
.option('--json', 'Output machine readable JSON')
.option(
'-s, --schema <type:string>',
Expand Down
17 changes: 15 additions & 2 deletions bids-validator/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export function getVersion(): string {
export async function getVersion(): string {
const url = import.meta.url
if (url.startsWith('file:https://')) {
return 'local'
// Get parent directory of current file, without file:/
const parent = url.slice(7).split('/').slice(0, -1).join('/')
return await getLocalVersion(parent)
} else if (url.startsWith('https://deno.land/x/')) {
// Retrieve version X from https://deno.land/x/bids-validator@X/version.ts
return url.split('@')[1].split('/')[0]
Expand All @@ -11,3 +13,14 @@ export function getVersion(): string {
}
return url
}

export async function getLocalVersion(path: string): string {
const p = Deno.run({
cmd: ['git', 'describe', '--tags', '--always'],
stdout: 'piped',
stderr: 'piped',
cwd: path,
})
const description = new TextDecoder().decode(await p.output()).trim()
return description
}

0 comments on commit a019092

Please sign in to comment.