@joystick.js/cli-canary 0.0.0-canary.1653 → 0.0.0-canary.1655

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 +1 @@
1
- import{exec as u}from"child_process";import i from"path";import{fileURLToPath as $}from"url";import"https";import g from"fs";import h from"os";import"tar";import"adm-zip";const y=$(import.meta.url),c=i.dirname(y),O=i.join(h.homedir(),".joystick","docker"),D=(t="",a="",{apt_deps:s=[],snap_deps:d=[],npm_deps:l=[]}={})=>new Promise(async(m,r)=>{if(!check_docker_installation()){process.loader.print("Push requires Docker to be installed on your machine. Downloading...");try{await get_docker_binary(),process.loader.print("Docker installed!")}catch(o){r(new Error(`Failed to download Docker binary: ${o.message}`));return}}process.loader.print("Building Docker image for deployment...");const p=get_docker_binary_path(),e=i.join(c,"Dockerfile");if(!g.existsSync(e)){r(new Error(`Dockerfile not found at ${e}`));return}const f=[`CUSTOM_APT_DEPS=${s.join(" ")}`,`CUSTOM_SNAP_DEPS=${d.join(" ")}`,`GLOBAL_NPM_PACKAGES=${l.join(" ")}`].map(o=>`--build-arg ${o}`).join(" "),_=`"${p}" build ${f} -t ${t} -f "${e}" "${a||c}"`;u(_,(o,k,n)=>{if(o){console.error(`Error building Docker image: ${o.message}`),r(o);return}n&&console.error(`Docker build stderr: ${n}`),process.loader.print(k),process.loader.print(`Successfully built Docker image: ${t}`),m()})});var U=D;export{U as default};
1
+ import{exec as y,execSync as $}from"child_process";import l from"path";import{fileURLToPath as b}from"url";import D from"https";import a from"fs";import d from"os";import S from"tar";import x from"adm-zip";const P=b(import.meta.url),u=l.dirname(P),s=l.join(d.homedir(),".joystick","docker"),k=()=>l.join(s,d.platform()==="win32"?"docker.exe":"docker"),j=()=>{const o=k();try{return $(`"${o}" --version`,{stdio:"ignore"}),!0}catch{return console.warn("Warning: Docker is not installed or the binary is not accessible."),!1}},z=(o,e)=>new Promise((t,i)=>{const r=a.createWriteStream(e);D.get(o,c=>{c.pipe(r),r.on("finish",()=>{r.close(t)})}).on("error",c=>{a.unlink(e,()=>i(c))})}),A=async()=>{const o=d.platform(),e=d.arch();let t,i;if(o==="linux")t=`https://download.docker.com/linux/static/stable/${e}/docker-24.0.7.tgz`,i="docker.tgz";else if(o==="darwin")t=`https://download.docker.com/mac/static/stable/${e}/docker-24.0.7.tgz`,i="docker.tgz";else if(o==="win32")t="https://download.docker.com/win/static/stable/x86_64/docker-24.0.7.zip",i="docker.zip";else throw new Error("Unsupported operating system");a.mkdirSync(s,{recursive:!0});const r=l.join(s,i);await z(t,r),o==="win32"?new x(r).extractAllTo(s,!0):await S.x({file:r,cwd:s,strip:1}),a.unlinkSync(r),o!=="win32"&&a.chmodSync(k(),"755"),process.loader.print(`Docker binaries downloaded and extracted to ${s}`)},E=(o="",e="",{apt_deps:t=[],snap_deps:i=[],npm_deps:r=[]}={})=>new Promise(async(c,p)=>{if(!j()){process.loader.print("Push requires Docker to be installed on your machine. Downloading...");try{await A(),process.loader.print("Docker installed!")}catch(n){p(new Error(`Failed to download Docker binary: ${n.message}`));return}}process.loader.print("Building Docker image for deployment...");const _=k(),m=l.join(u,"Dockerfile");if(!a.existsSync(m)){p(new Error(`Dockerfile not found at ${m}`));return}const h=[`CUSTOM_APT_DEPS=${t.join(" ")}`,`CUSTOM_SNAP_DEPS=${i.join(" ")}`,`GLOBAL_NPM_PACKAGES=${r.join(" ")}`].map(n=>`--build-arg ${n}`).join(" "),w=`"${_}" build ${h} -t ${o} -f "${m}" "${e||u}"`;y(w,(n,g,f)=>{if(n){console.error(`Error building Docker image: ${n.message}`),p(n);return}f&&console.error(`Docker build stderr: ${f}`),process.loader.print(g),process.loader.print(`Successfully built Docker image: ${o}`),c()})});var G=E;export{G 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.1653",
5
- "canary_version": "0.0.0-canary.1652",
4
+ "version": "0.0.0-canary.1655",
5
+ "canary_version": "0.0.0-canary.1654",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -32,7 +32,6 @@
32
32
  "node-fetch": "^3.3.2",
33
33
  "pg": "^8.11.3",
34
34
  "query-string": "^8.1.0",
35
- "tar": "^7.4.3",
36
35
  "ws": "^8.15.1"
37
36
  }
