runcloud 0.1.134 → 0.1.135
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/dist/commands/website.js
CHANGED
|
@@ -4,6 +4,7 @@ import { create as tarCreate } from 'tar';
|
|
|
4
4
|
import { ApiClient, friendlyApiError } from '../api.js';
|
|
5
5
|
import { createSnapshot } from '../archive.js';
|
|
6
6
|
import { requireCredentials, resolveProject } from '../config.js';
|
|
7
|
+
import { isBundleDeployMode } from './deploy.js';
|
|
7
8
|
function makeClient(project) {
|
|
8
9
|
const creds = requireCredentials();
|
|
9
10
|
return {
|
|
@@ -12,6 +13,8 @@ function makeClient(project) {
|
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
const BUILD_ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16
|
+
const PUBLISH_POLL_INTERVAL_MS = 3_000;
|
|
17
|
+
const PUBLISH_POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
15
18
|
export function renderDeployment(d) {
|
|
16
19
|
const at = d.published_at ?? d.created_at ?? '';
|
|
17
20
|
const suffix = d.error_message ? ` (${d.error_message})` : '';
|
|
@@ -100,8 +103,39 @@ export async function createStaticSiteArchive(dir) {
|
|
|
100
103
|
}
|
|
101
104
|
return Buffer.concat(chunks);
|
|
102
105
|
}
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
function assertBundleModeExport(dir) {
|
|
107
|
+
if (!existsSync(`${resolve(dir)}/index.html`)) {
|
|
108
|
+
throw new Error(`No static export at ${dir}. Build it first, then run \`newly website publish ${dir}\`.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function finishPublish(client, projectId, result, log, pollOpts = {}) {
|
|
112
|
+
if (result.deployment.status !== 'building') {
|
|
113
|
+
log(`Published ${result.deployment.id}`);
|
|
114
|
+
log(`URL: ${result.default_url}`);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const intervalMs = pollOpts.intervalMs ?? PUBLISH_POLL_INTERVAL_MS;
|
|
118
|
+
const timeoutMs = pollOpts.timeoutMs ?? PUBLISH_POLL_TIMEOUT_MS;
|
|
119
|
+
log(`Publishing ${result.deployment.id}...`);
|
|
120
|
+
const deadline = Date.now() + timeoutMs;
|
|
121
|
+
for (;;) {
|
|
122
|
+
const { deployments = [] } = (await client.get(`/projects/${projectId}/website/deployments`));
|
|
123
|
+
const match = deployments.find((d) => d.id === result.deployment.id);
|
|
124
|
+
if (match?.status === 'active') {
|
|
125
|
+
log(`Published ${match.id}`);
|
|
126
|
+
log(`URL: ${result.default_url}`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (match?.status === 'failed') {
|
|
130
|
+
throw new Error(match.error_message ?? `Publish ${result.deployment.id} failed.`);
|
|
131
|
+
}
|
|
132
|
+
if (Date.now() > deadline) {
|
|
133
|
+
throw new Error(`Publish ${result.deployment.id} timed out after ${timeoutMs / 1000}s`);
|
|
134
|
+
}
|
|
135
|
+
await new Promise((r) => setTimeout(r, intervalMs));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function runWebsitePublish(client, projectId, opts = {}, log = console.log, pollOpts = {}) {
|
|
105
139
|
if (opts.remoteBuild) {
|
|
106
140
|
const sourceDir = opts.localPath ?? '.';
|
|
107
141
|
assertDirectory(sourceDir, 'Website source directory');
|
|
@@ -115,19 +149,33 @@ export async function runWebsitePublish(client, projectId, opts = {}, log = cons
|
|
|
115
149
|
output_dir: opts.outputDir,
|
|
116
150
|
}));
|
|
117
151
|
form.set('source', new Blob([new Uint8Array(archive)], { type: 'application/gzip' }), 'source.tar.gz');
|
|
118
|
-
result = (await client.uploadForm(`/projects/${projectId}/website/build-upload`, form));
|
|
152
|
+
const result = (await client.uploadForm(`/projects/${projectId}/website/build-upload`, form));
|
|
153
|
+
log(`Published ${result.deployment.id}`);
|
|
154
|
+
log(`URL: ${result.default_url}`);
|
|
155
|
+
return;
|
|
119
156
|
}
|
|
120
|
-
|
|
157
|
+
if (opts.localPath) {
|
|
121
158
|
log('Packaging static site...');
|
|
122
159
|
const archive = await createStaticSiteArchive(opts.localPath);
|
|
123
160
|
log(`Uploading static site (${archiveKib(archive.length)} KiB)...`);
|
|
124
|
-
result = (await client.upload(`/projects/${projectId}/website/publish-upload`, archive, 'application/gzip'));
|
|
161
|
+
const result = (await client.upload(`/projects/${projectId}/website/publish-upload`, archive, 'application/gzip'));
|
|
162
|
+
await finishPublish(client, projectId, result, log, pollOpts);
|
|
163
|
+
return;
|
|
125
164
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
165
|
+
const stackInfo = (await client.get(`/newly_backend/stack/${projectId}`));
|
|
166
|
+
if (isBundleDeployMode(stackInfo)) {
|
|
167
|
+
const dir = opts.sourcePath ?? 'website/out';
|
|
168
|
+
assertBundleModeExport(dir);
|
|
169
|
+
log('Packaging static site...');
|
|
170
|
+
const archive = await createStaticSiteArchive(dir);
|
|
171
|
+
log(`Uploading static site (${archiveKib(archive.length)} KiB)...`);
|
|
172
|
+
const result = (await client.upload(`/projects/${projectId}/website/publish-upload`, archive, 'application/gzip'));
|
|
173
|
+
await finishPublish(client, projectId, result, log, pollOpts);
|
|
174
|
+
return;
|
|
130
175
|
}
|
|
176
|
+
const result = (await client.post(`/projects/${projectId}/website/publish`, {
|
|
177
|
+
source_path: opts.sourcePath ?? 'website/out',
|
|
178
|
+
}));
|
|
131
179
|
log(`Published ${result.deployment.id}`);
|
|
132
180
|
log(`URL: ${result.default_url}`);
|
|
133
181
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = '0.1.
|
|
1
|
+
export const CLI_VERSION = '0.1.135';
|
package/package.json
CHANGED
|
index 6d97a4f..8be8f43 100644
|
|
|
Binary file
|