@constructive-io/cli 0.0.2

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.
Files changed (122) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +412 -0
  3. package/commands/add.d.ts +7 -0
  4. package/commands/add.js +86 -0
  5. package/commands/admin-users/add.d.ts +4 -0
  6. package/commands/admin-users/add.js +89 -0
  7. package/commands/admin-users/bootstrap.d.ts +4 -0
  8. package/commands/admin-users/bootstrap.js +50 -0
  9. package/commands/admin-users/remove.d.ts +4 -0
  10. package/commands/admin-users/remove.js +82 -0
  11. package/commands/admin-users.d.ts +4 -0
  12. package/commands/admin-users.js +68 -0
  13. package/commands/analyze.d.ts +4 -0
  14. package/commands/analyze.js +21 -0
  15. package/commands/clear.d.ts +3 -0
  16. package/commands/clear.js +59 -0
  17. package/commands/deploy.d.ts +4 -0
  18. package/commands/deploy.js +146 -0
  19. package/commands/docker.d.ts +3 -0
  20. package/commands/docker.js +194 -0
  21. package/commands/env.d.ts +4 -0
  22. package/commands/env.js +124 -0
  23. package/commands/export.d.ts +3 -0
  24. package/commands/export.js +129 -0
  25. package/commands/extension.d.ts +4 -0
  26. package/commands/extension.js +48 -0
  27. package/commands/init/index.d.ts +7 -0
  28. package/commands/init/index.js +47 -0
  29. package/commands/init/module.d.ts +4 -0
  30. package/commands/init/module.js +71 -0
  31. package/commands/init/workspace.d.ts +4 -0
  32. package/commands/init/workspace.js +52 -0
  33. package/commands/install.d.ts +4 -0
  34. package/commands/install.js +37 -0
  35. package/commands/kill.d.ts +3 -0
  36. package/commands/kill.js +107 -0
  37. package/commands/migrate/deps.d.ts +4 -0
  38. package/commands/migrate/deps.js +186 -0
  39. package/commands/migrate/init.d.ts +4 -0
  40. package/commands/migrate/init.js +65 -0
  41. package/commands/migrate/list.d.ts +4 -0
  42. package/commands/migrate/list.js +85 -0
  43. package/commands/migrate/status.d.ts +4 -0
  44. package/commands/migrate/status.js +94 -0
  45. package/commands/migrate.d.ts +4 -0
  46. package/commands/migrate.js +69 -0
  47. package/commands/package.d.ts +3 -0
  48. package/commands/package.js +65 -0
  49. package/commands/plan.d.ts +3 -0
  50. package/commands/plan.js +62 -0
  51. package/commands/remove.d.ts +3 -0
  52. package/commands/remove.js +42 -0
  53. package/commands/rename.d.ts +4 -0
  54. package/commands/rename.js +35 -0
  55. package/commands/revert.d.ts +3 -0
  56. package/commands/revert.js +107 -0
  57. package/commands/tag.d.ts +6 -0
  58. package/commands/tag.js +168 -0
  59. package/commands/verify.d.ts +3 -0
  60. package/commands/verify.js +85 -0
  61. package/commands.d.ts +6 -0
  62. package/commands.js +113 -0
  63. package/dist/README.md +412 -0
  64. package/dist/package.json +64 -0
  65. package/esm/commands/add.js +51 -0
  66. package/esm/commands/admin-users/add.js +87 -0
  67. package/esm/commands/admin-users/bootstrap.js +48 -0
  68. package/esm/commands/admin-users/remove.js +80 -0
  69. package/esm/commands/admin-users.js +63 -0
  70. package/esm/commands/analyze.js +16 -0
  71. package/esm/commands/clear.js +54 -0
  72. package/esm/commands/deploy.js +144 -0
  73. package/esm/commands/docker.js +192 -0
  74. package/esm/commands/env.js +122 -0
  75. package/esm/commands/export.js +127 -0
  76. package/esm/commands/extension.js +46 -0
  77. package/esm/commands/init/index.js +42 -0
  78. package/esm/commands/init/module.js +68 -0
  79. package/esm/commands/init/workspace.js +46 -0
  80. package/esm/commands/install.js +35 -0
  81. package/esm/commands/kill.js +105 -0
  82. package/esm/commands/migrate/deps.js +184 -0
  83. package/esm/commands/migrate/init.js +63 -0
  84. package/esm/commands/migrate/list.js +83 -0
  85. package/esm/commands/migrate/status.js +92 -0
  86. package/esm/commands/migrate.js +64 -0
  87. package/esm/commands/package.js +63 -0
  88. package/esm/commands/plan.js +60 -0
  89. package/esm/commands/remove.js +40 -0
  90. package/esm/commands/rename.js +30 -0
  91. package/esm/commands/revert.js +105 -0
  92. package/esm/commands/tag.js +133 -0
  93. package/esm/commands/verify.js +83 -0
  94. package/esm/commands.js +105 -0
  95. package/esm/index.js +48 -0
  96. package/esm/package.js +26 -0
  97. package/esm/utils/argv.js +92 -0
  98. package/esm/utils/cli-error.js +48 -0
  99. package/esm/utils/database.js +78 -0
  100. package/esm/utils/deployed-changes.js +68 -0
  101. package/esm/utils/display.js +58 -0
  102. package/esm/utils/index.js +6 -0
  103. package/esm/utils/module-utils.js +51 -0
  104. package/index.d.ts +25 -0
  105. package/index.js +87 -0
  106. package/package.d.ts +1 -0
  107. package/package.js +29 -0
  108. package/package.json +64 -0
  109. package/utils/argv.d.ts +46 -0
  110. package/utils/argv.js +100 -0
  111. package/utils/cli-error.d.ts +8 -0
  112. package/utils/cli-error.js +52 -0
  113. package/utils/database.d.ts +21 -0
  114. package/utils/database.js +83 -0
  115. package/utils/deployed-changes.d.ts +4 -0
  116. package/utils/deployed-changes.js +72 -0
  117. package/utils/display.d.ts +3 -0
  118. package/utils/display.js +66 -0
  119. package/utils/index.d.ts +6 -0
  120. package/utils/index.js +22 -0
  121. package/utils/module-utils.d.ts +8 -0
  122. package/utils/module-utils.js +54 -0
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@launchql/core");
4
+ const env_1 = require("@launchql/env");
5
+ const logger_1 = require("@launchql/logger");
6
+ const pg_env_1 = require("pg-env");
7
+ const utils_1 = require("../utils");
8
+ const cli_error_1 = require("../utils/cli-error");
9
+ const log = new logger_1.Logger('remove');
10
+ exports.default = async (argv, prompter, _options) => {
11
+ if (!argv.to) {
12
+ await (0, cli_error_1.cliExitWithError)('No change specified. Usage: constructive remove --to <change>');
13
+ }
14
+ const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
15
+ message: 'Select database'
16
+ });
17
+ const questions = [
18
+ {
19
+ name: 'yes',
20
+ type: 'confirm',
21
+ message: 'Are you sure you want to proceed with removing changes?',
22
+ required: true
23
+ }
24
+ ];
25
+ let { yes, cwd } = await prompter.prompt(argv, questions);
26
+ if (!yes) {
27
+ log.info('Operation cancelled.');
28
+ return;
29
+ }
30
+ log.debug(`Using current directory: ${cwd}`);
31
+ const pkg = new core_1.LaunchQLPackage(cwd);
32
+ if (!pkg.isInModule()) {
33
+ throw new Error('Not in a LaunchQL module directory. Please run this command from within a module.');
34
+ }
35
+ const opts = (0, env_1.getEnvOptions)({
36
+ pg: (0, pg_env_1.getPgEnvOptions)({ database })
37
+ });
38
+ const toChange = argv.to;
39
+ await pkg.removeFromPlan(toChange);
40
+ log.success(`✅ Successfully removed changes from '${toChange}' to end of plan.`);
41
+ return argv;
42
+ };
@@ -0,0 +1,4 @@
1
+ import { Inquirerer } from 'inquirerer';
2
+ import { ParsedArgs } from 'minimist';
3
+ declare const _default: (argv: Partial<ParsedArgs>, _prompter: Inquirerer) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,35 @@
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
+ const core_1 = require("@launchql/core");
7
+ const path_1 = __importDefault(require("path"));
8
+ const cli_error_1 = require("../utils/cli-error");
9
+ exports.default = async (argv, _prompter) => {
10
+ const cwd = argv.cwd || process.cwd();
11
+ const to = argv.to || (argv._ && argv._[0]);
12
+ if (!to) {
13
+ await (0, cli_error_1.cliExitWithError)('Missing new name. Use --to <name> or provide as positional argument.');
14
+ }
15
+ const dryRun = !!argv['dry-run'] || !!argv.dryRun;
16
+ const syncPkg = !!argv['sync-pkg-name'] || !!argv.syncPkgName;
17
+ const proj = new core_1.LaunchQLPackage(path_1.default.resolve(cwd));
18
+ const res = proj.renameModule(to, { dryRun, syncPackageJsonName: syncPkg });
19
+ if (dryRun) {
20
+ console.log('Dry run');
21
+ }
22
+ if (res.changed.length > 0) {
23
+ console.log('Changed:');
24
+ for (const f of res.changed)
25
+ console.log(`- ${f}`);
26
+ }
27
+ else {
28
+ console.log('No changes');
29
+ }
30
+ if (res.warnings.length > 0) {
31
+ console.log('Warnings:');
32
+ for (const w of res.warnings)
33
+ console.log(`- ${w}`);
34
+ }
35
+ };
@@ -0,0 +1,3 @@
1
+ import { CLIOptions, Inquirerer } from 'inquirerer';
2
+ declare const _default: (argv: Partial<Record<string, any>>, prompter: Inquirerer, _options: CLIOptions) => Promise<Partial<Record<string, any>>>;
3
+ export default _default;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@launchql/core");
4
+ const env_1 = require("@launchql/env");
5
+ const logger_1 = require("@launchql/logger");
6
+ const pg_env_1 = require("pg-env");
7
+ const utils_1 = require("../utils");
8
+ const cli_error_1 = require("../utils/cli-error");
9
+ const deployed_changes_1 = require("../utils/deployed-changes");
10
+ const log = new logger_1.Logger('revert');
11
+ const revertUsageText = `
12
+ Revert Command:
13
+
14
+ constructive revert [OPTIONS]
15
+
16
+ Revert database changes and migrations.
17
+
18
+ Options:
19
+ --help, -h Show this help message
20
+ --recursive Revert recursively through dependencies
21
+ --package <name> Revert specific package
22
+ --to <target> Revert to specific change or tag
23
+ --to Interactive selection of deployed changes
24
+ --tx Use transactions (default: true)
25
+ --cwd <directory> Working directory (default: current directory)
26
+
27
+ Examples:
28
+ constructive revert Revert latest changes
29
+ constructive revert --to @v1.0.0 Revert to specific tag
30
+ constructive revert --to Interactive selection from deployed changes
31
+ `;
32
+ exports.default = async (argv, prompter, _options) => {
33
+ // Show usage if explicitly requested
34
+ if (argv.help || argv.h) {
35
+ console.log(revertUsageText);
36
+ process.exit(0);
37
+ }
38
+ const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
39
+ message: 'Select database'
40
+ });
41
+ const questions = [
42
+ {
43
+ name: 'yes',
44
+ type: 'confirm',
45
+ message: 'Are you sure you want to proceed?',
46
+ required: true
47
+ },
48
+ {
49
+ name: 'recursive',
50
+ type: 'confirm',
51
+ message: 'Deploy recursively through dependencies?',
52
+ useDefault: true,
53
+ default: true,
54
+ required: false
55
+ },
56
+ {
57
+ name: 'tx',
58
+ type: 'confirm',
59
+ message: 'Use Transaction?',
60
+ useDefault: true,
61
+ default: true,
62
+ required: false
63
+ }
64
+ ];
65
+ let { yes, recursive, cwd, tx } = await prompter.prompt(argv, questions);
66
+ if (!yes) {
67
+ log.info('Operation cancelled.');
68
+ return;
69
+ }
70
+ log.debug(`Using current directory: ${cwd}`);
71
+ let packageName;
72
+ if (recursive && argv.to !== true) {
73
+ packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'revert');
74
+ if (!packageName) {
75
+ await (0, cli_error_1.cliExitWithError)('No package found to revert');
76
+ }
77
+ }
78
+ const pkg = new core_1.LaunchQLPackage(cwd);
79
+ const opts = (0, env_1.getEnvOptions)({
80
+ pg: (0, pg_env_1.getPgEnvOptions)({ database }),
81
+ deployment: {
82
+ useTx: tx
83
+ }
84
+ });
85
+ let target;
86
+ if (argv.to === true) {
87
+ target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'revert');
88
+ if (!target) {
89
+ await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
90
+ }
91
+ }
92
+ else if (packageName && argv.to) {
93
+ target = `${packageName}:${argv.to}`;
94
+ }
95
+ else if (packageName) {
96
+ target = packageName;
97
+ }
98
+ else if (argv.package && argv.to) {
99
+ target = `${argv.package}:${argv.to}`;
100
+ }
101
+ else if (argv.package) {
102
+ target = argv.package;
103
+ }
104
+ await pkg.revert(opts, target, recursive);
105
+ log.success('Revert complete.');
106
+ return argv;
107
+ };
@@ -0,0 +1,6 @@
1
+ import { CLIOptions, Inquirerer } from 'inquirerer';
2
+ declare const _default: (argv: Partial<Record<string, any>>, prompter: Inquirerer, _options: CLIOptions) => Promise<{
3
+ _: string[];
4
+ "--"?: string[] | undefined;
5
+ }>;
6
+ export default _default;
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@launchql/core");
37
+ const logger_1 = require("@launchql/logger");
38
+ const types_1 = require("@launchql/types");
39
+ const path = __importStar(require("path"));
40
+ const argv_1 = require("../utils/argv");
41
+ const module_utils_1 = require("../utils/module-utils");
42
+ const log = new logger_1.Logger('tag');
43
+ const tagUsageText = `
44
+ Tag Command:
45
+
46
+ constructive tag [tag_name] [OPTIONS]
47
+
48
+ Add tags to changes for versioning.
49
+
50
+ Arguments:
51
+ tag_name Name of the tag to create
52
+
53
+ Options:
54
+ --help, -h Show this help message
55
+ --package <name> Target specific package
56
+ --changeName <name> Target specific change (default: latest)
57
+ --comment <text> Optional tag comment
58
+ --cwd <directory> Working directory (default: current directory)
59
+
60
+ Examples:
61
+ constructive tag v1.0.0 Add tag to latest change
62
+ constructive tag v1.0.0 --comment "Initial release" Add tag with comment
63
+ constructive tag v1.1.0 --package mypackage --changeName my-change Tag specific change in package
64
+ `;
65
+ exports.default = async (argv, prompter, _options) => {
66
+ // Show usage if explicitly requested
67
+ if (argv.help || argv.h) {
68
+ console.log(tagUsageText);
69
+ process.exit(0);
70
+ }
71
+ const { first: tagName, newArgv } = (0, argv_1.extractFirst)(argv);
72
+ const cwdResult = await prompter.prompt(newArgv, [
73
+ {
74
+ type: 'text',
75
+ name: 'cwd',
76
+ message: 'Working directory',
77
+ required: false,
78
+ default: process.cwd(),
79
+ useDefault: true
80
+ }
81
+ ]);
82
+ const cwd = cwdResult.cwd || process.cwd();
83
+ const pkg = new core_1.LaunchQLPackage(cwd);
84
+ let packageName;
85
+ if (argv.package) {
86
+ packageName = argv.package;
87
+ log.info(`Using specified package: ${packageName}`);
88
+ }
89
+ else if (pkg.isInModule()) {
90
+ packageName = pkg.getModuleName();
91
+ log.info(`Using current module: ${packageName}`);
92
+ }
93
+ else if (pkg.isInWorkspace()) {
94
+ packageName = await (0, module_utils_1.selectPackage)(newArgv, prompter, cwd, 'add tag to', log);
95
+ if (!packageName) {
96
+ throw new Error('No package selected. Cannot add tag without specifying a target package.');
97
+ }
98
+ }
99
+ else {
100
+ throw new Error('This command must be run inside a LaunchQL workspace or module.');
101
+ }
102
+ const questions = [];
103
+ if (!tagName) {
104
+ questions.push({
105
+ type: 'text',
106
+ name: 'tagName',
107
+ message: 'Tag name',
108
+ required: true,
109
+ validate: (value) => {
110
+ if (!value || value.trim().length === 0) {
111
+ return false;
112
+ }
113
+ if (value.includes('/')) {
114
+ return false;
115
+ }
116
+ if (value.includes('@')) {
117
+ return false;
118
+ }
119
+ return true;
120
+ }
121
+ });
122
+ }
123
+ questions.push({
124
+ type: 'text',
125
+ name: 'changeName',
126
+ message: 'Target change name (leave empty for latest change)',
127
+ required: false
128
+ }, {
129
+ type: 'text',
130
+ name: 'comment',
131
+ message: 'Tag comment (optional)',
132
+ required: false
133
+ });
134
+ const answers = await prompter.prompt(newArgv, questions);
135
+ const finalTagName = tagName || answers.tagName;
136
+ const changeName = answers.changeName;
137
+ const comment = answers.comment;
138
+ try {
139
+ if (argv.package || !pkg.isInModule()) {
140
+ const moduleMap = pkg.getModuleMap();
141
+ const module = moduleMap[packageName];
142
+ if (!module) {
143
+ throw types_1.errors.MODULE_NOT_FOUND({ name: packageName });
144
+ }
145
+ const workspacePath = pkg.getWorkspacePath();
146
+ const absoluteModulePath = path.resolve(workspacePath, module.path);
147
+ const originalCwd = process.cwd();
148
+ process.chdir(absoluteModulePath);
149
+ try {
150
+ const modulePkg = new core_1.LaunchQLPackage(absoluteModulePath);
151
+ modulePkg.addTag(finalTagName.trim(), changeName?.trim() || undefined, comment?.trim() || undefined);
152
+ log.info(`Successfully added tag '${finalTagName}' to ${changeName || 'latest change'} in package '${packageName}'`);
153
+ }
154
+ finally {
155
+ process.chdir(originalCwd);
156
+ }
157
+ }
158
+ else {
159
+ pkg.addTag(finalTagName.trim(), changeName?.trim() || undefined, comment?.trim() || undefined);
160
+ log.info(`Successfully added tag '${finalTagName}' to ${changeName || 'latest change'}`);
161
+ }
162
+ }
163
+ catch (error) {
164
+ log.error(`Failed to add tag: ${error instanceof Error ? error.message : String(error)}`);
165
+ throw error;
166
+ }
167
+ return newArgv;
168
+ };
@@ -0,0 +1,3 @@
1
+ import { CLIOptions, Inquirerer } from 'inquirerer';
2
+ declare const _default: (argv: Partial<Record<string, any>>, prompter: Inquirerer, _options: CLIOptions) => Promise<Partial<Record<string, any>>>;
3
+ export default _default;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@launchql/core");
4
+ const env_1 = require("@launchql/env");
5
+ const logger_1 = require("@launchql/logger");
6
+ const pg_env_1 = require("pg-env");
7
+ const utils_1 = require("../utils");
8
+ const cli_error_1 = require("../utils/cli-error");
9
+ const deployed_changes_1 = require("../utils/deployed-changes");
10
+ const log = new logger_1.Logger('verify');
11
+ const verifyUsageText = `
12
+ Verify Command:
13
+
14
+ constructive verify [OPTIONS]
15
+
16
+ Verify database state matches expected migrations.
17
+
18
+ Options:
19
+ --help, -h Show this help message
20
+ --recursive Verify recursively through dependencies
21
+ --package <name> Verify specific package
22
+ --to <target> Verify up to specific change or tag
23
+ --to Interactive selection of deployed changes
24
+ --cwd <directory> Working directory (default: current directory)
25
+
26
+ Examples:
27
+ constructive verify Verify current database state
28
+ constructive verify --package mypackage Verify specific package
29
+ constructive verify --to Interactive selection from deployed changes
30
+ `;
31
+ exports.default = async (argv, prompter, _options) => {
32
+ // Show usage if explicitly requested
33
+ if (argv.help || argv.h) {
34
+ console.log(verifyUsageText);
35
+ process.exit(0);
36
+ }
37
+ const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
38
+ message: 'Select database'
39
+ });
40
+ const questions = [
41
+ {
42
+ name: 'recursive',
43
+ type: 'confirm',
44
+ message: 'Deploy recursively through dependencies?',
45
+ useDefault: true,
46
+ default: true,
47
+ required: false
48
+ },
49
+ ];
50
+ let { recursive, cwd } = await prompter.prompt(argv, questions);
51
+ log.debug(`Using current directory: ${cwd}`);
52
+ let packageName;
53
+ if (recursive && argv.to !== true) {
54
+ packageName = await (0, deployed_changes_1.selectDeployedPackage)(database, argv, prompter, log, 'verify');
55
+ if (!packageName) {
56
+ await (0, cli_error_1.cliExitWithError)('No package found to verify');
57
+ }
58
+ }
59
+ const project = new core_1.LaunchQLPackage(cwd);
60
+ const opts = (0, env_1.getEnvOptions)({
61
+ pg: (0, pg_env_1.getPgEnvOptions)({ database })
62
+ });
63
+ let target;
64
+ if (argv.to === true) {
65
+ target = await (0, deployed_changes_1.selectDeployedChange)(database, argv, prompter, log, 'verify');
66
+ if (!target) {
67
+ await (0, cli_error_1.cliExitWithError)('No target selected, operation cancelled');
68
+ }
69
+ }
70
+ else if (packageName && argv.to) {
71
+ target = `${packageName}:${argv.to}`;
72
+ }
73
+ else if (packageName) {
74
+ target = packageName;
75
+ }
76
+ else if (argv.package && argv.to) {
77
+ target = `${argv.package}:${argv.to}`;
78
+ }
79
+ else if (argv.package) {
80
+ target = argv.package;
81
+ }
82
+ await project.verify(opts, target, recursive);
83
+ log.success('Verify complete.');
84
+ return argv;
85
+ };
package/commands.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { CLIOptions, Inquirerer } from 'inquirerer';
2
+ import { ParsedArgs } from 'minimist';
3
+ export declare const createConstructiveCommandMap: (skipPgTeardown?: boolean) => Record<string, Function>;
4
+ export declare const commands: (argv: Partial<ParsedArgs>, prompter: Inquirerer, options: CLIOptions & {
5
+ skipPgTeardown?: boolean;
6
+ }) => Promise<Partial<ParsedArgs>>;
package/commands.js ADDED
@@ -0,0 +1,113 @@
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.commands = exports.createConstructiveCommandMap = void 0;
7
+ const pg_cache_1 = require("pg-cache");
8
+ const add_1 = __importDefault(require("./commands/add"));
9
+ const admin_users_1 = __importDefault(require("./commands/admin-users"));
10
+ const analyze_1 = __importDefault(require("./commands/analyze"));
11
+ const clear_1 = __importDefault(require("./commands/clear"));
12
+ const deploy_1 = __importDefault(require("./commands/deploy"));
13
+ const docker_1 = __importDefault(require("./commands/docker"));
14
+ const env_1 = __importDefault(require("./commands/env"));
15
+ const export_1 = __importDefault(require("./commands/export"));
16
+ const extension_1 = __importDefault(require("./commands/extension"));
17
+ const init_1 = __importDefault(require("./commands/init"));
18
+ const install_1 = __importDefault(require("./commands/install"));
19
+ const kill_1 = __importDefault(require("./commands/kill"));
20
+ const migrate_1 = __importDefault(require("./commands/migrate"));
21
+ const package_1 = __importDefault(require("./commands/package"));
22
+ const plan_1 = __importDefault(require("./commands/plan"));
23
+ const remove_1 = __importDefault(require("./commands/remove"));
24
+ const rename_1 = __importDefault(require("./commands/rename"));
25
+ const revert_1 = __importDefault(require("./commands/revert"));
26
+ const tag_1 = __importDefault(require("./commands/tag"));
27
+ const verify_1 = __importDefault(require("./commands/verify"));
28
+ const package_2 = require("./package");
29
+ const utils_1 = require("./utils");
30
+ const cli_error_1 = require("./utils/cli-error");
31
+ const withPgTeardown = (fn, skipTeardown = false) => async (...args) => {
32
+ try {
33
+ await fn(...args);
34
+ }
35
+ finally {
36
+ if (!skipTeardown) {
37
+ await (0, pg_cache_1.teardownPgPools)();
38
+ }
39
+ }
40
+ };
41
+ const createConstructiveCommandMap = (skipPgTeardown = false) => {
42
+ const pgt = (fn) => withPgTeardown(fn, skipPgTeardown);
43
+ return {
44
+ add: add_1.default,
45
+ 'admin-users': pgt(admin_users_1.default),
46
+ clear: pgt(clear_1.default),
47
+ deploy: pgt(deploy_1.default),
48
+ docker: docker_1.default,
49
+ env: env_1.default,
50
+ verify: pgt(verify_1.default),
51
+ revert: pgt(revert_1.default),
52
+ remove: pgt(remove_1.default),
53
+ init: pgt(init_1.default),
54
+ extension: pgt(extension_1.default),
55
+ plan: pgt(plan_1.default),
56
+ export: pgt(export_1.default),
57
+ package: pgt(package_1.default),
58
+ tag: pgt(tag_1.default),
59
+ kill: pgt(kill_1.default),
60
+ install: pgt(install_1.default),
61
+ migrate: pgt(migrate_1.default),
62
+ analyze: pgt(analyze_1.default),
63
+ rename: pgt(rename_1.default)
64
+ };
65
+ };
66
+ exports.createConstructiveCommandMap = createConstructiveCommandMap;
67
+ const commands = async (argv, prompter, options) => {
68
+ if (argv.version || argv.v) {
69
+ const pkg = (0, package_2.readAndParsePackageJson)();
70
+ console.log(pkg.version);
71
+ process.exit(0);
72
+ }
73
+ let { first: command, newArgv } = (0, utils_1.extractFirst)(argv);
74
+ if ((argv.help || argv.h || command === 'help') && !command) {
75
+ console.log(utils_1.usageText);
76
+ process.exit(0);
77
+ }
78
+ if (command === 'help') {
79
+ console.log(utils_1.usageText);
80
+ process.exit(0);
81
+ }
82
+ const commandMap = (0, exports.createConstructiveCommandMap)(options?.skipPgTeardown);
83
+ if (!command) {
84
+ const answer = await prompter.prompt(argv, [
85
+ {
86
+ type: 'autocomplete',
87
+ name: 'command',
88
+ message: 'What do you want to do?',
89
+ options: Object.keys(commandMap)
90
+ }
91
+ ]);
92
+ command = answer.command;
93
+ }
94
+ newArgv = await prompter.prompt(newArgv, [
95
+ {
96
+ type: 'text',
97
+ name: 'cwd',
98
+ message: 'Working directory',
99
+ required: false,
100
+ default: process.cwd(),
101
+ useDefault: true
102
+ }
103
+ ]);
104
+ const commandFn = commandMap[command];
105
+ if (!commandFn) {
106
+ console.log(utils_1.usageText);
107
+ await (0, cli_error_1.cliExitWithError)(`Unknown command: ${command}`);
108
+ }
109
+ await commandFn(newArgv, prompter, options);
110
+ prompter.close();
111
+ return argv;
112
+ };
113
+ exports.commands = commands;