38
37
  }
@@ -12,7 +12,78 @@ const __dirname = path.dirname(__filename);
12
12
 
13
13
  const joystick_docker_path = path.join(os.homedir(), '.joystick', 'docker');
14
14
 
15
- // ... (previous functions remain the same)
15
+ const get_docker_binary_path = () => {
16
+ return path.join(joystick_docker_path, os.platform() === 'win32' ? 'docker.exe' : 'docker');
17
+ };
18
+
19
+ const check_docker_installation = () => {
20
+ const docker_path = get_docker_binary_path();
21
+ try {
22
+ execSync(`"${docker_path}" --version`, { stdio: 'ignore' });
23
+ return true;
24
+ } catch (error) {
25
+ console.warn('Warning: Docker is not installed or the binary is not accessible.');
26
+ return false;
27
+ }
28
+ };
29
+
30
+ const download_file = (url, dest) => {
31
+ return new Promise((resolve, reject) => {
32
+ const file = fs.createWriteStream(dest);
33
+ https.get(url, (response) => {
34
+ response.pipe(file);
35
+ file.on('finish', () => {
36
+ file.close(resolve);
37
+ });
38
+ }).on('error', (error) => {
39
+ fs.unlink(dest, () => reject(error));
40
+ });
41
+ });
42
+ };
43
+
44
+ const get_docker_binary = async () => {
45
+ const platform = os.platform();
46
+ const arch = os.arch();
47
+ let url;
48
+ let archive_name;
49
+
50
+ if (platform === 'linux') {
51
+ url = `https://download.docker.com/linux/static/stable/${arch}/docker-24.0.7.tgz`;
52
+ archive_name = 'docker.tgz';
53
+ } else if (platform === 'darwin') {
54
+ url = `https://download.docker.com/mac/static/stable/${arch}/docker-24.0.7.tgz`;
55
+ archive_name = 'docker.tgz';
56
+ } else if (platform === 'win32') {
57
+ url = 'https://download.docker.com/win/static/stable/x86_64/docker-24.0.7.zip';
58
+ archive_name = 'docker.zip';
59
+ } else {
60
+ throw new Error('Unsupported operating system');
61
+ }
62
+
63
+ fs.mkdirSync(joystick_docker_path, { recursive: true });
64
+ const archive_path = path.join(joystick_docker_path, archive_name);
65
+ await download_file(url, archive_path);
66
+
67
+ if (platform === 'win32') {
68
+ const zip = new AdmZip(archive_path);
69
+ zip.extractAllTo(joystick_docker_path, true);
70
+ } else {
71
+ await tar.x({
72
+ file: archive_path,
73
+ cwd: joystick_docker_path,
74
+ strip: 1
75
+ });
76
+ }
77
+
78
+ fs.unlinkSync(archive_path);
79
+
80
+ // Make the docker binary executable on Unix-like systems
81
+ if (platform !== 'win32') {
82
+ fs.chmodSync(get_docker_binary_path(), '755');
83
+ }
84
+
85
+ process.loader.print(`Docker binaries downloaded and extracted to ${joystick_docker_path}`);
86
+ };
16
87
 
17
88
  const build_docker_image = (
18
89
  image_name = '',