@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.
- package/LICENSE +23 -0
- package/README.md +412 -0
- package/commands/add.d.ts +7 -0
- package/commands/add.js +86 -0
- package/commands/admin-users/add.d.ts +4 -0
- package/commands/admin-users/add.js +89 -0
- package/commands/admin-users/bootstrap.d.ts +4 -0
- package/commands/admin-users/bootstrap.js +50 -0
- package/commands/admin-users/remove.d.ts +4 -0
- package/commands/admin-users/remove.js +82 -0
- package/commands/admin-users.d.ts +4 -0
- package/commands/admin-users.js +68 -0
- package/commands/analyze.d.ts +4 -0
- package/commands/analyze.js +21 -0
- package/commands/clear.d.ts +3 -0
- package/commands/clear.js +59 -0
- package/commands/deploy.d.ts +4 -0
- package/commands/deploy.js +146 -0
- package/commands/docker.d.ts +3 -0
- package/commands/docker.js +194 -0
- package/commands/env.d.ts +4 -0
- package/commands/env.js +124 -0
- package/commands/export.d.ts +3 -0
- package/commands/export.js +129 -0
- package/commands/extension.d.ts +4 -0
- package/commands/extension.js +48 -0
- package/commands/init/index.d.ts +7 -0
- package/commands/init/index.js +47 -0
- package/commands/init/module.d.ts +4 -0
- package/commands/init/module.js +71 -0
- package/commands/init/workspace.d.ts +4 -0
- package/commands/init/workspace.js +52 -0
- package/commands/install.d.ts +4 -0
- package/commands/install.js +37 -0
- package/commands/kill.d.ts +3 -0
- package/commands/kill.js +107 -0
- package/commands/migrate/deps.d.ts +4 -0
- package/commands/migrate/deps.js +186 -0
- package/commands/migrate/init.d.ts +4 -0
- package/commands/migrate/init.js +65 -0
- package/commands/migrate/list.d.ts +4 -0
- package/commands/migrate/list.js +85 -0
- package/commands/migrate/status.d.ts +4 -0
- package/commands/migrate/status.js +94 -0
- package/commands/migrate.d.ts +4 -0
- package/commands/migrate.js +69 -0
- package/commands/package.d.ts +3 -0
- package/commands/package.js +65 -0
- package/commands/plan.d.ts +3 -0
- package/commands/plan.js +62 -0
- package/commands/remove.d.ts +3 -0
- package/commands/remove.js +42 -0
- package/commands/rename.d.ts +4 -0
- package/commands/rename.js +35 -0
- package/commands/revert.d.ts +3 -0
- package/commands/revert.js +107 -0
- package/commands/tag.d.ts +6 -0
- package/commands/tag.js +168 -0
- package/commands/verify.d.ts +3 -0
- package/commands/verify.js +85 -0
- package/commands.d.ts +6 -0
- package/commands.js +113 -0
- package/dist/README.md +412 -0
- package/dist/package.json +64 -0
- package/esm/commands/add.js +51 -0
- package/esm/commands/admin-users/add.js +87 -0
- package/esm/commands/admin-users/bootstrap.js +48 -0
- package/esm/commands/admin-users/remove.js +80 -0
- package/esm/commands/admin-users.js +63 -0
- package/esm/commands/analyze.js +16 -0
- package/esm/commands/clear.js +54 -0
- package/esm/commands/deploy.js +144 -0
- package/esm/commands/docker.js +192 -0
- package/esm/commands/env.js +122 -0
- package/esm/commands/export.js +127 -0
- package/esm/commands/extension.js +46 -0
- package/esm/commands/init/index.js +42 -0
- package/esm/commands/init/module.js +68 -0
- package/esm/commands/init/workspace.js +46 -0
- package/esm/commands/install.js +35 -0
- package/esm/commands/kill.js +105 -0
- package/esm/commands/migrate/deps.js +184 -0
- package/esm/commands/migrate/init.js +63 -0
- package/esm/commands/migrate/list.js +83 -0
- package/esm/commands/migrate/status.js +92 -0
- package/esm/commands/migrate.js +64 -0
- package/esm/commands/package.js +63 -0
- package/esm/commands/plan.js +60 -0
- package/esm/commands/remove.js +40 -0
- package/esm/commands/rename.js +30 -0
- package/esm/commands/revert.js +105 -0
- package/esm/commands/tag.js +133 -0
- package/esm/commands/verify.js +83 -0
- package/esm/commands.js +105 -0
- package/esm/index.js +48 -0
- package/esm/package.js +26 -0
- package/esm/utils/argv.js +92 -0
- package/esm/utils/cli-error.js +48 -0
- package/esm/utils/database.js +78 -0
- package/esm/utils/deployed-changes.js +68 -0
- package/esm/utils/display.js +58 -0
- package/esm/utils/index.js +6 -0
- package/esm/utils/module-utils.js +51 -0
- package/index.d.ts +25 -0
- package/index.js +87 -0
- package/package.d.ts +1 -0
- package/package.js +29 -0
- package/package.json +64 -0
- package/utils/argv.d.ts +46 -0
- package/utils/argv.js +100 -0
- package/utils/cli-error.d.ts +8 -0
- package/utils/cli-error.js +52 -0
- package/utils/database.d.ts +21 -0
- package/utils/database.js +83 -0
- package/utils/deployed-changes.d.ts +4 -0
- package/utils/deployed-changes.js +72 -0
- package/utils/display.d.ts +3 -0
- package/utils/display.js +66 -0
- package/utils/index.d.ts +6 -0
- package/utils/index.js +22 -0
- package/utils/module-utils.d.ts +8 -0
- package/utils/module-utils.js +54 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@launchql/core");
|
|
4
|
+
const logger_1 = require("@launchql/logger");
|
|
5
|
+
const pg_env_1 = require("pg-env");
|
|
6
|
+
const log = new logger_1.Logger('admin-users-remove');
|
|
7
|
+
const removeUsageText = `
|
|
8
|
+
Admin Users Remove Command:
|
|
9
|
+
|
|
10
|
+
constructive admin-users remove [OPTIONS]
|
|
11
|
+
|
|
12
|
+
Remove database users and revoke their postgres roles.
|
|
13
|
+
|
|
14
|
+
Options:
|
|
15
|
+
--help, -h Show this help message
|
|
16
|
+
--username <username> Username for the database user to remove
|
|
17
|
+
--test Remove test users (app_user, app_admin)
|
|
18
|
+
--cwd <directory> Working directory (default: current directory)
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
constructive admin-users remove --username myuser
|
|
22
|
+
constructive admin-users remove --test # Remove test users
|
|
23
|
+
constructive admin-users remove # Will prompt for username
|
|
24
|
+
`;
|
|
25
|
+
exports.default = async (argv, prompter, _options) => {
|
|
26
|
+
// Show usage if explicitly requested
|
|
27
|
+
if (argv.help || argv.h) {
|
|
28
|
+
console.log(removeUsageText);
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
const pgEnv = (0, pg_env_1.getPgEnvOptions)();
|
|
32
|
+
const isTest = argv.test;
|
|
33
|
+
const init = new core_1.LaunchQLInit(pgEnv);
|
|
34
|
+
try {
|
|
35
|
+
if (isTest) {
|
|
36
|
+
const { yes: confirmTest } = await prompter.prompt(argv, [
|
|
37
|
+
{
|
|
38
|
+
type: 'confirm',
|
|
39
|
+
name: 'yes',
|
|
40
|
+
message: 'Are you sure you want to remove test users (app_user, app_admin)?',
|
|
41
|
+
default: false
|
|
42
|
+
}
|
|
43
|
+
]);
|
|
44
|
+
if (!confirmTest) {
|
|
45
|
+
log.info('Operation cancelled.');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
await init.removeDbRoles('app_user');
|
|
49
|
+
await init.removeDbRoles('app_admin');
|
|
50
|
+
log.success('Test users removed successfully.');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const prompts = [
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
name: 'username',
|
|
57
|
+
message: 'Enter username for database user to remove:',
|
|
58
|
+
validate: (input) => input && input.trim().length > 0
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
const { username } = await prompter.prompt(argv, prompts);
|
|
62
|
+
const { yes } = await prompter.prompt(argv, [
|
|
63
|
+
{
|
|
64
|
+
type: 'confirm',
|
|
65
|
+
name: 'yes',
|
|
66
|
+
message: `Are you sure you want to remove database user "${username}"?`,
|
|
67
|
+
default: false
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
if (!yes) {
|
|
71
|
+
log.info('Operation cancelled.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await init.removeDbRoles(username);
|
|
75
|
+
log.success(`Database user "${username}" removed successfully.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
await init.close();
|
|
80
|
+
}
|
|
81
|
+
return argv;
|
|
82
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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 utils_1 = require("../utils");
|
|
7
|
+
const add_1 = __importDefault(require("./admin-users/add"));
|
|
8
|
+
const bootstrap_1 = __importDefault(require("./admin-users/bootstrap"));
|
|
9
|
+
const remove_1 = __importDefault(require("./admin-users/remove"));
|
|
10
|
+
const subcommandMap = {
|
|
11
|
+
add: add_1.default,
|
|
12
|
+
bootstrap: bootstrap_1.default,
|
|
13
|
+
remove: remove_1.default
|
|
14
|
+
};
|
|
15
|
+
const adminUsersUsageText = `
|
|
16
|
+
Admin Users Commands:
|
|
17
|
+
|
|
18
|
+
constructive admin-users bootstrap Initialize postgres roles and permissions (must be run first)
|
|
19
|
+
constructive admin-users add Add database users with roles
|
|
20
|
+
constructive admin-users remove Remove database users and revoke roles
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
--help, -h Show this help message
|
|
24
|
+
--cwd Working directory (default: current directory)
|
|
25
|
+
`;
|
|
26
|
+
exports.default = async (argv, prompter, options) => {
|
|
27
|
+
let { first: subcommand, newArgv } = (0, utils_1.extractFirst)(argv);
|
|
28
|
+
// Prompt if no subcommand provided
|
|
29
|
+
if (!subcommand) {
|
|
30
|
+
// Show usage if explicitly requested and no subcommand provided
|
|
31
|
+
if (argv.help || argv.h) {
|
|
32
|
+
console.log(adminUsersUsageText);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
const answer = await prompter.prompt(argv, [
|
|
36
|
+
{
|
|
37
|
+
type: 'autocomplete',
|
|
38
|
+
name: 'subcommand',
|
|
39
|
+
message: 'What admin users operation do you want to perform?',
|
|
40
|
+
options: Object.keys(subcommandMap).map(cmd => ({
|
|
41
|
+
name: cmd,
|
|
42
|
+
value: cmd,
|
|
43
|
+
description: getSubcommandDescription(cmd)
|
|
44
|
+
}))
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
subcommand = answer.subcommand;
|
|
48
|
+
}
|
|
49
|
+
if (subcommand === 'help') {
|
|
50
|
+
console.log(adminUsersUsageText);
|
|
51
|
+
process.exit(0);
|
|
52
|
+
}
|
|
53
|
+
const subcommandFn = subcommandMap[subcommand];
|
|
54
|
+
if (!subcommandFn) {
|
|
55
|
+
console.error(`Unknown admin-users subcommand: ${subcommand}`);
|
|
56
|
+
console.log(adminUsersUsageText);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
await subcommandFn(newArgv, prompter, options);
|
|
60
|
+
};
|
|
61
|
+
function getSubcommandDescription(cmd) {
|
|
62
|
+
const descriptions = {
|
|
63
|
+
bootstrap: 'Initialize postgres roles and permissions (must be run first)',
|
|
64
|
+
add: 'Add database users with roles',
|
|
65
|
+
remove: 'Remove database users and revoke roles'
|
|
66
|
+
};
|
|
67
|
+
return descriptions[cmd] || '';
|
|
68
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
exports.default = async (argv, _prompter) => {
|
|
9
|
+
const cwd = argv.cwd || process.cwd();
|
|
10
|
+
const proj = new core_1.LaunchQLPackage(path_1.default.resolve(cwd));
|
|
11
|
+
const result = proj.analyzeModule();
|
|
12
|
+
if (result.ok) {
|
|
13
|
+
console.log(`OK ${result.name}`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
console.log(`NOT OK ${result.name}`);
|
|
17
|
+
for (const issue of result.issues) {
|
|
18
|
+
const loc = issue.file ? ` (${issue.file})` : '';
|
|
19
|
+
console.log(`- [${issue.code}] ${issue.message}${loc}`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 core_2 = require("@launchql/core");
|
|
8
|
+
const env_1 = require("@launchql/env");
|
|
9
|
+
const logger_1 = require("@launchql/logger");
|
|
10
|
+
const types_1 = require("@launchql/types");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const pg_env_1 = require("pg-env");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const log = new logger_1.Logger('clear');
|
|
15
|
+
exports.default = async (argv, prompter, _options) => {
|
|
16
|
+
const database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
|
|
17
|
+
message: 'Select database'
|
|
18
|
+
});
|
|
19
|
+
const questions = [
|
|
20
|
+
{
|
|
21
|
+
name: 'yes',
|
|
22
|
+
type: 'confirm',
|
|
23
|
+
message: 'Are you sure you want to clear ALL changes from the plan? This will remove all changes and their associated files.',
|
|
24
|
+
required: true
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
let { yes, cwd } = await prompter.prompt(argv, questions);
|
|
28
|
+
if (!yes) {
|
|
29
|
+
log.info('Operation cancelled.');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
log.debug(`Using current directory: ${cwd}`);
|
|
33
|
+
const pkg = new core_1.LaunchQLPackage(cwd);
|
|
34
|
+
if (!pkg.isInModule()) {
|
|
35
|
+
throw new Error('Not in a LaunchQL module directory. Please run this command from within a module.');
|
|
36
|
+
}
|
|
37
|
+
const modulePath = pkg.getModulePath();
|
|
38
|
+
if (!modulePath) {
|
|
39
|
+
throw new Error('Could not resolve module path');
|
|
40
|
+
}
|
|
41
|
+
const planPath = path_1.default.join(modulePath, 'pgpm.plan');
|
|
42
|
+
const result = (0, core_2.parsePlanFile)(planPath);
|
|
43
|
+
if (result.errors.length > 0) {
|
|
44
|
+
throw types_1.errors.PLAN_PARSE_ERROR({ planPath, errors: result.errors.map(e => e.message).join(', ') });
|
|
45
|
+
}
|
|
46
|
+
const plan = result.data;
|
|
47
|
+
if (plan.changes.length === 0) {
|
|
48
|
+
log.info('Plan is already empty - nothing to clear.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const firstChange = plan.changes[0].name;
|
|
52
|
+
log.info(`Found ${plan.changes.length} changes in plan. Clearing from first change: ${firstChange}`);
|
|
53
|
+
const opts = (0, env_1.getEnvOptions)({
|
|
54
|
+
pg: (0, pg_env_1.getPgEnvOptions)({ database })
|
|
55
|
+
});
|
|
56
|
+
await pkg.removeFromPlan(firstChange);
|
|
57
|
+
log.success(`â
Successfully cleared all changes from the plan.`);
|
|
58
|
+
return argv;
|
|
59
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
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 child_process_1 = require("child_process");
|
|
7
|
+
const pg_env_1 = require("pg-env");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const module_utils_1 = require("../utils/module-utils");
|
|
10
|
+
const deployUsageText = `
|
|
11
|
+
Deploy Command:
|
|
12
|
+
|
|
13
|
+
constructive deploy [OPTIONS]
|
|
14
|
+
|
|
15
|
+
Deploy database changes and migrations to target database.
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
--help, -h Show this help message
|
|
19
|
+
--createdb Create database if it doesn't exist
|
|
20
|
+
--recursive Deploy recursively through dependencies
|
|
21
|
+
--package <name> Target specific package
|
|
22
|
+
--to <target> Deploy to specific change or tag
|
|
23
|
+
--tx Use transactions (default: true)
|
|
24
|
+
--fast Use fast deployment strategy
|
|
25
|
+
--logOnly Log-only mode, skip script execution
|
|
26
|
+
--usePlan Use deployment plan
|
|
27
|
+
--cache Enable caching
|
|
28
|
+
--cwd <directory> Working directory (default: current directory)
|
|
29
|
+
|
|
30
|
+
Examples:
|
|
31
|
+
constructive deploy Deploy to selected database
|
|
32
|
+
constructive deploy --createdb Deploy with database creation
|
|
33
|
+
constructive deploy --package mypackage --to @v1.0.0 Deploy specific package to tag
|
|
34
|
+
constructive deploy --fast --no-tx Fast deployment without transactions
|
|
35
|
+
`;
|
|
36
|
+
exports.default = async (argv, prompter, _options) => {
|
|
37
|
+
// Show usage if explicitly requested
|
|
38
|
+
if (argv.help || argv.h) {
|
|
39
|
+
console.log(deployUsageText);
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
const pgEnv = (0, pg_env_1.getPgEnvOptions)();
|
|
43
|
+
const log = new logger_1.Logger('cli');
|
|
44
|
+
// Get target database
|
|
45
|
+
let database;
|
|
46
|
+
if (argv.createdb) {
|
|
47
|
+
// Prompt for selection
|
|
48
|
+
({ database } = await prompter.prompt(argv, [
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
name: 'database',
|
|
52
|
+
message: 'Database name',
|
|
53
|
+
required: true
|
|
54
|
+
}
|
|
55
|
+
]));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
database = await (0, utils_1.getTargetDatabase)(argv, prompter, {
|
|
59
|
+
message: 'Select database'
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const questions = [
|
|
63
|
+
{
|
|
64
|
+
name: 'yes',
|
|
65
|
+
type: 'confirm',
|
|
66
|
+
message: 'Are you sure you want to proceed?',
|
|
67
|
+
required: true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'recursive',
|
|
71
|
+
type: 'confirm',
|
|
72
|
+
message: 'Deploy recursively through dependencies?',
|
|
73
|
+
useDefault: true,
|
|
74
|
+
default: true,
|
|
75
|
+
required: false
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'tx',
|
|
79
|
+
type: 'confirm',
|
|
80
|
+
message: 'Use Transaction?',
|
|
81
|
+
useDefault: true,
|
|
82
|
+
default: true,
|
|
83
|
+
required: false
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'fast',
|
|
87
|
+
type: 'confirm',
|
|
88
|
+
message: 'Use Fast Deployment?',
|
|
89
|
+
useDefault: true,
|
|
90
|
+
default: false,
|
|
91
|
+
required: false
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'logOnly',
|
|
95
|
+
type: 'confirm',
|
|
96
|
+
message: 'Log-only mode (skip script execution)?',
|
|
97
|
+
useDefault: true,
|
|
98
|
+
default: false,
|
|
99
|
+
required: false
|
|
100
|
+
}
|
|
101
|
+
];
|
|
102
|
+
let { yes, recursive, createdb, cwd, tx, fast, logOnly } = await prompter.prompt(argv, questions);
|
|
103
|
+
if (!yes) {
|
|
104
|
+
log.info('Operation cancelled.');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
log.debug(`Using current directory: ${cwd}`);
|
|
108
|
+
if (createdb) {
|
|
109
|
+
log.info(`Creating database ${database}...`);
|
|
110
|
+
(0, child_process_1.execSync)(`createdb ${database}`, {
|
|
111
|
+
env: (0, pg_env_1.getSpawnEnvWithPg)(pgEnv)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
let packageName;
|
|
115
|
+
if (recursive) {
|
|
116
|
+
packageName = await (0, module_utils_1.selectPackage)(argv, prompter, cwd, 'deploy', log);
|
|
117
|
+
}
|
|
118
|
+
const cliOverrides = {
|
|
119
|
+
pg: (0, pg_env_1.getPgEnvOptions)({ database }),
|
|
120
|
+
deployment: {
|
|
121
|
+
useTx: tx !== false,
|
|
122
|
+
fast: fast !== false,
|
|
123
|
+
usePlan: argv.usePlan !== false,
|
|
124
|
+
cache: argv.cache !== false,
|
|
125
|
+
logOnly: argv.logOnly !== false,
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const opts = (0, env_1.getEnvOptions)(cliOverrides);
|
|
129
|
+
const project = new core_1.LaunchQLPackage(cwd);
|
|
130
|
+
let target;
|
|
131
|
+
if (packageName && argv.to) {
|
|
132
|
+
target = `${packageName}:${argv.to}`;
|
|
133
|
+
}
|
|
134
|
+
else if (packageName) {
|
|
135
|
+
target = packageName;
|
|
136
|
+
}
|
|
137
|
+
else if (argv.package && argv.to) {
|
|
138
|
+
target = `${argv.package}:${argv.to}`;
|
|
139
|
+
}
|
|
140
|
+
else if (argv.package) {
|
|
141
|
+
target = argv.package;
|
|
142
|
+
}
|
|
143
|
+
await project.deploy(opts, target, recursive);
|
|
144
|
+
log.success('Deployment complete.');
|
|
145
|
+
return argv;
|
|
146
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const child_process_1 = require("child_process");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const dockerUsageText = `
|
|
6
|
+
Docker Command:
|
|
7
|
+
|
|
8
|
+
constructive docker <subcommand> [OPTIONS]
|
|
9
|
+
|
|
10
|
+
Manage PostgreSQL Docker containers for local development.
|
|
11
|
+
|
|
12
|
+
Subcommands:
|
|
13
|
+
start Start PostgreSQL container
|
|
14
|
+
stop Stop PostgreSQL container
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--help, -h Show this help message
|
|
18
|
+
--name <name> Container name (default: postgres)
|
|
19
|
+
--image <image> Docker image (default: pyramation/pgvector:13.3-alpine)
|
|
20
|
+
--port <port> Host port mapping (default: 5432)
|
|
21
|
+
--user <user> PostgreSQL user (default: postgres)
|
|
22
|
+
--password <pass> PostgreSQL password (default: password)
|
|
23
|
+
--recreate Remove and recreate container on start
|
|
24
|
+
|
|
25
|
+
Examples:
|
|
26
|
+
constructive docker start Start default PostgreSQL container
|
|
27
|
+
constructive docker start --port 5433 Start on custom port
|
|
28
|
+
constructive docker start --recreate Remove and recreate container
|
|
29
|
+
constructive docker stop Stop PostgreSQL container
|
|
30
|
+
`;
|
|
31
|
+
function run(command, args, options = {}) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const stdio = options.stdio || 'pipe';
|
|
34
|
+
const child = (0, child_process_1.spawn)(command, args, { stdio });
|
|
35
|
+
let stdout = '';
|
|
36
|
+
let stderr = '';
|
|
37
|
+
if (stdio === 'pipe') {
|
|
38
|
+
child.stdout?.on('data', (data) => {
|
|
39
|
+
stdout += data.toString();
|
|
40
|
+
});
|
|
41
|
+
child.stderr?.on('data', (data) => {
|
|
42
|
+
stderr += data.toString();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
child.on('error', (error) => {
|
|
46
|
+
reject(error);
|
|
47
|
+
});
|
|
48
|
+
child.on('close', (code) => {
|
|
49
|
+
resolve({
|
|
50
|
+
code: code ?? 0,
|
|
51
|
+
stdout: stdout.trim(),
|
|
52
|
+
stderr: stderr.trim()
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function checkDockerAvailable() {
|
|
58
|
+
try {
|
|
59
|
+
const result = await run('docker', ['--version']);
|
|
60
|
+
return result.code === 0;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function isContainerRunning(name) {
|
|
67
|
+
try {
|
|
68
|
+
const result = await run('docker', ['inspect', '-f', '{{.State.Running}}', name]);
|
|
69
|
+
if (result.code === 0) {
|
|
70
|
+
return result.stdout.trim() === 'true';
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function containerExists(name) {
|
|
79
|
+
try {
|
|
80
|
+
const result = await run('docker', ['inspect', name]);
|
|
81
|
+
return result.code === 0;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function startContainer(options) {
|
|
88
|
+
const { name, image, port, user, password, recreate } = options;
|
|
89
|
+
const dockerAvailable = await checkDockerAvailable();
|
|
90
|
+
if (!dockerAvailable) {
|
|
91
|
+
await (0, utils_1.cliExitWithError)('Docker is not installed or not available in PATH. Please install Docker first.');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const exists = await containerExists(name);
|
|
95
|
+
const running = await isContainerRunning(name);
|
|
96
|
+
if (running === true) {
|
|
97
|
+
console.log(`â
Container "${name}" is already running`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (recreate && exists) {
|
|
101
|
+
console.log(`đī¸ Removing existing container "${name}"...`);
|
|
102
|
+
const removeResult = await run('docker', ['rm', '-f', name], { stdio: 'inherit' });
|
|
103
|
+
if (removeResult.code !== 0) {
|
|
104
|
+
await (0, utils_1.cliExitWithError)(`Failed to remove container "${name}"`);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (exists && running === false) {
|
|
109
|
+
console.log(`đ Starting existing container "${name}"...`);
|
|
110
|
+
const startResult = await run('docker', ['start', name], { stdio: 'inherit' });
|
|
111
|
+
if (startResult.code === 0) {
|
|
112
|
+
console.log(`â
Container "${name}" started successfully`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
await (0, utils_1.cliExitWithError)(`Failed to start container "${name}"`);
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
console.log(`đ Creating and starting new container "${name}"...`);
|
|
120
|
+
const runArgs = [
|
|
121
|
+
'run',
|
|
122
|
+
'-d',
|
|
123
|
+
'--name', name,
|
|
124
|
+
'-e', `POSTGRES_USER=${user}`,
|
|
125
|
+
'-e', `POSTGRES_PASSWORD=${password}`,
|
|
126
|
+
'-p', `${port}:5432`,
|
|
127
|
+
image
|
|
128
|
+
];
|
|
129
|
+
const runResult = await run('docker', runArgs, { stdio: 'inherit' });
|
|
130
|
+
if (runResult.code === 0) {
|
|
131
|
+
console.log(`â
Container "${name}" created and started successfully`);
|
|
132
|
+
console.log(`đ PostgreSQL is available at localhost:${port}`);
|
|
133
|
+
console.log(`đ¤ User: ${user}`);
|
|
134
|
+
console.log(`đ Password: ${password}`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
await (0, utils_1.cliExitWithError)(`Failed to create container "${name}". Check if port ${port} is already in use.`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function stopContainer(name) {
|
|
141
|
+
const dockerAvailable = await checkDockerAvailable();
|
|
142
|
+
if (!dockerAvailable) {
|
|
143
|
+
await (0, utils_1.cliExitWithError)('Docker is not installed or not available in PATH. Please install Docker first.');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const exists = await containerExists(name);
|
|
147
|
+
if (!exists) {
|
|
148
|
+
console.log(`âšī¸ Container "${name}" not found`);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const running = await isContainerRunning(name);
|
|
152
|
+
if (running === false) {
|
|
153
|
+
console.log(`âšī¸ Container "${name}" is already stopped`);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
console.log(`đ Stopping container "${name}"...`);
|
|
157
|
+
const stopResult = await run('docker', ['stop', name], { stdio: 'inherit' });
|
|
158
|
+
if (stopResult.code === 0) {
|
|
159
|
+
console.log(`â
Container "${name}" stopped successfully`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
await (0, utils_1.cliExitWithError)(`Failed to stop container "${name}"`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.default = async (argv, _prompter, _options) => {
|
|
166
|
+
if (argv.help || argv.h) {
|
|
167
|
+
console.log(dockerUsageText);
|
|
168
|
+
process.exit(0);
|
|
169
|
+
}
|
|
170
|
+
const { first: subcommand, newArgv } = (0, utils_1.extractFirst)(argv);
|
|
171
|
+
const args = newArgv;
|
|
172
|
+
if (!subcommand) {
|
|
173
|
+
console.log(dockerUsageText);
|
|
174
|
+
await (0, utils_1.cliExitWithError)('No subcommand provided. Use "start" or "stop".');
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const name = args.name || 'postgres';
|
|
178
|
+
const image = args.image || 'pyramation/pgvector:13.3-alpine';
|
|
179
|
+
const port = typeof args.port === 'number' ? args.port : 5432;
|
|
180
|
+
const user = args.user || 'postgres';
|
|
181
|
+
const password = args.password || 'password';
|
|
182
|
+
const recreate = args.recreate === true;
|
|
183
|
+
switch (subcommand) {
|
|
184
|
+
case 'start':
|
|
185
|
+
await startContainer({ name, image, port, user, password, recreate });
|
|
186
|
+
break;
|
|
187
|
+
case 'stop':
|
|
188
|
+
await stopContainer(name);
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
console.log(dockerUsageText);
|
|
192
|
+
await (0, utils_1.cliExitWithError)(`Unknown subcommand: ${subcommand}. Use "start" or "stop".`);
|
|
193
|
+
}
|
|
194
|
+
};
|