@joystick.js/cli-canary 0.0.0-canary.1413 → 0.0.0-canary.1414
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 h from"fs";import x from"util";import k from"os";import
|
|
2
|
-
`,""),$=process.platform==="linux"?`sudo -u postgres ${_} -h 127.0.0.1 -p ${i} app`:`${_} -h 127.0.0.1 -p ${i} app`;s($).then(()=>{
|
|
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:j,mkdir:b}=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 j(".joystick/data/postgresql",`.joystick/data/postgresql_${t}`),e=!0),e||(await b(`.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`,r=`${a}/bin/${o}`,_=`${a}/bin/${e}`;await I(a),await L(t)||(process.platform==="linux"?await s(`sudo -u postgres ${r} init -D .joystick/data/postgresql_${t} --options=--no-locale`):await s(`${r} init -D .joystick/data/postgresql_${t} --options=--no-locale`));const i=t,n=parseInt(await y(i),10);n&&(process.platform==="linux"?await s(`sudo -u postgres ${r} kill KILL ${n}`):await s(`${r} kill KILL ${n}`));const{uid:P,gid:R}=await q(),g=process.platform!=="linux"?l.spawn(r,["-o",`"-p ${i}"`,"-D",f(`.joystick/data/postgresql_${t}`),"start"]):l.spawn(`su - postgres -c "${r} start -o "-p ${i}" -D ${f(`${process.cwd()}/.joystick/data/postgresql_${t}`)}"`);return new Promise(m=>{g.stderr.on("data",async p=>{const c=p?.toString();console.log(c),c?.includes("another server might be running")||console.warn(c)}),g.stdout.on("data",async p=>{const c=p?.toString();if(console.log(c),c.includes("database system is ready to accept connections")){const u=(await y(i))?.replace(`
|
|
2
|
+
`,""),$=process.platform==="linux"?`sudo -u postgres ${_} -h 127.0.0.1 -p ${i} app`:`${_} -h 127.0.0.1 -p ${i} 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.1414",
|
|
5
|
+
"canary_version": "0.0.0-canary.1413",
|
|
6
6
|
"description": "The CLI for Joystick.",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -2,15 +2,10 @@ import child_process from "child_process";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import util from "util";
|
|
4
4
|
import os from "os";
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
6
|
-
import { dirname } from 'path';
|
|
7
5
|
import get_platform_safe_path from "../../../get_platform_safe_path.js";
|
|
8
6
|
import get_process_id_from_port from "../../../get_process_id_from_port.js";
|
|
9
7
|
import path_exists from "../../../path_exists.js";
|
|
10
8
|
|
|
11
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
-
const __dirname = dirname(__filename);
|
|
13
|
-
|
|
14
9
|
const exec = util.promisify(child_process.exec);
|
|
15
10
|
const { rename, mkdir } = fs.promises;
|
|
16
11
|
|
|
@@ -121,13 +116,18 @@ const start_postgresql = async (port = 2610) => {
|
|
|
121
116
|
get_platform_safe_path(`.joystick/data/postgresql_${port}`),
|
|
122
117
|
'start',
|
|
123
118
|
],
|
|
124
|
-
) : child_process.spawn(
|
|
125
|
-
joystick_pg_ctl_path
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
119
|
+
) : child_process.spawn(
|
|
120
|
+
`su - postgres -c "${joystick_pg_ctl_path} start -o \"-p ${postgresql_port}\" -D ${get_platform_safe_path(`${process.cwd()}/.joystick/data/postgresql_${port}`)}"`
|
|
121
|
+
// `sudo -u postgres bin/pg_ctl`,
|
|
122
|
+
// [
|
|
123
|
+
// '-o',
|
|
124
|
+
// `"-p ${postgresql_port}"`,
|
|
125
|
+
// '-D',
|
|
126
|
+
// get_platform_safe_path(`${process.cwd()}/.joystick/data/postgresql_${port}`),
|
|
127
|
+
// 'start'
|
|
128
|
+
// ],
|
|
129
|
+
// { cwd: joystick_postgresql_bin_path, shell: '/bin/bash' }
|
|
130
|
+
);
|
|
131
131
|
|
|
132
132
|
return new Promise((resolve) => {
|
|
133
133
|
database_process.stderr.on('data', async (data) => {
|