@joystick.js/cli-canary 0.0.0-canary.644 → 0.0.0-canary.645
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 u from"../kill_port_process.js";import h from"../load_settings.js";import
|
|
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:
|
|
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)}},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};
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import util from 'util';
|
|
|
8
8
|
import check_if_port_occupied from './check_if_port_occupied.js';
|
|
9
9
|
import cli_log from '../cli_log.js';
|
|
10
10
|
import get_database_process_ids from './get_database_process_ids.js';
|
|
11
|
+
import get_platform_safe_path from '../get_platform_safe_path.js';
|
|
11
12
|
import kill_port_process from '../kill_port_process.js';
|
|
12
13
|
import load_settings from '../load_settings.js';
|
|
13
14
|
import Loader from '../loader.js';
|
|
@@ -248,7 +249,7 @@ const get_port = (port = 2600) => {
|
|
|
248
249
|
};
|
|
249
250
|
|
|
250
251
|
const clean_up_existing_build = async () => {
|
|
251
|
-
const build_path = `${process.cwd()}/.joystick/build
|
|
252
|
+
const build_path = get_platform_safe_path(`${process.cwd()}/.joystick/build`);
|
|
252
253
|
|
|
253
254
|
if (await path_exists(build_path)) {
|
|
254
255
|
await exec(`${os.platform() === 'win32' ? 'rmdir /s /q' : 'rm -rf'} ${build_path}`);
|