@joystick.js/cli-canary 0.0.0-canary.633 → 0.0.0-canary.635

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 k from"chalk";import j from"fs";import r from"../../get_platform_safe_path.js";import c from"../../constants.js";import g from"./set_component_id.js";import x from"../../path_exists.js";const{readFile:f,writeFile:E}=j.promises,$=(t="",o=[])=>{for(let n=0;n<o?.length;n+=1){const _=o[n];t=t.replace(`%example:${n}%`,_)}},O=(t="",o="",n="")=>t.replace(`${o};`,`if (
1
+ import"chalk";import k from"fs";import r from"../../get_platform_safe_path.js";import c from"../../constants.js";import j from"./set_component_id.js";import E from"../../path_exists.js";const{readFile:f,writeFile:g}=k.promises,x=(t="",o=[])=>{for(let _=0;_<o?.length;_+=1){const n=o[_];t=t.replace(`%example:${_}%`,n)}},$=(t="",o="",_="")=>t.replace(`${o};`,`if (
2
2
  typeof window !== 'undefined' &&
3
3
  window.__joystick_should_auto_mount__ === true &&
4
4
  !window.__joystick_layout_url__ &&
@@ -7,11 +7,11 @@ import k from"chalk";import j from"fs";import r from"../../get_platform_safe_pat
7
7
  joystick &&
8
8
  joystick.mount
9
9
  ) {
10
- joystick.mount(${n}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
10
+ joystick.mount(${_}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
11
11
  }
12
12
 
13
- export default ${n};
14
- `),P=(t="",o="",n="")=>t.replace(`${o};`,`if (
13
+ export default ${_};
14
+ `),O=(t="",o="",_="")=>t.replace(`${o};`,`if (
15
15
  typeof window !== 'undefined' &&
16
16
  window.__joystick_should_auto_mount__ === true &&
17
17
  window.__joystick_layout_url__ &&
@@ -29,5 +29,5 @@ import k from"chalk";import j from"fs";import r from"../../get_platform_safe_pat
29
29
  })();
30
30
  }
31
31
 
32
- export default ${n};
33
- `),X=(t="")=>t.replace(c.JOYSTICK_COMMENT_REGEX,""),y=(t="")=>{let o=0;return t.replace(c.EXAMPLE_CODE_REGEX,()=>`%example:${o++}%`)},w=(t="")=>t.match(c.EXAMPLE_CODE_REGEX)||[],M=(t=null)=>(t&&t.split(" ")||[])?.pop(),C=(t="")=>{console.log(" "),console.warn(k.yellowBright(`All Joystick components in the /ui directory must have an export default statement (e.g., export default MyComponent, export default MyLayout, or export default MyPage). Please check the file at ${t}.`)),console.log(" ")},R=(t=!1,o=null)=>t&&!!o,v=(t="")=>{const o=t.match(c.EXPORT_DEFAULT_REGEX)||[];return o&&o[0]},h=(t="")=>{const o=t.match(c.JOYSTICK_UI_REGEX)||[];return!!o&&!!o[0]},u=(t="",o={})=>[r(t)].some(n=>o.path.includes(n)),G=(t="")=>[r("ui/"),r("email/")].some(o=>t.includes(o)),I=(t={})=>{t.onLoad({filter:/\.js$/},async(o={})=>{const n=u("ui/layouts",o),_=u("ui/pages",o),l=u("email/",o);if(n||_||l){let e=await f(r(o.path),"utf-8");const p=h(e),i=v(e);if(!R(p,i)){C(o.path);return}const m=w(e),a=M(i);return e=y(e),e=X(e),e=a&&n?P(e,i,a):e,e=a&&_?O(e,i,a):e,$(e,m),{contents:e,loader:"js"}}}),t.onEnd(()=>new Promise(async o=>{for(let n=0;n<t?.initialOptions?.entryPoints?.length;n+=1){const _=t?.initialOptions?.entryPoints[n],l=G(_),d=await x(`${t?.initialOptions?.outdir}/${_}`);if(l&&d){let e=await f(`${t?.initialOptions?.outdir}/${_}`,"utf-8");const p=h(e),i=w(e);if(e=y(e),p){e=await g(e);for(let s=0;s<i?.length;s+=1){const m=i[s];e=e.replace(`%example:${s}%`,m)}await E(`${t?.initialOptions?.outdir}/${_}`,e)}}}o()}))};var J=I;export{J as default};
32
+ export default ${_};
33
+ `),X=(t="")=>t.replace(c.JOYSTICK_COMMENT_REGEX,""),y=(t="")=>{let o=0;return t.replace(c.EXAMPLE_CODE_REGEX,()=>`%example:${o++}%`)},w=(t="")=>t.match(c.EXAMPLE_CODE_REGEX)||[],P=(t=null)=>(t&&t.split(" ")||[])?.pop(),R=(t=!1,o=null)=>t&&!!o,C=(t="")=>{const o=t.match(c.EXPORT_DEFAULT_REGEX)||[];return o&&o[0]},h=(t="")=>{const o=t.match(c.JOYSTICK_UI_REGEX)||[];return!!o&&!!o[0]},u=(t="",o={})=>[r(t)].some(_=>o.path.includes(_)),G=(t="")=>[r("ui/"),r("email/")].some(o=>t.includes(o)),I=(t={})=>{t.onLoad({filter:/\.js$/},async(o={})=>{const _=u("ui/layouts",o),n=u("ui/pages",o),p=u("email/",o);if(_||n||p){let e=await f(r(o.path),"utf-8");const l=h(e),i=C(e),s=R(l,i),m=w(e),a=P(i);return e=y(e),e=X(e),e=a&&_?O(e,i,a):e,e=a&&n?$(e,i,a):e,x(e,m),{contents:e,loader:"js"}}}),t.onEnd(()=>new Promise(async o=>{for(let _=0;_<t?.initialOptions?.entryPoints?.length;_+=1){const n=t?.initialOptions?.entryPoints[_],p=G(n),d=await E(`${t?.initialOptions?.outdir}/${n}`);if(p&&d){let e=await f(`${t?.initialOptions?.outdir}/${n}`,"utf-8");const l=h(e),i=w(e);if(e=y(e),l){e=await j(e);for(let s=0;s<i?.length;s+=1){const m=i[s];e=e.replace(`%example:${s}%`,m)}await g(`${t?.initialOptions?.outdir}/${n}`,e)}}}o()}))};var B=I;export{B as default};
@@ -1,4 +1,4 @@
1
- import i from"chalk";import g from"child_process";import E from"fs";import w,{dirname as O}from"path";import{fileURLToPath as k}from"url";import b from"util";import m 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 S 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=b.promisify(g.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=g.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 S,s?.environment==="test"&&process.loader.print("Initializing test environment..."),console.log(s),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 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 u from"../kill_port_process.js";import h from"../load_settings.js";import S 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=b.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 S,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
 
@@ -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)}},Q=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))},W=async(s={})=>{await Q(),await K(),await X();const e=z(s?.port),t=await m(e),r=await m(e+1);t&&B(e),r&&u(e),F(s,e);const o=await h(process.env.NODE_ENV);await j({environment:process.env.NODE_ENV,port:e,settings:o}),T({hot_module_reload:(c=[])=>V(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}))||[]}),P(l,d,f)};var vs=W;export{vs as default};
10
+ `)}`}}n(r,{level:"danger",docs:"https://cheatcode.co/docs/joystick/structure"}),process.exit(0)}},Q=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))},W=async(s={})=>{await Q(),await K(),await X();const e=z(s?.port),t=await g(e),r=await g(e+1);t&&B(e),r&&u(e),F(s,e);const o=await h(process.env.NODE_ENV);await j({environment:process.env.NODE_ENV,port:e,settings:o}),T({hot_module_reload:(c=[])=>V(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}))||[]}),P(l,d,f)};var vs=W;export{vs 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.633",
4
+ "version": "0.0.0-canary.635",
5
5
  "description": "The CLI for Joystick.",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
@@ -91,16 +91,6 @@ const get_component_name = (default_export = null) => {
91
91
  return default_export_parts?.pop();
92
92
  };
93
93
 
94
- const warn_invalid_component_file = (path = '') => {
95
- console.log(" ");
96
- console.warn(
97
- chalk.yellowBright(
98
- `All Joystick components in the /ui directory must have an export default statement (e.g., export default MyComponent, export default MyLayout, or export default MyPage). Please check the file at ${path}.`
99
- )
100
- );
101
- console.log(" ");
102
- };
103
-
104
94
  const check_if_valid_component_file = (has_joystick_ui = false, default_export = null) => {
105
95
  return has_joystick_ui && !!default_export;
106
96
  };
@@ -145,12 +135,6 @@ const bootstrap_component = (build = {}) => {
145
135
  const has_joystick_ui = check_if_has_joystick_ui(file_contents);
146
136
  const default_export = get_default_export(file_contents);
147
137
  const is_valid_component_file = check_if_valid_component_file(has_joystick_ui, default_export);
148
-
149
- if (!is_valid_component_file) {
150
- warn_invalid_component_file(build_args.path);
151
- return;
152
- }
153
-
154
138
  const examples_before_replacement = get_examples_before_replacement(file_contents);
155
139
  const component_name = get_component_name(default_export);
156
140
 
@@ -228,8 +228,6 @@ const set_process_variables = (development_server_options = {}, port = 2600) =>
228
228
  process.loader.print("Initializing test environment...");
229
229
  }
230
230
 
231
- console.log(development_server_options);
232
-
233
231
  process.env.LOGS_PATH = development_server_options?.logs || null;
234
232
  process.env.NODE_ENV = development_server_options?.environment || "development";
235
233
  process.env.PORT = port;