@roxyon/deploy-core 0.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.
@@ -0,0 +1,168 @@
1
+ import { Ignore } from 'ignore';
2
+ import { RuntimeName, DeployKind, Roxyon } from '@roxyon/api-client';
3
+ export { DeployKind } from '@roxyon/api-client';
4
+
5
+ /** Always excluded, regardless of ignore files — build artefacts and VCS/OS cruft. */
6
+ declare const ALWAYS_IGNORE: string[];
7
+ /** Build the ignore matcher: `.roxyonignore` if present, else `.gitignore`, plus the always-list. */
8
+ declare function buildIgnore(root: string): Promise<Ignore>;
9
+ /** Recursively list files under `root` that survive the ignore matcher (POSIX-relative paths). */
10
+ declare function listFiles(root: string, ig: Ignore): Promise<string[]>;
11
+ interface PackResult {
12
+ buffer: Buffer;
13
+ files: string[];
14
+ bytes: number;
15
+ }
16
+ /**
17
+ * Create a deterministic gzipped tarball of `root` (minus ignored paths).
18
+ * `prefix`, when given, is prepended to every entry path inside the archive.
19
+ */
20
+ declare function packDirectory(root: string, opts?: {
21
+ prefix?: string;
22
+ maxBytes?: number;
23
+ }): Promise<PackResult>;
24
+ /** Total on-disk size of a set of files. */
25
+ declare function measure(root: string, files: string[]): Promise<number>;
26
+
27
+ interface Detection {
28
+ runtime: RuntimeName;
29
+ /** why we think so — shown to the user, who can override */
30
+ reason: string;
31
+ /** best-guess start command for a server runtime */
32
+ start?: string;
33
+ }
34
+ /** Best-effort project-type detection. Deterministic; the caller confirms. */
35
+ declare function detectRuntime(root: string): Promise<Detection>;
36
+
37
+ interface ProjectConfig {
38
+ name: string;
39
+ /** `Applications.objectId`, filled after the first `app`-kind deploy. */
40
+ application?: string;
41
+ /** Route host — `Domains.Name`. */
42
+ host: string;
43
+ /** Sub-path under the host's docroot / source tree. `""` = root. */
44
+ folder: string;
45
+ runtime: RuntimeName;
46
+ runtimeVersion?: string;
47
+ preset?: string;
48
+ kind: DeployKind;
49
+ /** Local build command (LumenJS / static). Empty for server runtimes. */
50
+ build?: string;
51
+ /** Directory the build writes to (relative to project root). */
52
+ outDir?: string;
53
+ /** Web-process start command (app kind only). */
54
+ start?: string;
55
+ /** Serve the app on the host instead of the host's own files. */
56
+ public?: boolean;
57
+ }
58
+ declare const PROJECT_FILE = "roxyon.json";
59
+ declare function projectConfigPath(cwd?: string): string;
60
+ declare function loadProjectConfig(cwd?: string): Promise<ProjectConfig | undefined>;
61
+ declare function saveProjectConfig(config: ProjectConfig, cwd?: string): Promise<string>;
62
+ interface BuildConfigInput {
63
+ cwd: string;
64
+ runtime: RuntimeName;
65
+ host: string;
66
+ folder?: string;
67
+ name?: string;
68
+ start?: string;
69
+ }
70
+ /**
71
+ * Produce a `ProjectConfig` from a resolved runtime + host. Shared by the CLI's
72
+ * `roxyon init` and the MCP `roxyon_init` tool so both write the same shape.
73
+ */
74
+ declare function buildProjectConfig(input: BuildConfigInput): ProjectConfig;
75
+
76
+ interface DeployReporter {
77
+ /** A high-level phase change ("Building", "Uploading", "Live"). */
78
+ step?: (msg: string) => void;
79
+ /** A single build- or runtime-log line. */
80
+ log?: (line: string) => void;
81
+ }
82
+ interface DeployParams {
83
+ cwd: string;
84
+ /** An authenticated client. */
85
+ roxyon: Roxyon;
86
+ /** Subscription objectId / Name to prefer when the account has several. */
87
+ preferredSubscription?: string;
88
+ /** Run the configured build command (default true). */
89
+ build?: boolean;
90
+ /** For app deploys: poll until running/failed (default true). */
91
+ follow?: boolean;
92
+ pollMs?: number;
93
+ timeoutMs?: number;
94
+ reporter?: DeployReporter;
95
+ /** Override the build-command runner (default: spawn a shell). */
96
+ runCommand?: (command: string, cwd: string, reporter?: DeployReporter) => Promise<number>;
97
+ }
98
+ type DeployOutcome = {
99
+ kind: 'static';
100
+ ok: true;
101
+ url: string;
102
+ files: number;
103
+ config: ProjectConfig;
104
+ } | {
105
+ kind: 'app';
106
+ ok: true;
107
+ application: string;
108
+ status: string;
109
+ revision: number;
110
+ url?: string;
111
+ config: ProjectConfig;
112
+ logs: string[];
113
+ } | {
114
+ kind: 'app';
115
+ ok: false;
116
+ application: string;
117
+ status: string;
118
+ error: string;
119
+ config: ProjectConfig;
120
+ logs: string[];
121
+ };
122
+ declare class DeployError extends Error {
123
+ readonly code: 'no-config' | 'auth' | 'bad-host' | 'build-failed' | 'no-build-output' | 'upload-failed' | 'create-failed';
124
+ constructor(message: string, code: DeployError['code']);
125
+ }
126
+ /**
127
+ * Build (if configured), archive, upload, and — for app runtimes — poll until
128
+ * the deploy settles. Self-contained: one `/account/context` call validates the
129
+ * host (works with a session token or a `roxp_` PAT), and the console creates
130
+ * the application on the first deploy — the new id is written back to
131
+ * `roxyon.json`.
132
+ */
133
+ declare function deployProject(params: DeployParams): Promise<DeployOutcome>;
134
+
135
+ /**
136
+ * Default build-command runner: spawn a shell, stream output to the reporter.
137
+ * Callers in a non-local context (a hosted server) can pass their own.
138
+ */
139
+ declare function runShellCommand(command: string, cwd: string, reporter?: DeployReporter): Promise<number>;
140
+
141
+ /**
142
+ * Stored login for Roxyon tooling — `~/.roxyon/config.json`, mode 0600. Written
143
+ * by `roxyon login`; read by the CLI and the MCP server alike.
144
+ */
145
+ interface Credentials {
146
+ sessionToken: string;
147
+ refreshToken?: string;
148
+ userId: string;
149
+ email?: string;
150
+ /** Preferred subscription (objectId / Name) when the account has several. */
151
+ subscription?: string;
152
+ savedAt: string;
153
+ }
154
+ interface Endpoints {
155
+ apiUrl?: string;
156
+ consoleUrl?: string;
157
+ }
158
+ declare function credentialsDir(): string;
159
+ declare function credentialsPath(): string;
160
+ /** Endpoint overrides from the environment (`ROXYON_API_URL`, `ROXYON_CONSOLE_URL`). */
161
+ declare function endpointsFromEnv(): Endpoints;
162
+ /** A token supplied out-of-band (CI, or an MCP host env). Skips the stored login. */
163
+ declare function tokenFromEnv(): string | undefined;
164
+ declare function loadCredentials(): Promise<Credentials | undefined>;
165
+ declare function saveCredentials(creds: Credentials): Promise<string>;
166
+ declare function clearCredentials(): Promise<void>;
167
+
168
+ export { ALWAYS_IGNORE, type BuildConfigInput, type Credentials, DeployError, type DeployOutcome, type DeployParams, type DeployReporter, type Detection, type Endpoints, PROJECT_FILE, type PackResult, type ProjectConfig, buildIgnore, buildProjectConfig, clearCredentials, credentialsDir, credentialsPath, deployProject, detectRuntime, endpointsFromEnv, listFiles, loadCredentials, loadProjectConfig, measure, packDirectory, projectConfigPath, runShellCommand, saveCredentials, saveProjectConfig, tokenFromEnv };
@@ -0,0 +1,168 @@
1
+ import { Ignore } from 'ignore';
2
+ import { RuntimeName, DeployKind, Roxyon } from '@roxyon/api-client';
3
+ export { DeployKind } from '@roxyon/api-client';
4
+
5
+ /** Always excluded, regardless of ignore files — build artefacts and VCS/OS cruft. */
6
+ declare const ALWAYS_IGNORE: string[];
7
+ /** Build the ignore matcher: `.roxyonignore` if present, else `.gitignore`, plus the always-list. */
8
+ declare function buildIgnore(root: string): Promise<Ignore>;
9
+ /** Recursively list files under `root` that survive the ignore matcher (POSIX-relative paths). */
10
+ declare function listFiles(root: string, ig: Ignore): Promise<string[]>;
11
+ interface PackResult {
12
+ buffer: Buffer;
13
+ files: string[];
14
+ bytes: number;
15
+ }
16
+ /**
17
+ * Create a deterministic gzipped tarball of `root` (minus ignored paths).
18
+ * `prefix`, when given, is prepended to every entry path inside the archive.
19
+ */
20
+ declare function packDirectory(root: string, opts?: {
21
+ prefix?: string;
22
+ maxBytes?: number;
23
+ }): Promise<PackResult>;
24
+ /** Total on-disk size of a set of files. */
25
+ declare function measure(root: string, files: string[]): Promise<number>;
26
+
27
+ interface Detection {
28
+ runtime: RuntimeName;
29
+ /** why we think so — shown to the user, who can override */
30
+ reason: string;
31
+ /** best-guess start command for a server runtime */
32
+ start?: string;
33
+ }
34
+ /** Best-effort project-type detection. Deterministic; the caller confirms. */
35
+ declare function detectRuntime(root: string): Promise<Detection>;
36
+
37
+ interface ProjectConfig {
38
+ name: string;
39
+ /** `Applications.objectId`, filled after the first `app`-kind deploy. */
40
+ application?: string;
41
+ /** Route host — `Domains.Name`. */
42
+ host: string;
43
+ /** Sub-path under the host's docroot / source tree. `""` = root. */
44
+ folder: string;
45
+ runtime: RuntimeName;
46
+ runtimeVersion?: string;
47
+ preset?: string;
48
+ kind: DeployKind;
49
+ /** Local build command (LumenJS / static). Empty for server runtimes. */
50
+ build?: string;
51
+ /** Directory the build writes to (relative to project root). */
52
+ outDir?: string;
53
+ /** Web-process start command (app kind only). */
54
+ start?: string;
55
+ /** Serve the app on the host instead of the host's own files. */
56
+ public?: boolean;
57
+ }
58
+ declare const PROJECT_FILE = "roxyon.json";
59
+ declare function projectConfigPath(cwd?: string): string;
60
+ declare function loadProjectConfig(cwd?: string): Promise<ProjectConfig | undefined>;
61
+ declare function saveProjectConfig(config: ProjectConfig, cwd?: string): Promise<string>;
62
+ interface BuildConfigInput {
63
+ cwd: string;
64
+ runtime: RuntimeName;
65
+ host: string;
66
+ folder?: string;
67
+ name?: string;
68
+ start?: string;
69
+ }
70
+ /**
71
+ * Produce a `ProjectConfig` from a resolved runtime + host. Shared by the CLI's
72
+ * `roxyon init` and the MCP `roxyon_init` tool so both write the same shape.
73
+ */
74
+ declare function buildProjectConfig(input: BuildConfigInput): ProjectConfig;
75
+
76
+ interface DeployReporter {
77
+ /** A high-level phase change ("Building", "Uploading", "Live"). */
78
+ step?: (msg: string) => void;
79
+ /** A single build- or runtime-log line. */
80
+ log?: (line: string) => void;
81
+ }
82
+ interface DeployParams {
83
+ cwd: string;
84
+ /** An authenticated client. */
85
+ roxyon: Roxyon;
86
+ /** Subscription objectId / Name to prefer when the account has several. */
87
+ preferredSubscription?: string;
88
+ /** Run the configured build command (default true). */
89
+ build?: boolean;
90
+ /** For app deploys: poll until running/failed (default true). */
91
+ follow?: boolean;
92
+ pollMs?: number;
93
+ timeoutMs?: number;
94
+ reporter?: DeployReporter;
95
+ /** Override the build-command runner (default: spawn a shell). */
96
+ runCommand?: (command: string, cwd: string, reporter?: DeployReporter) => Promise<number>;
97
+ }
98
+ type DeployOutcome = {
99
+ kind: 'static';
100
+ ok: true;
101
+ url: string;
102
+ files: number;
103
+ config: ProjectConfig;
104
+ } | {
105
+ kind: 'app';
106
+ ok: true;
107
+ application: string;
108
+ status: string;
109
+ revision: number;
110
+ url?: string;
111
+ config: ProjectConfig;
112
+ logs: string[];
113
+ } | {
114
+ kind: 'app';
115
+ ok: false;
116
+ application: string;
117
+ status: string;
118
+ error: string;
119
+ config: ProjectConfig;
120
+ logs: string[];
121
+ };
122
+ declare class DeployError extends Error {
123
+ readonly code: 'no-config' | 'auth' | 'bad-host' | 'build-failed' | 'no-build-output' | 'upload-failed' | 'create-failed';
124
+ constructor(message: string, code: DeployError['code']);
125
+ }
126
+ /**
127
+ * Build (if configured), archive, upload, and — for app runtimes — poll until
128
+ * the deploy settles. Self-contained: one `/account/context` call validates the
129
+ * host (works with a session token or a `roxp_` PAT), and the console creates
130
+ * the application on the first deploy — the new id is written back to
131
+ * `roxyon.json`.
132
+ */
133
+ declare function deployProject(params: DeployParams): Promise<DeployOutcome>;
134
+
135
+ /**
136
+ * Default build-command runner: spawn a shell, stream output to the reporter.
137
+ * Callers in a non-local context (a hosted server) can pass their own.
138
+ */
139
+ declare function runShellCommand(command: string, cwd: string, reporter?: DeployReporter): Promise<number>;
140
+
141
+ /**
142
+ * Stored login for Roxyon tooling — `~/.roxyon/config.json`, mode 0600. Written
143
+ * by `roxyon login`; read by the CLI and the MCP server alike.
144
+ */
145
+ interface Credentials {
146
+ sessionToken: string;
147
+ refreshToken?: string;
148
+ userId: string;
149
+ email?: string;
150
+ /** Preferred subscription (objectId / Name) when the account has several. */
151
+ subscription?: string;
152
+ savedAt: string;
153
+ }
154
+ interface Endpoints {
155
+ apiUrl?: string;
156
+ consoleUrl?: string;
157
+ }
158
+ declare function credentialsDir(): string;
159
+ declare function credentialsPath(): string;
160
+ /** Endpoint overrides from the environment (`ROXYON_API_URL`, `ROXYON_CONSOLE_URL`). */
161
+ declare function endpointsFromEnv(): Endpoints;
162
+ /** A token supplied out-of-band (CI, or an MCP host env). Skips the stored login. */
163
+ declare function tokenFromEnv(): string | undefined;
164
+ declare function loadCredentials(): Promise<Credentials | undefined>;
165
+ declare function saveCredentials(creds: Credentials): Promise<string>;
166
+ declare function clearCredentials(): Promise<void>;
167
+
168
+ export { ALWAYS_IGNORE, type BuildConfigInput, type Credentials, DeployError, type DeployOutcome, type DeployParams, type DeployReporter, type Detection, type Endpoints, PROJECT_FILE, type PackResult, type ProjectConfig, buildIgnore, buildProjectConfig, clearCredentials, credentialsDir, credentialsPath, deployProject, detectRuntime, endpointsFromEnv, listFiles, loadCredentials, loadProjectConfig, measure, packDirectory, projectConfigPath, runShellCommand, saveCredentials, saveProjectConfig, tokenFromEnv };