@joystick.js/cli-canary 0.0.0-canary.1421 → 0.0.0-canary.1423
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
|
|
2
|
-
`,"")
|
|
1
|
+
import l from"child_process";import h from"fs";import x from"util";import k from"os";import f from"../../../get_platform_safe_path.js";import y from"../../../get_process_id_from_port.js";import w from"../../../path_exists.js";const s=x.promisify(l.exec),{rename:b,mkdir:j}=h.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 w(".joystick/data/postgresql");let e=await w(`.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=`${k.homedir()}/.joystick/databases/postgresql/bin`,c=`${a}/bin/${o}`,_=`${a}/bin/${e}`;await I(a),await L(t)||(process.platform==="linux"?await s(`sudo -u postgres ${c} init -D .joystick/data/postgresql_${t} --options=--no-locale`):await s(`${c} init -D .joystick/data/postgresql_${t} --options=--no-locale`));const r=t,n=parseInt(await y(r),10);n&&(process.platform==="linux"?await s(`sudo -u postgres ${c} kill KILL ${n}`):await s(`${c} kill KILL ${n}`));const{uid:P,gid:R}=await q(),g=process.platform!=="linux"?l.spawn(c,["-o",`"-p ${r}"`,"-D",f(`.joystick/data/postgresql_${t}`),"start"]):l.spawn("sudo",["-u","postgres","pg_ctl","-o",`"-p ${r}"`,"-D",f(`${process.cwd()}/.joystick/data/postgresql_${t}`),"start"],{cwd:`${a}/bin`,shell:"/bin/bash"});return new Promise(m=>{g.stderr.on("data",async p=>{const i=p?.toString();console.log(i),i?.includes("another server might be running")||console.warn(i)}),g.stdout.on("data",async p=>{const i=p?.toString();if(console.log(i),i.includes("database system is ready to accept connections")){const u=(await y(r))?.replace(`
|
|
2
|
+
`,""),$=process.platform==="linux"?`sudo -u postgres ${_} -h 127.0.0.1 -p ${r} app`:`${_} -h 127.0.0.1 -p ${r} app`;s($).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.
|
|
5
|
-
"canary_version": "0.0.0-canary.
|
|
4
|
+
"version": "0.0.0-canary.1423",
|
|
5
|
+
"canary_version": "0.0.0-canary.1422",
|
|
6
6
|
"description": "The CLI for Joystick.",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -116,18 +116,20 @@ const start_postgresql = async (port = 2610) => {
|
|
|
116
116
|
get_platform_safe_path(`.joystick/data/postgresql_${port}`),
|
|
117
117
|
'start',
|
|
118
118
|
],
|
|
119
|
+
// Theory: location is correct, but the only thing that's not correct is the app's
|
|
120
|
+
// data directory is not owned by postgres. If this ends up being it, then we need
|
|
121
|
+
// to properly grant permissions to that folder based on the DB. Pain in the ass.
|
|
119
122
|
) : child_process.spawn(`sudo`,
|
|
120
|
-
[
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// ],
|
|
123
|
+
[
|
|
124
|
+
'-u',
|
|
125
|
+
'postgres',
|
|
126
|
+
'pg_ctl',
|
|
127
|
+
'-o',
|
|
128
|
+
`"-p ${postgresql_port}"`,
|
|
129
|
+
'-D',
|
|
130
|
+
get_platform_safe_path(`${process.cwd()}/.joystick/data/postgresql_${port}`),
|
|
131
|
+
'start'
|
|
132
|
+
],
|
|
131
133
|
{ cwd: `${joystick_postgresql_bin_path}/bin`, shell: '/bin/bash' }
|
|
132
134
|
);
|
|
133
135
|
|