@joystick.js/cli-canary 0.0.0-canary.1302 → 0.0.0-canary.1303

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,10 +1,10 @@
1
- import i from"chalk";import m from"child_process";import N from"fs";import"os";import w,{dirname as x}from"path";import{fileURLToPath as O}from"url";import k 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 S from"../get_platform_safe_path.js";import u from"../kill_port_process.js";import h from"../load_settings.js";import b from"../loader.js";import _ from"../path_exists.js";import v from"../required_files.js";import T from"./start_app_server.js";import $ from"./start_databases.js";import j from"./start_hmr_server.js";import D from"./watch_for_changes/index.js";import R from"../constants.js";import I from"./kill_process_ids.js";import H from"./run_tests.js";import A from"../debounce.js";const{stat:C}=N.promises,M=k.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),L=O(import.meta.url),f=x(L),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,r="")=>{const t=["--no-warnings"];e<19&&t.push("--experimental-specifier-resolution=node");const o=m.fork(w.resolve(`${r}/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()})},q=async(s=[])=>{const e=s?.find(a=>a?.path?.match(R.SETTINGS_FILE_NAME_REGEX)?.length>0),r=s?.find(a=>a?.path?.includes("i18n")),t=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:!!r,index_html_change:!!t,index_css_change:!!o,index_client_change:!!c}))},G=(s=0,e=!1,r={})=>{process.hmr_server_process.on("message",async t=>{["HAS_HMR_CONNECTIONS","HAS_NO_HMR_CONNECTIONS","HMR_UPDATE_COMPLETE"].includes(t?.type)||process.loader.print(t),t?.type==="HAS_HMR_CONNECTIONS"&&(process.hmr_server_process.has_connections=!0),t?.type==="HAS_NO_HMR_CONNECTIONS"&&(process.hmr_server_process.has_connections=!1),t?.type==="HMR_UPDATE_COMPLETE"&&process.app_server_process&&!process.app_server_restarting&&(process.app_server_restarting=!0,y(s,e,r))})},J=()=>{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"})})},U=(s=0,e="",r=!1,t={})=>{process.hmr_server_process=j(s,e),l.push(process.hmr_server_process?.pid),J(),G(s,r,t)},F=async(s={})=>{const e=await h(process.env.NODE_ENV),r=e?.config?.databases?JSON.stringify(e?.config?.databases):"",t=s?.config?.databases?JSON.stringify(s?.config?.databases):"";return r!==t},y=async(s=0,e=!1,r=null)=>{A(async()=>{if(await F(r)){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"}),console.log("KILL THESE RESTART",[process.hmr_server_process?.pid,process.app_server_process?.pid,...o,...process.app_server_process.external_process_ids||[]]),I([process.hmr_server_process?.pid,process.app_server_process?.pid,...o,...process.app_server_process.external_process_ids||[]]),process.exit(0)}else await u(process.env.PORT),E(s,e)},300)},B=(s=!1)=>{process.app_server_process.external_process_ids=[],process.app_server_process.on("message",e=>{e?.external_process_id&&(console.log(e?.external_process_id),process.app_server_process.external_process_ids=[...process.app_server_process.external_process_ids||[],e?.external_process_id])}),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 r=e.toString(),t=r.includes("App running at:");r&&t&&process.env.NODE_ENV!=="test"&&process.loader.print(r),r&&!t&&!r.includes("BUILD_ERROR")&&console.log(r),r&&t&&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"})})},E=(s=0,e=!1)=>{process.app_server_process=T(s,e),l.push(process.app_server_process?.pid),B(e),process.app_server_restarting=!1},z=(s={},e=2600)=>{process.title=s?.environment==="test"?"joystick_test":"joystick",process.loader=new b,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},K=(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),Q=async()=>{const s=S(`${process.cwd()}/.joystick/build`);await _(s)&&await M(`${process.platform==="win32"?"rmdir /s /q":"rm -rf"} ${s}`)},W=async()=>{const s=[];for(let e=0;e<v?.length;e+=1){const r=v[e],t=await _(`${process.cwd()}/${r.path}`),o=t&&await C(`${process.cwd()}/${r.path}`);r&&r.type==="file"&&(!t||t&&!o.isFile())&&s.push({type:"file",path:r.path}),r&&r.type==="directory"&&(!t||t&&!o.isDirectory())&&s.push({type:"directory",path:r.path})}if(s?.length>0){const e=s?.filter(o=>o.type==="file"),r=s?.filter(o=>o.type==="directory");let t=`The following paths are missing and required in a Joystick project:
1
+ import i from"chalk";import m from"child_process";import w from"fs";import"os";import x,{dirname as O}from"path";import{fileURLToPath as k}from"url";import b 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 S from"../get_platform_safe_path.js";import u from"../kill_port_process.js";import h from"../load_settings.js";import $ from"../loader.js";import _ from"../path_exists.js";import y from"../required_files.js";import j from"./start_app_server.js";import D from"./start_databases.js";import T from"./start_hmr_server.js";import R from"./watch_for_changes/index.js";import I from"../constants.js";import v from"./kill_process_ids.js";import H from"./run_tests.js";import C from"../debounce.js";const{stat:M}=w.promises,A=b.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),P=k(import.meta.url),f=O(P),l=[],V=async(s=!1)=>{const e=p();await H({watch:s,__dirname:f,process_ids:[...l,...e],cleanup_process:process.cleanup_process})},L=(s=[],e=0,t="")=>{const r=["--no-warnings"];e<19&&r.push("--experimental-specifier-resolution=node");const o=m.fork(x.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()})},q=async(s=[])=>{const e=s?.find(a=>a?.path?.match(I.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}))},G=(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,N(s,e,t))})},J=()=>{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"})})},U=(s=0,e="",t=!1,r={})=>{process.hmr_server_process=T(s,e),l.push(process.hmr_server_process?.pid),J(),G(s,t,r)},F=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},N=async(s=0,e=!1,t=null)=>{C(async()=>{if(await F(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"}),v([process.hmr_server_process?.pid,process.app_server_process?.pid,...o]),process.exit(0)}else v([...process.app_server_process.external_process_ids||[]]),await u(process.env.PORT),E(s,e)},300)},B=(s=!1)=>{process.app_server_process.external_process_ids=[],process.app_server_process.on("message",e=>{e?.external_process_id&&(console.log(e?.external_process_id),process.app_server_process.external_process_ids=[...process.app_server_process.external_process_ids||[],e?.external_process_id])}),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"&&V(s)}),process.app_server_process.stderr.on("data",e=>{n(e.toString(),{level:"danger",docs:"https://cheatcode.co/docs/joystick"})})},E=(s=0,e=!1)=>{process.app_server_process=j(s,e),l.push(process.app_server_process?.pid),B(e),process.app_server_restarting=!1},z=(s={},e=2600)=>{process.title=s?.environment==="test"?"joystick_test":"joystick",process.loader=new $,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},X=(s=2600)=>{n(`Port ${s} is already occupied. To start Joystick on this port, clear it and try again.`,{level:"danger"}),process.exit(0)},K=(s=2600)=>parseInt(s||2600,10),Q=async()=>{const s=S(`${process.cwd()}/.joystick/build`);await _(s)&&await A(`${process.platform==="win32"?"rmdir /s /q":"rm -rf"} ${s}`)},W=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 M(`${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
- `;if(e?.length>0){t+=` ${i.yellow(">")} Required Files:
3
+ `;if(e?.length>0){r+=` ${i.yellow(">")} Required Files:
4
4
 
5
- `;for(let o=0;o<e?.length;o+=1){const c=e[o],a=o+1===e?.length;t+=` ${i.red(`/${c.path}
6
- ${a&&r?.length>0?`
7
- `:""}`)}`}}if(r?.length>0){t+=` ${i.yellow(">")} Required Directories:
5
+ `;for(let o=0;o<e?.length;o+=1){const c=e[o],a=o+1===e?.length;r+=` ${i.red(`/${c.path}
6
+ ${a&&t?.length>0?`
7
+ `:""}`)}`}}if(t?.length>0){r+=` ${i.yellow(">")} Required Directories:
8
8
 
9
- `;for(let o=0;o<r?.length;o+=1){const c=r[o];t+=` ${i.red(`/${c.path}
10
- `)}`}}n(t,{level:"danger",docs:"https://cheatcode.co/docs/joystick/structure"}),process.exit(0)}},Y=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))},Z=async(s={})=>{await Y(),await W(),await Q();const e=X(s?.port),r=await g(e),t=await g(e+1);r&&K(e),t&&u(e),z(s,e);const o=await h(process.env.NODE_ENV);await $({environment:process.env.NODE_ENV,port:e,settings:o}),D({hot_module_reload:(c=[])=>q(c),restart_app_server:()=>y(d,s?.watch,o),start_app_server:()=>E(d,s?.watch),start_hmr_server:s?.environment!=="test"?()=>U(d,f,s?.watch,o):null},{excluded_paths:o?.config?.build?.excluded_paths,custom_copy_paths:o?.config?.build?.copy_paths?.map(c=>({path:c}))||[]}),V(l,d,f)};var ks=Z;export{ks as default};
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)}},Y=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))},Z=async(s={})=>{await Y(),await W(),await Q();const e=K(s?.port),t=await g(e),r=await g(e+1);t&&X(e),r&&u(e),z(s,e);const o=await h(process.env.NODE_ENV);await D({environment:process.env.NODE_ENV,port:e,settings:o}),R({hot_module_reload:(c=[])=>q(c),restart_app_server:()=>N(d,s?.watch,o),start_app_server:()=>E(d,s?.watch),start_hmr_server:s?.environment!=="test"?()=>U(d,f,s?.watch,o):null},{excluded_paths:o?.config?.build?.excluded_paths,custom_copy_paths:o?.config?.build?.copy_paths?.map(c=>({path:c}))||[]}),L(l,d,f)};var ks=Z;export{ks 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.1302",
5
- "canary_version": "0.0.0-canary.1301",
4
+ "version": "0.0.0-canary.1303",
5
+ "canary_version": "0.0.0-canary.1302",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -174,22 +174,18 @@ const handle_restart_app_server = async (node_major_version = 0, watch = false,
174
174
  docs: "https://cheatcode.co/docs/joystick/structure",
175
175
  });
176
176
 
177
- console.log('KILL THESE RESTART', [
177
+ kill_process_ids([
178
178
  process.hmr_server_process?.pid,
179
179
  process.app_server_process?.pid,
180
180
  ...database_process_ids,
181
- ...(process.app_server_process.external_process_ids || []),
182
181
  ]);
183
182
 
183
+ process.exit(0);
184
+ } else {
184
185
  kill_process_ids([
185
- process.hmr_server_process?.pid,
186
- process.app_server_process?.pid,
187
- ...database_process_ids,
188
186
  ...(process.app_server_process.external_process_ids || []),
189
187
  ]);
190
188
 
191
- process.exit(0);
192
- } else {
193
189
  await kill_port_process(process.env.PORT);
194
190
  handle_start_app_server(node_major_version, watch);
195
191
  }