Skip to content
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
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
"find-and-require-package-json": "^0.8.2",
"inquirerer": "^4.1.0",
"@inquirerer/utils": "^3.1.1",
"inquirerer": "^4.1.1",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"pg-cache": "workspace:^",
Expand Down
14 changes: 8 additions & 6 deletions packages/cli/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { findAndRequirePackageJson } from 'find-and-require-package-json';
import { cliExitWithError, checkForUpdates, extractFirst } from '@inquirerer/utils';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';

import codegen from './commands/codegen';
import explorer from './commands/explorer';
import getGraphqlSchema from './commands/get-graphql-schema';
import server from './commands/server';
import { cliExitWithError, extractFirst, usageText } from './utils';
import { checkForUpdates } from './utils/update-check';
import { usageText } from './utils';

const createCommandMap = (): Record<string, Function> => {
return {
Expand All @@ -22,16 +22,18 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,
let { first: command, newArgv } = extractFirst(argv);

// Run update check early so it shows on help/version paths too
// (checkForUpdates auto-skips in CI or when INQUIRERER_SKIP_UPDATE_CHECK / CONSTRUCTIVE_SKIP_UPDATE_CHECK is set)
try {
const pkg = findAndRequirePackageJson(__dirname);
await checkForUpdates({
command: command || 'help',
const updateResult = await checkForUpdates({
pkgName: pkg.name,
pkgVersion: pkg.version,
toolName: 'constructive',
key: pkg.name,
updateCommand: `Run npm i -g ${pkg.name}@latest to upgrade.`
});
if (updateResult.hasUpdate && updateResult.message) {
console.warn(updateResult.message);
console.warn(`Run npm i -g ${pkg.name}@latest to upgrade.`);
}
} catch {
// ignore update check failures
}
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/src/utils/argv.ts

This file was deleted.

37 changes: 0 additions & 37 deletions packages/cli/src/utils/cli-error.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/cli/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export { extractFirst } from './argv';
export { cliExitWithError } from './cli-error';
export { usageText } from './display';
141 changes: 0 additions & 141 deletions packages/cli/src/utils/update-check.ts

This file was deleted.

5 changes: 3 additions & 2 deletions pgpm/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@
"ts-node": "^10.9.2"
},
"dependencies": {
"@inquirerer/utils": "^3.1.1",
"@pgpmjs/core": "workspace:^",
"@pgpmjs/env": "workspace:^",
"@pgpmjs/logger": "workspace:^",
"@pgpmjs/types": "workspace:^",
"appstash": "^0.2.6",
"genomic": "^5.0.1",
"find-and-require-package-json": "^0.8.2",
"inquirerer": "^4.1.0",
"genomic": "^5.0.2",
"inquirerer": "^4.1.1",
"js-yaml": "^4.1.0",
"minimist": "^1.2.8",
"pg-cache": "workspace:^",
Expand Down
31 changes: 20 additions & 11 deletions pgpm/cli/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { findAndRequirePackageJson } from 'find-and-require-package-json';
import { cliExitWithError, checkForUpdates, extractFirst } from '@inquirerer/utils';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';
import { teardownPgPools } from 'pg-cache';
Expand Down Expand Up @@ -27,9 +28,7 @@ import revert from './commands/revert';
import tag from './commands/tag';
import testPackages from './commands/test-packages';
import verify from './commands/verify';
import { extractFirst, usageText } from './utils';
import { cliExitWithError } from './utils/cli-error';
import { checkForUpdates } from './utils/update-check';
import { usageText } from './utils';

const withPgTeardown = (fn: Function, skipTeardown: boolean = false) => async (...args: any[]) => {
try {
Expand Down Expand Up @@ -104,13 +103,23 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,
command = answer.command;
}

try {
await checkForUpdates({
command,
pkgVersion: findAndRequirePackageJson(__dirname).version
});
} catch {
// ignore update check failures
// Run update check (skip on 'update' command to avoid redundant check)
// (checkForUpdates auto-skips in CI or when INQUIRERER_SKIP_UPDATE_CHECK / PGPM_SKIP_UPDATE_CHECK is set)
if (command !== 'update') {
try {
const pkg = findAndRequirePackageJson(__dirname);
const updateResult = await checkForUpdates({
pkgName: pkg.name,
pkgVersion: pkg.version,
toolName: 'pgpm',
});
if (updateResult.hasUpdate && updateResult.message) {
console.warn(updateResult.message);
console.warn('Run pgpm update to upgrade.');
}
} catch {
// ignore update check failures
}
}

newArgv = await prompter.prompt(newArgv, [
Expand All @@ -128,7 +137,7 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,

if (!commandFn) {
console.log(usageText);
await cliExitWithError(`Unknown command: ${command}`);
await cliExitWithError(`Unknown command: ${command}`, { beforeExit: teardownPgPools });
}

await commandFn(newArgv, prompter, options);
Expand Down
3 changes: 1 addition & 2 deletions pgpm/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { extractFirst } from '@inquirerer/utils';
import { PgpmPackage } from '@pgpmjs/core';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';
import * as path from 'path';

import { extractFirst } from '../utils/argv';

const addUsageText = `
Add Command:

Expand Down
3 changes: 1 addition & 2 deletions pgpm/cli/src/commands/admin-users.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { extractFirst } from '@inquirerer/utils';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';

import { extractFirst } from '../utils';
import add from './admin-users/add';
import bootstrap from './admin-users/bootstrap';
import remove from './admin-users/remove';
Expand Down
2 changes: 1 addition & 1 deletion pgpm/cli/src/commands/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cliExitWithError } from '@inquirerer/utils';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { CacheManager } from 'genomic';
import { cliExitWithError } from '../utils/cli-error';

const cacheUsageText = `
Cache Command:
Expand Down
3 changes: 1 addition & 2 deletions pgpm/cli/src/commands/docker.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { spawn } from 'child_process';
import { cliExitWithError, extractFirst } from '@inquirerer/utils';
import { CLIOptions, Inquirerer } from 'inquirerer';

import { cliExitWithError,extractFirst } from '../utils';

const dockerUsageText = `
Docker Command:

Expand Down
3 changes: 1 addition & 2 deletions pgpm/cli/src/commands/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { extractFirst } from '@inquirerer/utils';
import { CLIOptions, Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';

import { extractFirst } from '../utils';
import deps from './migrate/deps';
// Migrate subcommands
import init from './migrate/init';
Expand Down
2 changes: 1 addition & 1 deletion pgpm/cli/src/commands/remove.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { cliExitWithError } from '@inquirerer/utils';
import { PgpmPackage } from '@pgpmjs/core';
import { getEnvOptions } from '@pgpmjs/env';
import { Logger } from '@pgpmjs/logger';
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
import { getPgEnvOptions } from 'pg-env';

import { getTargetDatabase } from '../utils';
import { cliExitWithError } from '../utils/cli-error';

const log = new Logger('remove');

Expand Down
3 changes: 1 addition & 2 deletions pgpm/cli/src/commands/rename.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { cliExitWithError } from '@inquirerer/utils';
import { PgpmPackage } from '@pgpmjs/core';
import { Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';
import path from 'path';

import { cliExitWithError } from '../utils/cli-error';

export default async (argv: Partial<ParsedArgs>, _prompter: Inquirerer) => {
const cwd = (argv.cwd as string) || process.cwd();
const to = (argv.to as string) || (argv._ && argv._[0] as string);
Expand Down
Loading