@xano/cli 1.0.3 → 1.0.4-beta.1
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/README.md +69 -3
- package/dist/base-command.d.ts +27 -0
- package/dist/base-command.js +124 -1
- package/dist/commands/auth/index.d.ts +10 -0
- package/dist/commands/auth/index.js +146 -9
- package/dist/commands/static_host/build/create/index.d.ts +9 -1
- package/dist/commands/static_host/build/create/index.js +54 -4
- package/dist/commands/static_host/build/delete/index.d.ts +19 -0
- package/dist/commands/static_host/build/delete/index.js +114 -0
- package/dist/commands/static_host/build/get/index.d.ts +1 -1
- package/dist/commands/static_host/build/get/index.js +16 -10
- package/dist/commands/static_host/build/pull/index.d.ts +52 -0
- package/dist/commands/static_host/build/pull/index.js +300 -0
- package/dist/commands/static_host/build/push/index.d.ts +23 -0
- package/dist/commands/static_host/build/push/index.js +225 -0
- package/dist/commands/static_host/create/index.d.ts +17 -0
- package/dist/commands/static_host/create/index.js +86 -0
- package/dist/commands/static_host/deploy/index.d.ts +18 -0
- package/dist/commands/static_host/deploy/index.js +105 -0
- package/dist/commands/static_host/edit/index.d.ts +23 -0
- package/dist/commands/static_host/edit/index.js +151 -0
- package/dist/commands/static_host/get/index.d.ts +18 -0
- package/dist/commands/static_host/get/index.js +94 -0
- package/dist/commands/static_host/migrate/index.d.ts +44 -0
- package/dist/commands/static_host/migrate/index.js +205 -0
- package/dist/commands/tenant/snapshot/create/index.d.ts +17 -0
- package/dist/commands/tenant/snapshot/create/index.js +78 -0
- package/dist/commands/tenant/snapshot/delete/index.d.ts +19 -0
- package/dist/commands/tenant/snapshot/delete/index.js +102 -0
- package/dist/commands/tenant/snapshot/list/index.d.ts +16 -0
- package/dist/commands/tenant/snapshot/list/index.js +96 -0
- package/dist/commands/tenant/snapshot/swap/index.d.ts +19 -0
- package/dist/commands/tenant/snapshot/swap/index.js +103 -0
- package/dist/utils/multidoc-push.js +21 -17
- package/dist/utils/reference-checker.js +2 -2
- package/oclif.manifest.json +3831 -2484
- package/package.json +3 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import BaseCommand from '../../../../base-command.js';
|
|
3
|
+
export default class StaticHostBuildDelete extends BaseCommand {
|
|
4
|
+
static args = {
|
|
5
|
+
static_host: Args.string({
|
|
6
|
+
description: 'Static Host name',
|
|
7
|
+
required: true,
|
|
8
|
+
}),
|
|
9
|
+
};
|
|
10
|
+
static description = 'Delete a static host build permanently. This action cannot be undone.';
|
|
11
|
+
static examples = [
|
|
12
|
+
`$ xano static_host build delete default --build_id 52
|
|
13
|
+
Are you sure you want to delete build 52 from static host 'default'? This action cannot be undone. (y/N) y
|
|
14
|
+
Deleted build 52 from static host 'default'
|
|
15
|
+
`,
|
|
16
|
+
`$ xano static_host build delete default --build_id 52 --force
|
|
17
|
+
Deleted build 52 from static host 'default'
|
|
18
|
+
`,
|
|
19
|
+
`$ xano static_host build delete myhost --build_id 123 -w 40 -f
|
|
20
|
+
Deleted build 123 from static host 'myhost'
|
|
21
|
+
`,
|
|
22
|
+
`$ xano static_host build delete default --build_id 52 -f -o json`,
|
|
23
|
+
];
|
|
24
|
+
static flags = {
|
|
25
|
+
...BaseCommand.baseFlags,
|
|
26
|
+
build_id: Flags.string({
|
|
27
|
+
description: 'Build ID to delete',
|
|
28
|
+
required: true,
|
|
29
|
+
}),
|
|
30
|
+
force: Flags.boolean({
|
|
31
|
+
char: 'f',
|
|
32
|
+
default: false,
|
|
33
|
+
description: '[CRITICAL] NEVER run without explicit user confirmation. Skips the confirmation prompt.',
|
|
34
|
+
required: false,
|
|
35
|
+
}),
|
|
36
|
+
output: Flags.string({
|
|
37
|
+
char: 'o',
|
|
38
|
+
default: 'summary',
|
|
39
|
+
description: 'Output format',
|
|
40
|
+
options: ['summary', 'json'],
|
|
41
|
+
required: false,
|
|
42
|
+
}),
|
|
43
|
+
workspace: Flags.string({
|
|
44
|
+
char: 'w',
|
|
45
|
+
description: 'Workspace ID (optional if set in profile)',
|
|
46
|
+
required: false,
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
async run() {
|
|
50
|
+
const { args, flags } = await this.parse(StaticHostBuildDelete);
|
|
51
|
+
const { profile, profileName } = this.resolveProfile(flags);
|
|
52
|
+
// Determine workspace_id from flag or profile
|
|
53
|
+
let workspaceId;
|
|
54
|
+
if (flags.workspace) {
|
|
55
|
+
workspaceId = flags.workspace;
|
|
56
|
+
}
|
|
57
|
+
else if (profile.workspace) {
|
|
58
|
+
workspaceId = profile.workspace;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.error(`Workspace ID is required. Either:\n` +
|
|
62
|
+
` 1. Provide it as a flag: xano static_host build delete <static_host> --build_id <id> -w <workspace_id>\n` +
|
|
63
|
+
` 2. Set it in your profile using: xano profile edit ${profileName} -w <workspace_id>`);
|
|
64
|
+
}
|
|
65
|
+
if (!flags.force) {
|
|
66
|
+
const confirmed = await this.confirm(`Are you sure you want to delete build ${flags.build_id} from static host '${args.static_host}'? This action cannot be undone.`);
|
|
67
|
+
if (!confirmed) {
|
|
68
|
+
this.log('Deletion cancelled.');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${args.static_host}/build/${flags.build_id}`;
|
|
73
|
+
try {
|
|
74
|
+
const response = await this.verboseFetch(apiUrl, {
|
|
75
|
+
headers: {
|
|
76
|
+
'accept': 'application/json',
|
|
77
|
+
'Authorization': `Bearer ${profile.access_token}`,
|
|
78
|
+
},
|
|
79
|
+
method: 'DELETE',
|
|
80
|
+
}, flags.verbose, profile.access_token);
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const errorText = await response.text();
|
|
83
|
+
this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
|
|
84
|
+
}
|
|
85
|
+
if (flags.output === 'json') {
|
|
86
|
+
this.log(JSON.stringify({ build_id: flags.build_id, deleted: true, static_host: args.static_host }, null, 2));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.log(`Deleted build ${flags.build_id} from static host '${args.static_host}'`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error instanceof Error) {
|
|
94
|
+
this.error(`Failed to delete build: ${error.message}`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.error(`Failed to delete build: ${String(error)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async confirm(message) {
|
|
102
|
+
const readline = await import('node:readline');
|
|
103
|
+
const rl = readline.createInterface({
|
|
104
|
+
input: process.stdin,
|
|
105
|
+
output: process.stdout,
|
|
106
|
+
});
|
|
107
|
+
return new Promise((resolve) => {
|
|
108
|
+
rl.question(`${message} (y/N) `, (answer) => {
|
|
109
|
+
rl.close();
|
|
110
|
+
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import BaseCommand from '../../../../base-command.js';
|
|
2
2
|
export default class StaticHostBuildGet extends BaseCommand {
|
|
3
3
|
static args: {
|
|
4
|
-
build_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
4
|
static_host: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
6
5
|
};
|
|
7
6
|
static description: string;
|
|
8
7
|
static examples: string[];
|
|
9
8
|
static flags: {
|
|
9
|
+
build_id: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
10
|
output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
11
|
workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
12
|
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -2,10 +2,6 @@ import { Args, Flags } from '@oclif/core';
|
|
|
2
2
|
import BaseCommand from '../../../../base-command.js';
|
|
3
3
|
export default class StaticHostBuildGet extends BaseCommand {
|
|
4
4
|
static args = {
|
|
5
|
-
build_id: Args.string({
|
|
6
|
-
description: 'Build ID',
|
|
7
|
-
required: true,
|
|
8
|
-
}),
|
|
9
5
|
static_host: Args.string({
|
|
10
6
|
description: 'Static Host name',
|
|
11
7
|
required: true,
|
|
@@ -13,24 +9,24 @@ export default class StaticHostBuildGet extends BaseCommand {
|
|
|
13
9
|
};
|
|
14
10
|
static description = 'Get details of a specific build for a static host';
|
|
15
11
|
static examples = [
|
|
16
|
-
`$ xano static_host:build:get default 52
|
|
12
|
+
`$ xano static_host:build:get default --build_id 52
|
|
17
13
|
Build Details:
|
|
18
14
|
ID: 52
|
|
19
15
|
Name: v1.0.0
|
|
20
16
|
Status: completed
|
|
21
17
|
`,
|
|
22
|
-
`$ xano static_host:build:get default 52 -w 40
|
|
18
|
+
`$ xano static_host:build:get default --build_id 52 -w 40
|
|
23
19
|
Build Details:
|
|
24
20
|
ID: 52
|
|
25
21
|
Name: v1.0.0
|
|
26
22
|
Status: completed
|
|
27
23
|
`,
|
|
28
|
-
`$ xano static_host:build:get myhost 123 --profile production
|
|
24
|
+
`$ xano static_host:build:get myhost --build_id 123 --profile production
|
|
29
25
|
Build Details:
|
|
30
26
|
ID: 123
|
|
31
27
|
Name: production-build
|
|
32
28
|
`,
|
|
33
|
-
`$ xano static_host:build:get default 52 -o json
|
|
29
|
+
`$ xano static_host:build:get default --build_id 52 -o json
|
|
34
30
|
{
|
|
35
31
|
"id": 52,
|
|
36
32
|
"name": "v1.0.0",
|
|
@@ -40,6 +36,10 @@ Name: production-build
|
|
|
40
36
|
];
|
|
41
37
|
static flags = {
|
|
42
38
|
...BaseCommand.baseFlags,
|
|
39
|
+
build_id: Flags.string({
|
|
40
|
+
description: 'Build ID',
|
|
41
|
+
required: true,
|
|
42
|
+
}),
|
|
43
43
|
output: Flags.string({
|
|
44
44
|
char: 'o',
|
|
45
45
|
default: 'summary',
|
|
@@ -66,11 +66,11 @@ Name: production-build
|
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
68
|
this.error(`Workspace ID is required. Either:\n` +
|
|
69
|
-
` 1. Provide it as a flag: xano static_host:build:get <static_host> <
|
|
69
|
+
` 1. Provide it as a flag: xano static_host:build:get <static_host> --build_id <id> -w <workspace_id>\n` +
|
|
70
70
|
` 2. Set it in your profile using: xano profile:edit ${profileName} -w <workspace_id>`);
|
|
71
71
|
}
|
|
72
72
|
// Construct the API URL
|
|
73
|
-
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${args.static_host}/build/${
|
|
73
|
+
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${args.static_host}/build/${flags.build_id}`;
|
|
74
74
|
// Fetch build from the API
|
|
75
75
|
try {
|
|
76
76
|
const response = await this.verboseFetch(apiUrl, {
|
|
@@ -104,6 +104,12 @@ Name: production-build
|
|
|
104
104
|
if (build.status) {
|
|
105
105
|
this.log(`Status: ${build.status}`);
|
|
106
106
|
}
|
|
107
|
+
if (typeof build.file_count === 'number') {
|
|
108
|
+
this.log(`Files: ${build.file_count}`);
|
|
109
|
+
}
|
|
110
|
+
if (typeof build.file_bytes === 'number') {
|
|
111
|
+
this.log(`Size: ${build.file_bytes} bytes`);
|
|
112
|
+
}
|
|
107
113
|
if (build.created_at) {
|
|
108
114
|
this.log(`Created: ${build.created_at}`);
|
|
109
115
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import BaseCommand from '../../../../base-command.js';
|
|
2
|
+
export interface StaticHostEnv {
|
|
3
|
+
canonical?: null | string;
|
|
4
|
+
}
|
|
5
|
+
export interface StaticHostSummary {
|
|
6
|
+
[k: string]: unknown;
|
|
7
|
+
dev?: StaticHostEnv;
|
|
8
|
+
name: string;
|
|
9
|
+
prod?: StaticHostEnv;
|
|
10
|
+
}
|
|
11
|
+
export interface BuildSummary {
|
|
12
|
+
canonical?: string;
|
|
13
|
+
id: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Find the deployed `canonical` for a static host's env from a list of hosts.
|
|
17
|
+
* Returns null when the host isn't present or nothing is deployed to that env.
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractEnvCanonical(hosts: StaticHostSummary[], staticHost: string, env: string): null | string;
|
|
20
|
+
/** Find the build whose unique `canonical` matches, or null if none do. */
|
|
21
|
+
export declare function findBuildByCanonical(builds: BuildSummary[], canonical: string): BuildSummary | null;
|
|
22
|
+
export default class StaticHostBuildPull extends BaseCommand {
|
|
23
|
+
static args: {
|
|
24
|
+
static_host: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
25
|
+
};
|
|
26
|
+
static description: string;
|
|
27
|
+
static examples: string[];
|
|
28
|
+
static flags: {
|
|
29
|
+
build_id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
|
+
directory: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
|
+
env: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
32
|
+
latest: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
33
|
+
source: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
|
+
workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
35
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
36
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
37
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
38
|
+
};
|
|
39
|
+
run(): Promise<void>;
|
|
40
|
+
private parseFileDocument;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the build ID currently deployed to a static host's dev/prod env.
|
|
43
|
+
*
|
|
44
|
+
* The deployed env stores the `canonical` of the build it was created from
|
|
45
|
+
* (static_host.{env}.canonical). Each build carries that same unique
|
|
46
|
+
* `canonical`, so we match the env's canonical against the build list to
|
|
47
|
+
* recover the build ID — a shortcut for "list builds, find the deployed one,
|
|
48
|
+
* then pull it".
|
|
49
|
+
*/
|
|
50
|
+
private resolveEnvBuild;
|
|
51
|
+
private resolveLatestBuild;
|
|
52
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import BaseCommand from '../../../../base-command.js';
|
|
5
|
+
/**
|
|
6
|
+
* Find the deployed `canonical` for a static host's env from a list of hosts.
|
|
7
|
+
* Returns null when the host isn't present or nothing is deployed to that env.
|
|
8
|
+
*/
|
|
9
|
+
export function extractEnvCanonical(hosts, staticHost, env) {
|
|
10
|
+
const host = hosts.find((h) => h.name === staticHost);
|
|
11
|
+
if (!host) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const envObj = host[env];
|
|
15
|
+
return envObj?.canonical ?? null;
|
|
16
|
+
}
|
|
17
|
+
/** Find the build whose unique `canonical` matches, or null if none do. */
|
|
18
|
+
export function findBuildByCanonical(builds, canonical) {
|
|
19
|
+
return builds.find((b) => b.canonical === canonical) ?? null;
|
|
20
|
+
}
|
|
21
|
+
export default class StaticHostBuildPull extends BaseCommand {
|
|
22
|
+
static args = {
|
|
23
|
+
static_host: Args.string({
|
|
24
|
+
description: 'Static Host name',
|
|
25
|
+
required: true,
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
static description = 'Pull a static host build to disk. Defaults to the original uploaded source (including package.json); use --source built for the compiled/served output.';
|
|
29
|
+
static examples = [
|
|
30
|
+
`$ xano static_host build pull default --build_id 52
|
|
31
|
+
Pulled 15 files to current directory
|
|
32
|
+
`,
|
|
33
|
+
`$ xano static_host build pull default --build_id 52 -d ./output
|
|
34
|
+
Pulled 15 files to ./output
|
|
35
|
+
`,
|
|
36
|
+
`$ xano static_host build pull myhost --build_id 123 -w 40
|
|
37
|
+
Pulled 8 files to current directory
|
|
38
|
+
`,
|
|
39
|
+
`$ xano static_host build pull default --latest
|
|
40
|
+
Pulled 22 files to current directory
|
|
41
|
+
`,
|
|
42
|
+
`$ xano static_host build pull default --env dev
|
|
43
|
+
Pulled 18 files to current directory
|
|
44
|
+
`,
|
|
45
|
+
`$ xano static_host build pull default --env prod -d ./prod-release
|
|
46
|
+
Pulled 18 files to ./prod-release
|
|
47
|
+
`,
|
|
48
|
+
`$ xano static_host build pull default --build_id 52 --source built
|
|
49
|
+
Pulled the compiled/served output instead of the original source
|
|
50
|
+
`,
|
|
51
|
+
];
|
|
52
|
+
static flags = {
|
|
53
|
+
...BaseCommand.baseFlags,
|
|
54
|
+
build_id: Flags.string({
|
|
55
|
+
description: 'Build ID to pull',
|
|
56
|
+
exclusive: ['latest', 'env'],
|
|
57
|
+
required: false,
|
|
58
|
+
}),
|
|
59
|
+
directory: Flags.string({
|
|
60
|
+
char: 'd',
|
|
61
|
+
default: '.',
|
|
62
|
+
description: 'Output directory for pulled files (defaults to current directory)',
|
|
63
|
+
required: false,
|
|
64
|
+
}),
|
|
65
|
+
env: Flags.string({
|
|
66
|
+
description: 'Pull the build currently deployed to this environment',
|
|
67
|
+
exclusive: ['build_id', 'latest'],
|
|
68
|
+
options: ['dev', 'prod'],
|
|
69
|
+
required: false,
|
|
70
|
+
}),
|
|
71
|
+
latest: Flags.boolean({
|
|
72
|
+
default: false,
|
|
73
|
+
description: 'Pull the latest build',
|
|
74
|
+
exclusive: ['build_id', 'env'],
|
|
75
|
+
required: false,
|
|
76
|
+
}),
|
|
77
|
+
source: Flags.string({
|
|
78
|
+
default: 'original',
|
|
79
|
+
description: 'Which files to pull: "original" (the uploaded source, including package.json) or "built" (the compiled/served output)',
|
|
80
|
+
options: ['original', 'built'],
|
|
81
|
+
required: false,
|
|
82
|
+
}),
|
|
83
|
+
workspace: Flags.string({
|
|
84
|
+
char: 'w',
|
|
85
|
+
description: 'Workspace ID (optional if set in profile)',
|
|
86
|
+
required: false,
|
|
87
|
+
}),
|
|
88
|
+
};
|
|
89
|
+
async run() {
|
|
90
|
+
const { args, flags } = await this.parse(StaticHostBuildPull);
|
|
91
|
+
if (!flags.build_id && !flags.latest && !flags.env) {
|
|
92
|
+
this.error('One of --build_id <id>, --latest, or --env <dev|prod> is required');
|
|
93
|
+
}
|
|
94
|
+
const { profile, profileName } = this.resolveProfile(flags);
|
|
95
|
+
let workspaceId;
|
|
96
|
+
if (flags.workspace) {
|
|
97
|
+
workspaceId = flags.workspace;
|
|
98
|
+
}
|
|
99
|
+
else if (profile.workspace) {
|
|
100
|
+
workspaceId = profile.workspace;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.error(`Workspace ID is required. Either:\n` +
|
|
104
|
+
` 1. Provide it as a flag: xano static_host build pull <static_host> --build_id <id> -w <workspace_id>\n` +
|
|
105
|
+
` 2. Set it in your profile using: xano profile edit ${profileName} -w <workspace_id>`);
|
|
106
|
+
}
|
|
107
|
+
let buildId;
|
|
108
|
+
if (flags.build_id) {
|
|
109
|
+
buildId = flags.build_id;
|
|
110
|
+
}
|
|
111
|
+
else if (flags.env) {
|
|
112
|
+
buildId = await this.resolveEnvBuild({
|
|
113
|
+
env: flags.env,
|
|
114
|
+
profile,
|
|
115
|
+
staticHost: args.static_host,
|
|
116
|
+
verbose: flags.verbose,
|
|
117
|
+
workspaceId,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
buildId = await this.resolveLatestBuild(profile, workspaceId, args.static_host, flags.verbose);
|
|
122
|
+
}
|
|
123
|
+
// Default is "original" (the uploaded source); only append the param when
|
|
124
|
+
// pulling the built output, so default requests stay clean.
|
|
125
|
+
const query = flags.source === 'built' ? '?source=built' : '';
|
|
126
|
+
const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${args.static_host}/build/${buildId}/multidoc${query}`;
|
|
127
|
+
let responseText;
|
|
128
|
+
try {
|
|
129
|
+
const response = await this.verboseFetch(apiUrl, {
|
|
130
|
+
headers: {
|
|
131
|
+
accept: 'application/json',
|
|
132
|
+
Authorization: `Bearer ${profile.access_token}`,
|
|
133
|
+
},
|
|
134
|
+
method: 'GET',
|
|
135
|
+
}, flags.verbose, profile.access_token);
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
const errorText = await response.text();
|
|
138
|
+
this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
|
|
139
|
+
}
|
|
140
|
+
responseText = await response.text();
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
if (error instanceof Error) {
|
|
144
|
+
this.error(`Failed to fetch build multidoc: ${error.message}`);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.error(`Failed to fetch build multidoc: ${String(error)}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!responseText.trim()) {
|
|
151
|
+
this.log('No files found in build');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const rawDocuments = responseText.split('\n---\n');
|
|
155
|
+
const files = [];
|
|
156
|
+
for (const raw of rawDocuments) {
|
|
157
|
+
const trimmed = raw.trim();
|
|
158
|
+
if (!trimmed)
|
|
159
|
+
continue;
|
|
160
|
+
const parsed = this.parseFileDocument(trimmed);
|
|
161
|
+
if (parsed) {
|
|
162
|
+
files.push(parsed);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (files.length === 0) {
|
|
166
|
+
this.log('No files found in response');
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const outputDir = path.resolve(flags.directory);
|
|
170
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
171
|
+
let writtenCount = 0;
|
|
172
|
+
for (const file of files) {
|
|
173
|
+
const filePath = path.resolve(outputDir, file.path);
|
|
174
|
+
if (!filePath.startsWith(outputDir + path.sep) && filePath !== outputDir) {
|
|
175
|
+
this.warn(`Skipping file with path outside output directory: ${file.path}`);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const fileDir = path.dirname(filePath);
|
|
179
|
+
fs.mkdirSync(fileDir, { recursive: true });
|
|
180
|
+
if (file.encoding === 'base64') {
|
|
181
|
+
const buffer = Buffer.from(file.content, 'base64');
|
|
182
|
+
fs.writeFileSync(filePath, buffer);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
fs.writeFileSync(filePath, file.content, 'utf8');
|
|
186
|
+
}
|
|
187
|
+
writtenCount++;
|
|
188
|
+
}
|
|
189
|
+
this.log(`Pulled ${writtenCount} files to ${flags.directory}`);
|
|
190
|
+
}
|
|
191
|
+
parseFileDocument(raw) {
|
|
192
|
+
const lines = raw.split('\n');
|
|
193
|
+
const firstLine = lines[0];
|
|
194
|
+
if (!firstLine.startsWith('path: ')) {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const filePath = firstLine.slice('path: '.length).trim();
|
|
198
|
+
if (lines.length > 1 && lines[1] === 'encoding: base64') {
|
|
199
|
+
const content = lines.slice(2).join('\n');
|
|
200
|
+
return { content, encoding: 'base64', path: filePath };
|
|
201
|
+
}
|
|
202
|
+
const content = lines.slice(1).join('\n');
|
|
203
|
+
return { content, path: filePath };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Resolve the build ID currently deployed to a static host's dev/prod env.
|
|
207
|
+
*
|
|
208
|
+
* The deployed env stores the `canonical` of the build it was created from
|
|
209
|
+
* (static_host.{env}.canonical). Each build carries that same unique
|
|
210
|
+
* `canonical`, so we match the env's canonical against the build list to
|
|
211
|
+
* recover the build ID — a shortcut for "list builds, find the deployed one,
|
|
212
|
+
* then pull it".
|
|
213
|
+
*/
|
|
214
|
+
async resolveEnvBuild(opts) {
|
|
215
|
+
const { env, profile, staticHost, verbose, workspaceId } = opts;
|
|
216
|
+
// 1. Look up the static host to read the deployed canonical for this env.
|
|
217
|
+
const hostUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host`;
|
|
218
|
+
const hostResponse = await this.verboseFetch(hostUrl, {
|
|
219
|
+
headers: {
|
|
220
|
+
accept: 'application/json',
|
|
221
|
+
Authorization: `Bearer ${profile.access_token}`,
|
|
222
|
+
},
|
|
223
|
+
method: 'GET',
|
|
224
|
+
}, verbose, profile.access_token);
|
|
225
|
+
if (!hostResponse.ok) {
|
|
226
|
+
const errorText = await hostResponse.text();
|
|
227
|
+
this.error(`Failed to list static hosts: ${hostResponse.status} ${hostResponse.statusText}\n${errorText}`);
|
|
228
|
+
}
|
|
229
|
+
const hostData = (await hostResponse.json());
|
|
230
|
+
const hosts = Array.isArray(hostData)
|
|
231
|
+
? hostData
|
|
232
|
+
: hostData && typeof hostData === 'object' && 'items' in hostData && Array.isArray(hostData.items)
|
|
233
|
+
? hostData.items
|
|
234
|
+
: [];
|
|
235
|
+
const canonical = extractEnvCanonical(hosts, staticHost, env);
|
|
236
|
+
if (!canonical) {
|
|
237
|
+
if (!hosts.some((h) => h.name === staticHost)) {
|
|
238
|
+
this.error(`Static host '${staticHost}' not found`);
|
|
239
|
+
}
|
|
240
|
+
this.error(`No build is deployed to the '${env}' environment of static host '${staticHost}'`);
|
|
241
|
+
}
|
|
242
|
+
// 2. Page through builds to find the one matching the deployed canonical.
|
|
243
|
+
const perPage = 100;
|
|
244
|
+
for (let page = 1;; page++) {
|
|
245
|
+
const listUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${staticHost}/build?page=${page}&per_page=${perPage}`;
|
|
246
|
+
// eslint-disable-next-line no-await-in-loop
|
|
247
|
+
const response = await this.verboseFetch(listUrl, {
|
|
248
|
+
headers: {
|
|
249
|
+
accept: 'application/json',
|
|
250
|
+
Authorization: `Bearer ${profile.access_token}`,
|
|
251
|
+
},
|
|
252
|
+
method: 'GET',
|
|
253
|
+
}, verbose, profile.access_token);
|
|
254
|
+
if (!response.ok) {
|
|
255
|
+
// eslint-disable-next-line no-await-in-loop
|
|
256
|
+
const errorText = await response.text();
|
|
257
|
+
this.error(`Failed to list builds: ${response.status} ${response.statusText}\n${errorText}`);
|
|
258
|
+
}
|
|
259
|
+
// eslint-disable-next-line no-await-in-loop
|
|
260
|
+
const data = (await response.json());
|
|
261
|
+
const builds = Array.isArray(data)
|
|
262
|
+
? data
|
|
263
|
+
: data && typeof data === 'object' && 'items' in data && Array.isArray(data.items)
|
|
264
|
+
? data.items
|
|
265
|
+
: [];
|
|
266
|
+
const match = findBuildByCanonical(builds, canonical);
|
|
267
|
+
if (match) {
|
|
268
|
+
return String(match.id);
|
|
269
|
+
}
|
|
270
|
+
if (builds.length < perPage) {
|
|
271
|
+
// Reached the last page without a match.
|
|
272
|
+
this.error(`Could not find the build deployed to '${env}' (canonical ${canonical}) in the build list for '${staticHost}'`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async resolveLatestBuild(profile, workspaceId, staticHost, verbose) {
|
|
277
|
+
const listUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${staticHost}/build?page=1&per_page=1`;
|
|
278
|
+
const response = await this.verboseFetch(listUrl, {
|
|
279
|
+
headers: {
|
|
280
|
+
accept: 'application/json',
|
|
281
|
+
Authorization: `Bearer ${profile.access_token}`,
|
|
282
|
+
},
|
|
283
|
+
method: 'GET',
|
|
284
|
+
}, verbose, profile.access_token);
|
|
285
|
+
if (!response.ok) {
|
|
286
|
+
const errorText = await response.text();
|
|
287
|
+
this.error(`Failed to list builds: ${response.status} ${response.statusText}\n${errorText}`);
|
|
288
|
+
}
|
|
289
|
+
const data = await response.json();
|
|
290
|
+
const builds = Array.isArray(data)
|
|
291
|
+
? data
|
|
292
|
+
: data && typeof data === 'object' && 'items' in data && Array.isArray(data.items)
|
|
293
|
+
? data.items
|
|
294
|
+
: [];
|
|
295
|
+
if (builds.length === 0) {
|
|
296
|
+
this.error(`No builds found for static host '${staticHost}'`);
|
|
297
|
+
}
|
|
298
|
+
return String(builds[0].id);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import BaseCommand from '../../../../base-command.js';
|
|
2
|
+
export default class StaticHostBuildPush extends BaseCommand {
|
|
3
|
+
static args: {
|
|
4
|
+
static_host: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
+
};
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static flags: {
|
|
9
|
+
description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
directory: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
file: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
|
+
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
19
|
+
};
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
private countFiles;
|
|
22
|
+
private createZipBuffer;
|
|
23
|
+
}
|