-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathupload.ts
More file actions
70 lines (61 loc) · 1.93 KB
/
upload.ts
File metadata and controls
70 lines (61 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type yargs from "yargs";
import { DEPLOYMENT_MAPPING_ENV_NAME } from "../templates/skew-protection.js";
import { runWrangler } from "../utils/run-wrangler.js";
import { getEnvFromPlatformProxy, quoteShellMeta } from "./helpers.js";
import { populateCache, withPopulateCacheOptions } from "./populate-cache.js";
import { getDeploymentMapping } from "./skew-protection.js";
import type { WithWranglerArgs } from "./utils.js";
import {
getNormalizedOptions,
printHeaders,
readWranglerConfig,
retrieveCompiledConfig,
withWranglerPassthroughArgs,
} from "./utils.js";
/**
* Implementation of the `opennextjs-cloudflare upload` command.
*
* @param args
*/
export async function uploadCommand(args: WithWranglerArgs<{ cacheChunkSize?: number }>): Promise<void> {
printHeaders("upload");
const { config } = await retrieveCompiledConfig();
const options = getNormalizedOptions(config);
const wranglerConfig = readWranglerConfig(args);
const envVars = await getEnvFromPlatformProxy({
configPath: args.wranglerConfigPath,
environment: args.env,
});
const deploymentMapping = await getDeploymentMapping(options, config, envVars);
await populateCache(options, config, wranglerConfig, {
target: "remote",
environment: args.env,
wranglerConfigPath: args.wranglerConfigPath,
cacheChunkSize: args.cacheChunkSize,
shouldUsePreviewId: false,
});
runWrangler(
options,
[
"versions upload",
...args.wranglerArgs,
...(deploymentMapping
? [`--var ${DEPLOYMENT_MAPPING_ENV_NAME}:${quoteShellMeta(JSON.stringify(deploymentMapping))}`]
: []),
],
{ logging: "all" }
);
}
/**
* Add the `upload` command to yargs configuration.
*
* Consumes 1 positional parameter.
*/
export function addUploadCommand<T extends yargs.Argv>(y: T) {
return y.command(
"upload",
"Upload a built OpenNext app to Cloudflare Workers",
(c) => withPopulateCacheOptions(c),
(args) => uploadCommand(withWranglerPassthroughArgs(args))
);
}