@joystick.js/node-canary 0.0.0-canary.450 → 0.0.0-canary.452
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.
- package/dist/app/api/test/bootstrap.js +1 -1
- package/dist/app/ssr/index.js +6 -5
- package/dist/app/start_node_as_cluster.js +1 -1
- package/dist/lib/dynamic_import.js +1 -1
- package/dist/lib/get_platform_safe_path.js +1 -0
- package/dist/lib/get_translations.js +1 -1
- package/dist/lib/path_exists.js +1 -1
- package/package.json +1 -1
- package/src/app/api/test/bootstrap.js +4 -1
- package/src/app/ssr/index.js +2 -0
- package/src/app/start_node_as_cluster.js +0 -5
- package/src/lib/dynamic_import.js +2 -0
- package/src/lib/get_platform_safe_path.js +8 -0
- package/src/lib/get_translations.js +7 -2
- package/src/lib/path_exists.js +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import p from"../../../lib/dynamic_import.js";import c from"../get_api_for_data_functions.js";import m from"../../../lib/get_browser_safe_request.js";import d from"../../../lib/
|
|
1
|
+
import p from"../../../lib/dynamic_import.js";import c from"../get_api_for_data_functions.js";import m from"../../../lib/get_browser_safe_request.js";import d from"../../../lib/get_platform_safe_path.js";import f from"../../../lib/get_translations.js";import u from"../../settings/load.js";const l=async(t={},a={},_={})=>{const n=`${process.cwd()}/.joystick/build/`,s=t?.query?.path_to_component?await p(d(`${n}/${t?.query?.path_to_component}?v=${new Date().getTime()}`)):null;if(s){const o=s(),r=c(t,_?.options?.api),e=m(t),i=await o.fetch_data(r,e,{},o);return a.status(200).send({data:{[o?.id]:i},req:e,settings:u(),translations:await f({joystick_build_path:n,render_component_path:t?.query?.path_to_component,req:t})})}a.status(200).send({data:{},translations:{}})};var j=l;export{j as default};
|
package/dist/app/ssr/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import u from"fs";import{parseHTML as p}from"linkedom";import y from"../api/get_api_for_data_functions.js";import
|
|
1
|
+
import u from"fs";import{parseHTML as p}from"linkedom";import y from"os";import $ from"../api/get_api_for_data_functions.js";import f from"../../lib/get_browser_safe_request.js";import h from"../settings/load.js";import w from"./set_base_attributes_in_html.js";import b from"./set_head_tags_in_html.js";import i from"../../lib/path_exists.js";import g from"../accounts/get_browser_safe_user.js";const{readFile:a}=u.promises,_=h(),s=process.env.NODE_ENV==="development",{document:j}=p("<div></div>"),k=(e={})=>e?.base_html.replace("${css}",`<style type="text/css" js-css>${e?.css}</style>`).replace('<div id="app"></div>',`
|
|
2
2
|
<div id="app">${e?.html}</div>
|
|
3
3
|
<script>
|
|
4
4
|
window.joystick = {
|
|
@@ -8,25 +8,26 @@ import u from"fs";import{parseHTML as p}from"linkedom";import y from"../api/get_
|
|
|
8
8
|
},
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
window.__joystick_platform__ = '${y.platform()}';
|
|
11
12
|
window.__joystick_data__ = '${Buffer.from(JSON.stringify(e?.data)).toString("base64")}';
|
|
12
13
|
window.__joystick_i18n__ = ${JSON.stringify(e?.translations)};
|
|
13
14
|
${s?`window.__joystick_hmr_port__ = ${parseInt(process.env.PORT,10)+1}`:""}
|
|
14
15
|
window.__joystick_layout_url__ = ${e?.render_layout_path?`"/_joystick/${e?.render_layout_path}"`:null};
|
|
15
16
|
window.__joystick_page_url__ = ${e?.render_component_path?`"/_joystick/${e?.render_component_path}"`:null};
|
|
16
|
-
window.__joystick_request__ = ${JSON.stringify(
|
|
17
|
+
window.__joystick_request__ = ${JSON.stringify(f(e?.req))};
|
|
17
18
|
window.__joystick_settings__ = ${JSON.stringify({global:_?.global,public:_?.public})};
|
|
18
19
|
|
|
19
20
|
window.__joystick_should_auto_mount__ = true;
|
|
20
21
|
window.__joystick_ssr_props__ = ${JSON.stringify(e?.props)};
|
|
21
22
|
window.__joystick_url__ = ${JSON.stringify(e?.url)};
|
|
22
|
-
window.__joystick_user__ = ${JSON.stringify(
|
|
23
|
+
window.__joystick_user__ = ${JSON.stringify(g(e?.req?.context?.user))};
|
|
23
24
|
</script>
|
|
24
25
|
<script type="module" src="/_joystick/utils/process.js"></script>
|
|
25
26
|
<script type="module" src="/_joystick/index.client.js"></script>
|
|
26
27
|
${e?.render_component_path?`<script type="module" src="/_joystick/${e?.render_component_path}"></script>`:""}
|
|
27
28
|
${e?.render_layout_path?`<script type="module" src="/_joystick/${e?.render_layout_path}"></script>`:""}
|
|
28
29
|
${s?'<script type="module" src="/_joystick/hmr/client.js"></script>':""}
|
|
29
|
-
`),
|
|
30
|
+
`),v=(e={})=>e?.base_html.replace("${css}",`<style type="text/css">${e?.css}</style>`).replace("${subject}",e?.email_options?.subject).replace("${preheader}",e?.email_options?.preheader||"").replace('<div id="email"></div>',`<div id="email">${e?.html}</div>`),N=(e={})=>e?.is_email?v(e):k(e),O=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.html`)?a(`email/${e?`base_${e}`:"base"}.html`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.html`),""),S=async(e="")=>await i(`email/${e?`base_${e}`:"base"}.css`)?a(`email/${e?`base_${e}`:"base"}.css`,"utf-8"):(console.warn(`Could not find email/${e?`base_${e}`:"base"}.css`),""),q=(e=null,t={})=>e(t),J=async(e={})=>{const t=q(e?.component_to_render,e?.component_options),c=$(e?.req,e?.api_schema),l=[],r=await t.render_for_ssr(c,e?.req,l,{linkedom_document:j,is_email:e?.is_email}),n=e?.is_email?await S(e?.email_options?.base_html_name):null,o=e?.is_email?await O(e?.email_options?.base_html_name):null,m=N({is_email:e?.is_email,attributes:e?.attributes,base_html:e?.is_email?o:e?.base_html,component_instance:t,css:e?.is_email?`
|
|
30
31
|
${n}
|
|
31
32
|
${r?.css}
|
|
32
|
-
`:r?.css,data:r?.data,email_options:e?.email_options,head:e?.head,html:r?.html,props:e?.component_options?.props,render_component_path:e?.render_component_path,render_layout_path:e?.render_layout_path,req:e?.req,translations:e?.component_options?.translations,url:e?.component_options?.url}),d=
|
|
33
|
+
`:r?.css,data:r?.data,email_options:e?.email_options,head:e?.head,html:r?.html,props:e?.component_options?.props,render_component_path:e?.render_component_path,render_layout_path:e?.render_layout_path,req:e?.req,translations:e?.component_options?.translations,url:e?.component_options?.url}),d=b(m,e?.head,e?.req);return w(d,e?.attributes)};var P=J;export{P as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import o from"cluster";import c from"os";const i=(n=null)=>{const t=c.cpus().length;if(o.isPrimary){for(let s=0;s<t;s++){const r=o.fork();r.on("message",e=>{process.send&&process.send(e)}),process.on("message",e=>{r.send(e)})}o.on("exit",s=>{console.warn(`Worker ${s.process.pid} died.`)})}else n()};var d=i;export{d as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const a=async(t="")=>(await import(t))?.default;var
|
|
1
|
+
import"./get_platform_safe_path.js";const a=async(t="")=>(await import(t))?.default;var f=a;export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"os";const e=(r="")=>t.platform()==="win32"?r.replace(/\//g,"\\"):r;var a=e;export{a as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p from"fs";import _ from"./dynamic_import.js";import f from"./get_platform_safe_path.js";import h from"../app/settings/load.js";import d from"./path_exists.js";import m from"./types.js";const c=h(),$=async(t="",n="",a="")=>{const r=await _(f(`${n}/i18n/${t}?v=${new Date().getTime()}`));if(r&&m.is_object(r)){const e=r[a];return e||r}return{}},w=(t="",n=[],a="")=>{let r=[];t&&r.push(t);const i=n?.filter(e=>!e?.includes("*"));return r.push(...i),(c?.config?.i18n?.defaultLanguage||c?.config?.i18n?.default_language)&&r.push(c?.config?.i18n?.defaultLanguage||c?.config?.i18n?.default_language),r?.flatMap(e=>{const s=[e];return e?.length===2&&s.push(`${e.substring(0,2)}-`),e?.length>2&&(s.push(`${e?.split("-")[0]}`),s.push(`${e?.split("-")[0]}-`)),s})?.map(e=>e[e.length-1]==="-"?new RegExp(a?`^${a}_${e}[A-Z]+.js`:`^${e}[A-Z]+.js`,"g"):new RegExp(a?`^${a}_${e}.js`:`^${e}.js`,"g"))},b=(t="")=>t.split(",")?.map(a=>a.split(";")[0]),j=async(t={})=>{const n=t?.is_email?f(`${t?.joystick_build_path}i18n/email`):f(`${t?.joystick_build_path}i18n`),a=await d(n)&&p.readdirSync(n)||[],r=t?.is_email?[]:b(t?.req?.headers["accept-language"]),i=w(t?.req?.context?.user?.language,r,t?.email_template_name);let e=null;for(let l=0;l<i.length;l+=1){const o=i[l],u=a.find(g=>!!g.match(o));if(u){e=u;break}}return(e?await $(e,t?.joystick_build_path,t?.render_component_path):null)||{}};var E=j;export{E as default};
|
package/dist/lib/path_exists.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import t from"fs";import r from"./get_platform_safe_path.js";const a=(s="")=>new Promise(e=>{t.access(r(s),t.constants.F_OK,o=>{e(!o)})});var p=a;export{p as default};
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import dynamic_import from "../../../lib/dynamic_import.js";
|
|
2
2
|
import get_api_for_data_functions from "../get_api_for_data_functions.js";
|
|
3
3
|
import get_browser_safe_request from "../../../lib/get_browser_safe_request.js";
|
|
4
|
+
import get_platform_safe_path from "../../../lib/get_platform_safe_path.js";
|
|
4
5
|
import get_translations from "../../../lib/get_translations.js";
|
|
5
6
|
import load_settings from "../../settings/load.js";
|
|
6
7
|
|
|
7
8
|
const test_bootstrap = async (req = {}, res = {}, app_instance = {}) => {
|
|
8
9
|
const joystick_build_path = `${process.cwd()}/.joystick/build/`;
|
|
9
10
|
const component_to_render = req?.query?.path_to_component ?
|
|
10
|
-
await dynamic_import(
|
|
11
|
+
await dynamic_import(
|
|
12
|
+
get_platform_safe_path(`${joystick_build_path}/${req?.query?.path_to_component}?v=${new Date().getTime()}`)
|
|
13
|
+
) :
|
|
11
14
|
null;
|
|
12
15
|
|
|
13
16
|
if (component_to_render) {
|
package/src/app/ssr/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { parseHTML } from 'linkedom';
|
|
3
|
+
import os from 'os';
|
|
3
4
|
import get_api_for_data_functions from "../api/get_api_for_data_functions.js";
|
|
4
5
|
import get_browser_safe_request from "../../lib/get_browser_safe_request.js";
|
|
5
6
|
import load_settings from '../settings/load.js';
|
|
@@ -29,6 +30,7 @@ const build_html_response_for_browser = (options = {}) => {
|
|
|
29
30
|
},
|
|
30
31
|
};
|
|
31
32
|
|
|
33
|
+
window.__joystick_platform__ = '${os.platform()}';
|
|
32
34
|
window.__joystick_data__ = '${Buffer.from(JSON.stringify(options?.data)).toString('base64')}';
|
|
33
35
|
window.__joystick_i18n__ = ${JSON.stringify(options?.translations)};
|
|
34
36
|
${is_development ? `window.__joystick_hmr_port__ = ${parseInt(process.env.PORT, 10) + 1}` : ''}
|
|
@@ -8,11 +8,6 @@ const start_node_as_cluster = (callback = null) => {
|
|
|
8
8
|
for (let i = 0; i < cpus; i++) {
|
|
9
9
|
const worker = cluster.fork();
|
|
10
10
|
|
|
11
|
-
// NOTE: Intentionally track the worker index on its process so we can
|
|
12
|
-
// check for a primary in our code (e.g., when running cluster of an app that
|
|
13
|
-
// has code we only want to run on 1/X workers, not all workers).
|
|
14
|
-
worker.joystick_process = i + 1;
|
|
15
|
-
|
|
16
11
|
worker.on("message", (message) => {
|
|
17
12
|
if (process.send) {
|
|
18
13
|
process.send(message);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import dynamic_import from './dynamic_import.js';
|
|
3
|
+
import get_platform_safe_path from './get_platform_safe_path.js';
|
|
3
4
|
import load_settings from "../app/settings/load.js";
|
|
4
5
|
import path_exists from './path_exists.js';
|
|
5
6
|
import types from './types.js';
|
|
@@ -7,7 +8,9 @@ import types from './types.js';
|
|
|
7
8
|
const settings = load_settings();
|
|
8
9
|
|
|
9
10
|
const get_translations_file = async (language_file_path = '', joystick_build_path = '', render_component_path = '') => {
|
|
10
|
-
const language_file = await dynamic_import(
|
|
11
|
+
const language_file = await dynamic_import(
|
|
12
|
+
get_platform_safe_path(`${joystick_build_path}/i18n/${language_file_path}?v=${new Date().getTime()}`)
|
|
13
|
+
);
|
|
11
14
|
const is_valid_language_file = language_file && types.is_object(language_file);
|
|
12
15
|
|
|
13
16
|
if (is_valid_language_file) {
|
|
@@ -68,7 +71,9 @@ const parse_browser_languages = (languages = '') => {
|
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
const get_translations = async (get_translations_options = {}) => {
|
|
71
|
-
const language_files_path = get_translations_options?.is_email ?
|
|
74
|
+
const language_files_path = get_translations_options?.is_email ?
|
|
75
|
+
get_platform_safe_path(`${get_translations_options?.joystick_build_path}i18n/email`) :
|
|
76
|
+
get_platform_safe_path(`${get_translations_options?.joystick_build_path}i18n`);
|
|
72
77
|
const language_files = (await path_exists(language_files_path) && fs.readdirSync(language_files_path)) || [];
|
|
73
78
|
const browser_languages = get_translations_options?.is_email ? [] : parse_browser_languages(get_translations_options?.req?.headers['accept-language']);
|
|
74
79
|
const language_preferences = get_language_preference_regexes(
|
package/src/lib/path_exists.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import get_platform_safe_path from './get_platform_safe_path.js';
|
|
2
3
|
|
|
3
4
|
const path_exists = (path = '') => {
|
|
4
5
|
return new Promise((resolve) => {
|
|
5
|
-
fs.access(path, fs.constants.F_OK, error => {
|
|
6
|
+
fs.access(get_platform_safe_path(path), fs.constants.F_OK, error => {
|
|
6
7
|
resolve(!error);
|
|
7
8
|
});
|
|
8
9
|
});
|