@constructive-io/cli 0.0.2 → 5.1.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.
Files changed (130) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +320 -189
  3. package/commands/{analyze.d.ts → codegen.d.ts} +2 -2
  4. package/commands/codegen.js +131 -0
  5. package/commands/explorer.js +94 -0
  6. package/commands/get-graphql-schema.js +73 -0
  7. package/commands/server.js +187 -0
  8. package/commands.d.ts +0 -1
  9. package/commands.js +42 -61
  10. package/esm/commands/codegen.js +126 -0
  11. package/esm/commands/explorer.js +92 -0
  12. package/esm/commands/get-graphql-schema.js +71 -0
  13. package/esm/commands/server.js +185 -0
  14. package/esm/commands.js +41 -59
  15. package/esm/index.js +16 -36
  16. package/esm/utils/display.js +26 -23
  17. package/esm/utils/index.js +3 -6
  18. package/index.d.ts +0 -22
  19. package/index.js +16 -72
  20. package/package.json +44 -29
  21. package/utils/display.d.ts +1 -1
  22. package/utils/display.js +26 -23
  23. package/utils/index.d.ts +3 -6
  24. package/utils/index.js +7 -20
  25. package/commands/add.d.ts +0 -7
  26. package/commands/add.js +0 -86
  27. package/commands/admin-users/add.d.ts +0 -4
  28. package/commands/admin-users/add.js +0 -89
  29. package/commands/admin-users/bootstrap.d.ts +0 -4
  30. package/commands/admin-users/bootstrap.js +0 -50
  31. package/commands/admin-users/remove.d.ts +0 -4
  32. package/commands/admin-users/remove.js +0 -82
  33. package/commands/admin-users.d.ts +0 -4
  34. package/commands/admin-users.js +0 -68
  35. package/commands/analyze.js +0 -21
  36. package/commands/clear.d.ts +0 -3
  37. package/commands/clear.js +0 -59
  38. package/commands/deploy.d.ts +0 -4
  39. package/commands/deploy.js +0 -146
  40. package/commands/docker.d.ts +0 -3
  41. package/commands/docker.js +0 -194
  42. package/commands/env.d.ts +0 -4
  43. package/commands/env.js +0 -124
  44. package/commands/export.js +0 -129
  45. package/commands/extension.js +0 -48
  46. package/commands/init/index.d.ts +0 -7
  47. package/commands/init/index.js +0 -47
  48. package/commands/init/module.d.ts +0 -4
  49. package/commands/init/module.js +0 -71
  50. package/commands/init/workspace.d.ts +0 -4
  51. package/commands/init/workspace.js +0 -52
  52. package/commands/install.d.ts +0 -4
  53. package/commands/install.js +0 -37
  54. package/commands/kill.js +0 -107
  55. package/commands/migrate/deps.d.ts +0 -4
  56. package/commands/migrate/deps.js +0 -186
  57. package/commands/migrate/init.d.ts +0 -4
  58. package/commands/migrate/init.js +0 -65
  59. package/commands/migrate/list.d.ts +0 -4
  60. package/commands/migrate/list.js +0 -85
  61. package/commands/migrate/status.d.ts +0 -4
  62. package/commands/migrate/status.js +0 -94
  63. package/commands/migrate.d.ts +0 -4
  64. package/commands/migrate.js +0 -69
  65. package/commands/package.d.ts +0 -3
  66. package/commands/package.js +0 -65
  67. package/commands/plan.d.ts +0 -3
  68. package/commands/plan.js +0 -62
  69. package/commands/remove.d.ts +0 -3
  70. package/commands/remove.js +0 -42
  71. package/commands/rename.d.ts +0 -4
  72. package/commands/rename.js +0 -35
  73. package/commands/revert.d.ts +0 -3
  74. package/commands/revert.js +0 -107
  75. package/commands/tag.d.ts +0 -6
  76. package/commands/tag.js +0 -168
  77. package/commands/verify.d.ts +0 -3
  78. package/commands/verify.js +0 -85
  79. package/dist/README.md +0 -412
  80. package/dist/package.json +0 -64
  81. package/esm/commands/add.js +0 -51
  82. package/esm/commands/admin-users/add.js +0 -87
  83. package/esm/commands/admin-users/bootstrap.js +0 -48
  84. package/esm/commands/admin-users/remove.js +0 -80
  85. package/esm/commands/admin-users.js +0 -63
  86. package/esm/commands/analyze.js +0 -16
  87. package/esm/commands/clear.js +0 -54
  88. package/esm/commands/deploy.js +0 -144
  89. package/esm/commands/docker.js +0 -192
  90. package/esm/commands/env.js +0 -122
  91. package/esm/commands/export.js +0 -127
  92. package/esm/commands/extension.js +0 -46
  93. package/esm/commands/init/index.js +0 -42
  94. package/esm/commands/init/module.js +0 -68
  95. package/esm/commands/init/workspace.js +0 -46
  96. package/esm/commands/install.js +0 -35
  97. package/esm/commands/kill.js +0 -105
  98. package/esm/commands/migrate/deps.js +0 -184
  99. package/esm/commands/migrate/init.js +0 -63
  100. package/esm/commands/migrate/list.js +0 -83
  101. package/esm/commands/migrate/status.js +0 -92
  102. package/esm/commands/migrate.js +0 -64
  103. package/esm/commands/package.js +0 -63
  104. package/esm/commands/plan.js +0 -60
  105. package/esm/commands/remove.js +0 -40
  106. package/esm/commands/rename.js +0 -30
  107. package/esm/commands/revert.js +0 -105
  108. package/esm/commands/tag.js +0 -133
  109. package/esm/commands/verify.js +0 -83
  110. package/esm/package.js +0 -26
  111. package/esm/utils/argv.js +0 -92
  112. package/esm/utils/cli-error.js +0 -48
  113. package/esm/utils/database.js +0 -78
  114. package/esm/utils/deployed-changes.js +0 -68
  115. package/esm/utils/module-utils.js +0 -51
  116. package/package.d.ts +0 -1
  117. package/package.js +0 -29
  118. package/utils/argv.d.ts +0 -46
  119. package/utils/argv.js +0 -100
  120. package/utils/cli-error.d.ts +0 -8
  121. package/utils/cli-error.js +0 -52
  122. package/utils/database.d.ts +0 -21
  123. package/utils/database.js +0 -83
  124. package/utils/deployed-changes.d.ts +0 -4
  125. package/utils/deployed-changes.js +0 -72
  126. package/utils/module-utils.d.ts +0 -8
  127. package/utils/module-utils.js +0 -54
  128. /package/commands/{export.d.ts → explorer.d.ts} +0 -0
  129. /package/commands/{extension.d.ts → get-graphql-schema.d.ts} +0 -0
  130. /package/commands/{kill.d.ts → server.d.ts} +0 -0
