@joystick.js/cli-canary 0.0.0-canary.1321 → 0.0.0-canary.1323

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 r from"fs";import e from"path";import p from"os";import"https";import{promisify as m}from"util";import{pipeline as u}from"stream";import{execFile as g}from"child_process";const h=m(u),d=m(g),c={mongodb:"MongoDB",postgresql:"PostgreSQL",redis:"Redis"},x=async t=>{if(p.platform()!=="win32"){const s=await r.promises.readdir(t);for(const i of s)await r.promises.chmod(e.join(t,i),"755")}},b=async(t,o,s,i)=>{const a=p.platform();if(t==="redis")if(a==="win32")await d("powershell",["Expand-Archive","-Path",o,"-DestinationPath",i]);else{await d("tar",["-xzf",o,"-C",s,"--strip-components=1"]),await r.promises.unlink(o);const n=e.join(s,"src");await d("make",["-C",n]);const l=e.join(n,"redis-server"),f=e.join(n,"redis-cli");await r.promises.copyFile(l,e.join(i,"redis-server")),await r.promises.copyFile(f,e.join(i,"redis-cli"))}else a==="win32"?await d("powershell",["Expand-Archive","-Path",o,"-DestinationPath",i]):await d("tar",["-xzf",o,"-C",i,"--strip-components=1"]),await r.promises.unlink(o)},y=async(t,o)=>{const s=await fetch(t);if(!s.ok)throw new Error(`Failed to download: ${s.statusText}`);await h(s.body,r.createWriteStream(o))},w=async t=>{try{return await r.promises.access(t),!0}catch{return!1}},z=async()=>{if(p.platform()==="darwin"){const{stdout:t}=await d("sysctl",["-n","machdep.cpu.brand_string"]);return t.trim()}return p.arch()},_=async(t,o)=>{if(o){const n=await r.promises.readFile(o,"utf-8");return JSON.parse(n)[t].url}const s=p.platform();return{mongodb:{win32:"https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-6.0.5.zip",darwin:(await z()).includes("ARM")?"https://fastdl.mongodb.org/osx/mongodb-macos-arm64-6.0.5.tgz":"https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-6.0.5.tgz",linux:"https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-6.0.5.tgz"},redis:{win32:"https://github.com/tporadowski/redis/releases/download/v5.0.14.1/Redis-x64-5.0.14.1.zip",darwin:"https://download.redis.io/releases/redis-6.2.6.tar.gz",linux:"https://download.redis.io/releases/redis-6.2.6.tar.gz"},postgresql:{win32:"https://get.enterprisedb.com/postgresql/postgresql-14.7-1-windows-x64-binaries.zip",darwin:"https://get.enterprisedb.com/postgresql/postgresql-14.7-1-osx-binaries.zip",linux:"https://ftp.postgresql.org/pub/source/v14.7/postgresql-14.7.tar.gz"}}[t][s]},j=async(t,o)=>{await r.promises.mkdir(t,{recursive:!0}),await r.promises.mkdir(o,{recursive:!0})},k=async(t,o=null)=>{const s=e.join(p.homedir(),".joystick","databases",t),i=e.join(s,"bin");if(await w(s))return;await j(s,i);const a=await _(t,o),n=e.basename(new URL(a).pathname),l=e.join(s,n);await w(l)||(process.loader.print(`${c[t]} not found. Downloading...`),await y(a,l),process.loader.print(`Installing ${c[t]}...`),await b(t,l,s,i),await x(i),process.loader.print(`${c[t]} installed!`))};var C=k;export{C as default};
1
+ import i from"fs";import n from"path";import d from"os";import"https";import{promisify as w}from"util";import{pipeline as u}from"stream";import{execFile as g}from"child_process";const h=w(u),c=w(g),m={mongodb:"MongoDB",postgresql:"PostgreSQL",redis:"Redis"},x=async t=>{if(d.platform()!=="win32"){const o=await i.promises.readdir(t);for(const r of o)await i.promises.chmod(n.join(t,r),"755")}},b=async(t,s,o,r)=>{const p=d.platform();if(t==="redis")if(p==="win32")await c("powershell",["Expand-Archive","-Path",s,"-DestinationPath",r]);else{await c("tar",["-xzf",s,"-C",o,"--strip-components=1"]),await i.promises.unlink(s);const e=n.join(o,"src");await c("make",["-C",e]);const a=n.join(e,"redis-server"),l=n.join(e,"redis-cli");await i.promises.copyFile(a,n.join(r,"redis-server")),await i.promises.copyFile(l,n.join(r,"redis-cli"))}else{if(p==="win32"){const e=n.join(o,"temp");await c("powershell",["Expand-Archive","-Path",s,"-DestinationPath",e]);const a=(await i.promises.readdir(e))[0],l=n.join(e,a,"bin");await i.promises.rename(l,r),await i.promises.rm(e,{recursive:!0,force:!0})}else await c("tar",["-xzf",s,"-C",r,"--strip-components=1"]);await i.promises.unlink(s)}},y=async(t,s)=>{const o=await fetch(t);if(!o.ok)throw new Error(`Failed to download: ${o.statusText}`);await h(o.body,i.createWriteStream(s))},f=async t=>{try{return await i.promises.access(t),!0}catch{return!1}},_=async()=>{if(d.platform()==="darwin"){const{stdout:t}=await c("sysctl",["-n","machdep.cpu.brand_string"]);return t.trim()}return d.arch()},j=async(t,s)=>{if(s){const e=await i.promises.readFile(s,"utf-8");return JSON.parse(e)[t].url}const o=d.platform();return{mongodb:{win32:"https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-6.0.5.zip",darwin:(await _()).includes("ARM")?"https://fastdl.mongodb.org/osx/mongodb-macos-arm64-6.0.5.tgz":"https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-6.0.5.tgz",linux:"https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-6.0.5.tgz"},redis:{win32:"https://github.com/tporadowski/redis/releases/download/v5.0.14.1/Redis-x64-5.0.14.1.zip",darwin:"https://download.redis.io/releases/redis-6.2.6.tar.gz",linux:"https://download.redis.io/releases/redis-6.2.6.tar.gz"},postgresql:{win32:"https://get.enterprisedb.com/postgresql/postgresql-14.7-1-windows-x64-binaries.zip",darwin:"https://get.enterprisedb.com/postgresql/postgresql-14.7-1-osx-binaries.zip",linux:"https://ftp.postgresql.org/pub/source/v14.7/postgresql-14.7.tar.gz"}}[t][o]},z=async(t,s)=>{await i.promises.mkdir(t,{recursive:!0}),await i.promises.mkdir(s,{recursive:!0})},k=async(t,s=null)=>{const o=n.join(d.homedir(),".joystick","databases",t),r=n.join(o,"bin");if(await f(o))return;await z(o,r);const p=await j(t,s),e=n.basename(new URL(p).pathname),a=n.join(o,e);await f(a)||(process.loader.print(`${m[t]} not found. Downloading...`),await y(p,a),process.loader.print(`Installing ${m[t]}...`),await b(t,a,o,r),await x(r),process.loader.print(`${m[t]} installed!`))};var C=k;export{C as default};
@@ -1,2 +1,2 @@
1
- import g from"child_process";import w from"fs";import h from"util";import m from"../../../cli_log.js";import y from"../../../command_exists.js";import x from"../../../get_platform_safe_path.js";import f from"../../../get_process_id_from_port.js";import"../../../kill_port_process.js";import u from"../../../path_exists.js";const c=h.promisify(g.exec),{rename:q}=w.promises,k=async(t=2610)=>{const n=await u(".joystick/data/postgresql");let s=await u(`.joystick/data/postgresql_${t}`);return n&&!s&&(await q(".joystick/data/postgresql",`.joystick/data/postgresql_${t}`),s=!0),s},j=()=>{m("PostgreSQL is not installed on this computer. You can download PostgreSQL at https://www.postgresql.org/download. After you've installed PostgreSQL, run joystick start again, or, remove PostgreSQL from your databases list in your settings.development.json file to skip startup.",{level:"danger",docs:"https://cheatcode.co/docs/joystick/cli#databases"})},b=()=>y("psql"),P=()=>y("pg_ctl"),L=async(t=2610)=>{await b()||(j(),process.exit(1));const s=await P();s||m("PostgreSQL is installed on this computer, but pg_ctl (what Joystick uses to start and manage PostgreSQL) is not in your command line's PATH variable. Add pg_ctl to your command line's PATH, restart your command line, and try again.",{level:"danger",docs:"https://cheatcode.co/docs/joystick/postgresql#path"});try{!await k(t)&&s&&await c(`pg_ctl init -D .joystick/data/postgresql_${t} --options=--no-locale`);const o=t,p=parseInt(await f(o),10);p&&await c(`pg_ctl kill KILL ${p}`);const d=g.spawn("pg_ctl",["-o",`"-p ${o}"`,"-D",x(`.joystick/data/postgresql_${t}`),"start"].filter(e=>!!e));return new Promise(e=>{d.stderr.on("data",async r=>{const i=r?.toString();i?.includes("another server might be running")||console.warn(i)}),d.stdout.on("data",async r=>{if((r?.toString()).includes("database system is ready to accept connections")){const _=(await f(o))?.replace(`
2
- `,"");c(`createdb -h 127.0.0.1 -p ${o} app`).then(a=>{e(parseInt(_,10))}).catch(({stderr:a})=>{a&&a.includes('database "app" already exists')?e(parseInt(_,10)):console.log(a)})}})})}catch(l){console.warn(l),process.exit(1)}};var K=L;export{K as default};
1
+ import _ from"child_process";import u from"fs";import h from"util";import m from"os";import w from"../../../cli_log.js";import g from"../../../command_exists.js";import k from"../../../get_platform_safe_path.js";import y from"../../../get_process_id_from_port.js";import"../../../kill_port_process.js";import f from"../../../path_exists.js";const n=h.promisify(_.exec),{rename:x}=u.promises,b=async(t=2610)=>{const s=await f(".joystick/data/postgresql");let o=await f(`.joystick/data/postgresql_${t}`);return s&&!o&&(await x(".joystick/data/postgresql",`.joystick/data/postgresql_${t}`),o=!0),o},z=()=>{w("PostgreSQL is not installed on this computer. You can download PostgreSQL at https://www.postgresql.org/download. After you've installed PostgreSQL, run joystick start again, or, remove PostgreSQL from your databases list in your settings.development.json file to skip startup.",{level:"danger",docs:"https://cheatcode.co/docs/joystick/cli#databases"})},B=()=>g("psql"),C=()=>g("pg_ctl"),q=async(t=2610)=>{try{const s=`${m.homedir()}/.joystick/databases/postgresql/bin/bin/pg_ctl`,o=`${m.homedir()}/.joystick/databases/postgresql/bin/bin/createdb`;await b(t)||await n(`${s} init -D .joystick/data/postgresql_${t} --options=--no-locale`);const e=t,p=parseInt(await y(e),10);p&&await n(`${s} kill KILL ${p}`);const d=_.spawn(`${s}`,["-o",`"-p ${e}"`,"-D",k(`.joystick/data/postgresql_${t}`),"start"].filter(a=>!!a));return new Promise(a=>{d.stderr.on("data",async i=>{const c=i?.toString();c?.includes("another server might be running")||console.warn(c)}),d.stdout.on("data",async i=>{if((i?.toString()).includes("database system is ready to accept connections")){const l=(await y(e))?.replace(`
2
+ `,"");n(`${o} -h 127.0.0.1 -p ${e} app`).then(r=>{a(parseInt(l,10))}).catch(({stderr:r})=>{r&&r.includes('database "app" already exists')?a(parseInt(l,10)):console.log(r)})}})})}catch(s){console.warn(s),process.exit(1)}};var E=q;export{E 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.1321",
5
- "canary_version": "0.0.0-canary.1320",
4
+ "version": "0.0.0-canary.1323",
5
+ "canary_version": "0.0.0-canary.1322",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -46,7 +46,12 @@ const extract_and_build = async (database_name_lowercase, file_path, base_direct
46
46
  }
47
47
  } else {
48
48
  if (platform === 'win32') {
49
- await execFileAsync('powershell', ['Expand-Archive', '-Path', file_path, '-DestinationPath', bin_directory]);
49
+ const temp_directory = path.join(base_directory, 'temp');
50
+ await execFileAsync('powershell', ['Expand-Archive', '-Path', file_path, '-DestinationPath', temp_directory]);
51
+ const extracted_folder = (await fs.promises.readdir(temp_directory))[0];
52
+ const extracted_bin_path = path.join(temp_directory, extracted_folder, 'bin');
53
+ await fs.promises.rename(extracted_bin_path, bin_directory);
54
+ await fs.promises.rm(temp_directory, { recursive: true, force: true });
50
55
  } else {
51
56
  await execFileAsync('tar', ['-xzf', file_path, '-C', bin_directory, '--strip-components=1']);
52
57
  }
@@ -1,6 +1,7 @@
1
1
  import child_process from "child_process";
2
2
  import fs from "fs";
3
3
  import util from "util";
4
+ import os from "os";
4
5
  import cli_log from "../../../cli_log.js";
5
6
  import command_exists from "../../../command_exists.js";
6
7
  import get_platform_safe_path from "../../../get_platform_safe_path.js";
@@ -42,31 +43,33 @@ const check_if_postgresql_control_exists = () => {
42
43
  };
43
44
 
44
45
  const start_postgresql = async (port = 2610) => {
45
- const postgresql_exists = await check_if_postgresql_exists();
46
+ // const postgresql_exists = await check_if_postgresql_exists();
46
47
 
47
- if (!postgresql_exists) {
48
- warn_postgresql_is_missing();
49
- process.exit(1);
50
- }
48
+ // if (!postgresql_exists) {
49
+ // warn_postgresql_is_missing();
50
+ // process.exit(1);
51
+ // }
51
52
 
52
- const postgresql_control_exists = await check_if_postgresql_control_exists();
53
+ // const postgresql_control_exists = await check_if_postgresql_control_exists();
53
54
 
54
- if (!postgresql_control_exists) {
55
- cli_log(
56
- 'PostgreSQL is installed on this computer, but pg_ctl (what Joystick uses to start and manage PostgreSQL) is not in your command line\'s PATH variable. Add pg_ctl to your command line\'s PATH, restart your command line, and try again.',
57
- {
58
- level: 'danger',
59
- docs: 'https://cheatcode.co/docs/joystick/postgresql#path'
60
- }
61
- );
62
- }
55
+ // if (!postgresql_control_exists) {
56
+ // cli_log(
57
+ // 'PostgreSQL is installed on this computer, but pg_ctl (what Joystick uses to start and manage PostgreSQL) is not in your command line\'s PATH variable. Add pg_ctl to your command line\'s PATH, restart your command line, and try again.',
58
+ // {
59
+ // level: 'danger',
60
+ // docs: 'https://cheatcode.co/docs/joystick/postgresql#path'
61
+ // }
62
+ // );
63
+ // }
63
64
 
64
65
  try {
66
+ const joystick_pg_ctl_path = `${os.homedir()}/.joystick/databases/postgresql/bin/bin/pg_ctl`;
67
+ const joystick_createdb_path = `${os.homedir()}/.joystick/databases/postgresql/bin/bin/createdb`;
65
68
  const data_directory_exists = await setup_data_directory(port);
66
69
 
67
- if (!data_directory_exists && postgresql_control_exists) {
70
+ if (!data_directory_exists) {
68
71
  await exec(
69
- `pg_ctl init -D .joystick/data/postgresql_${port} --options=--no-locale`
72
+ `${joystick_pg_ctl_path} init -D .joystick/data/postgresql_${port} --options=--no-locale`
70
73
  );
71
74
  }
72
75
 
@@ -74,11 +77,11 @@ const start_postgresql = async (port = 2610) => {
74
77
  const existing_process_id = parseInt(await get_process_id_from_port(postgresql_port), 10);
75
78
 
76
79
  if (existing_process_id) {
77
- await exec(`pg_ctl kill KILL ${existing_process_id}`);
80
+ await exec(`${joystick_pg_ctl_path} kill KILL ${existing_process_id}`);
78
81
  }
79
82
 
80
83
  const database_process = child_process.spawn(
81
- `pg_ctl`,
84
+ `${joystick_pg_ctl_path}`,
82
85
  [
83
86
  '-o',
84
87
  `"-p ${postgresql_port}"`,
@@ -103,7 +106,7 @@ const start_postgresql = async (port = 2610) => {
103
106
  if (stdout.includes('database system is ready to accept connections')) {
104
107
  const process_id = (await get_process_id_from_port(postgresql_port))?.replace('\n', '');
105
108
 
106
- exec(`createdb -h 127.0.0.1 -p ${postgresql_port} app`).then((data) => {
109
+ exec(`${joystick_createdb_path} -h 127.0.0.1 -p ${postgresql_port} app`).then((data) => {
107
110
  resolve(parseInt(process_id, 10));
108
111
  }).catch(({ stderr: error }) => {
109
112
  // NOTE: PostgreSQL does not have a clean way to create database if it doesn't exist. Use this as a hack