@joystick.js/cli-canary 0.0.0-canary.581 → 0.0.0-canary.583
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 f from"chokidar";import h from"fs";import{dirname as m}from"path";import
|
|
1
|
+
import f from"chokidar";import h from"fs";import{dirname as m}from"path";import y from"../../build/build_files.js";import g from"../../debounce.js";import s from"./get_after_run_tasks.js";import k from"./get_file_codependencies.js";import l from"../../build/get_file_operation.js";import v from"../../build/get_path_platform.js";import w from"../../types.js";import b from"./watch_paths.js";const{mkdir:p,copyFile:R,rm:u}=h.promises,c=async(e={},i={})=>{const a=process.initial_build_complete?await k(e?.path):[];if(i?.is_build_file&&await y({files:[{path:e?.path,platform:v(e?.path)}]}).catch((t=[])=>{if(!process.initial_build_complete&&t?.length>0&&process.exit(0),process.initial_build_complete&&t?.length>0)throw process.app_server_process.send(JSON.stringify({type:"BUILD_ERROR",paths:t.filter(({success:r})=>!r)})),new Error("BUILD_ERROR")}),a?.length>0)for(let t=0;t<a?.length;t+=1){const r=a[t];return c({path:r})}return Promise.resolve()},$=async(e={})=>{switch(e?.operation){case"add_directory":return p(`.joystick/build/${e?.path}`,{recursive:!0});case"build_file":return c(e,{is_build_file:!0});case"copy_file":return await p(m(`.joystick/build/${e?.path}`),{recursive:!0}),await R(e?.path,`.joystick/build/${e?.path}`),c(e,{is_build_file:!1});case"delete_directory":return u(`.joystick/build/${e?.path}`,{recursive:!0});case"delete_file":return await u(`.joystick/build/${e?.path}`,{recursive:!0}),c(e,{is_build_file:!1});default:return!0}},D=(e={})=>({operation:e?.event,path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),E=(e={})=>({operation:e?.event,path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),O=(e={})=>({operation:e?.event,path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),x=(e={})=>({operation:l(e?.path),path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),B=(e={})=>({operation:l(e?.path),path:e?.path,after_run_tasks:process.initial_build_complete?s(e?.path):["start_app_server","start_hmr_server"]}),I=(e={})=>{switch(e?.event){case"add_file":return B(e);case"change_file":return x(e);case"delete_file":return O(e);case"add_directory":return E(e);case"delete_directory":return D(e)}},L=async(e=[],i={})=>{try{const a=new Set([]);for(let r=0;r<e?.length;r+=1){const _=e[r],n=I(_);if(await $(n),n?.after_run_tasks)for(let o=0;o<n?.after_run_tasks?.length;o+=1){const d=n?.after_run_tasks[o];a.add(d)}}const t=Array.from(a);for(let r=0;r<t?.length;r+=1){const _=t[r];w.is_function(i[_])&&await i[_](e)}}catch{}},S=(e="")=>{switch(e){case"add":return"add_file";case"change":return"change_file";case"unlink":return"delete_file";case"addDir":return"add_directory";case"unlinkDir":return"delete_directory"}},U=(e={})=>{const i=f.watch(b.map(({path:t})=>t),{ignored:".joystick"});let a=[];process.initial_build_complete=!1,i.on("error",t=>console.error(t)),i.on("all",(t,r)=>{a.push({event:S(t),path:r}),g(async()=>{await L(a,e),process.initial_build_complete=!0,a=[]},100)})};var M=U;export{M as default};
|
package/package.json
CHANGED
|
@@ -22,10 +22,19 @@ const handle_build_files = async (job = {}, options = {}) => {
|
|
|
22
22
|
await build_files({
|
|
23
23
|
files: [{ path: job?.path, platform: get_path_platform(job?.path) }],
|
|
24
24
|
}).catch((errors = []) => {
|
|
25
|
-
if (!process.initial_build_complete) {
|
|
25
|
+
if (!process.initial_build_complete && errors?.length > 0) {
|
|
26
26
|
process.exit(0);
|
|
27
|
-
}
|
|
28
|
-
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (process.initial_build_complete && errors?.length > 0) {
|
|
30
|
+
process.app_server_process.send(
|
|
31
|
+
JSON.stringify({
|
|
32
|
+
type: "BUILD_ERROR",
|
|
33
|
+
paths: errors.filter(({ success }) => !success),
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
throw new Error('BUILD_ERROR');
|
|
29
38
|
}
|
|
30
39
|
});
|
|
31
40
|
}
|
|
@@ -119,30 +128,36 @@ const get_job_to_be_done = (job = {}) => {
|
|
|
119
128
|
};
|
|
120
129
|
|
|
121
130
|
const process_file_watcher_jobs = async (jobs = [], after_run_functions = {}) => {
|
|
122
|
-
|
|
131
|
+
try {
|
|
132
|
+
const after_run_tasks = new Set([]);
|
|
123
133
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
134
|
+
for (let i = 0; i < jobs?.length; i += 1) {
|
|
135
|
+
const job_to_run = jobs[i];
|
|
136
|
+
const job = get_job_to_be_done(job_to_run);
|
|
127
137
|
|
|
128
|
-
|
|
138
|
+
await run_job(job);
|
|
129
139
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
if (job?.after_run_tasks) {
|
|
141
|
+
for (let i = 0; i < job?.after_run_tasks?.length; i += 1) {
|
|
142
|
+
const after_run_task = job?.after_run_tasks[i];
|
|
143
|
+
after_run_tasks.add(after_run_task);
|
|
144
|
+
}
|
|
134
145
|
}
|
|
135
146
|
}
|
|
136
|
-
}
|
|
137
147
|
|
|
138
|
-
|
|
148
|
+
const tasks_to_run = Array.from(after_run_tasks);
|
|
139
149
|
|
|
140
|
-
|
|
141
|
-
|
|
150
|
+
for (let i = 0; i < tasks_to_run?.length; i += 1) {
|
|
151
|
+
const after_run_task = tasks_to_run[i];
|
|
142
152
|
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
if (types.is_function(after_run_functions[after_run_task])) {
|
|
154
|
+
await after_run_functions[after_run_task](jobs);
|
|
155
|
+
}
|
|
145
156
|
}
|
|
157
|
+
} catch(error) {
|
|
158
|
+
// NOTE: Dead catch as we just want to avoid after_run_tasks from running. Actual
|
|
159
|
+
// errors are handled as part of run_job() (e.g., build errors are handled as a part
|
|
160
|
+
// of handle_build_files()).
|
|
146
161
|
}
|
|
147
162
|
};
|
|
148
163
|
|