@@ -1,63 +0,0 @@
1
- import { LaunchQLMigrate } from '@launchql/core';
2
- import { Logger } from '@launchql/logger';
3
- import { getPgEnvOptions } from 'pg-env';
4
- import { getTargetDatabase } from '../../utils/database';
5
- const log = new Logger('migrate-init');
6
- export default async (argv, prompter, _options) => {
7
- const pgEnv = getPgEnvOptions();
8
- // Get target database
9
- const database = await getTargetDatabase(argv, prompter, {
10
- message: 'Select database to initialize migration tracking'
11
- });
12
- const questions = [
13
- {
14
- name: 'yes',
15
- type: 'confirm',
16
- message: `Initialize constructive migration schema in database "${database}"?`,
17
- required: true
18
- }
19
- ];
20
- const { yes } = await prompter.prompt(argv, questions);
21
- if (!yes) {
22
- log.info('Operation cancelled.');
23
- return;
24
- }
25
- log.info(`Initializing migration schema in database ${database}...`);
26
- const config = {
27
- host: pgEnv.host,
28
- port: pgEnv.port,
29
- user: pgEnv.user,
30
- password: pgEnv.password,
31
- database
32
- };
33
- const client = new LaunchQLMigrate(config);
34
- try {
35
- await client.initialize();
36
- log.success('Migration schema initialized successfully.');
37
- // Check if there's an existing Sqitch deployment to import
38
- const hasSquitch = await client.hasSqitchTables();
39
- if (hasSquitch) {
40
- const { importSquitch } = await prompter.prompt(argv, [
41
- {
42
- name: 'importSquitch',
43
- type: 'confirm',
44
- message: 'Existing Sqitch deployment detected. Import it?',
45
- required: true
46
- }
47
- ]);
48
- if (importSquitch) {
49
- log.info('Importing Sqitch deployment history...');
50
- await client.importFromSqitch();
51
- log.success('Sqitch deployment imported successfully.');
52
- }
53
- }
54
- }
55
- catch (error) {
56
- log.error(`Failed to initialize migration schema: ${error instanceof Error ? error.message : error}`);
57
- throw error;
58
- }
59
- finally {
60
- await client.close();
61
- }
62
- return argv;
63
- };
@@ -1,83 +0,0 @@
1
- import { LaunchQLMigrate } from '@launchql/core';
2
- import { parsePlanFile } from '@launchql/core';
3
- import { Logger } from '@launchql/logger';
4
- import { existsSync } from 'fs';
5
- import { join } from 'path';
6
- import { getPgEnvOptions } from 'pg-env';
7
- import { getTargetDatabase } from '../../utils/database';
8
- const log = new Logger('migrate-list');
9
- export default async (argv, prompter, options) => {
10
- const cwd = argv.cwd || process.cwd();
11
- const planPath = join(cwd, 'pgpm.plan');
12
- if (!existsSync(planPath)) {
13
- log.error(`No pgpm.plan found in ${cwd}`);
14
- process.exit(1);
15
- }
16
- // Get database configuration
17
- const pgEnv = getPgEnvOptions();
18
- const targetDatabase = await getTargetDatabase(argv, prompter, {
19
- message: 'Select database to list migrations'
20
- });
21
- const client = new LaunchQLMigrate({
22
- host: pgEnv.host,
23
- port: pgEnv.port,
24
- user: pgEnv.user,
25
- password: pgEnv.password,
26
- database: pgEnv.database
27
- });
28
- try {
29
- // Get all changes from plan file
30
- const planResult = parsePlanFile(planPath);
31
- if (!planResult.data || planResult.errors.length > 0) {
32
- log.error('Failed to parse plan file:', planResult.errors);
33
- process.exit(1);
34
- }
35
- const plan = planResult.data;
36
- const allChanges = plan.changes;
37
- // Get deployed changes from database
38
- const deployedChanges = await client.getDeployedChanges(targetDatabase, plan.package);
39
- console.log('\n📋 All Changes\n');
40
- console.log(`Package: ${plan.package}`);
41
- console.log(`Total Changes: ${allChanges.length}`);
42
- console.log(`Deployed: ${deployedChanges.length}`);
43
- console.log(`Pending: ${allChanges.length - deployedChanges.length}\n`);
44
- // Create a map for quick lookup
45
- const deployedMap = new Map(deployedChanges.map(c => [c.change_name, c]));
46
- // List all changes with their status
47
- const showAll = argv.all || allChanges.length <= 20;
48
- const changesToShow = showAll ? allChanges : allChanges.slice(0, 20);
49
- console.log('Status Change Name Dependencies');
50
- console.log('------ ----------------------------- --------------------------------');
51
- changesToShow.forEach(change => {
52
- const deployed = deployedMap.get(change.name);
53
- const status = deployed ? '✅' : '⏳';
54
- const deps = change.dependencies.length > 0 ? change.dependencies.join(', ') : '-';
55
- const depsDisplay = deps.length > 30 ? deps.substring(0, 27) + '...' : deps;
56
- console.log(`${status} ${change.name.padEnd(30)} ${depsDisplay}`);
57
- });
58
- if (!showAll && allChanges.length > 20) {
59
- console.log(`\n... and ${allChanges.length - 20} more changes. Use --all to see all changes.`);
60
- }
61
- // Show summary by status
62
- if (argv.summary !== false) {
63
- console.log('\n📊 Summary by Status:\n');
64
- const pending = allChanges.filter(c => !deployedMap.has(c.name));
65
- const deployed = allChanges.filter(c => deployedMap.has(c.name));
66
- console.log(`✅ Deployed: ${deployed.length}`);
67
- console.log(`⏳ Pending: ${pending.length}`);
68
- // Show deployment timeline
69
- if (deployedChanges.length > 0) {
70
- const sortedDeployed = [...deployedChanges].sort((a, b) => new Date(a.deployed_at).getTime() - new Date(b.deployed_at).getTime());
71
- const firstDeploy = new Date(sortedDeployed[0].deployed_at);
72
- const lastDeploy = new Date(sortedDeployed[sortedDeployed.length - 1].deployed_at);
73
- console.log(`\n📅 Deployment Timeline:`);
74
- console.log(` First: ${firstDeploy.toLocaleString()}`);
75
- console.log(` Last: ${lastDeploy.toLocaleString()}`);
76
- }
77
- }
78
- }
79
- catch (error) {
80
- log.error('Failed to list changes:', error);
81
- process.exit(1);
82
- }
83
- };
@@ -1,92 +0,0 @@
1
- import { LaunchQLMigrate } from '@launchql/core';
2
- import { parsePlanFile } from '@launchql/core';
3
- import { Logger } from '@launchql/logger';
4
- import { existsSync } from 'fs';
5
- import { join } from 'path';
6
- import { getPgEnvOptions } from 'pg-env';
7
- import { getTargetDatabase } from '../../utils/database';
8
- const log = new Logger('migrate-status');
9
- export default async (argv, prompter, options) => {
10
- const cwd = argv.cwd || process.cwd();
11
- const planPath = join(cwd, 'pgpm.plan');
12
- if (!existsSync(planPath)) {
13
- log.error(`No pgpm.plan found in ${cwd}`);
14
- process.exit(1);
15
- }
16
- // Get database configuration
17
- const pgEnv = getPgEnvOptions();
18
- const targetDatabase = await getTargetDatabase(argv, prompter, {
19
- message: 'Select database to check migration status'
20
- });
21
- const client = new LaunchQLMigrate({
22
- host: pgEnv.host,
23
- port: pgEnv.port,
24
- user: pgEnv.user,
25
- password: pgEnv.password,
26
- database: pgEnv.database
27
- });
28
- try {
29
- // Parse plan file to get package name
30
- const planResult = parsePlanFile(planPath);
31
- if (!planResult.data || planResult.errors.length > 0) {
32
- log.error('Failed to parse plan file:', planResult.errors);
33
- process.exit(1);
34
- }
35
- const plan = planResult.data;
36
- // Switch to target database
37
- const targetClient = new LaunchQLMigrate({
38
- host: pgEnv.host,
39
- port: pgEnv.port,
40
- user: pgEnv.user,
41
- password: pgEnv.password,
42
- database: targetDatabase
43
- });
44
- const statusResults = await targetClient.status(plan.package);
45
- console.log('\n📊 Migration Status\n');
46
- console.log(`Database: ${targetDatabase}`);
47
- if (statusResults.length > 0) {
48
- const status = statusResults[0];
49
- console.log(`Package: ${status.package}`);
50
- console.log(`Total Deployed: ${status.totalDeployed}`);
51
- if (status.lastChange) {
52
- console.log(`Last Change: ${status.lastChange}`);
53
- console.log(`Last Deployed: ${status.lastDeployed.toLocaleString()}`);
54
- }
55
- else {
56
- console.log('No changes deployed yet');
57
- }
58
- }
59
- else {
60
- console.log(`Package: ${plan.package}`);
61
- console.log('No deployment history found');
62
- }
63
- // Show recent changes
64
- const recentChanges = await targetClient.getRecentChanges(targetDatabase, 5);
65
- if (recentChanges.length > 0) {
66
- console.log('\n📋 Recent Changes:\n');
67
- recentChanges.forEach((change) => {
68
- const status = change.deployed_at ? '✅' : '⏳';
69
- const date = change.deployed_at ? new Date(change.deployed_at).toLocaleString() : 'Not deployed';
70
- console.log(`${status} ${change.change_name.padEnd(30)} ${date}`);
71
- });
72
- }
73
- // Show pending changes
74
- const pendingChanges = await targetClient.getPendingChanges(planPath, targetDatabase);
75
- if (pendingChanges.length > 0) {
76
- console.log(`\n⏳ Pending Changes: ${pendingChanges.length}\n`);
77
- pendingChanges.slice(0, 5).forEach((change) => {
78
- console.log(` - ${change}`);
79
- });
80
- if (pendingChanges.length > 5) {
81
- console.log(` ... and ${pendingChanges.length - 5} more`);
82
- }
83
- }
84
- else {
85
- console.log('\n✅ All changes deployed');
86
- }
87
- }
88
- catch (error) {
89
- log.error('Failed to get migration status:', error);
90
- process.exit(1);
91
- }
92
- };
@@ -1,64 +0,0 @@
1
- import { extractFirst } from '../utils';
2
- import deps from './migrate/deps';
3
- // Migrate subcommands
4
- import init from './migrate/init';
5
- import list from './migrate/list';
6
- import status from './migrate/status';
7
- const subcommandMap = {
8
- init,
9
- status,
10
- list,
11
- deps
12
- };
13
- const migrateUsageText = `
14
- Migrate Commands:
15
-
16
- launchql migrate init Initialize migration tracking in database
17
- launchql migrate status Show current migration status
18
- launchql migrate list List all changes (deployed and pending)
19
- launchql migrate deps Show change dependencies
20
-
21
- Options:
22
- --help, -h Show this help message
23
- --cwd Working directory (default: current directory)
24
- `;
25
- export default async (argv, prompter, options) => {
26
- let { first: subcommand, newArgv } = extractFirst(argv);
27
- // Show usage if explicitly requested
28
- if (argv.help || argv.h || subcommand === 'help') {
29
- console.log(migrateUsageText);
30
- process.exit(0);
31
- }
32
- // Prompt if no subcommand provided
33
- if (!subcommand) {
34
- const answer = await prompter.prompt(argv, [
35
- {
36
- type: 'autocomplete',
37
- name: 'subcommand',
38
- message: 'What migrate operation do you want to perform?',
39
- options: Object.keys(subcommandMap).map(cmd => ({
40
- name: cmd,
41
- value: cmd,
42
- description: getSubcommandDescription(cmd)
43
- }))
44
- }
45
- ]);
46
- subcommand = answer.subcommand;
47
- }
48
- const subcommandFn = subcommandMap[subcommand];
49
- if (!subcommandFn) {
50
- console.error(`Unknown migrate subcommand: ${subcommand}`);
51
- console.log(migrateUsageText);
52
- process.exit(1);
53
- }
54
- await subcommandFn(newArgv, prompter, options);
55
- };
56
- function getSubcommandDescription(cmd) {
57
- const descriptions = {
58
- init: 'Initialize migration tracking in database',
59
- status: 'Show current migration status',
60
- list: 'List all changes (deployed and pending)',
61
- deps: 'Show change dependencies'
62
- };
63
- return descriptions[cmd] || '';
64
- }
@@ -1,63 +0,0 @@
1
- import { LaunchQLPackage, writePackage } from '@launchql/core';
2
- const packageUsageText = `
3
- Package Command:
4
-
5
- constructive package [OPTIONS]
6
-
7
- Package module for distribution.
8
-
9
- Options:
10
- --help, -h Show this help message
11
- --plan Include deployment plan (default: true)
12
- --pretty Pretty-print output (default: true)
13
- --functionDelimiter <delimiter> Function delimiter (default: $EOFCODE$)
14
- --cwd <directory> Working directory (default: current directory)
15
-
16
- Examples:
17
- constructive package Package with defaults
18
- constructive package --no-plan Package without plan
19
- `;
20
- export default async (argv, prompter, _options) => {
21
- // Show usage if explicitly requested
22
- if (argv.help || argv.h) {
23
- console.log(packageUsageText);
24
- process.exit(0);
25
- }
26
- const questions = [
27
- {
28
- type: 'confirm',
29
- name: 'plan',
30
- default: true,
31
- useDefault: true,
32
- required: true
33
- },
34
- {
35
- type: 'confirm',
36
- name: 'pretty',
37
- default: true,
38
- useDefault: true,
39
- required: true
40
- },
41
- {
42
- type: 'text',
43
- name: 'functionDelimiter',
44
- default: '$EOFCODE$',
45
- useDefault: true,
46
- required: false
47
- }
48
- ];
49
- let { cwd, plan, pretty, functionDelimiter } = await prompter.prompt(argv, questions);
50
- const project = new LaunchQLPackage(cwd);
51
- project.ensureModule();
52
- const info = project.getModuleInfo();
53
- info.version;
54
- await writePackage({
55
- version: info.version,
56
- extension: true,
57
- usePlan: plan,
58
- packageDir: project.modulePath,
59
- pretty,
60
- functionDelimiter
61
- });
62
- return argv;
63
- };
@@ -1,60 +0,0 @@
1
- import { LaunchQLPackage } from '@launchql/core';
2
- import { Logger } from '@launchql/logger';
3
- const log = new Logger('plan');
4
- const planUsageText = `
5
- Plan Command:
6
-
7
- constructive plan [OPTIONS]
8
-
9
- Generate module deployment plans.
10
-
11
- Options:
12
- --help, -h Show this help message
13
- --includePackages Include packages in plan (default: true)
14
- --includeTags Prefer @tag references for external packages when available (default: true)
15
- --cwd <directory> Working directory (default: current directory)
16
-
17
- Examples:
18
- constructive plan Generate deployment plan for current module with defaults
19
- constructive plan --includePackages false Disable including external packages
20
- constructive plan --includeTags false Do not prefer tags for external packages
21
- `;
22
- export default async (argv, prompter, _options) => {
23
- // Show usage if explicitly requested
24
- if (argv.help || argv.h) {
25
- console.log(planUsageText);
26
- process.exit(0);
27
- }
28
- const questions = [
29
- {
30
- type: 'confirm',
31
- name: 'includePackages',
32
- message: 'Include packages in plan?',
33
- useDefault: true,
34
- default: true
35
- },
36
- {
37
- type: 'confirm',
38
- name: 'includeTags',
39
- message: 'Prefer @tag references for external packages when available?',
40
- useDefault: true,
41
- default: true
42
- }
43
- ];
44
- let { cwd, includePackages, includeTags } = await prompter.prompt(argv, questions);
45
- if (!cwd) {
46
- cwd = process.cwd();
47
- log.info(`Using current directory: ${cwd}`);
48
- }
49
- const pkg = new LaunchQLPackage(cwd);
50
- if (!pkg.isInModule()) {
51
- throw new Error('This command must be run inside a LaunchQL module.');
52
- }
53
- const includePackagesFlag = typeof includePackages === 'boolean' ? includePackages : true;
54
- const includeTagsFlag = typeof includeTags === 'boolean' ? includeTags : true;
55
- pkg.writeModulePlan({
56
- includePackages: includePackagesFlag,
57
- includeTags: includeTagsFlag
58
- });
59
- return argv;
60
- };
@@ -1,40 +0,0 @@
1
- import { LaunchQLPackage } from '@launchql/core';
2
- import { getEnvOptions } from '@launchql/env';
3
- import { Logger } from '@launchql/logger';
4
- import { getPgEnvOptions } from 'pg-env';
5
- import { getTargetDatabase } from '../utils';
6
- import { cliExitWithError } from '../utils/cli-error';
7
- const log = new Logger('remove');
8
- export default async (argv, prompter, _options) => {
9
- if (!argv.to) {
10
- await cliExitWithError('No change specified. Usage: constructive remove --to <change>');
11
- }
12
- const database = await getTargetDatabase(argv, prompter, {
13
- message: 'Select database'
14
- });
15
- const questions = [
16
- {
17
- name: 'yes',
18
- type: 'confirm',
19
- message: 'Are you sure you want to proceed with removing changes?',
20
- required: true
21
- }
22
- ];
23
- let { yes, cwd } = await prompter.prompt(argv, questions);
24
- if (!yes) {
25
- log.info('Operation cancelled.');
26
- return;
27
- }
28
- log.debug(`Using current directory: ${cwd}`);
29
- const pkg = new LaunchQLPackage(cwd);
30
- if (!pkg.isInModule()) {
31
- throw new Error('Not in a LaunchQL module directory. Please run this command from within a module.');
32
- }
33
- const opts = getEnvOptions({
34
- pg: getPgEnvOptions({ database })
35
- });
36
- const toChange = argv.to;
37
- await pkg.removeFromPlan(toChange);
38
- log.success(`✅ Successfully removed changes from '${toChange}' to end of plan.`);
39
- return argv;
40
- };
@@ -1,30 +0,0 @@
1
- import { LaunchQLPackage } from '@launchql/core';
2
- import path from 'path';
3
- import { cliExitWithError } from '../utils/cli-error';
4
- export default async (argv, _prompter) => {
5
- const cwd = argv.cwd || process.cwd();
6
- const to = argv.to || (argv._ && argv._[0]);
7
- if (!to) {
8
- await cliExitWithError('Missing new name. Use --to <name> or provide as positional argument.');
9
- }
10
- const dryRun = !!argv['dry-run'] || !!argv.dryRun;
11
- const syncPkg = !!argv['sync-pkg-name'] || !!argv.syncPkgName;
12
- const proj = new LaunchQLPackage(path.resolve(cwd));
13
- const res = proj.renameModule(to, { dryRun, syncPackageJsonName: syncPkg });
14
- if (dryRun) {
15
- console.log('Dry run');
16
- }
17
- if (res.changed.length > 0) {
18
- console.log('Changed:');
19
- for (const f of res.changed)
20
- console.log(`- ${f}`);
21
- }
22
- else {
23
- console.log('No changes');
24
- }
25
- if (res.warnings.length > 0) {
26
- console.log('Warnings:');
27
- for (const w of res.warnings)
28
- console.log(`- ${w}`);
29
- }
30
- };
@@ -1,105 +0,0 @@
1
- import { LaunchQLPackage } from '@launchql/core';
2
- import { getEnvOptions } from '@launchql/env';
3
- import { Logger } from '@launchql/logger';
4
- import { getPgEnvOptions } from 'pg-env';
5
- import { getTargetDatabase } from '../utils';
6
- import { cliExitWithError } from '../utils/cli-error';
7
- import { selectDeployedChange, selectDeployedPackage } from '../utils/deployed-changes';
8
- const log = new Logger('revert');
9
- const revertUsageText = `
10
- Revert Command:
11
-
12
- constructive revert [OPTIONS]
13
-
14
- Revert database changes and migrations.
15
-
16
- Options:
17
- --help, -h Show this help message
18
- --recursive Revert recursively through dependencies
19
- --package <name> Revert specific package
20
- --to <target> Revert to specific change or tag
21
- --to Interactive selection of deployed changes
22
- --tx Use transactions (default: true)
23
- --cwd <directory> Working directory (default: current directory)
24
-
25
- Examples:
26
- constructive revert Revert latest changes
27
- constructive revert --to @v1.0.0 Revert to specific tag
28
- constructive revert --to Interactive selection from deployed changes
29
- `;
30
- export default async (argv, prompter, _options) => {
31
- // Show usage if explicitly requested
32
- if (argv.help || argv.h) {
33
- console.log(revertUsageText);
34
- process.exit(0);
35
- }
36
- const database = await getTargetDatabase(argv, prompter, {
37
- message: 'Select database'
38
- });
39
- const questions = [
40
- {
41
- name: 'yes',
42
- type: 'confirm',
43
- message: 'Are you sure you want to proceed?',
44
- required: true
45
- },
46
- {
47
- name: 'recursive',
48
- type: 'confirm',
49
- message: 'Deploy recursively through dependencies?',
50
- useDefault: true,
51
- default: true,
52
- required: false
53
- },
54
- {
55
- name: 'tx',
56
- type: 'confirm',
57
- message: 'Use Transaction?',
58
- useDefault: true,
59
- default: true,
60
- required: false
61
- }
62
- ];
63
- let { yes, recursive, cwd, tx } = await prompter.prompt(argv, questions);
64
- if (!yes) {
65
- log.info('Operation cancelled.');
66
- return;
67
- }
68
- log.debug(`Using current directory: ${cwd}`);
69
- let packageName;
70
- if (recursive && argv.to !== true) {
71
- packageName = await selectDeployedPackage(database, argv, prompter, log, 'revert');
72
- if (!packageName) {
73
- await cliExitWithError('No package found to revert');
74
- }
75
- }
76
- const pkg = new LaunchQLPackage(cwd);
77
- const opts = getEnvOptions({
78
- pg: getPgEnvOptions({ database }),
79
- deployment: {
80
- useTx: tx
81
- }
82
- });
83
- let target;
84
- if (argv.to === true) {
85
- target = await selectDeployedChange(database, argv, prompter, log, 'revert');
86
- if (!target) {
87
- await cliExitWithError('No target selected, operation cancelled');
88
- }
89
- }
90
- else if (packageName && argv.to) {
91
- target = `${packageName}:${argv.to}`;
92
- }
93
- else if (packageName) {
94
- target = packageName;
95
- }
96
- else if (argv.package && argv.to) {
97
- target = `${argv.package}:${argv.to}`;
98
- }
99
- else if (argv.package) {
100
- target = argv.package;
101
- }
102
- await pkg.revert(opts, target, recursive);
103
- log.success('Revert complete.');
104
- return argv;
105
- };