kodu 1.1.21 → 2.0.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/AGENTS.md +36 -68
- package/README.md +97 -96
- package/dist/package.json +1 -2
- package/dist/src/app.module.js +0 -8
- package/dist/src/app.module.js.map +1 -1
- package/dist/src/commands/init/init.command.d.ts +2 -9
- package/dist/src/commands/init/init.command.js +15 -241
- package/dist/src/commands/init/init.command.js.map +1 -1
- package/dist/src/commands/pack/pack.command.d.ts +9 -0
- package/dist/src/commands/pack/pack.command.js +72 -3
- package/dist/src/commands/pack/pack.command.js.map +1 -1
- package/dist/src/core/config/config.schema.d.ts +0 -46
- package/dist/src/core/config/config.schema.js +1 -51
- package/dist/src/core/config/config.schema.js.map +1 -1
- package/dist/src/core/config/config.service.js +2 -2
- package/dist/src/core/config/config.service.js.map +1 -1
- package/dist/src/core/config/prompt.service.d.ts +1 -4
- package/dist/src/core/config/prompt.service.js +4 -17
- package/dist/src/core/config/prompt.service.js.map +1 -1
- package/dist/src/core/file-system/fs.service.d.ts +1 -0
- package/dist/src/core/file-system/fs.service.js +4 -1
- package/dist/src/core/file-system/fs.service.js.map +1 -1
- package/dist/src/shared/constants.d.ts +0 -4
- package/dist/src/shared/constants.js +1 -5
- package/dist/src/shared/constants.js.map +1 -1
- package/dist/src/shared/git/git.module.js +0 -2
- package/dist/src/shared/git/git.module.js.map +1 -1
- package/dist/src/shared/git/git.service.d.ts +0 -8
- package/dist/src/shared/git/git.service.js +2 -34
- package/dist/src/shared/git/git.service.js.map +1 -1
- package/dist/src/shared/tokenizer/tokenizer.module.js +0 -2
- package/dist/src/shared/tokenizer/tokenizer.module.js.map +1 -1
- package/dist/src/shared/tokenizer/tokenizer.service.d.ts +0 -6
- package/dist/src/shared/tokenizer/tokenizer.service.js +8 -38
- package/dist/src/shared/tokenizer/tokenizer.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/kodu.schema.json +0 -139
- package/package.json +1 -2
- package/skills/kodu-ops/SKILL.md +184 -0
- package/src/app.module.ts +0 -8
- package/src/commands/init/init.command.ts +15 -310
- package/src/commands/pack/pack.command.ts +66 -3
- package/src/core/config/config.schema.ts +1 -68
- package/src/core/config/config.service.ts +2 -2
- package/src/core/config/prompt.service.ts +4 -26
- package/src/core/file-system/fs.service.ts +7 -1
- package/src/shared/constants.ts +0 -4
- package/src/shared/git/git.module.ts +0 -2
- package/src/shared/git/git.service.ts +1 -33
- package/src/shared/tokenizer/tokenizer.module.ts +0 -2
- package/src/shared/tokenizer/tokenizer.service.ts +9 -39
- package/.kodu/prompts/.keep +0 -0
- package/.kodu/prompts/commit.md +0 -9
- package/.kodu/prompts/pack.md +0 -7
- package/.kodu/prompts/review-bug.md +0 -6
- package/.kodu/prompts/review-security.md +0 -6
- package/.kodu/prompts/review-style.md +0 -6
- package/.opencode/command/openspec-apply.md +0 -24
- package/.opencode/command/openspec-archive.md +0 -27
- package/.opencode/command/openspec-proposal.md +0 -29
- package/.opencode/skills/kodu-ops/SKILL.md +0 -60
- package/dist/src/commands/commit/commit.command.d.ts +0 -18
- package/dist/src/commands/commit/commit.command.js +0 -149
- package/dist/src/commands/commit/commit.command.js.map +0 -1
- package/dist/src/commands/commit/commit.module.d.ts +0 -2
- package/dist/src/commands/commit/commit.module.js +0 -25
- package/dist/src/commands/commit/commit.module.js.map +0 -1
- package/dist/src/commands/ops/ops.command.d.ts +0 -4
- package/dist/src/commands/ops/ops.command.js +0 -39
- package/dist/src/commands/ops/ops.command.js.map +0 -1
- package/dist/src/commands/ops/ops.module.d.ts +0 -2
- package/dist/src/commands/ops/ops.module.js +0 -33
- package/dist/src/commands/ops/ops.module.js.map +0 -1
- package/dist/src/commands/ops/ops.types.d.ts +0 -13
- package/dist/src/commands/ops/ops.types.js +0 -12
- package/dist/src/commands/ops/ops.types.js.map +0 -1
- package/dist/src/commands/ops/ops.utils.d.ts +0 -13
- package/dist/src/commands/ops/ops.utils.js +0 -121
- package/dist/src/commands/ops/ops.utils.js.map +0 -1
- package/dist/src/commands/ops/subcommands/ops-env.command.d.ts +0 -24
- package/dist/src/commands/ops/subcommands/ops-env.command.js +0 -156
- package/dist/src/commands/ops/subcommands/ops-env.command.js.map +0 -1
- package/dist/src/commands/ops/subcommands/ops-routes.command.d.ts +0 -22
- package/dist/src/commands/ops/subcommands/ops-routes.command.js +0 -203
- package/dist/src/commands/ops/subcommands/ops-routes.command.js.map +0 -1
- package/dist/src/commands/ops/subcommands/ops-service.command.d.ts +0 -22
- package/dist/src/commands/ops/subcommands/ops-service.command.js +0 -169
- package/dist/src/commands/ops/subcommands/ops-service.command.js.map +0 -1
- package/dist/src/commands/ops/subcommands/ops-sysinfo.command.d.ts +0 -14
- package/dist/src/commands/ops/subcommands/ops-sysinfo.command.js +0 -75
- package/dist/src/commands/ops/subcommands/ops-sysinfo.command.js.map +0 -1
- package/dist/src/commands/review/review.command.d.ts +0 -26
- package/dist/src/commands/review/review.command.js +0 -205
- package/dist/src/commands/review/review.command.js.map +0 -1
- package/dist/src/commands/review/review.module.d.ts +0 -2
- package/dist/src/commands/review/review.module.js +0 -26
- package/dist/src/commands/review/review.module.js.map +0 -1
- package/dist/src/core/config/default-prompts.d.ts +0 -9
- package/dist/src/core/config/default-prompts.js +0 -49
- package/dist/src/core/config/default-prompts.js.map +0 -1
- package/dist/src/shared/ai/ai.module.d.ts +0 -2
- package/dist/src/shared/ai/ai.module.js +0 -23
- package/dist/src/shared/ai/ai.module.js.map +0 -1
- package/dist/src/shared/ai/ai.service.d.ts +0 -22
- package/dist/src/shared/ai/ai.service.js +0 -164
- package/dist/src/shared/ai/ai.service.js.map +0 -1
- package/dist/src/shared/ssh/ssh.module.d.ts +0 -2
- package/dist/src/shared/ssh/ssh.module.js +0 -21
- package/dist/src/shared/ssh/ssh.module.js.map +0 -1
- package/dist/src/shared/ssh/ssh.service.d.ts +0 -11
- package/dist/src/shared/ssh/ssh.service.js +0 -53
- package/dist/src/shared/ssh/ssh.service.js.map +0 -1
- package/src/commands/commit/commit.command.ts +0 -139
- package/src/commands/commit/commit.module.ts +0 -12
- package/src/commands/ops/ops.command.ts +0 -30
- package/src/commands/ops/ops.module.ts +0 -20
- package/src/commands/ops/ops.types.ts +0 -24
- package/src/commands/ops/ops.utils.ts +0 -160
- package/src/commands/ops/subcommands/ops-env.command.ts +0 -165
- package/src/commands/ops/subcommands/ops-routes.command.ts +0 -221
- package/src/commands/ops/subcommands/ops-service.command.ts +0 -190
- package/src/commands/ops/subcommands/ops-sysinfo.command.ts +0 -77
- package/src/commands/review/review.command.ts +0 -199
- package/src/commands/review/review.module.ts +0 -13
- package/src/core/config/default-prompts.ts +0 -53
- package/src/shared/ai/ai.module.ts +0 -10
- package/src/shared/ai/ai.service.ts +0 -216
- package/src/shared/ssh/ssh.module.ts +0 -8
- package/src/shared/ssh/ssh.service.ts +0 -61
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ServerConfig } from '../../core/config/config.schema';
|
|
2
|
-
export type OpsErrorCode = 'CLI_ERROR' | 'CONFIG_ERROR' | 'NOT_FOUND' | 'VALIDATION_ERROR';
|
|
3
|
-
export type ResolvedServerConfig = ServerConfig & {
|
|
4
|
-
sshKeyPath: string;
|
|
5
|
-
paths?: {
|
|
6
|
-
apps: string;
|
|
7
|
-
caddy?: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export declare class OpsCliError extends Error {
|
|
11
|
-
readonly code: OpsErrorCode;
|
|
12
|
-
constructor(code: OpsErrorCode, message: string);
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpsCliError = void 0;
|
|
4
|
-
class OpsCliError extends Error {
|
|
5
|
-
code;
|
|
6
|
-
constructor(code, message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.code = code;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.OpsCliError = OpsCliError;
|
|
12
|
-
//# sourceMappingURL=ops.types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ops.types.js","sourceRoot":"","sources":["../../../../src/commands/ops/ops.types.ts"],"names":[],"mappings":";;;AAgBA,MAAa,WAAY,SAAQ,KAAK;IAElB;IADlB,YACkB,IAAkB,EAClC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAc;IAIpC,CAAC;CACF;AAPD,kCAOC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { KoduConfig } from '../../core/config/config.schema';
|
|
2
|
-
import type { SshResult } from '../../shared/ssh/ssh.service';
|
|
3
|
-
import { type ResolvedServerConfig } from './ops.types';
|
|
4
|
-
export declare function printJson(payload: unknown, isError?: boolean): void;
|
|
5
|
-
export declare function printCliError(error: unknown): void;
|
|
6
|
-
export declare function printSshError(result: SshResult, command: string): void;
|
|
7
|
-
export declare function resolveServerOrThrow(config: KoduConfig, alias: string): Promise<ResolvedServerConfig>;
|
|
8
|
-
export declare function resolveAppsPath(server: ResolvedServerConfig): string;
|
|
9
|
-
export declare function resolveCaddyPath(server: ResolvedServerConfig): string;
|
|
10
|
-
export declare function shellQuote(value: string): string;
|
|
11
|
-
export declare function ensureEnvKey(key: string | undefined): string;
|
|
12
|
-
export declare function ensureRequired(value: string | undefined, name: string): string;
|
|
13
|
-
export declare function ensureAction<T extends string>(value: string, allowed: readonly T[], context: string): T;
|
|
@@ -1,121 +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.printJson = printJson;
|
|
7
|
-
exports.printCliError = printCliError;
|
|
8
|
-
exports.printSshError = printSshError;
|
|
9
|
-
exports.resolveServerOrThrow = resolveServerOrThrow;
|
|
10
|
-
exports.resolveAppsPath = resolveAppsPath;
|
|
11
|
-
exports.resolveCaddyPath = resolveCaddyPath;
|
|
12
|
-
exports.shellQuote = shellQuote;
|
|
13
|
-
exports.ensureEnvKey = ensureEnvKey;
|
|
14
|
-
exports.ensureRequired = ensureRequired;
|
|
15
|
-
exports.ensureAction = ensureAction;
|
|
16
|
-
const promises_1 = require("node:fs/promises");
|
|
17
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
18
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
19
|
-
const ops_types_1 = require("./ops.types");
|
|
20
|
-
const DEFAULT_APPS_PATH = '/var/agent-apps';
|
|
21
|
-
function printJson(payload, isError = false) {
|
|
22
|
-
const line = JSON.stringify(payload);
|
|
23
|
-
if (isError) {
|
|
24
|
-
console.error(line);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
console.log(line);
|
|
28
|
-
}
|
|
29
|
-
function printCliError(error) {
|
|
30
|
-
const cliError = toCliError(error);
|
|
31
|
-
printJson({
|
|
32
|
-
status: 'error',
|
|
33
|
-
code: cliError.code,
|
|
34
|
-
error: cliError.message,
|
|
35
|
-
}, true);
|
|
36
|
-
}
|
|
37
|
-
function printSshError(result, command) {
|
|
38
|
-
printJson({
|
|
39
|
-
status: 'error',
|
|
40
|
-
code: result.exitCode,
|
|
41
|
-
stderr: result.stderr || result.error || 'Unknown SSH error',
|
|
42
|
-
command,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async function resolveServerOrThrow(config, alias) {
|
|
46
|
-
const servers = config.ops?.servers;
|
|
47
|
-
if (!servers) {
|
|
48
|
-
throw new ops_types_1.OpsCliError('CONFIG_ERROR', 'ops.servers not configured in kodu.json');
|
|
49
|
-
}
|
|
50
|
-
const server = servers[alias];
|
|
51
|
-
if (!server) {
|
|
52
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', `Server alias '${alias}' not found in kodu.json`);
|
|
53
|
-
}
|
|
54
|
-
const resolved = normalizeServer(server);
|
|
55
|
-
await assertSshKeyExists(resolved.sshKeyPath);
|
|
56
|
-
return resolved;
|
|
57
|
-
}
|
|
58
|
-
function resolveAppsPath(server) {
|
|
59
|
-
return server.paths?.apps ?? DEFAULT_APPS_PATH;
|
|
60
|
-
}
|
|
61
|
-
function resolveCaddyPath(server) {
|
|
62
|
-
return (server.paths?.caddy ?? node_path_1.default.posix.join(resolveAppsPath(server), 'caddy'));
|
|
63
|
-
}
|
|
64
|
-
function shellQuote(value) {
|
|
65
|
-
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
66
|
-
}
|
|
67
|
-
function ensureEnvKey(key) {
|
|
68
|
-
if (!key) {
|
|
69
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', 'Option --key is required');
|
|
70
|
-
}
|
|
71
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
|
|
72
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', 'Invalid env key format. Allowed: [A-Za-z_][A-Za-z0-9_]*');
|
|
73
|
-
}
|
|
74
|
-
return key;
|
|
75
|
-
}
|
|
76
|
-
function ensureRequired(value, name) {
|
|
77
|
-
if (!value) {
|
|
78
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', `Option --${name} is required`);
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
function ensureAction(value, allowed, context) {
|
|
83
|
-
if (!allowed.includes(value)) {
|
|
84
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', `Unsupported ${context}: '${value}'. Allowed: ${allowed.join(', ')}`);
|
|
85
|
-
}
|
|
86
|
-
return value;
|
|
87
|
-
}
|
|
88
|
-
function normalizeServer(server) {
|
|
89
|
-
const sshKeyPath = server.sshKeyPath.startsWith('~')
|
|
90
|
-
? node_path_1.default.join(node_os_1.default.homedir(), server.sshKeyPath.slice(1))
|
|
91
|
-
: server.sshKeyPath;
|
|
92
|
-
const apps = server.paths?.apps ?? DEFAULT_APPS_PATH;
|
|
93
|
-
return {
|
|
94
|
-
...server,
|
|
95
|
-
sshKeyPath: node_path_1.default.isAbsolute(sshKeyPath)
|
|
96
|
-
? sshKeyPath
|
|
97
|
-
: node_path_1.default.resolve(process.cwd(), sshKeyPath),
|
|
98
|
-
paths: {
|
|
99
|
-
apps,
|
|
100
|
-
caddy: server.paths?.caddy,
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
async function assertSshKeyExists(sshKeyPath) {
|
|
105
|
-
try {
|
|
106
|
-
await (0, promises_1.access)(sshKeyPath);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', `SSH key file not found or inaccessible: ${sshKeyPath}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function toCliError(error) {
|
|
113
|
-
if (error instanceof ops_types_1.OpsCliError) {
|
|
114
|
-
return { code: error.code, message: error.message };
|
|
115
|
-
}
|
|
116
|
-
if (error instanceof Error) {
|
|
117
|
-
return { code: 'CLI_ERROR', message: error.message };
|
|
118
|
-
}
|
|
119
|
-
return { code: 'CLI_ERROR', message: 'Unknown CLI error' };
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=ops.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ops.utils.js","sourceRoot":"","sources":["../../../../src/commands/ops/ops.utils.ts"],"names":[],"mappings":";;;;;AAaA,8BAOC;AAED,sCAUC;AAED,sCAOC;AAED,oDAuBC;AAED,0CAEC;AAED,4CAIC;AAED,gCAEC;AAED,oCAaC;AAED,wCAQC;AAED,oCAYC;AAvHD,+CAA0C;AAC1C,sDAAyB;AACzB,0DAA6B;AAG7B,2CAIqB;AAErB,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C,SAAgB,SAAS,CAAC,OAAgB,EAAE,OAAO,GAAG,KAAK;IACzD,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vD,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { CommandRunner } from 'nest-commander';
|
|
2
|
-
import { ConfigService } from '../../../core/config/config.service';
|
|
3
|
-
import { SshService } from '../../../shared/ssh/ssh.service';
|
|
4
|
-
type OpsEnvOptions = {
|
|
5
|
-
server?: string;
|
|
6
|
-
action?: string;
|
|
7
|
-
project?: string;
|
|
8
|
-
key?: string;
|
|
9
|
-
val?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare class OpsEnvCommand extends CommandRunner {
|
|
12
|
-
private readonly configService;
|
|
13
|
-
private readonly sshService;
|
|
14
|
-
constructor(configService: ConfigService, sshService: SshService);
|
|
15
|
-
parseServer(value: string): string;
|
|
16
|
-
parseAction(value: string): string;
|
|
17
|
-
parseProject(value: string): string;
|
|
18
|
-
parseKey(value: string): string;
|
|
19
|
-
parseVal(value: string): string;
|
|
20
|
-
run(passedParams: string[], options?: OpsEnvOptions): Promise<void>;
|
|
21
|
-
private buildCommand;
|
|
22
|
-
private buildBashScript;
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.OpsEnvCommand = void 0;
|
|
16
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
-
const nest_commander_1 = require("nest-commander");
|
|
18
|
-
const config_service_1 = require("../../../core/config/config.service");
|
|
19
|
-
const ssh_service_1 = require("../../../shared/ssh/ssh.service");
|
|
20
|
-
const ops_types_1 = require("../ops.types");
|
|
21
|
-
const ops_utils_1 = require("../ops.utils");
|
|
22
|
-
let OpsEnvCommand = class OpsEnvCommand extends nest_commander_1.CommandRunner {
|
|
23
|
-
configService;
|
|
24
|
-
sshService;
|
|
25
|
-
constructor(configService, sshService) {
|
|
26
|
-
super();
|
|
27
|
-
this.configService = configService;
|
|
28
|
-
this.sshService = sshService;
|
|
29
|
-
}
|
|
30
|
-
parseServer(value) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
parseAction(value) {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
parseProject(value) {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
parseKey(value) {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
parseVal(value) {
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
async run(passedParams, options = {}) {
|
|
46
|
-
try {
|
|
47
|
-
if (passedParams.length > 0) {
|
|
48
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', 'Positional arguments are not supported. Use named flags (e.g., --server, --action). Run with --help for examples.');
|
|
49
|
-
}
|
|
50
|
-
const serverAlias = (0, ops_utils_1.ensureRequired)(options.server, 'server');
|
|
51
|
-
const rawAction = (0, ops_utils_1.ensureRequired)(options.action, 'action');
|
|
52
|
-
const project = (0, ops_utils_1.ensureRequired)(options.project, 'project');
|
|
53
|
-
const action = (0, ops_utils_1.ensureAction)(rawAction, ['get', 'set', 'unset'], 'env action');
|
|
54
|
-
const server = await (0, ops_utils_1.resolveServerOrThrow)(this.configService.getConfig(), serverAlias);
|
|
55
|
-
const envPath = node_path_1.default.posix.join((0, ops_utils_1.resolveAppsPath)(server), project, '.env');
|
|
56
|
-
const command = this.buildCommand(action, envPath, options);
|
|
57
|
-
const result = await this.sshService.execute(server, command);
|
|
58
|
-
if (!result.success) {
|
|
59
|
-
(0, ops_utils_1.printSshError)(result, command);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (action === 'get') {
|
|
63
|
-
(0, ops_utils_1.printJson)({ status: 'ok', data: { content: result.stdout } });
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
(0, ops_utils_1.printJson)({ status: 'ok', message: 'Env updated' });
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
(0, ops_utils_1.printCliError)(error);
|
|
70
|
-
process.exitCode = 1;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
buildCommand(action, envPath, options) {
|
|
74
|
-
const quotedPath = (0, ops_utils_1.shellQuote)(envPath);
|
|
75
|
-
if (action === 'get') {
|
|
76
|
-
return `cat ${quotedPath}`;
|
|
77
|
-
}
|
|
78
|
-
const key = (0, ops_utils_1.ensureEnvKey)(options.key);
|
|
79
|
-
const quotedKey = (0, ops_utils_1.shellQuote)(key);
|
|
80
|
-
if (action === 'set') {
|
|
81
|
-
const val = (0, ops_utils_1.ensureRequired)(options.val, 'val');
|
|
82
|
-
const quotedVal = (0, ops_utils_1.shellQuote)(val);
|
|
83
|
-
const scriptLines = [
|
|
84
|
-
`ENV_FILE=${quotedPath}`,
|
|
85
|
-
`KEY=${quotedKey}`,
|
|
86
|
-
`VAL=${quotedVal}`,
|
|
87
|
-
'mkdir -p "$(dirname "$ENV_FILE")"',
|
|
88
|
-
'touch "$ENV_FILE"',
|
|
89
|
-
'awk -v k="$KEY" -v v="$VAL" \'BEGIN{found=0} $0 ~ "^" k "=" { print k "=" v; found=1; next } { print } END { if (!found) print k "=" v }\' "$ENV_FILE" > "$ENV_FILE.tmp"',
|
|
90
|
-
'mv "$ENV_FILE.tmp" "$ENV_FILE"',
|
|
91
|
-
];
|
|
92
|
-
return this.buildBashScript(scriptLines);
|
|
93
|
-
}
|
|
94
|
-
const scriptLines = [
|
|
95
|
-
`ENV_FILE=${quotedPath}`,
|
|
96
|
-
`KEY=${quotedKey}`,
|
|
97
|
-
'if [ ! -f "$ENV_FILE" ]; then exit 0; fi',
|
|
98
|
-
'grep -v "^$KEY=" "$ENV_FILE" > "$ENV_FILE.tmp"',
|
|
99
|
-
'mv "$ENV_FILE.tmp" "$ENV_FILE"',
|
|
100
|
-
];
|
|
101
|
-
return this.buildBashScript(scriptLines);
|
|
102
|
-
}
|
|
103
|
-
buildBashScript(scriptLines) {
|
|
104
|
-
const script = scriptLines.join(' && ');
|
|
105
|
-
return `bash -lc ${(0, ops_utils_1.shellQuote)(script)}`;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
exports.OpsEnvCommand = OpsEnvCommand;
|
|
109
|
-
__decorate([
|
|
110
|
-
(0, nest_commander_1.Option)({
|
|
111
|
-
flags: '-s, --server <name>',
|
|
112
|
-
description: 'Server alias defined in kodu.json (e.g., dev)',
|
|
113
|
-
}),
|
|
114
|
-
__metadata("design:type", Function),
|
|
115
|
-
__metadata("design:paramtypes", [String]),
|
|
116
|
-
__metadata("design:returntype", String)
|
|
117
|
-
], OpsEnvCommand.prototype, "parseServer", null);
|
|
118
|
-
__decorate([
|
|
119
|
-
(0, nest_commander_1.Option)({
|
|
120
|
-
flags: '-a, --action <type>',
|
|
121
|
-
description: 'Action to perform: get | set | unset',
|
|
122
|
-
}),
|
|
123
|
-
__metadata("design:type", Function),
|
|
124
|
-
__metadata("design:paramtypes", [String]),
|
|
125
|
-
__metadata("design:returntype", String)
|
|
126
|
-
], OpsEnvCommand.prototype, "parseAction", null);
|
|
127
|
-
__decorate([
|
|
128
|
-
(0, nest_commander_1.Option)({
|
|
129
|
-
flags: '-p, --project <name>',
|
|
130
|
-
description: 'Target project directory name',
|
|
131
|
-
}),
|
|
132
|
-
__metadata("design:type", Function),
|
|
133
|
-
__metadata("design:paramtypes", [String]),
|
|
134
|
-
__metadata("design:returntype", String)
|
|
135
|
-
], OpsEnvCommand.prototype, "parseProject", null);
|
|
136
|
-
__decorate([
|
|
137
|
-
(0, nest_commander_1.Option)({ flags: '--key <key>', description: 'Environment key' }),
|
|
138
|
-
__metadata("design:type", Function),
|
|
139
|
-
__metadata("design:paramtypes", [String]),
|
|
140
|
-
__metadata("design:returntype", String)
|
|
141
|
-
], OpsEnvCommand.prototype, "parseKey", null);
|
|
142
|
-
__decorate([
|
|
143
|
-
(0, nest_commander_1.Option)({ flags: '--val <value>', description: 'Environment value' }),
|
|
144
|
-
__metadata("design:type", Function),
|
|
145
|
-
__metadata("design:paramtypes", [String]),
|
|
146
|
-
__metadata("design:returntype", String)
|
|
147
|
-
], OpsEnvCommand.prototype, "parseVal", null);
|
|
148
|
-
exports.OpsEnvCommand = OpsEnvCommand = __decorate([
|
|
149
|
-
(0, nest_commander_1.SubCommand)({
|
|
150
|
-
name: 'env',
|
|
151
|
-
description: 'Manage remote .env files for a specific project.\nExamples:\n kodu ops env --server dev --action get --project my-app\n kodu ops env --server dev --action set --project my-app --key PORT --val 3000\n kodu ops env --server dev --action unset --project my-app --key PORT',
|
|
152
|
-
}),
|
|
153
|
-
__metadata("design:paramtypes", [config_service_1.ConfigService,
|
|
154
|
-
ssh_service_1.SshService])
|
|
155
|
-
], OpsEnvCommand);
|
|
156
|
-
//# sourceMappingURL=ops-env.command.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ops-env.command.js","sourceRoot":"","sources":["../../../../../src/commands/ops/subcommands/ops-env.command.ts"],"names":[],"mappings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C,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC;;;;6CAGhE;AAGD;IADC,IAAA,uBAAM,EAAC,EAAE,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;;;;6CAGpE;wBAxCU,aAAa;IALzB,IAAA,2BAAU,EAAC;QACV,IAAI,EAAE,KAAK;QACX,WAAW,EACT,iRAAiR;KACpR,CAAC;qCAGkC,8BAAa;QAChB,wBAAU;GAH9B,aAAa,CAoIzB"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { CommandRunner } from 'nest-commander';
|
|
2
|
-
import { ConfigService } from '../../../core/config/config.service';
|
|
3
|
-
import { SshService } from '../../../shared/ssh/ssh.service';
|
|
4
|
-
type OpsRoutesOptions = {
|
|
5
|
-
server?: string;
|
|
6
|
-
action?: string;
|
|
7
|
-
domain?: string;
|
|
8
|
-
upstream?: string;
|
|
9
|
-
};
|
|
10
|
-
export declare class OpsRoutesCommand extends CommandRunner {
|
|
11
|
-
private readonly configService;
|
|
12
|
-
private readonly sshService;
|
|
13
|
-
constructor(configService: ConfigService, sshService: SshService);
|
|
14
|
-
parseServer(value: string): string;
|
|
15
|
-
parseAction(value: string): string;
|
|
16
|
-
parseDomain(value: string): string;
|
|
17
|
-
parseUpstream(value: string): string;
|
|
18
|
-
run(passedParams: string[], options?: OpsRoutesOptions): Promise<void>;
|
|
19
|
-
private buildEditCommand;
|
|
20
|
-
private buildPythonScript;
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.OpsRoutesCommand = void 0;
|
|
16
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
-
const nest_commander_1 = require("nest-commander");
|
|
18
|
-
const config_service_1 = require("../../../core/config/config.service");
|
|
19
|
-
const ssh_service_1 = require("../../../shared/ssh/ssh.service");
|
|
20
|
-
const ops_types_1 = require("../ops.types");
|
|
21
|
-
const ops_utils_1 = require("../ops.utils");
|
|
22
|
-
let OpsRoutesCommand = class OpsRoutesCommand extends nest_commander_1.CommandRunner {
|
|
23
|
-
configService;
|
|
24
|
-
sshService;
|
|
25
|
-
constructor(configService, sshService) {
|
|
26
|
-
super();
|
|
27
|
-
this.configService = configService;
|
|
28
|
-
this.sshService = sshService;
|
|
29
|
-
}
|
|
30
|
-
parseServer(value) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
parseAction(value) {
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
parseDomain(value) {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
parseUpstream(value) {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
async run(passedParams, options = {}) {
|
|
43
|
-
try {
|
|
44
|
-
if (passedParams.length > 0) {
|
|
45
|
-
throw new ops_types_1.OpsCliError('VALIDATION_ERROR', 'Positional arguments are not supported. Use named flags (e.g., --server, --action). Run with --help for examples.');
|
|
46
|
-
}
|
|
47
|
-
const serverAlias = (0, ops_utils_1.ensureRequired)(options.server, 'server');
|
|
48
|
-
const rawAction = (0, ops_utils_1.ensureRequired)(options.action, 'action');
|
|
49
|
-
const action = (0, ops_utils_1.ensureAction)(rawAction, ['list', 'add', 'remove', 'update'], 'routes action');
|
|
50
|
-
const server = await (0, ops_utils_1.resolveServerOrThrow)(this.configService.getConfig(), serverAlias);
|
|
51
|
-
const caddyRoot = (0, ops_utils_1.resolveCaddyPath)(server);
|
|
52
|
-
const caddyfilePath = node_path_1.default.posix.join(caddyRoot, 'data', 'Caddyfile');
|
|
53
|
-
if (action === 'list') {
|
|
54
|
-
const command = `cat ${(0, ops_utils_1.shellQuote)(caddyfilePath)}`;
|
|
55
|
-
const result = await this.sshService.execute(server, command);
|
|
56
|
-
if (!result.success) {
|
|
57
|
-
(0, ops_utils_1.printSshError)(result, command);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
(0, ops_utils_1.printJson)({ status: 'ok', data: { caddyfile: result.stdout } });
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const domain = (0, ops_utils_1.ensureRequired)(options.domain, 'domain');
|
|
64
|
-
const upstream = action === 'add' || action === 'update'
|
|
65
|
-
? (0, ops_utils_1.ensureRequired)(options.upstream, 'upstream')
|
|
66
|
-
: '';
|
|
67
|
-
const editCommand = this.buildEditCommand({
|
|
68
|
-
action,
|
|
69
|
-
caddyfilePath,
|
|
70
|
-
domain,
|
|
71
|
-
upstream,
|
|
72
|
-
});
|
|
73
|
-
const editResult = await this.sshService.execute(server, editCommand);
|
|
74
|
-
if (!editResult.success) {
|
|
75
|
-
if (editResult.exitCode === 4) {
|
|
76
|
-
(0, ops_utils_1.printJson)({
|
|
77
|
-
status: 'error',
|
|
78
|
-
code: 'NOT_FOUND',
|
|
79
|
-
stderr: editResult.stderr || editResult.stdout || 'Route not found',
|
|
80
|
-
command: editCommand,
|
|
81
|
-
});
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
(0, ops_utils_1.printSshError)(editResult, editCommand);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const applyCommand = `cd ${(0, ops_utils_1.shellQuote)(caddyRoot)} && ./caddy.sh`;
|
|
88
|
-
const applyResult = await this.sshService.execute(server, applyCommand);
|
|
89
|
-
if (!applyResult.success) {
|
|
90
|
-
(0, ops_utils_1.printSshError)(applyResult, applyCommand);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
(0, ops_utils_1.printJson)({
|
|
94
|
-
status: 'ok',
|
|
95
|
-
message: 'Routes updated',
|
|
96
|
-
data: {
|
|
97
|
-
action,
|
|
98
|
-
domain,
|
|
99
|
-
upstream: upstream || undefined,
|
|
100
|
-
caddyOutput: applyResult.stdout,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
(0, ops_utils_1.printCliError)(error);
|
|
106
|
-
process.exitCode = 1;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
buildEditCommand(params) {
|
|
110
|
-
const script = this.buildPythonScript(params);
|
|
111
|
-
return `python3 -c ${(0, ops_utils_1.shellQuote)(script)}`;
|
|
112
|
-
}
|
|
113
|
-
buildPythonScript(params) {
|
|
114
|
-
return [
|
|
115
|
-
'import json',
|
|
116
|
-
'import os',
|
|
117
|
-
'import random',
|
|
118
|
-
'import re',
|
|
119
|
-
'import sys',
|
|
120
|
-
'import time',
|
|
121
|
-
'from pathlib import Path',
|
|
122
|
-
`file_path = ${JSON.stringify(params.caddyfilePath)}`,
|
|
123
|
-
`action = ${JSON.stringify(params.action)}`,
|
|
124
|
-
`domain = ${JSON.stringify(params.domain)}`,
|
|
125
|
-
`upstream = ${JSON.stringify(params.upstream)}`,
|
|
126
|
-
'with Path(file_path).open("r", encoding="utf-8") as handle:',
|
|
127
|
-
' text = handle.read()',
|
|
128
|
-
'domain_re = re.compile(r"(^|\\n)\\s*" + re.escape(domain) + r"\\s*\\{[\\s\\S]*?\\n\\}", re.MULTILINE)',
|
|
129
|
-
'if action == "add":',
|
|
130
|
-
' if domain_re.search(text):',
|
|
131
|
-
' sys.stderr.write("Route already exists for domain")',
|
|
132
|
-
' sys.exit(3)',
|
|
133
|
-
' block = "\\n" + domain + " {\\n reverse_proxy " + upstream + "\\n}\\n"',
|
|
134
|
-
' text = re.sub(r"\\s*$", "", text) + block',
|
|
135
|
-
'elif action == "remove":',
|
|
136
|
-
' if not domain_re.search(text):',
|
|
137
|
-
' sys.stderr.write("Route not found")',
|
|
138
|
-
' sys.exit(4)',
|
|
139
|
-
' text = domain_re.sub("\\n", text, count=1)',
|
|
140
|
-
' text = re.sub(r"\\n{3,}", "\\n\\n", text)',
|
|
141
|
-
' text = re.sub(r"^\\n+", "", text)',
|
|
142
|
-
'elif action == "update":',
|
|
143
|
-
' match = domain_re.search(text)',
|
|
144
|
-
' if not match:',
|
|
145
|
-
' sys.stderr.write("Route not found")',
|
|
146
|
-
' sys.exit(4)',
|
|
147
|
-
' block = match.group(0)',
|
|
148
|
-
' updated = re.sub(r"reverse_proxy\\s+[^\\n]+", "reverse_proxy " + upstream, block, count=1)',
|
|
149
|
-
' text = domain_re.sub(updated, text, count=1)',
|
|
150
|
-
'tmp = os.path.join(os.path.dirname(file_path), ".tmp-" + str(int(time.time() * 1000)) + "-" + format(random.getrandbits(48), "x"))',
|
|
151
|
-
'with open(tmp, "w", encoding="utf-8") as handle:',
|
|
152
|
-
' handle.write(text)',
|
|
153
|
-
'os.replace(tmp, file_path)',
|
|
154
|
-
'print(json.dumps({"status": "ok"}))',
|
|
155
|
-
].join('\n');
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
exports.OpsRoutesCommand = OpsRoutesCommand;
|
|
159
|
-
__decorate([
|
|
160
|
-
(0, nest_commander_1.Option)({
|
|
161
|
-
flags: '-s, --server <name>',
|
|
162
|
-
description: 'Server alias defined in kodu.json (e.g., dev)',
|
|
163
|
-
}),
|
|
164
|
-
__metadata("design:type", Function),
|
|
165
|
-
__metadata("design:paramtypes", [String]),
|
|
166
|
-
__metadata("design:returntype", String)
|
|
167
|
-
], OpsRoutesCommand.prototype, "parseServer", null);
|
|
168
|
-
__decorate([
|
|
169
|
-
(0, nest_commander_1.Option)({
|
|
170
|
-
flags: '-a, --action <type>',
|
|
171
|
-
description: 'Action to perform: list | add | remove | update',
|
|
172
|
-
}),
|
|
173
|
-
__metadata("design:type", Function),
|
|
174
|
-
__metadata("design:paramtypes", [String]),
|
|
175
|
-
__metadata("design:returntype", String)
|
|
176
|
-
], OpsRoutesCommand.prototype, "parseAction", null);
|
|
177
|
-
__decorate([
|
|
178
|
-
(0, nest_commander_1.Option)({
|
|
179
|
-
flags: '--domain <domain>',
|
|
180
|
-
description: 'Domain name (required for add, update, remove)',
|
|
181
|
-
}),
|
|
182
|
-
__metadata("design:type", Function),
|
|
183
|
-
__metadata("design:paramtypes", [String]),
|
|
184
|
-
__metadata("design:returntype", String)
|
|
185
|
-
], OpsRoutesCommand.prototype, "parseDomain", null);
|
|
186
|
-
__decorate([
|
|
187
|
-
(0, nest_commander_1.Option)({
|
|
188
|
-
flags: '--upstream <upstream>',
|
|
189
|
-
description: 'Upstream host:port (required for add, update)',
|
|
190
|
-
}),
|
|
191
|
-
__metadata("design:type", Function),
|
|
192
|
-
__metadata("design:paramtypes", [String]),
|
|
193
|
-
__metadata("design:returntype", String)
|
|
194
|
-
], OpsRoutesCommand.prototype, "parseUpstream", null);
|
|
195
|
-
exports.OpsRoutesCommand = OpsRoutesCommand = __decorate([
|
|
196
|
-
(0, nest_commander_1.SubCommand)({
|
|
197
|
-
name: 'routes',
|
|
198
|
-
description: 'Manage remote Caddy reverse proxy routes.\nExamples:\n kodu ops routes --server dev --action list\n kodu ops routes --server dev --action add --domain api.example.com --upstream 127.0.0.1:3000\n kodu ops routes --server dev --action update --domain api.example.com --upstream 127.0.0.1:4000\n kodu ops routes --server dev --action remove --domain api.example.com',
|
|
199
|
-
}),
|
|
200
|
-
__metadata("design:paramtypes", [config_service_1.ConfigService,
|
|
201
|
-
ssh_service_1.SshService])
|
|
202
|
-
], OpsRoutesCommand);
|
|
203
|
-
//# sourceMappingURL=ops-routes.command.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ops-routes.command.js","sourceRoot":"","sources":["../../../../../src/commands/ops/subcommands/ops-routes.command.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAA6B;AAC7B,mDAAmE;AACnE,wEAAoE;AACpE,iEAA6D;AAC7D,4CAA2C;AAC3C,4CASsB;AAgBf,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,8BAAa;IAE9B;IACA;IAFnB,YACmB,aAA4B,EAC5B,UAAsB;QAEvC,KAAK,EAAE,CAAC;QAHS,kBAAa,GAAb,aAAa,CAAe;QAC5B,eAAU,GAAV,UAAU,CAAY;IAGzC,CAAC;IAMD,WAAW,CAAC,KAAa;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAMD,WAAW,CAAC,KAAa;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAMD,WAAW,CAAC,KAAa;QACvB,OAAO,KAAK,CAAC;IACf,CAAC;IAMD,aAAa,CAAC,KAAa;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,GAAG,CACP,YAAsB,EACtB,UAA4B,EAAE;QAE9B,IAAI,CAAC;YACH,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,uBAAW,CACnB,kBAAkB,EAClB,mHAAmH,CACpH,CAAC;YACJ,CAAC;YAED,MAAM,WAAW,GAAG,IAAA,0BAAc,EAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC7D,MAAM,SAAS,GAAG,IAAA,0BAAc,EAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;Y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qB;QAC5B,WAAW,EAAE,iDAAiD;KAC/D,CAAC;;;;mDAGD;AAMD;IAJC,IAAA,uBAAM,EAAC;QACN,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EAAE,gDAAgD;KAC9D,CAAC;;;;mDAGD;AAMD;IAJC,IAAA,uBAAM,EAAC;QACN,KAAK,EAAE,uBAAuB;QAC9B,WAAW,EAAE,+CAA+C;KAC7D,CAAC;;;;qDAGD;2BAtCU,gBAAgB;IAL5B,IAAA,2BAAU,EAAC;QACV,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,gXAAgX;KACnX,CAAC;qCAGkC,8BAAa;QAChB,wBAAU;GAH9B,gBAAgB,CA8L5B"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { CommandRunner } from 'nest-commander';
|
|
2
|
-
import { ConfigService } from '../../../core/config/config.service';
|
|
3
|
-
import { SshService } from '../../../shared/ssh/ssh.service';
|
|
4
|
-
type OpsServiceOptions = {
|
|
5
|
-
server?: string;
|
|
6
|
-
action?: string;
|
|
7
|
-
project?: string;
|
|
8
|
-
repo?: string;
|
|
9
|
-
};
|
|
10
|
-
export declare class OpsServiceCommand extends CommandRunner {
|
|
11
|
-
private readonly configService;
|
|
12
|
-
private readonly sshService;
|
|
13
|
-
constructor(configService: ConfigService, sshService: SshService);
|
|
14
|
-
parseServer(value: string): string;
|
|
15
|
-
parseAction(value: string): string;
|
|
16
|
-
parseProject(value: string): string;
|
|
17
|
-
parseRepo(value: string): string;
|
|
18
|
-
run(passedParams: string[], options?: OpsServiceOptions): Promise<void>;
|
|
19
|
-
private buildActionCommand;
|
|
20
|
-
private runStatus;
|
|
21
|
-
}
|
|
22
|
-
export {};
|