@constructive-io/cli 5.2.2 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/commands.js CHANGED
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.commands = void 0;
7
7
  const find_and_require_package_json_1 = require("find-and-require-package-json");
8
+ const utils_1 = require("@inquirerer/utils");
8
9
  const codegen_1 = __importDefault(require("./commands/codegen"));
9
10
  const explorer_1 = __importDefault(require("./commands/explorer"));
10
11
  const get_graphql_schema_1 = __importDefault(require("./commands/get-graphql-schema"));
11
12
  const server_1 = __importDefault(require("./commands/server"));
12
- const utils_1 = require("./utils");
13
- const update_check_1 = require("./utils/update-check");
13
+ const utils_2 = require("./utils");
14
14
  const createCommandMap = () => {
15
15
  return {
16
16
  server: server_1.default,
@@ -22,16 +22,18 @@ const createCommandMap = () => {
22
22
  const commands = async (argv, prompter, options) => {
23
23
  let { first: command, newArgv } = (0, utils_1.extractFirst)(argv);
24
24
  // Run update check early so it shows on help/version paths too
25
+ // (checkForUpdates auto-skips in CI or when INQUIRERER_SKIP_UPDATE_CHECK / CONSTRUCTIVE_SKIP_UPDATE_CHECK is set)
25
26
  try {
26
27
  const pkg = (0, find_and_require_package_json_1.findAndRequirePackageJson)(__dirname);
27
- await (0, update_check_1.checkForUpdates)({
28
- command: command || 'help',
28
+ const updateResult = await (0, utils_1.checkForUpdates)({
29
29
  pkgName: pkg.name,
30
30
  pkgVersion: pkg.version,
31
31
  toolName: 'constructive',
32
- key: pkg.name,
33
- updateCommand: `Run npm i -g ${pkg.name}@latest to upgrade.`
34
32
  });
33
+ if (updateResult.hasUpdate && updateResult.message) {
34
+ console.warn(updateResult.message);
35
+ console.warn(`Run npm i -g ${pkg.name}@latest to upgrade.`);
36
+ }
35
37
  }
36
38
  catch {
37
39
  // ignore update check failures
@@ -43,12 +45,12 @@ const commands = async (argv, prompter, options) => {
43
45
  }
44
46
  // Show usage if explicitly requested but no command specified
45
47
  if ((argv.help || argv.h || command === 'help') && !command) {
46
- console.log(utils_1.usageText);
48
+ console.log(utils_2.usageText);
47
49
  process.exit(0);
48
50
  }
49
51
  // Show usage for help command specifically
50
52
  if (command === 'help') {
51
- console.log(utils_1.usageText);
53
+ console.log(utils_2.usageText);
52
54
  process.exit(0);
53
55
  }
54
56
  const commandMap = createCommandMap();
@@ -77,7 +79,7 @@ const commands = async (argv, prompter, options) => {
77
79
  ]);
78
80
  const commandFn = commandMap[command];
79
81
  if (!commandFn) {
80
- console.log(utils_1.usageText);
82
+ console.log(utils_2.usageText);
81
83
  await (0, utils_1.cliExitWithError)(`Unknown command: ${command}`);
82
84
  }
83
85
  await commandFn(newArgv, prompter, options);
package/esm/commands.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { findAndRequirePackageJson } from 'find-and-require-package-json';
2
+ import { cliExitWithError, checkForUpdates, extractFirst } from '@inquirerer/utils';
2
3
  import codegen from './commands/codegen';
3
4
  import explorer from './commands/explorer';
4
5
  import getGraphqlSchema from './commands/get-graphql-schema';
5
6
  import server from './commands/server';
6
- import { cliExitWithError, extractFirst, usageText } from './utils';
7
- import { checkForUpdates } from './utils/update-check';
7
+ import { usageText } from './utils';
8
8
  const createCommandMap = () => {
9
9
  return {
10
10
  server,
@@ -16,16 +16,18 @@ const createCommandMap = () => {
16
16
  export const commands = async (argv, prompter, options) => {
17
17
  let { first: command, newArgv } = extractFirst(argv);
18
18
  // Run update check early so it shows on help/version paths too
19
+ // (checkForUpdates auto-skips in CI or when INQUIRERER_SKIP_UPDATE_CHECK / CONSTRUCTIVE_SKIP_UPDATE_CHECK is set)
19
20
  try {
20
21
  const pkg = findAndRequirePackageJson(__dirname);
21
- await checkForUpdates({
22
- command: command || 'help',
22
+ const updateResult = await checkForUpdates({
23
23
  pkgName: pkg.name,
24
24
  pkgVersion: pkg.version,
25
25
  toolName: 'constructive',
26
- key: pkg.name,
27
- updateCommand: `Run npm i -g ${pkg.name}@latest to upgrade.`
28
26
  });
27
+ if (updateResult.hasUpdate && updateResult.message) {
28
+ console.warn(updateResult.message);
29
+ console.warn(`Run npm i -g ${pkg.name}@latest to upgrade.`);
30
+ }
29
31
  }
30
32
  catch {
31
33
  // ignore update check failures
@@ -1,3 +1 @@
1
- export { extractFirst } from './argv';
2
- export { cliExitWithError } from './cli-error';
3
1
  export { usageText } from './display';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/cli",
3
- "version": "5.2.2",
3
+ "version": "5.3.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive CLI",
6
6
  "main": "index.js",
@@ -46,21 +46,22 @@
46
46
  "ts-node": "^10.9.2"
47
47
  },
48
48
  "dependencies": {
49
- "@constructive-io/graphql-codegen": "^2.17.35",
49
+ "@constructive-io/graphql-codegen": "^2.17.36",
50
50
  "@constructive-io/graphql-env": "^2.8.11",
51
- "@constructive-io/graphql-explorer": "^2.10.28",
52
- "@constructive-io/graphql-server": "^2.10.28",
53
- "@pgpmjs/core": "^4.2.1",
51
+ "@constructive-io/graphql-explorer": "^2.10.29",
52
+ "@constructive-io/graphql-server": "^2.10.29",
53
+ "@inquirerer/utils": "^3.1.1",
54
+ "@pgpmjs/core": "^4.3.0",
54
55
  "@pgpmjs/logger": "^1.3.5",
55
56
  "@pgpmjs/server-utils": "^2.8.11",
56
57
  "@pgpmjs/types": "^2.12.8",
57
58
  "find-and-require-package-json": "^0.8.2",
58
- "inquirerer": "^2.4.0",
59
+ "inquirerer": "^4.1.1",
59
60
  "js-yaml": "^4.1.0",
60
61
  "minimist": "^1.2.8",
61
62
  "pg-cache": "^1.6.11",
62
63
  "pg-env": "^1.2.4",
63
- "pgpm": "^2.4.1",
64
+ "pgpm": "^2.5.0",
64
65
  "shelljs": "^0.10.0",
65
66
  "yanse": "^0.1.8"
66
67
  },
@@ -75,5 +76,5 @@
75
76
  "postgres",
76
77
  "graphile"
77
78
  ],
78
- "gitHead": "5b93211b63e72bedcfabc7c4aa41c69ed33d0f6c"
79
+ "gitHead": "7ac931c063d48e281349b748ba2eb9c9f47ffb06"
79
80
  }
package/utils/index.d.ts CHANGED
@@ -1,3 +1 @@
1
- export { extractFirst } from './argv';
2
- export { cliExitWithError } from './cli-error';
3
1
  export { usageText } from './display';
package/utils/index.js CHANGED
@@ -1,9 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usageText = exports.cliExitWithError = exports.extractFirst = void 0;
4
- var argv_1 = require("./argv");
5
- Object.defineProperty(exports, "extractFirst", { enumerable: true, get: function () { return argv_1.extractFirst; } });
6
- var cli_error_1 = require("./cli-error");
7
- Object.defineProperty(exports, "cliExitWithError", { enumerable: true, get: function () { return cli_error_1.cliExitWithError; } });
3
+ exports.usageText = void 0;
8
4
  var display_1 = require("./display");
9
5
  Object.defineProperty(exports, "usageText", { enumerable: true, get: function () { return display_1.usageText; } });
package/esm/utils/argv.js DELETED
@@ -1,8 +0,0 @@
1
- export const extractFirst = (argv) => {
2
- const first = argv._?.[0];
3
- const newArgv = {
4
- ...argv,
5
- _: argv._?.slice(1) ?? []
6
- };
7
- return { first, newArgv };
8
- };
@@ -1,31 +0,0 @@
1
- import { Logger } from '@pgpmjs/logger';
2
- import { PgpmError } from '@pgpmjs/types';
3
- const log = new Logger('cli');
4
- /**
5
- * CLI error utility that logs error information and exits with code 1.
6
- * Provides consistent error handling and user experience across all CLI commands.
7
- */
8
- export const cliExitWithError = async (error, context) => {
9
- if (error instanceof PgpmError) {
10
- log.error(`Error: ${error.message}`);
11
- if (error.context && Object.keys(error.context).length > 0) {
12
- log.debug('Error context:', error.context);
13
- }
14
- if (context) {
15
- log.debug('Additional context:', context);
16
- }
17
- }
18
- else if (error instanceof Error) {
19
- log.error(`Error: ${error.message}`);
20
- if (context) {
21
- log.debug('Context:', context);
22
- }
23
- }
24
- else if (typeof error === 'string') {
25
- log.error(`Error: ${error}`);
26
- if (context) {
27
- log.debug('Context:', context);
28
- }
29
- }
30
- process.exit(1);
31
- };
@@ -1,107 +0,0 @@
1
- import { findAndRequirePackageJson } from 'find-and-require-package-json';
2
- import { Logger } from '@pgpmjs/logger';
3
- import fs from 'fs';
4
- import path from 'path';
5
- import os from 'os';
6
- const log = new Logger('update-check');
7
- const UPDATE_CHECK_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
8
- const shouldSkip = (command) => {
9
- if (process.env.PGPM_SKIP_UPDATE_CHECK)
10
- return true;
11
- if (process.env.CI === 'true')
12
- return true;
13
- return false;
14
- };
15
- function getConfigPath(toolName, key) {
16
- const configDir = path.join(os.homedir(), `.${toolName}`);
17
- return path.join(configDir, `${key}.json`);
18
- }
19
- function readConfig(toolName, key) {
20
- try {
21
- const configPath = getConfigPath(toolName, key);
22
- if (!fs.existsSync(configPath))
23
- return null;
24
- const content = fs.readFileSync(configPath, 'utf8');
25
- return JSON.parse(content);
26
- }
27
- catch {
28
- return null;
29
- }
30
- }
31
- function writeConfig(toolName, key, config) {
32
- try {
33
- const configPath = getConfigPath(toolName, key);
34
- const configDir = path.dirname(configPath);
35
- if (!fs.existsSync(configDir)) {
36
- fs.mkdirSync(configDir, { recursive: true });
37
- }
38
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
39
- }
40
- catch {
41
- // Ignore write errors
42
- }
43
- }
44
- async function fetchLatestVersion(pkgName) {
45
- try {
46
- const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`);
47
- if (!response.ok)
48
- return null;
49
- const data = await response.json();
50
- return data.version || null;
51
- }
52
- catch {
53
- return null;
54
- }
55
- }
56
- function compareVersions(current, latest) {
57
- const currentParts = current.replace(/^v/, '').split('.').map(Number);
58
- const latestParts = latest.replace(/^v/, '').split('.').map(Number);
59
- for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
60
- const c = currentParts[i] || 0;
61
- const l = latestParts[i] || 0;
62
- if (c < l)
63
- return -1;
64
- if (c > l)
65
- return 1;
66
- }
67
- return 0;
68
- }
69
- export async function checkForUpdates(options = {}) {
70
- const { pkgName = '@constructive-io/cli', pkgVersion = findAndRequirePackageJson(__dirname).version, command, now = Date.now(), key = 'update-check', toolName = 'constructive' } = options;
71
- if (shouldSkip(command)) {
72
- return null;
73
- }
74
- try {
75
- const existing = readConfig(toolName, key);
76
- let latestKnownVersion = existing?.latestKnownVersion ?? pkgVersion;
77
- const needsCheck = !existing?.lastCheckedAt || (now - existing.lastCheckedAt) > UPDATE_CHECK_TTL_MS;
78
- if (needsCheck) {
79
- const fetched = await fetchLatestVersion(pkgName);
80
- if (fetched) {
81
- latestKnownVersion = fetched;
82
- }
83
- writeConfig(toolName, key, {
84
- lastCheckedAt: now,
85
- latestKnownVersion
86
- });
87
- }
88
- const comparison = compareVersions(pkgVersion, latestKnownVersion);
89
- const isOutdated = comparison < 0;
90
- if (isOutdated) {
91
- const updateInstruction = options.updateCommand ?? `Run npm i -g ${pkgName}@latest to upgrade.`;
92
- log.warn(`A new version of ${pkgName} is available (current ${pkgVersion}, latest ${latestKnownVersion}). ${updateInstruction}`);
93
- writeConfig(toolName, key, {
94
- lastCheckedAt: now,
95
- latestKnownVersion
96
- });
97
- }
98
- return {
99
- lastCheckedAt: now,
100
- latestKnownVersion
101
- };
102
- }
103
- catch (error) {
104
- log.debug('Update check skipped due to error:', error);
105
- return null;
106
- }
107
- }
package/utils/argv.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { ParsedArgs } from 'minimist';
2
- export declare const extractFirst: (argv: Partial<ParsedArgs>) => {
3
- first: string;
4
- newArgv: {
5
- _: string[];
6
- "--"?: string[] | undefined;
7
- };
8
- };
package/utils/argv.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFirst = void 0;
4
- const extractFirst = (argv) => {
5
- const first = argv._?.[0];
6
- const newArgv = {
7
- ...argv,
8
- _: argv._?.slice(1) ?? []
9
- };
10
- return { first, newArgv };
11
- };
12
- exports.extractFirst = extractFirst;
@@ -1,6 +0,0 @@
1
- import { PgpmError } from '@pgpmjs/types';
2
- /**
3
- * CLI error utility that logs error information and exits with code 1.
4
- * Provides consistent error handling and user experience across all CLI commands.
5
- */
6
- export declare const cliExitWithError: (error: PgpmError | Error | string, context?: Record<string, any>) => Promise<never>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cliExitWithError = void 0;
4
- const logger_1 = require("@pgpmjs/logger");
5
- const types_1 = require("@pgpmjs/types");
6
- const log = new logger_1.Logger('cli');
7
- /**
8
- * CLI error utility that logs error information and exits with code 1.
9
- * Provides consistent error handling and user experience across all CLI commands.
10
- */
11
- const cliExitWithError = async (error, context) => {
12
- if (error instanceof types_1.PgpmError) {
13
- log.error(`Error: ${error.message}`);
14
- if (error.context && Object.keys(error.context).length > 0) {
15
- log.debug('Error context:', error.context);
16
- }
17
- if (context) {
18
- log.debug('Additional context:', context);
19
- }
20
- }
21
- else if (error instanceof Error) {
22
- log.error(`Error: ${error.message}`);
23
- if (context) {
24
- log.debug('Context:', context);
25
- }
26
- }
27
- else if (typeof error === 'string') {
28
- log.error(`Error: ${error}`);
29
- if (context) {
30
- log.debug('Context:', context);
31
- }
32
- }
33
- process.exit(1);
34
- };
35
- exports.cliExitWithError = cliExitWithError;
@@ -1,15 +0,0 @@
1
- export interface CheckForUpdatesOptions {
2
- pkgName?: string;
3
- pkgVersion?: string;
4
- command?: string;
5
- now?: number;
6
- updateCommand?: string;
7
- toolName?: string;
8
- key?: string;
9
- }
10
- interface UpdateCheckConfig {
11
- lastCheckedAt: number;
12
- latestKnownVersion: string;
13
- }
14
- export declare function checkForUpdates(options?: CheckForUpdatesOptions): Promise<UpdateCheckConfig | null>;
15
- export {};
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkForUpdates = checkForUpdates;
7
- const find_and_require_package_json_1 = require("find-and-require-package-json");
8
- const logger_1 = require("@pgpmjs/logger");
9
- const fs_1 = __importDefault(require("fs"));
10
- const path_1 = __importDefault(require("path"));
11
- const os_1 = __importDefault(require("os"));
12
- const log = new logger_1.Logger('update-check');
13
- const UPDATE_CHECK_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
14
- const shouldSkip = (command) => {
15
- if (process.env.PGPM_SKIP_UPDATE_CHECK)
16
- return true;
17
- if (process.env.CI === 'true')
18
- return true;
19
- return false;
20
- };
21
- function getConfigPath(toolName, key) {
22
- const configDir = path_1.default.join(os_1.default.homedir(), `.${toolName}`);
23
- return path_1.default.join(configDir, `${key}.json`);
24
- }
25
- function readConfig(toolName, key) {
26
- try {
27
- const configPath = getConfigPath(toolName, key);
28
- if (!fs_1.default.existsSync(configPath))
29
- return null;
30
- const content = fs_1.default.readFileSync(configPath, 'utf8');
31
- return JSON.parse(content);
32
- }
33
- catch {
34
- return null;
35
- }
36
- }
37
- function writeConfig(toolName, key, config) {
38
- try {
39
- const configPath = getConfigPath(toolName, key);
40
- const configDir = path_1.default.dirname(configPath);
41
- if (!fs_1.default.existsSync(configDir)) {
42
- fs_1.default.mkdirSync(configDir, { recursive: true });
43
- }
44
- fs_1.default.writeFileSync(configPath, JSON.stringify(config, null, 2));
45
- }
46
- catch {
47
- // Ignore write errors
48
- }
49
- }
50
- async function fetchLatestVersion(pkgName) {
51
- try {
52
- const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`);
53
- if (!response.ok)
54
- return null;
55
- const data = await response.json();
56
- return data.version || null;
57
- }
58
- catch {
59
- return null;
60
- }
61
- }
62
- function compareVersions(current, latest) {
63
- const currentParts = current.replace(/^v/, '').split('.').map(Number);
64
- const latestParts = latest.replace(/^v/, '').split('.').map(Number);
65
- for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) {
66
- const c = currentParts[i] || 0;
67
- const l = latestParts[i] || 0;
68
- if (c < l)
69
- return -1;
70
- if (c > l)
71
- return 1;
72
- }
73
- return 0;
74
- }
75
- async function checkForUpdates(options = {}) {
76
- const { pkgName = '@constructive-io/cli', pkgVersion = (0, find_and_require_package_json_1.findAndRequirePackageJson)(__dirname).version, command, now = Date.now(), key = 'update-check', toolName = 'constructive' } = options;
77
- if (shouldSkip(command)) {
78
- return null;
79
- }
80
- try {
81
- const existing = readConfig(toolName, key);
82
- let latestKnownVersion = existing?.latestKnownVersion ?? pkgVersion;
83
- const needsCheck = !existing?.lastCheckedAt || (now - existing.lastCheckedAt) > UPDATE_CHECK_TTL_MS;
84
- if (needsCheck) {
85
- const fetched = await fetchLatestVersion(pkgName);
86
- if (fetched) {
87
- latestKnownVersion = fetched;
88
- }
89
- writeConfig(toolName, key, {
90
- lastCheckedAt: now,
91
- latestKnownVersion
92
- });
93
- }
94
- const comparison = compareVersions(pkgVersion, latestKnownVersion);
95
- const isOutdated = comparison < 0;
96
- if (isOutdated) {
97
- const updateInstruction = options.updateCommand ?? `Run npm i -g ${pkgName}@latest to upgrade.`;
98
- log.warn(`A new version of ${pkgName} is available (current ${pkgVersion}, latest ${latestKnownVersion}). ${updateInstruction}`);
99
- writeConfig(toolName, key, {
100
- lastCheckedAt: now,
101
- latestKnownVersion
102
- });
103
- }
104
- return {
105
- lastCheckedAt: now,
106
- latestKnownVersion
107
- };
108
- }
109
- catch (error) {
110
- log.debug('Update check skipped due to error:', error);
111
- return null;
112
- }
113
- }