@joystick.js/cli-canary 0.0.0-canary.642 → 0.0.0-canary.644
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.
- package/dist/lib/development_server/databases/mongodb/index.js +2 -2
- package/dist/lib/development_server/databases/postgresql/index.js +2 -2
- package/dist/lib/development_server/index.js +2 -2
- package/dist/lib/get_process_id_from_port.js +2 -2
- package/package.json +1 -1
- package/src/lib/development_server/databases/mongodb/index.js +2 -1
- package/src/lib/development_server/databases/postgresql/index.js +2 -1
- package/src/lib/development_server/index.js +2 -1
- package/src/lib/get_process_id_from_port.js +11 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import n from"child_process";import d from"fs";import m from"../../../cli_log.js";import _ from"../../../command_exists.js";import p from"../../../
|
|
1
|
+
import n from"child_process";import d from"fs";import m from"../../../cli_log.js";import _ from"../../../command_exists.js";import p from"../../../get_platform_safe_path.js";import g from"../../../get_process_id_from_port.js";import l from"../../../kill_port_process.js";import r from"../../../path_exists.js";const{rename:f,readdir:y,mkdir:u}=d.promises,w=()=>{m(` MongoDB is not installed on this computer.
|
|
2
2
|
|
|
3
3
|
Download MongoDB at https://www.mongodb.com/try/download/community
|
|
4
4
|
|
|
5
|
-
After you've installed MongoDB, run joystick start again, or, remove MongoDB from your config.databases array in your settings.development.json file to skip starting it up.`,{level:"danger",docs:"https://github.com/cheatcode/joystick#databases"})},
|
|
5
|
+
After you've installed MongoDB, run joystick start again, or, remove MongoDB from your config.databases array in your settings.development.json file to skip starting it up.`,{level:"danger",docs:"https://github.com/cheatcode/joystick#databases"})},b=async()=>{if(process.platform==="win32"){const t=(await y("C:\\Program Files\\MongoDB\\Server\\"))?.sort().reverse();return t&&t.length>0}return _("mongod")},k=(t=2610)=>new Promise(s=>{const o=["--port",t,"--dbpath",p(`./.joystick/data/mongodb_${t}`),"--quiet","--replSet",`joystick_${t}`];n.spawn("mongod",o.filter(a=>!!a)).stdout.on("data",async a=>{(a?.toString()).includes("Waiting for connections")&&n.exec(`mongo --eval "rs.initiate()" --verbose --port ${t}`,async(e,D,i)=>{if(e||i)console.warn(e||i);else{const c=await g(t);return s(parseInt(c,10))}})})}),h=async(t=2610)=>{const s=await r(".joystick/data/mongodb"),o=await r(`.joystick/data/mongodb_${t}`);return s&&!o&&await f(".joystick/data/mongodb",`.joystick/data/mongodb_${t}`),o||await u(`.joystick/data/mongodb_${t}`,{recursive:!0}),o},x=async(t=2610)=>{await b()||(w(),process.exit(1)),await h(t);try{return await l(t),await k(t)}catch(o){console.warn(o),process.exit(1)}};var F=x;export{F 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
|
|
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(
|
|
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}`);const o=t,p=await f(o);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,4 +1,4 @@
|
|
|
1
|
-
import i from"chalk";import m from"child_process";import E from"fs";import w,{dirname as
|
|
1
|
+
import i from"chalk";import m from"child_process";import E from"fs";import w from"os";import O,{dirname as k}from"path";import{fileURLToPath as b}from"url";import S from"util";import g from"./check_if_port_occupied.js";import n from"../cli_log.js";import p from"./get_database_process_ids.js";import u from"../kill_port_process.js";import h from"../load_settings.js";import x from"../loader.js";import _ from"../path_exists.js";import y from"../required_files.js";import j from"./start_app_server.js";import $ from"./start_databases.js";import D from"./start_hmr_server.js";import T from"./watch_for_changes/index.js";import R from"../constants.js";import I from"./kill_process_ids.js";import H from"./run_tests.js";const{stat:C}=E.promises,M=S.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),A=b(import.meta.url),f=k(A),l=[],P=async(s=!1)=>{const e=p();await H({watch:s,__dirname:f,process_ids:[...l,...e],cleanup_process:process.cleanup_process})},V=(s=[],e=0,t="")=>{const r=["--no-warnings"];e<19&&r.push("--experimental-specifier-resolution=node");const o=m.fork(O.resolve(`${t}/cleanup.js`),[],{detached:!0,silent:!0});process.cleanup_process=o,process.on("SIGINT",async()=>{const c=p();o.send(JSON.stringify({process_ids:[...s,...c]})),process.exit()}),process.on("SIGTERM",async()=>{const c=p();o.send(JSON.stringify({process_ids:[...s,...c]})),process.exit()})},L=async(s=[])=>{const e=s?.find(a=>a?.path?.match(R.SETTINGS_FILE_NAME_REGEX)?.length>0),t=s?.find(a=>a?.path?.includes("i18n")),r=s?.find(a=>a?.path?.includes("index.html")),o=s?.find(a=>a?.path?.includes("index.css")),c=s?.find(a=>a?.path?.includes("index.client.js"));process.hmr_server_process.send(JSON.stringify({type:"FILE_CHANGE",settings:e?await h(process.env.NODE_ENV):null,i18n_change:!!t,index_html_change:!!r,index_css_change:!!o,index_client_change:!!c}))},q=(s=0,e=!1,t={})=>{process.hmr_server_process.on("message",async r=>{["HAS_HMR_CONNECTIONS","HAS_NO_HMR_CONNECTIONS","HMR_UPDATE_COMPLETE"].includes(r?.type)||process.loader.print(r),r?.type==="HAS_HMR_CONNECTIONS"&&(process.hmr_server_process.has_connections=!0),r?.type==="HAS_NO_HMR_CONNECTIONS"&&(process.hmr_server_process.has_connections=!1),r?.type==="HMR_UPDATE_COMPLETE"&&process.app_server_process&&!process.app_server_restarting&&(process.app_server_restarting=!0,v(s,e,t))})},G=()=>{process.hmr_server_process.on("error",s=>{n(s.toString(),{level:"danger",docs:"https://github.com/cheatcode/joystick"})}),process.hmr_server_process.stdout.on("data",s=>{console.log(s.toString())}),process.hmr_server_process.stderr.on("data",s=>{n(s.toString(),{level:"danger",docs:"https://github.com/cheatcode/joystick"})})},J=(s=0,e="",t=!1,r={})=>{process.hmr_server_process=D(s,e),l.push(process.hmr_server_process?.pid),G(),q(s,t,r)},U=async(s={})=>{const e=await h(process.env.NODE_ENV),t=e?.config?.databases?JSON.stringify(e?.config?.databases):"",r=s?.config?.databases?JSON.stringify(s?.config?.databases):"";return t!==r},v=async(s=0,e=!1,t=null)=>{if(await U(t)){const o=p();n(`Database configuration has changed in settings.${process.env.NODE_ENV}.json. Please restart your app to add, change, or remove databases.`,{level:"danger",docs:"https://cheatcode.co/docs/joystick/structure"}),I([process.hmr_server_process?.pid,process.app_server_process?.pid,...o]),process.exit(0)}else await u(process.env.PORT),N(s,e)},F=(s=!1)=>{process.app_server_process.on("error",e=>{n(e.toString(),{level:"danger",docs:"https://github.com/cheatcode/joystick"})}),process.app_server_process.stdout.on("data",e=>{const t=e.toString(),r=t.includes("App running at:");t&&r&&process.env.NODE_ENV!=="test"&&process.loader.print(t),t&&!r&&!t.includes("BUILD_ERROR")&&console.log(t),t&&r&&process.env.NODE_ENV==="test"&&P(s)}),process.app_server_process.stderr.on("data",e=>{n(e.toString(),{level:"danger",docs:"https://cheatcode.co/docs/joystick"})})},N=(s=0,e=!1)=>{process.app_server_process=j(s,e),l.push(process.app_server_process?.pid),F(e),process.app_server_restarting=!1},B=(s={},e=2600)=>{process.title=s?.environment==="test"?"joystick_test":"joystick",process.loader=new x,s?.environment==="test"&&process.loader.print("Initializing test environment..."),process.env.LOGS_PATH=s?.logs||null,process.env.NODE_ENV=s?.environment||"development",process.env.PORT=e,process.env.IS_DEBUG_MODE=s?.debug},z=(s=2600)=>{n(`Port ${s} is already occupied. To start Joystick on this port, clear it and try again.`,{level:"danger"}),process.exit(0)},X=(s=2600)=>parseInt(s||2600,10),K=async()=>{const s=`${process.cwd()}/.joystick/build`;await _(s)&&await M(`${w.platform()==="win32"?"rmdir /s /q":"rm -rf"} ${s}`)},Q=async()=>{const s=[];for(let e=0;e<y?.length;e+=1){const t=y[e],r=await _(`${process.cwd()}/${t.path}`),o=r&&await C(`${process.cwd()}/${t.path}`);t&&t.type==="file"&&(!r||r&&!o.isFile())&&s.push({type:"file",path:t.path}),t&&t.type==="directory"&&(!r||r&&!o.isDirectory())&&s.push({type:"directory",path:t.path})}if(s?.length>0){const e=s?.filter(o=>o.type==="file"),t=s?.filter(o=>o.type==="directory");let r=`The following paths are missing and required in a Joystick project:
|
|
2
2
|
|
|
3
3
|
`;if(e?.length>0){r+=` ${i.yellow(">")} Required Files:
|
|
4
4
|
|
|
@@ -7,4 +7,4 @@ ${a&&t?.length>0?`
|
|
|
7
7
|
`:""}`)}`}}if(t?.length>0){r+=` ${i.yellow(">")} Required Directories:
|
|
8
8
|
|
|
9
9
|
`;for(let o=0;o<t?.length;o+=1){const c=t[o];r+=` ${i.red(`/${c.path}
|
|
10
|
-
`)}`}}n(r,{level:"danger",docs:"https://cheatcode.co/docs/joystick/structure"}),process.exit(0)}},
|
|
10
|
+
`)}`}}n(r,{level:"danger",docs:"https://cheatcode.co/docs/joystick/structure"}),process.exit(0)}},W=async()=>{const s=await _(`${process.cwd()}/.joystick`),e=await _(`${process.cwd()}/tests`);process.env.NODE_ENV==="test"&&(!s||!e)&&(n("joystick test must be run in a directory with a .joystick folder and tests folder.",{level:"danger",docs:"https://cheatcode.co/docs/joystick/cli/test"}),process.exit(0)),process.env.NODE_ENV!=="test"&&!s&&(n("joystick start must be run in a directory with a .joystick folder.",{level:"danger",docs:"https://cheatcode.co/docs/joystick/cli/start"}),process.exit(0))},Y=async(s={})=>{await W(),await Q(),await K();const e=X(s?.port),t=await g(e),r=await g(e+1);t&&z(e),r&&u(e),B(s,e);const o=await h(process.env.NODE_ENV);await $({environment:process.env.NODE_ENV,port:e,settings:o}),T({hot_module_reload:(c=[])=>L(c),restart_app_server:(c=[])=>v(d,s?.watch,o),start_app_server:()=>N(d,s?.watch),start_hmr_server:s?.environment!=="test"?()=>J(d,f,s?.watch,o):null},{custom_copy_paths:o?.config?.build?.copy_paths?.map(c=>({path:c}))||[]}),V(l,d,f)};var Es=Y;export{Es as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
`);return s&&s[0]&&s[0]?.split(" ")?.filter(
|
|
1
|
+
import n from"child_process";import p from"util";const t=p.promisify(n.exec),i=async(e=0)=>process.platform==="win32"?t(`netstat -a -n -o | find "${e}"`).then(o=>{const s=o.stdout?.split(`
|
|
2
|
+
`);return s&&s[0]&&s[0]?.split(" ")?.filter(r=>r!=="")?.map(r=>r?.replace("\r",""))?.pop()||null}).catch(()=>null):(await t(`lsof -n -i:${e} | grep LISTEN | awk '{ print $2 }' | uniq`))?.stdout||null;var a=i;export{a as default};
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import child_process from "child_process";
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import cli_log from "../../../cli_log.js";
|
|
4
4
|
import command_exists from '../../../command_exists.js';
|
|
5
|
+
import get_platform_safe_path from '../../../get_platform_safe_path.js';
|
|
5
6
|
import get_process_id_from_port from "../../../get_process_id_from_port.js";
|
|
6
7
|
import kill_port_process from "../../../kill_port_process.js";
|
|
7
8
|
import path_exists from "../../../path_exists.js";
|
|
@@ -33,7 +34,7 @@ const start_mongodb_process = (mongodb_port = 2610) => {
|
|
|
33
34
|
'--port',
|
|
34
35
|
mongodb_port,
|
|
35
36
|
'--dbpath',
|
|
36
|
-
`./.joystick/data/mongodb_${mongodb_port}
|
|
37
|
+
get_platform_safe_path(`./.joystick/data/mongodb_${mongodb_port}`),
|
|
37
38
|
'--quiet',
|
|
38
39
|
'--replSet',
|
|
39
40
|
`joystick_${mongodb_port}`,
|
|
@@ -3,6 +3,7 @@ import fs from "fs";
|
|
|
3
3
|
import util from "util";
|
|
4
4
|
import cli_log from "../../../cli_log.js";
|
|
5
5
|
import command_exists from "../../../command_exists.js";
|
|
6
|
+
import get_platform_safe_path from "../../../get_platform_safe_path.js";
|
|
6
7
|
import get_process_id_from_port from "../../../get_process_id_from_port.js";
|
|
7
8
|
import kill_port_process from "../../../kill_port_process.js";
|
|
8
9
|
import path_exists from "../../../path_exists.js";
|
|
@@ -82,7 +83,7 @@ const start_postgresql = async (port = 2610) => {
|
|
|
82
83
|
'-o',
|
|
83
84
|
`"-p ${postgresql_port}"`,
|
|
84
85
|
'-D',
|
|
85
|
-
`.joystick/data/postgresql_${port}
|
|
86
|
+
get_platform_safe_path(`.joystick/data/postgresql_${port}`),
|
|
86
87
|
'start',
|
|
87
88
|
].filter((command) => !!command),
|
|
88
89
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import child_process from 'child_process';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import os from 'os';
|
|
4
5
|
import path, { dirname } from "path";
|
|
5
6
|
import { fileURLToPath } from "url";
|
|
6
7
|
import util from 'util';
|
|
@@ -250,7 +251,7 @@ const clean_up_existing_build = async () => {
|
|
|
250
251
|
const build_path = `${process.cwd()}/.joystick/build`;
|
|
251
252
|
|
|
252
253
|
if (await path_exists(build_path)) {
|
|
253
|
-
await exec(
|
|
254
|
+
await exec(`${os.platform() === 'win32' ? 'rmdir /s /q' : 'rm -rf'} ${build_path}`);
|
|
254
255
|
}
|
|
255
256
|
};
|
|
256
257
|
|
|
@@ -5,13 +5,18 @@ const exec = util.promisify(child_process.exec);
|
|
|
5
5
|
|
|
6
6
|
const get_process_id_from_port = async (port = 0) => {
|
|
7
7
|
if (process.platform === 'win32') {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return exec(`netstat -a -n -o | find "${port}"`)
|
|
9
|
+
.then((stat) => {
|
|
10
|
+
const stat_result = stat.stdout?.split('\n');
|
|
11
|
+
const process_id_response = stat_result && stat_result[0] && stat_result[0]?.split(' ')?.filter((value) => value !== '')?.map((value) => {
|
|
12
|
+
return value?.replace('\r', '');
|
|
13
|
+
})?.pop();
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
return process_id_response || null;
|
|
16
|
+
})
|
|
17
|
+
.catch(() => {
|
|
18
|
+
return null;
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
const process_id_response = await exec(`lsof -n -i:${port} | grep LISTEN | awk '{ print $2 }' | uniq`);
|