@joystick.js/cli-canary 0.0.0-canary.1667 → 0.0.0-canary.1669

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.
@@ -1,24 +1,11 @@
1
- # Use Debian Slim as the base image
2
- FROM debian:bullseye-slim
1
+ # Use Node.js 20 Slim as the base image
2
+ FROM node:20-slim
3
3
 
4
4
  # Avoid prompts from apt
5
5
  ENV DEBIAN_FRONTEND=noninteractive
6
6
 
7
- # Set up environment variables
8
- ENV NODE_VERSION=20.x
9
-
10
- # Install Node.js 20 and common dependencies
11
- RUN apt-get update && apt-get install -y \
12
- curl \
13
- ca-certificates \
14
- gnupg \
15
- && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
16
- && apt-get install -y nodejs \
17
- && apt-get clean \
18
- && rm -rf /var/lib/apt/lists/*
19
-
20
- # Verify Node.js version
21
- RUN node --version
7
+ # Set the working directory in the container
8
+ WORKDIR /app
22
9
 
23
10
  # Allow custom apt dependencies to be passed as build argument
24
11
  ARG CUSTOM_APT_DEPS=""
@@ -38,9 +25,6 @@ RUN if [ ! -z "$GLOBAL_NPM_PACKAGES" ]; then \
38
25
  npm install -g $GLOBAL_NPM_PACKAGES; \
39
26
  fi
40
27
 
41
- # Set the working directory in the container
42
- WORKDIR /app
43
-
44
28
  # Copy package.json and package-lock.json (if available)
45
29
  COPY ./.build/package*.json ./
46
30
 
@@ -1 +1 @@
1
- import n from"./index.js";const[o,d,...e]=process.argv,s={description:"Deploy your Joystick app using Push.",args:{},options:{domain:{flags:{"-d":{set:!!e.includes("-d"),value:!!e.includes("-d")&&e[e.indexOf("-d")+1],parent:"push"},"--domain":{set:!!e.includes("--domain"),value:!!e.includes("--domain")&&e[e.indexOf("--domain")+1],parent:"push"}},description:"The domain of the app Push should deploy to."},environment:{flags:{"-e":{set:!!e.includes("-e"),value:!!e.includes("-e")&&e[e.indexOf("-e")+1],parent:"push"},"--environment":{set:!!e.includes("--environment"),value:!!e.includes("--environment")&&e[e.indexOf("--environment")+1],parent:"push"}},description:"The value you want to use for NODE_ENV in the deployed app (e.g., staging or production). Default is production."},push_server:{flags:{"-s":{set:!!e.includes("-s"),value:!!e.includes("-s")&&e[e.indexOf("-s")+1],parent:"push"},"--server":{set:!!e.includes("--server"),value:!!e.includes("--server")&&e[e.indexOf("--server")+1],parent:"push"}},description:"The Push provision server to target (development or production)."}},command:n};var r=s;export{r as default};
1
+ import n from"./index.js";const[o,t,...e]=process.argv,s={description:"Deploy your Joystick app using Push.",args:{},options:{domain:{flags:{"-d":{set:!!e.includes("-d"),value:!!e.includes("-d")&&e[e.indexOf("-d")+1],parent:"push"},"--domain":{set:!!e.includes("--domain"),value:!!e.includes("--domain")&&e[e.indexOf("--domain")+1],parent:"push"}},description:"The domain of the app Push should deploy to."},environment:{flags:{"-e":{set:!!e.includes("-e"),value:!!e.includes("-e")&&e[e.indexOf("-e")+1],parent:"push"},"--environment":{set:!!e.includes("--environment"),value:!!e.includes("--environment")&&e[e.indexOf("--environment")+1],parent:"push"}},description:"The value you want to use for NODE_ENV in the deployed app (e.g., staging or production). Default is production."},push_server:{flags:{"-s":{set:!!e.includes("-s"),value:!!e.includes("-s")&&e[e.indexOf("-s")+1],parent:"push"},"--server":{set:!!e.includes("--server"),value:!!e.includes("--server")&&e[e.indexOf("--server")+1],parent:"push"}},description:"The Push provision server to target (development or production)."},deployment_token:{flags:{"-t":{set:!!e.includes("-t"),value:!!e.includes("-t")&&e[e.indexOf("-t")+1],parent:"push"},"--token":{set:!!e.includes("--token"),value:!!e.includes("--token")&&e[e.indexOf("--token")+1],parent:"push"}},description:"The deployment token for your Push user account."}},command:n};var d=s;export{d as default};
@@ -1 +1 @@
1
- import a from"node-fetch";const n=(e={})=>a(`${e?.push_domain}/api/deployments/${e?.domain}`,{method:"GET",headers:{"x-push-session-token":e?.session_token,Accept:"application/json"}})?.then(async t=>(await t.json())?.data).catch(t=>{console.warn(t)});var c=n;export{c as default};
1
+ import a from"node-fetch";const n=(e={})=>a(`${e?.push_domain}/api/deployments/${e?.domain}`,{method:"GET",headers:{"x-push-deployment-token":e?.deployment,Accept:"application/json"}})?.then(async t=>await t.json()).catch(t=>{console.warn(t)});var c=n;export{c as default};
@@ -0,0 +1 @@
1
+ import i from"os";import r from"fs";import o from"../../lib/path_exists.js";const{readFile:n,mkdir:a,writeFile:p}=r.promises,m=async(s="")=>{if(s)return await o(`${t}/.push`)||await a(`${t}/.push`),await p(`${t}/.push/deployment_token`,s),s;const t=i.homedir(),e=`${t}/.push/deployment_token`;return await o(e)?n(e,"utf-8"):null};var c=m;export{c as default};
@@ -1 +1 @@
1
- const t=(o="production")=>({development:"http://localhost:2603",staging:"https://staging.provision.cheatcode.co",production:"https://provision.cheatcode.co"})[o];var e=t;export{e as default};
1
+ const o=(t="production")=>({development:"http://localhost:2603",production:"https://push.cheatcode.co"})[t];var e=o;export{e as default};
@@ -1,8 +1 @@
1
- import m from"chalk";import"inquirer";import p from"../../lib/build/index.js";import c from"../../lib/cli_log.js";import"./prompts/confirm_deployment.js";import"./create_version.js";import"./get_deployment.js";import d from"./get_push_domain.js";import a from"./get_settings_file.js";import l from"./get_session_token.js";import"./handle_initial_deployment.js";import"./handle_version_deployment.js";import _ from"../../lib/loader.js";import"./upload_build_to_cdn.js";import"./validate_deployment.js";import"./validate_push_config.js";import f from"./build_docker_image.js";const R=(o="",t="",r={})=>{let e="";for(let n=0;n<r?.errors?.length;n+=1){const s=r?.errors[n];o==="push_config"&&(e+=`${m.yellowBright(`> ${s.field}`)}
2
- `),e+=`${s?.error}
3
- ${n+1===r?.errors?.length?"":`
4
- `}`}c(`${t?`${m.yellowBright(t)}
5
-
6
-
7
- `:""}${e}`,{level:"danger",docs:{push_config:"https://cheatcode.co/docs/push/config",deployment:"https://cheatcode.co/docs/push/subscription"}[o]}),process.exit(0)},u=async()=>{const o=await l();return o||(c(data?.error?.message,{level:"danger",docs:"https://cheatcode.co/docs/push/cli#authentication"}),process.exit(0))},T=(o="")=>(c(`settings.${o}.json must contain a push config object. Add this following the docs link below and try again.`,{level:"danger",docs:"https://cheatcode.co/docs/push/config"}),process.exit(0)),g=async(o={},t={})=>{process.loader=new _,process.loader.print("Starting deployment...");const r=await u(),e=t?.environment||"production",s=(await a({environment:e}))?.config?.push||{},h=d(t?.push_server),i={domain:"example.com",status:"undeployed",deployment_secret:"abc123"};if(!0){i?.status==="undeployed"&&console.log(`
8
- `);const w=new Date().toISOString();await p({type:"directory",environment:e,encrypt_build:!0,encryption_key:i?.deployment_secret,silence_confirmation:!0}),await f(`${i?.domain}:latest`,process.cwd())}};var U=g;export{U as default};
1
+ import a from"../../lib/build/index.js";import n from"../../lib/cli_log.js";import i from"./get_deployment.js";import p from"./get_push_domain.js";import c from"./get_settings_file.js";import m from"./get_deployment_token.js";import"./upload_build_to_push.js";import l from"../../lib/loader.js";const u=async(r="")=>{const e=await m(r);return e||(n(data?.error?.message,{level:"danger",docs:"https://cheatcode.co/docs/push/authentication"}),process.exit(0))},y=async(r={},e={})=>{if(!e?.domain)return n("Must pass a deployment via -d or --domain flag.",{level:"danger",docs:"https://cheatcode.co/docs/push/cli"}),process.exit(0);process.loader=new l,process.loader.print("Starting deployment...");const d=await u(e?.deployment_token),s=e?.environment||"production",_=await c({environment:s}),o=p(e?.push_server),t=await i({domain:e?.domain,deployment_token:d,push_domain:o});if(console.log(t),!t)return n(`Sorry, we couldn't find a deployment with the domain ${e?.domain} on your account. If you haven't created it yet, head over to the Push dashboard: https://push.cheatcode.co/deployments/create`,{level:"danger",docs:"https://cheatcode.co/docs/push/deployments/create-a-new-deployment"}),process.exit(0);const h=new Date().toISOString();await a({environment:s,encrypt_build:!0,encryption_key:t?.deployment_secret,silence_confirmation:!0}),process.loader.print("Deploying to Push..."),process.loader.print(t?.intial_deployment_completed?`Deploying. Monitor your deployment at ${o}/deployments/${t?._id}.`:`Deploying. Finish your deployment's setup at ${o}/deployments/${t?._id}/setup.`)};var S=y;export{S as default};
@@ -0,0 +1 @@
1
+ import d from"node-fetch";import m from"form-data";import o from"fs";import"lodash";const{readFile:r}=o.promises,n=async(e={})=>{const a=new m;return a.append("version_tar",await r(".build/build.encrypted.tar.gz"),`${e?.build_timestamp}.tar.gz`),a.append("build_timestamp",e?.build_timestamp),a.append("domain",e?.deployment?.domain),a.append("deployment_id",e?.deployment?._id),d(`${e?.push_domain}/api/deploy`,{method:"POST",headers:{...a.getHeaders(),"x-push-deployment-token":e?.deployment_token},body:a}).then(async t=>(await t.json())?.data).catch(t=>{console.warn(t)})};var c=n;export{c as default};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.1667",
5
- "canary_version": "0.0.0-canary.1666",
4
+ "version": "0.0.0-canary.1669",
5
+ "canary_version": "0.0.0-canary.1668",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -1,24 +1,11 @@
1
- # Use Debian Slim as the base image
2
- FROM debian:bullseye-slim
1
+ # Use Node.js 20 Slim as the base image
2
+ FROM node:20-slim
3
3
 
4
4
  # Avoid prompts from apt
5
5
  ENV DEBIAN_FRONTEND=noninteractive
6
6
 
7
- # Set up environment variables
8
- ENV NODE_VERSION=20.x
9
-
10
- # Install Node.js 20 and common dependencies
11
- RUN apt-get update && apt-get install -y \
12
- curl \
13
- ca-certificates \
14
- gnupg \
15
- && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
16
- && apt-get install -y nodejs \
17
- && apt-get clean \
18
- && rm -rf /var/lib/apt/lists/*
19
-
20
- # Verify Node.js version
21
- RUN node --version
7
+ # Set the working directory in the container
8
+ WORKDIR /app
22
9
 
23
10
  # Allow custom apt dependencies to be passed as build argument
24
11
  ARG CUSTOM_APT_DEPS=""
@@ -38,9 +25,6 @@ RUN if [ ! -z "$GLOBAL_NPM_PACKAGES" ]; then \
38
25
  npm install -g $GLOBAL_NPM_PACKAGES; \
39
26
  fi
40
27
 
41
- # Set the working directory in the container
42
- WORKDIR /app
43
-
44
28
  # Copy package.json and package-lock.json (if available)
45
29
  COPY ./.build/package*.json ./
46
30
 
@@ -51,6 +51,21 @@ const definition = {
51
51
  },
52
52
  description: 'The Push provision server to target (development or production).',
53
53
  },
54
+ deployment_token: {
55
+ flags: {
56
+ '-t': {
57
+ set: !!raw_args.includes('-t'),
58
+ value: !!raw_args.includes('-t') && raw_args[raw_args.indexOf('-t') + 1],
59
+ parent: 'push',
60
+ },
61
+ '--token': {
62
+ set: !!raw_args.includes('--token'),
63
+ value: !!raw_args.includes('--token') && raw_args[raw_args.indexOf('--token') + 1],
64
+ parent: 'push',
65
+ },
66
+ },
67
+ description: 'The deployment token for your Push user account.',
68
+ },
54
69
  },
55
70
  command: push,
56
71
  };
@@ -4,13 +4,13 @@ const get_deployment = (options = {}) => {
4
4
  return fetch(`${options?.push_domain}/api/deployments/${options?.domain}`, {
5
5
  method: 'GET',
6
6
  headers: {
7
- 'x-push-session-token': options?.session_token,
7
+ 'x-push-deployment-token': options?.deployment,
8
8
  Accept: 'application/json',
9
9
  },
10
10
  })?.then(async (response) => {
11
11
  // NOTE: We only care about the data in the response here so just return it.
12
12
  const data = await response.json();
13
- return data?.data;
13
+ return data;
14
14
  }).catch((error) => {
15
15
  console.warn(error);
16
16
  });
@@ -1,31 +1,29 @@
1
1
  import os from 'os';
2
2
  import fs from 'fs';
3
- import inquirer from 'inquirer';
4
3
  import path_exists from '../../lib/path_exists.js';
5
- import session_token_prompt from './prompts/session_token.js';
6
4
 
7
5
  const { readFile, mkdir, writeFile } = fs.promises;
8
6
 
9
- const get_session_token = async () => {
7
+ const get_deployment_token = async (deployment_token = '') => {
8
+ if (deployment_token) {
9
+ if (!(await path_exists(`${home_directory}/.push`))) {
10
+ await mkdir(`${home_directory}/.push`);
11
+ }
12
+
13
+ await writeFile(`${home_directory}/.push/deployment_token`, deployment_token);
14
+
15
+ return deployment_token;
16
+ }
17
+
10
18
  const home_directory = os.homedir();
11
- const session_token_path = `${home_directory}/.push/session_token`;
19
+ const session_token_path = `${home_directory}/.push/deployment_token`;
12
20
  const session_token_exists = await path_exists(session_token_path);
13
21
 
14
22
  if (session_token_exists) {
15
23
  return readFile(session_token_path, 'utf-8');
16
24
  }
17
-
18
- const { session_token } = await inquirer.prompt(session_token_prompt());
19
25
 
20
- if (session_token) {
21
- if (!(await path_exists(`${home_directory}/.push`))) {
22
- await mkdir(`${home_directory}/.push`);
23
- }
24
-
25
- await writeFile(`${home_directory}/.push/session_token`, session_token);
26
-
27
- return session_token;
28
- }
26
+ return null;
29
27
  };
30
28
 
31
- export default get_session_token;
29
+ export default get_deployment_token;
@@ -1,9 +1,8 @@
1
- const get_provision_domain = (provision_server = 'production') => {
1
+ const get_push_domain = (push_server = 'production') => {
2
2
  return {
3
3
  development: 'http://localhost:2603',
4
- staging: 'https://staging.provision.cheatcode.co',
5
- production: 'https://provision.cheatcode.co',
6
- }[provision_server];
4
+ production: 'https://push.cheatcode.co',
5
+ }[push_server];
7
6
  };
8
7
 
9
- export default get_provision_domain;
8
+ export default get_push_domain;
@@ -1,167 +1,91 @@
1
- import chalk from 'chalk';
2
- import inquirer from "inquirer";
3
1
  import build from '../../lib/build/index.js';
4
2
  import cli_log from '../../lib/cli_log.js';
5
- import confirm_deployment_prompt from './prompts/confirm_deployment.js';
6
- import create_version from './create_version.js';
7
3
  import get_deployment from './get_deployment.js';
8
4
  import get_push_domain from './get_push_domain.js';
9
5
  import get_settings_file from './get_settings_file.js';
10
- import get_session_token from './get_session_token.js';
11
- import handle_initial_deployment from './handle_initial_deployment.js';
12
- import handle_version_deployment from './handle_version_deployment.js';
6
+ import get_deployment_token from './get_deployment_token.js';
7
+ import upload_build_to_push from './upload_build_to_push.js';
13
8
  import Loader from '../../lib/loader.js';
14
- import upload_build_to_cdn from './upload_build_to_cdn.js';
15
- import validate_deployment from './validate_deployment.js';
16
- import validate_push_config from './validate_push_config.js';
17
- import build_docker_image from './build_docker_image.js';
18
9
 
19
- const log_validation_error_response = (validation_type = '', root_error = '', validation_response = {}) => {
20
- let errors_list = ``;
10
+ const get_token_for_deployment = async (input_deployment_token = '') => {
11
+ const deployment_token = await get_deployment_token(input_deployment_token);
21
12
 
22
- for (let i = 0; i < validation_response?.errors?.length; i += 1) {
23
- const validation_error = validation_response?.errors[i];
24
-
25
- if (validation_type === 'push_config') {
26
- errors_list += `${chalk.yellowBright(`> ${validation_error.field}`)}\n`;
27
- }
28
-
29
- errors_list += `${validation_error?.error}\n${i + 1 === validation_response?.errors?.length ? '' : '\n'}`;
30
- }
31
-
32
- cli_log(
33
- `${root_error ? `${chalk.yellowBright(root_error)}\n\n\n` : ''}${errors_list}`,
34
- {
35
- level: "danger",
36
- docs: {
37
- push_config: "https://cheatcode.co/docs/push/config",
38
- deployment: "https://cheatcode.co/docs/push/subscription",
39
- }[validation_type],
40
- }
41
- );
42
-
43
- process.exit(0);
44
- };
45
-
46
- const get_session_for_deployment = async () => {
47
- const session_token = await get_session_token();
48
-
49
- if (!session_token) {
13
+ if (!deployment_token) {
50
14
  cli_log(
51
15
  data?.error?.message,
52
16
  {
53
17
  level: "danger",
54
- docs: "https://cheatcode.co/docs/push/cli#authentication"
18
+ docs: "https://cheatcode.co/docs/push/authentication"
55
19
  }
56
20
  );
57
21
 
58
22
  return process.exit(0);
59
23
  }
60
24
 
61
- return session_token;
25
+ return deployment_token;
62
26
  };
63
27
 
64
- const warn_no_push_config = (environment = '') => {
65
- cli_log(
66
- `settings.${environment}.json must contain a push config object. Add this following the docs link below and try again.`,
67
- {
68
- level: "danger",
69
- docs: "https://cheatcode.co/docs/push/config"
70
- }
71
- );
28
+ const push = async (args = {}, options = {}) => {
29
+ if (!options?.domain) {
30
+ cli_log(
31
+ `Must pass a deployment via -d or --domain flag.`,
32
+ {
33
+ level: "danger",
34
+ docs: "https://cheatcode.co/docs/push/cli"
35
+ }
36
+ );
72
37
 
73
- return process.exit(0);
74
- };
38
+ return process.exit(0);
39
+ }
75
40
 
76
- const push = async (args = {}, options = {}) => {
77
41
  process.loader = new Loader();
78
42
  process.loader.print('Starting deployment...');
79
43
 
80
- const session_token = await get_session_for_deployment();
44
+ const deployment_token = await get_token_for_deployment(options?.deployment_token);
81
45
  const environment = options?.environment || 'production';
82
46
  const settings = await get_settings_file({ environment });
83
- const push_settings = settings?.config?.push || {};
84
47
  const push_domain = get_push_domain(options?.push_server);
85
48
 
86
- const deployment = {
87
- domain: 'example.com',
88
- status: 'undeployed',
89
- deployment_secret: 'abc123',
90
- } || await get_deployment({
91
- domain: settings?.push?.domain,
92
- session_token,
49
+ const deployment = await get_deployment({
50
+ domain: options?.domain,
51
+ deployment_token,
93
52
  push_domain,
94
53
  });
95
54
 
96
- // NOTE: A bit hacky but removes need for weird if {} statement nesting.
97
- const confirm_deployment = true;
98
- // const { confirm_deployment } = { confirm_deployment: true } || deployment?.status === 'undeployed' ? await inquirer.prompt(
99
- // confirm_deployment_prompt([] || push_config_validation_response?.instances)
100
- // ) : { confirm_deployment: true };
55
+ console.log(deployment);
56
+
57
+ if (!deployment) {
58
+ cli_log(
59
+ `Sorry, we couldn\'t find a deployment with the domain ${options?.domain} on your account. If you haven\'t created it yet, head over to the Push dashboard: https://push.cheatcode.co/deployments/create`,
60
+ {
61
+ level: "danger",
62
+ docs: "https://cheatcode.co/docs/push/deployments/create-a-new-deployment"
63
+ }
64
+ );
101
65
 
102
- if (confirm_deployment) {
103
- // NOTE: Do this to create a gap between the confirmation text above (only applies if
104
- // the deployment is a first-run).
105
- if (deployment?.status === 'undeployed') {
106
- console.log('\n');
107
- }
66
+ return process.exit(0);
67
+ }
108
68
 
109
- const build_timestamp = new Date().toISOString();
69
+ const build_timestamp = new Date().toISOString();
110
70
 
111
- await build({
112
- type: 'directory', // NOTE: Use this so we can copy it into the Docker image.
113
- environment,
114
- encrypt_build: true,
115
- encryption_key: deployment?.deployment_secret,
116
- silence_confirmation: true,
117
- });
118
-
119
- await build_docker_image(
120
- `${deployment?.domain}:latest`,
121
- process.cwd(), // NOTE: Dockerfile targets the .build directory.
122
- );
123
-
124
- // process.loader.print('Uploading version...');
125
-
126
- // await upload_build_to_cdn(
127
- // build_timestamp,
128
- // deployment,
129
- // session_token,
130
- // );
131
-
132
- // const create_version_response = await create_version({
133
- // push_domain,
134
- // domain: settings?.push?.domain,
135
- // session_token,
136
- // body: {
137
- // // NOTE: Endpoint anticipates a stringified version of settings.
138
- // settings: JSON.stringify(settings),
139
- // build_timestamp,
140
- // },
141
- // });
142
-
143
- // process.loader.print('Deploying app...');
144
-
145
- // if (deployment?.status === 'undeployed') {
146
- // return handle_initial_deployment({
147
- // push_domain,
148
- // push_domain,
149
- // session_token,
150
- // environment,
151
- // build_timestamp,
152
- // deployment,
153
- // });
154
- // }
155
-
156
- // return handle_version_deployment({
157
- // push_domain,
158
- // push_domain,
159
- // session_token,
160
- // environment,
161
- // build_timestamp,
162
- // deployment,
163
- // });
164
- }
71
+ await build({
72
+ environment,
73
+ encrypt_build: true,
74
+ encryption_key: deployment?.deployment_secret,
75
+ silence_confirmation: true,
76
+ });
77
+
78
+ process.loader.print('Deploying to Push...');
79
+
80
+ // await upload_build_to_push({
81
+ // build_timestamp,
82
+ // deployment,
83
+ // deployment_token,
84
+ // push_domain,
85
+ // settings,
86
+ // });
87
+
88
+ process.loader.print(deployment?.intial_deployment_completed ? `Deploying. Monitor your deployment at ${push_domain}/deployments/${deployment?._id}.` : `Deploying. Finish your deployment's setup at ${push_domain}/deployments/${deployment?._id}/setup.`);
165
89
  };
166
90
 
167
91
  export default push;
@@ -0,0 +1,36 @@
1
+ import fetch from "node-fetch";
2
+ import FormData from "form-data";
3
+ import fs from "fs";
4
+ import _ from 'lodash';
5
+
6
+ const { readFile } = fs.promises;
7
+
8
+ const upload_build_to_push = async (options = {}) => {
9
+ const form_data = new FormData();
10
+
11
+ form_data.append(
12
+ "version_tar",
13
+ await readFile(`.build/build.encrypted.tar.gz`),
14
+ `${options?.build_timestamp}.tar.gz`
15
+ );
16
+
17
+ form_data.append("build_timestamp", options?.build_timestamp);
18
+ form_data.append("domain", options?.deployment?.domain);
19
+ form_data.append("deployment_id", options?.deployment?._id);
20
+
21
+ return fetch(`${options?.push_domain}/api/deploy`, {
22
+ method: "POST",
23
+ headers: {
24
+ ...form_data.getHeaders(),
25
+ "x-push-deployment-token": options?.deployment_token,
26
+ },
27
+ body: form_data,
28
+ }).then(async (response) => {
29
+ const data = await response.json();
30
+ return data?.data;
31
+ }).catch((error) => {
32
+ console.warn(error);
33
+ });
34
+ };
35
+
36
+ export default upload_build_to_push;
@@ -1 +0,0 @@
1
- import i from"os";import n from"fs";import r from"inquirer";import e from"../../lib/path_exists.js";import p from"./prompts/session_token.js";const{readFile:m,mkdir:a,writeFile:_}=n.promises,f=async()=>{const s=i.homedir(),t=`${s}/.push/session_token`;if(await e(t))return m(t,"utf-8");const{session_token:o}=await r.prompt(p());if(o)return await e(`${s}/.push`)||await a(`${s}/.push`),await _(`${s}/.push/session_token`,o),o};var x=f;export{x as default};
@@ -1 +0,0 @@
1
- import n from"node-fetch";import i from"form-data";import d from"fs";import m from"lodash";import c from"./cdn_mirrors.js";const{readFile:l}=d.promises,p=async()=>{const a=(await Promise.allSettled(c?.map(async t=>{const o=new AbortController;setTimeout(()=>o.abort(),2e3);const e=await n(`${t}/api/ping`,{signal:o.signal}).catch(r=>({status:503}));return{mirror:t,status:e.status}})))?.map(t=>t.value);return m.orderBy(a,["status","mirror"])[0]},u=async(a="",t={},o="")=>{const e=await p(),r=new i;return r.append("version_tar",await l(".build/build.encrypted.tar.gz"),`${a}.tar.gz`),r.append("build_timestamp",a),r.append("domain",t?.domain),r.append("deployment_id",t?._id),n(`${e?.mirror}/api/versions`,{method:"POST",headers:{...r.getHeaders(),"x-push-session-token":o},body:r}).then(async s=>(await s.json())?.data).catch(s=>{console.warn(s)})};var y=u;export{y as default};
@@ -1,59 +0,0 @@
1
- import fetch from "node-fetch";
2
- import FormData from "form-data";
3
- import fs from "fs";
4
- import _ from 'lodash';
5
- import cdn_mirrors from './cdn_mirrors.js';
6
-
7
- const { readFile } = fs.promises;
8
-
9
- const get_first_available_mirror = async () => {
10
- const results = (await Promise.allSettled(cdn_mirrors?.map(async (mirror) => {
11
- const controller = new AbortController();
12
- setTimeout(() => controller.abort(), 2000);
13
-
14
- const result = await fetch(`${mirror}/api/ping`, { signal: controller.signal }).catch((error) => {
15
- return { status: 503 };
16
- });
17
-
18
- return {
19
- mirror,
20
- status: result.status,
21
- };
22
- })))?.map((result) => {
23
- return result.value;
24
- });
25
-
26
- return _.orderBy(results, ['status', 'mirror'])[0];
27
- };
28
-
29
- const upload_build_to_cdn = async (build_timestamp = '', deployment = {}, session_token = '') => {
30
- const first_available_mirror = await get_first_available_mirror();
31
- const form_data = new FormData();
32
-
33
- form_data.append(
34
- "version_tar",
35
- await readFile(`.build/build.encrypted.tar.gz`),
36
- `${build_timestamp}.tar.gz`
37
- );
38
-
39
- form_data.append("build_timestamp", build_timestamp);
40
- form_data.append("domain", deployment?.domain);
41
- form_data.append("deployment_id", deployment?._id);
42
-
43
- return fetch(`${first_available_mirror?.mirror}/api/versions`, {
44
- method: "POST",
45
- headers: {
46
- ...form_data.getHeaders(),
47
- "x-push-session-token": session_token,
48
- },
49
- body: form_data,
50
- }).then(async (response) => {
51
- const data = await response.json();
52
- return data?.data;
53
- }).catch((error) => {
54
- console.warn(error);
55
- });
56
- };
57
-
58
- export default upload_build_to_cdn;
59
-