@joystick.js/cli-canary 0.0.0-canary.611 → 0.0.0-canary.613

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 +1 @@
1
- import _ from"query-string";import{WebSocketServer as i}from"ws";import N from"../generate_id.js";import g from"./get_translations.js";process.title="joystick_hmr";var u=(()=>{const r=new i({port:parseInt(process.env.PORT,10)+1,path:"/_joystick/hmr"});process.on("message",async c=>{const e=JSON.parse(c);if(console.log("message callback",{connections:process.HMR_CONNECTIONS,connections_type:typeof process.HMR_CONNECTIONS,parsed_message:e}),typeof process.HMR_CONNECTIONS=="object"&&e?.type){const o=Object.values(process.HMR_CONNECTIONS);console.log("LENGTH",o?.length);for(let n=0;n<o?.length;n+=1){console.log("SEND TO",o[n],n);const s=o[n];if(s?.connection?.send){if(e?.type==="BUILD_ERROR")return s.connection.send(JSON.stringify({type:"BUILD_ERROR"}));if(e?.type==="FILE_CHANGE")return s.connection.send(JSON.stringify({type:"FILE_CHANGE",settings:e?.settings?{global:e?.settings?.global,public:e?.settings?.public}:null,i18n:e?.i18n_change?await g("./.joystick/build",s?.page_component_path,{headers:{"accept-language":s?.browser_language},context:{user:{language:s?.user_language}}}):null,index_html_changed:e?.index_html_change,index_css_changed:e?.index_css_change,index_client_changed:e?.index_client_change}))}}}}),r.on("connection",function(e,o={}){const n=N(16),[s,a]=o?.url?.split("?"),t=_.parse(a);console.log("ADD CONNECTION",n),process.HMR_CONNECTIONS={...process.HMR_CONNECTIONS||{},[n]:{connection:e,browser_language:t?.browser_language,user_language:t?.user_language,page_component_path:t?.page_component_path}},console.log("connection callback",process.HMR_CONNECTIONS),Object.keys(process.HMR_CONNECTIONS||{})?.length>0&&process.send({type:"HAS_HMR_CONNECTIONS"}),e.on("message",p=>{JSON.parse(p)?.type==="HMR_UPDATE_COMPLETE"&&process.send({type:"HMR_UPDATE_COMPLETE"})}),e.on("close",()=>{process.HMR_CONNECTIONS[n]&&(delete process.HMR_CONNECTIONS[n],console.log("DELETE CONNECTION",n),Object.keys(process.HMR_CONNECTIONS||{})?.length===0&&process.send({type:"HAS_NO_HMR_CONNECTIONS"}))})})})();export{u as default};
1
+ import p from"query-string";import{WebSocketServer as i}from"ws";import g from"../generate_id.js";import N from"./get_translations.js";process.title="joystick_hmr";var u=(()=>{const a=new i({port:parseInt(process.env.PORT,10)+1,path:"/_joystick/hmr"});process.on("message",async c=>{const e=JSON.parse(c);if(typeof process.HMR_CONNECTIONS=="object"&&e?.type){const t=Object.values(process.HMR_CONNECTIONS);for(let n=0;n<t?.length;n+=1){const s=t[n];s?.connection?.send&&(e?.type==="BUILD_ERROR"&&s.connection.send(JSON.stringify({type:"BUILD_ERROR"})),e?.type==="FILE_CHANGE"&&s.connection.send(JSON.stringify({type:"FILE_CHANGE",settings:e?.settings?{global:e?.settings?.global,public:e?.settings?.public}:null,i18n:e?.i18n_change?await N("./.joystick/build",s?.page_component_path,{headers:{"accept-language":s?.browser_language},context:{user:{language:s?.user_language}}}):null,index_html_changed:e?.index_html_change,index_css_changed:e?.index_css_change,index_client_changed:e?.index_client_change})))}}}),a.on("connection",function(e,t={}){const n=g(16),[s,r]=t?.url?.split("?"),o=p.parse(r);process.HMR_CONNECTIONS={...process.HMR_CONNECTIONS||{},[n]:{connection:e,browser_language:o?.browser_language,user_language:o?.user_language,page_component_path:o?.page_component_path}},Object.keys(process.HMR_CONNECTIONS||{})?.length>0&&process.send({type:"HAS_HMR_CONNECTIONS"}),e.on("message",_=>{JSON.parse(_)?.type==="HMR_UPDATE_COMPLETE"&&process.send({type:"HMR_UPDATE_COMPLETE"})}),e.on("close",()=>{process.HMR_CONNECTIONS[n]&&(delete process.HMR_CONNECTIONS[n],Object.keys(process.HMR_CONNECTIONS||{})?.length===0&&process.send({type:"HAS_NO_HMR_CONNECTIONS"}))})})})();export{u as default};
@@ -1,4 +1,4 @@
1
- import i from"chalk";import m from"child_process";import E from"fs";import w,{dirname as O}from"path";import{fileURLToPath as k}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 b from"../loader.js";import _ from"../path_exists.js";import y from"../required_files.js";import x from"./start_app_server.js";import j from"./start_databases.js";import D from"./start_hmr_server.js";import T from"./watch_for_changes/index.js";import $ from"../constants.js";import R from"./kill_process_ids.js";import I from"./run_tests.js";const{stat:H}=E.promises,C=S.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),M=k(import.meta.url),f=O(M),l=[],A=async(s=!1)=>{const e=p();await I({watch:s,__dirname:f,process_ids:[...l,...e],cleanup_process:process.cleanup_process})},P=(s=[],e=0,t="")=>{const r=["--no-warnings"];e<19&&r.push("--experimental-specifier-resolution=node");const o=m.fork(w.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()})},V=async(s=[])=>{const e=s?.find(a=>a?.path?.match($.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}))},L=(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&&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(),L(s,t,r)},q=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 q(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"}),R([process.hmr_server_process?.pid,process.app_server_process?.pid,...o]),process.exit(0)}else await u(process.env.PORT),N(s,e)},U=(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"&&A(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=x(s,e),l.push(process.app_server_process?.pid),U(e)},F=(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},B=(s=2600)=>{n(`Port ${s} is already occupied. To start Joystick on this port, clear it and try again.`,{level:"danger"}),process.exit(0)},z=(s=2600)=>parseInt(s||2600,10),X=async()=>{const s=`${process.cwd()}/.joystick/build`;await _(s)&&await C(`rm -rf ${s}`)},K=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 H(`${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:
1
+ import i from"chalk";import m from"child_process";import E from"fs";import w,{dirname as O}from"path";import{fileURLToPath as k}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 b from"../loader.js";import _ from"../path_exists.js";import y from"../required_files.js";import x from"./start_app_server.js";import j from"./start_databases.js";import D from"./start_hmr_server.js";import T from"./watch_for_changes/index.js";import $ from"../constants.js";import R from"./kill_process_ids.js";import I from"./run_tests.js";const{stat:H}=E.promises,C=S.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),M=k(import.meta.url),f=O(M),l=[],A=async(s=!1)=>{const e=p();await I({watch:s,__dirname:f,process_ids:[...l,...e],cleanup_process:process.cleanup_process})},P=(s=[],e=0,t="")=>{const r=["--no-warnings"];e<19&&r.push("--experimental-specifier-resolution=node");const o=m.fork(w.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()})},V=async(s=[])=>{const e=s?.find(a=>a?.path?.match($.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}))},L=(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(),L(s,t,r)},q=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 q(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"}),R([process.hmr_server_process?.pid,process.app_server_process?.pid,...o]),process.exit(0)}else await u(process.env.PORT),N(s,e)},U=(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"&&A(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=x(s,e),l.push(process.app_server_process?.pid),U(e),process.app_server_restarting=!1},F=(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},B=(s=2600)=>{n(`Port ${s} is already occupied. To start Joystick on this port, clear it and try again.`,{level:"danger"}),process.exit(0)},z=(s=2600)=>parseInt(s||2600,10),X=async()=>{const s=`${process.cwd()}/.joystick/build`;await _(s)&&await C(`rm -rf ${s}`)},K=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 H(`${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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.611",
4
+ "version": "0.0.0-canary.613",
5
5
  "description": "The CLI for Joystick.",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
@@ -14,29 +14,19 @@ export default (() => {
14
14
  process.on("message", async (message) => {
15
15
  const parsed_message = JSON.parse(message);
16
16
 
17
- console.log('message callback', {
18
- connections: process.HMR_CONNECTIONS,
19
- connections_type: typeof process.HMR_CONNECTIONS,
20
- parsed_message,
21
- });
22
-
23
17
  if (typeof process.HMR_CONNECTIONS === "object" && !!parsed_message?.type) {
24
18
  const connections = Object.values(process.HMR_CONNECTIONS);
25
19
 
26
- console.log('LENGTH', connections?.length);
27
-
28
20
  for (let i = 0; i < connections?.length; i += 1) {
29
- console.log('SEND TO', connections[i], i);
30
21
  const connection = connections[i];
31
22
 
32
-
33
23
  if (connection?.connection?.send) {
34
24
  if (parsed_message?.type === 'BUILD_ERROR') {
35
- return connection.connection.send(JSON.stringify({ type: 'BUILD_ERROR' }));
25
+ connection.connection.send(JSON.stringify({ type: 'BUILD_ERROR' }));
36
26
  }
37
27
 
38
28
  if (parsed_message?.type === 'FILE_CHANGE') {
39
- return connection.connection.send(
29
+ connection.connection.send(
40
30
  JSON.stringify({
41
31
  type: "FILE_CHANGE",
42
32
  settings: parsed_message?.settings ? {
@@ -69,8 +59,6 @@ export default (() => {
69
59
  const [_path, params] = connection_request?.url?.split("?");
70
60
  const connection_params = queryString.parse(params);
71
61
 
72
- console.log('ADD CONNECTION', connection_id);
73
-
74
62
  process.HMR_CONNECTIONS = {
75
63
  ...(process.HMR_CONNECTIONS || {}),
76
64
  [connection_id]: {
@@ -81,8 +69,6 @@ export default (() => {
81
69
  },
82
70
  };
83
71
 
84
- console.log('connection callback', process.HMR_CONNECTIONS);
85
-
86
72
  if (Object.keys(process.HMR_CONNECTIONS || {})?.length > 0) {
87
73
  process.send({ type: "HAS_HMR_CONNECTIONS" });
88
74
  }
@@ -99,8 +85,6 @@ export default (() => {
99
85
  if (process.HMR_CONNECTIONS[connection_id]) {
100
86
  delete process.HMR_CONNECTIONS[connection_id];
101
87
 
102
- console.log('DELETE CONNECTION', connection_id);
103
-
104
88
  if (Object.keys(process.HMR_CONNECTIONS || {})?.length === 0) {
105
89
  process.send({ type: "HAS_NO_HMR_CONNECTIONS" });
106
90
  }
@@ -117,7 +117,8 @@ const handle_hmr_server_process_messages = (node_major_version = 0, watch = fals
117
117
  }
118
118
 
119
119
  if (message?.type === "HMR_UPDATE_COMPLETE") {
120
- if (process.app_server_process) {
120
+ if (process.app_server_process && process.app_server_restarting) {
121
+ process.app_server_restarting = true;
121
122
  handle_restart_app_server(node_major_version, watch, old_settings);
122
123
  }
123
124
  }
@@ -216,6 +217,7 @@ const handle_start_app_server = (node_major_version = 0, watch = false) => {
216
217
  process.app_server_process = start_app_server(node_major_version, watch);
217
218
  process_ids.push(process.app_server_process?.pid);
218
219
  handle_app_server_process_stdio(watch);
220
+ process.app_server_restarting = false;
219
221
  };
220
222
 
221
223
  const set_process_variables = (development_server_options = {}, port = 2600) => {