@joystick.js/cli-canary 0.0.0-canary.1421 → 0.0.0-canary.1422

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 l from"child_process";import $ from"fs";import h from"util";import x from"os";import k from"../../../get_platform_safe_path.js";import f from"../../../get_process_id_from_port.js";import y from"../../../path_exists.js";const s=h.promisify(l.exec),{rename:b,mkdir:j}=$.promises,q=async()=>{if(process.platform!=="linux")return{};const{stdout:t}=await s("id -u postgres"),{stdout:o}=await s("id -g postgres");return{uid:parseInt(t),gid:parseInt(o)}},I=async t=>{if(process.platform==="linux")try{await s(`sudo chown -R postgres:postgres ${t}`),await s(`sudo chmod -R 755 ${t}`)}catch(o){throw console.error("Error setting PostgreSQL permissions:",o),o}},L=async(t=2610)=>{const o=await y(".joystick/data/postgresql");let e=await y(`.joystick/data/postgresql_${t}`);if(o&&!e&&(await b(".joystick/data/postgresql",`.joystick/data/postgresql_${t}`),e=!0),e||(await j(`.joystick/data/postgresql_${t}`,{recursive:!0}),e=!0),process.platform==="linux")try{await s(`sudo chown postgres:postgres .joystick/data/postgresql_${t}`),await s(`sudo chmod 700 .joystick/data/postgresql_${t}`)}catch(a){throw console.error("Error setting permissions for data directory:",a),a}return e},D=()=>process.platform==="win32"?"createdb.exe":"createdb",S=()=>process.platform==="win32"?"pg_ctl.exe":"pg_ctl",E=async(t=2610)=>{try{const o=S(),e=D(),a=`${x.homedir()}/.joystick/databases/postgresql/bin`,i=`${a}/bin/${o}`,_=`${a}/bin/${e}`;await I(a),await L(t)||(process.platform==="linux"?await s(`sudo -u postgres ${i} init -D .joystick/data/postgresql_${t} --options=--no-locale`):await s(`${i} init -D .joystick/data/postgresql_${t} --options=--no-locale`));const c=t,n=parseInt(await f(c),10);n&&(process.platform==="linux"?await s(`sudo -u postgres ${i} kill KILL ${n}`):await s(`${i} kill KILL ${n}`));const{uid:P,gid:R}=await q(),g=process.platform!=="linux"?l.spawn(i,["-o",`"-p ${c}"`,"-D",k(`.joystick/data/postgresql_${t}`),"start"]):l.spawn("sudo",["ls -al"],{cwd:`${a}/bin`,shell:"/bin/bash"});return new Promise(m=>{g.stderr.on("data",async p=>{const r=p?.toString();console.log(r),r?.includes("another server might be running")||console.warn(r)}),g.stdout.on("data",async p=>{const r=p?.toString();if(console.log(r),r.includes("database system is ready to accept connections")){const u=(await f(c))?.replace(`
1
+ import l from"child_process";import $ from"fs";import h from"util";import x from"os";import k from"../../../get_platform_safe_path.js";import f from"../../../get_process_id_from_port.js";import y from"../../../path_exists.js";const s=h.promisify(l.exec),{rename:b,mkdir:j}=$.promises,q=async()=>{if(process.platform!=="linux")return{};const{stdout:t}=await s("id -u postgres"),{stdout:o}=await s("id -g postgres");return{uid:parseInt(t),gid:parseInt(o)}},I=async t=>{if(process.platform==="linux")try{await s(`sudo chown -R postgres:postgres ${t}`),await s(`sudo chmod -R 755 ${t}`)}catch(o){throw console.error("Error setting PostgreSQL permissions:",o),o}},L=async(t=2610)=>{const o=await y(".joystick/data/postgresql");let e=await y(`.joystick/data/postgresql_${t}`);if(o&&!e&&(await b(".joystick/data/postgresql",`.joystick/data/postgresql_${t}`),e=!0),e||(await j(`.joystick/data/postgresql_${t}`,{recursive:!0}),e=!0),process.platform==="linux")try{await s(`sudo chown postgres:postgres .joystick/data/postgresql_${t}`),await s(`sudo chmod 700 .joystick/data/postgresql_${t}`)}catch(a){throw console.error("Error setting permissions for data directory:",a),a}return e},D=()=>process.platform==="win32"?"createdb.exe":"createdb",S=()=>process.platform==="win32"?"pg_ctl.exe":"pg_ctl",E=async(t=2610)=>{try{const o=S(),e=D(),a=`${x.homedir()}/.joystick/databases/postgresql/bin`,i=`${a}/bin/${o}`,_=`${a}/bin/${e}`;await I(a),await L(t)||(process.platform==="linux"?await s(`sudo -u postgres ${i} init -D .joystick/data/postgresql_${t} --options=--no-locale`):await s(`${i} init -D .joystick/data/postgresql_${t} --options=--no-locale`));const c=t,n=parseInt(await f(c),10);n&&(process.platform==="linux"?await s(`sudo -u postgres ${i} kill KILL ${n}`):await s(`${i} kill KILL ${n}`));const{uid:P,gid:R}=await q(),g=process.platform!=="linux"?l.spawn(i,["-o",`"-p ${c}"`,"-D",k(`.joystick/data/postgresql_${t}`),"start"]):l.spawn("sudo",["-u","postgres","ls -al"],{cwd:`${a}/bin`,shell:"/bin/bash"});return new Promise(m=>{g.stderr.on("data",async p=>{const r=p?.toString();console.log(r),r?.includes("another server might be running")||console.warn(r)}),g.stdout.on("data",async p=>{const r=p?.toString();if(console.log(r),r.includes("database system is ready to accept connections")){const u=(await f(c))?.replace(`
2
2
  `,""),w=process.platform==="linux"?`sudo -u postgres ${_} -h 127.0.0.1 -p ${c} app`:`${_} -h 127.0.0.1 -p ${c} app`;s(w).then(()=>{m(parseInt(u,10))}).catch(({stderr:d})=>{d&&d.includes('database "app" already exists')?m(parseInt(u,10)):console.log(d)})}})})}catch(o){console.warn(o),process.exit(1)}};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.1421",
5
- "canary_version": "0.0.0-canary.1420",
4
+ "version": "0.0.0-canary.1422",
5
+ "canary_version": "0.0.0-canary.1421",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -117,17 +117,17 @@ const start_postgresql = async (port = 2610) => {
117
117
  'start',
118
118
  ],
119
119
  ) : child_process.spawn(`sudo`,
120
- ['ls -al'],
121
- // [
122
- // '-u',
123
- // 'postgres',
124
- // 'pg_ctl',
125
- // '-o',
126
- // `"-p ${postgresql_port}"`,
127
- // '-D',
128
- // get_platform_safe_path(`${process.cwd()}/.joystick/data/postgresql_${port}`),
129
- // 'start'
130
- // ],
120
+ [
121
+ '-u',
122
+ 'postgres',
123
+ 'ls -al',
124
+ // 'pg_ctl',
125
+ // '-o',
126
+ // `"-p ${postgresql_port}"`,
127
+ // '-D',
128
+ // get_platform_safe_path(`${process.cwd()}/.joystick/data/postgresql_${port}`),
129
+ // 'start'
130
+ ],
131
131
  { cwd: `${joystick_postgresql_bin_path}/bin`, shell: '/bin/bash' }
132
132
  );
133
133