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

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,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.1322",
5
+ "canary_version": "0.0.0-canary.1321",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -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