@joystick.js/cli-canary 0.0.0-canary.660 → 0.0.0-canary.661

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,4 +1,4 @@
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 x from"../get_platform_safe_path.js";import u from"../kill_port_process.js";import h from"../load_settings.js";import j from"../loader.js";import _ from"../path_exists.js";import y from"../required_files.js";import $ 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 H from"./kill_process_ids.js";import C from"./run_tests.js";const{stat:M}=E.promises,A=S.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),P=b(import.meta.url),f=k(P),l=[],V=async(s=!1)=>{const e=p();await C({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(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()})},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,v(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},v=async(s=0,e=!1,t=null)=>{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"}),H([process.hmr_server_process?.pid,process.app_server_process?.pid,...o]),process.exit(0)}else await u(process.env.PORT),N(s,e)},B=(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"&&V(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=$(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 j,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=x(`${process.cwd()}/.joystick/build`);await _(s)&&await A(`${w.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:
1
+ import i from"chalk";import m from"child_process";import E from"fs";import"os";import w,{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 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=b.promisify(m.exec),d=parseInt(process?.version?.split(".")[0]?.replace("v",""),10),A=k(import.meta.url),f=O(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(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()})},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=S(`${process.cwd()}/.joystick/build`);await _(s)&&await M(`${process.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)}},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:(c=[])=>v(d,s?.watch,o),start_app_server:()=>N(d,s?.watch),start_hmr_server:s?.environment!=="test"?()=>U(d,f,s?.watch,o):null},{custom_copy_paths:o?.config?.build?.copy_paths?.map(c=>({path:c}))||[]}),L(l,d,f)};var Os=Z;export{Os as default};
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 Os=Y;export{Os as default};
@@ -1 +1 @@
1
- import r from"../../constants.js";const o=(s="")=>{const e=s==="index.html",_=s==="index.client.js",i=s.includes("lib/")&&!s.includes("lib/node"),n=s.includes("i18n"),t=s.match(r.SETTINGS_FILE_NAME_REGEX)?.length>0,c=s.includes("ui/")||s==="index.css"||e||_||i;return process.hmr_server_process&&process.hmr_server_process.has_connections&&(c||n||t)||!1?["hot_module_reload"]:["restart_app_server"]};var l=o;export{l as default};
1
+ import c from"../../constants.js";import e from"../../get_platform_safe_path.js";const l=(s="")=>{const t=s==="index.html",_=s==="index.client.js",i=s.includes(e("lib/"))&&!s.includes(e("lib/node")),n=s.includes("i18n"),r=s.match(c.SETTINGS_FILE_NAME_REGEX)?.length>0,o=s.includes(e("ui/"))||s==="index.css"||t||_||i;return process.hmr_server_process&&process.hmr_server_process.has_connections&&(o||n||r)||!1?["hot_module_reload"]:["restart_app_server"]};var p=l;export{p as default};
@@ -1 +1 @@
1
- import m from"./read_file_dependency_map.js";import u from"../../path_exists.js";const c=(t="",e={})=>Object.entries(e).filter(([s,r])=>{const i=r&&r.imports&&r.imports.some(a=>a.absolute_path.includes(t)),o=r&&r.requires&&r.requires.some(a=>a.absolute_path.includes(t));return i||o}).map(([s])=>s.replace(`${process.cwd()}/`,"")),l=async(t="")=>{const e=await m(),s=c(t,e);return Promise.all(s.filter(r=>u(r)))};var p=l;export{p as default};
1
+ import m from"./read_file_dependency_map.js";import u from"../../path_exists.js";import _ from"../../get_platform_safe_path.js";const c=(t="",a={})=>Object.entries(a).filter(([s,r])=>{const i=r&&r.imports&&r.imports.some(e=>e.absolute_path.includes(t)),o=r&&r.requires&&r.requires.some(e=>e.absolute_path.includes(t));return i||o}).map(([s])=>s.replace(_(`${process.cwd()}/`),"")),l=async(t="")=>{const a=await m(),s=c(t,a);return Promise.all(s.filter(r=>u(r)))};var h=l;export{h as default};
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.660",
4
+ "version": "0.0.0-canary.661",
5
5
  "description": "The CLI for Joystick.",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
@@ -252,7 +252,7 @@ const clean_up_existing_build = async () => {
252
252
  const build_path = get_platform_safe_path(`${process.cwd()}/.joystick/build`);
253
253
 
254
254
  if (await path_exists(build_path)) {
255
- await exec(`${os.platform() === 'win32' ? 'rmdir /s /q' : 'rm -rf'} ${build_path}`);
255
+ await exec(`${process.platform === 'win32' ? 'rmdir /s /q' : 'rm -rf'} ${build_path}`);
256
256
  }
257
257
  };
258
258
 
@@ -1,12 +1,19 @@
1
1
  import constants from "../../constants.js";
2
+ import get_platform_safe_path from "../../get_platform_safe_path.js";
2
3
 
3
4
  const get_after_run_tasks = (path = '') => {
4
5
  const is_html_update = path === 'index.html';
5
6
  const is_client_index_update = path === 'index.client.js';
6
- const is_client_lib_update = path.includes('lib/') && !path.includes('lib/node');
7
+ const is_client_lib_update = path.includes(
8
+ get_platform_safe_path('lib/')
9
+ ) && !path.includes(
10
+ get_platform_safe_path('lib/node')
11
+ );
7
12
  const is_i18n_path = path.includes('i18n');
8
13
  const is_settings_path = (path.match(constants.SETTINGS_FILE_NAME_REGEX))?.length > 0;
9
- const is_ui_path = path.includes("ui/") || path === 'index.css' || is_html_update || is_client_index_update || is_client_lib_update;
14
+ const is_ui_path = path.includes(
15
+ get_platform_safe_path("ui/")
16
+ ) || path === 'index.css' || is_html_update || is_client_index_update || is_client_lib_update;
10
17
  const is_ui_update = (process.hmr_server_process && process.hmr_server_process.has_connections) &&
11
18
  (is_ui_path || is_i18n_path || is_settings_path) ||
12
19
  false;
@@ -1,5 +1,6 @@
1
1
  import read_file_dependency_map from "./read_file_dependency_map.js";
2
2
  import path_exists from '../../path_exists.js';
3
+ import get_platform_safe_path from '../../get_platform_safe_path.js';
3
4
 
4
5
  const find_codependencies_in_map = (path_to_find = '', map = {}) => {
5
6
  // TODO: I don't care about path variations anymore because I have the absolute paths
@@ -25,7 +26,10 @@ const find_codependencies_in_map = (path_to_find = '', map = {}) => {
25
26
  return has_matching_imports || has_matching_requires;
26
27
  })
27
28
  .map(([matching_codependent_path]) => {
28
- return matching_codependent_path.replace(`${process.cwd()}/`, "");
29
+ return matching_codependent_path.replace(
30
+ get_platform_safe_path(`${process.cwd()}/`),
31
+ ""
32
+ );
29
33
  });
30
34
  };
31
35