@joystick.js/cli-canary 0.0.0-canary.1636 → 0.0.0-canary.1637

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"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)}},O=(t="",o="",_="")=>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 x from"../../path_exists.js";const{readFile:f,writeFile:E}=k.promises,g=(t="",o=[])=>{for(let n=0;n<o?.length;n+=1){const _=o[n];t=t.replace(`%example:${n}%`,_)}},$=(t="",o="",n="")=>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"chalk";import k from"fs";import r from"../../get_platform_safe_path.js";i
7
7
  joystick &&
8
8
  joystick.mount
9
9
  ) {
10
- joystick.mount(${_}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
10
+ joystick.mount(${n}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
11
11
  }
12
12
 
13
- export default ${_};
14
- `),$=(t="",o="",_="")=>t.replace(`${o};`,`if (
13
+ export default ${n};
14
+ `),O=(t="",o="",n="")=>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"chalk";import k from"fs";import r from"../../get_platform_safe_path.js";i
29
29
  })();
30
30
  }
31
31
 
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(_)),D=(t="")=>[r("ui/"),r("email/")].some(o=>t.includes(o)),G=(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&&_?$(e,i,a):e,e=a&&n?O(e,i,a):e,x(e,m),{contents:e,loader:"js"}}}).catch(o=>{console.log("ON LOAD",o)}),t.onEnd(()=>new Promise(async o=>{for(let _=0;_<t?.initialOptions?.entryPoints?.length;_+=1){const n=t?.initialOptions?.entryPoints[_],p=D(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()})).catch(o=>{console.log("ON END",o)})};var v=G;export{v as default};
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)||[],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(n=>o.path.includes(n)),G=(t="")=>[r("ui/"),r("email/")].some(o=>t.includes(o)),I=(t={})=>{t.onLoad({filter:/\.js$/},async(o={})=>{try{const n=u("ui/layouts",o),_=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&&n?O(e,i,a):e,e=a&&_?$(e,i,a):e,g(e,m),{contents:e,loader:"js"}}}catch(n){console.warn(n)}}),t.onEnd(()=>new Promise(async o=>{try{for(let n=0;n<t?.initialOptions?.entryPoints?.length;n+=1){const _=t?.initialOptions?.entryPoints[n],p=G(_),d=await x(`${t?.initialOptions?.outdir}/${_}`);if(p&&d){let e=await f(`${t?.initialOptions?.outdir}/${_}`,"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 E(`${t?.initialOptions?.outdir}/${_}`,e)}}}o()}catch(n){console.warn(n)}}))};var B=I;export{B as default};
@@ -1 +1 @@
1
- import p from"fs";import t from"../../get_platform_safe_path.js";import m from"./update_file_map.js";const{readFile:n}=p.promises,s=(a={})=>{a.onLoad({filter:/\.js$/},async o=>{if(!["node_modules",".joystick","?","commonjsHelpers.js"].some(e=>t(o.path).includes(e))){const e=await n(t(o.path),"utf-8");await m(t(o.path),e)}}).catch(o=>{console.log("GFDM ON LOAD",o)})};var r=s;export{r as default};
1
+ import p from"fs";import o from"../../get_platform_safe_path.js";import c from"./update_file_map.js";const{readFile:m}=p.promises,s=(n={})=>{n.onLoad({filter:/\.js$/},async e=>{try{if(!["node_modules",".joystick","?","commonjsHelpers.js"].some(t=>o(e.path).includes(t))){const t=await m(o(e.path),"utf-8");await c(o(e.path),t)}}catch(a){console.warn(a)}})};var i=s;export{i as default};
@@ -1,3 +1,3 @@
1
- import n from"fs";import t from"chalk";const{readFile:r}=n.promises,a=(e={})=>{e.onLoad({filter:/\.js$/},async(o={})=>{(await r(o.path,"utf-8"))?.match(/process.env.NODE_ENV\s+=\s/gi)?.length&&console.warn(t.yellowBright(`
1
+ import t from"fs";import r from"chalk";const{readFile:a}=t.promises,s=(o={})=>{o.onLoad({filter:/\.js$/},async(n={})=>{try{(await a(n.path,"utf-8"))?.match(/process.env.NODE_ENV\s+=\s/gi)?.length&&console.warn(r.yellowBright(`
2
2
  [WARNING] process.env.NODE_ENV should only be set via a CLI flag in development or via external environment variables in production.
3
- `))})};var c=a;export{c as default};
3
+ `))}catch(e){console.warn(e)}})};var l=s;export{l as default};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.1636",
5
- "canary_version": "0.0.0-canary.1635",
4
+ "version": "0.0.0-canary.1637",
5
+ "canary_version": "0.0.0-canary.1636",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -124,71 +124,75 @@ const check_if_should_set_component_id = (entry_point = '') => {
124
124
 
125
125
  const bootstrap_component = (build = {}) => {
126
126
  build.onLoad({ filter: /\.js$/ }, async (build_args = {}) => {
127
- const is_layout_component = check_if_is_component_type('ui/layouts', build_args);
128
- const is_page_component = check_if_is_component_type('ui/pages', build_args);
129
- const is_email_component = check_if_is_component_type('email/', build_args);
130
- const is_component = is_layout_component || is_page_component || is_email_component;
131
-
132
- if (is_component) {
133
- let file_contents = await readFile(get_platform_safe_path(build_args.path), "utf-8");
134
-
135
- const has_joystick_ui = check_if_has_joystick_ui(file_contents);
136
- const default_export = get_default_export(file_contents);
137
- const is_valid_component_file = check_if_valid_component_file(has_joystick_ui, default_export);
138
- const examples_before_replacement = get_examples_before_replacement(file_contents);
139
- const component_name = get_component_name(default_export);
140
-
141
- file_contents = set_placeholders_for_examples(file_contents);
142
- file_contents = replace_commented_code(file_contents);
143
- file_contents = component_name && is_layout_component ?
144
- add_layout_mounting_code(file_contents, default_export, component_name) :
145
- file_contents;
146
- file_contents = component_name && is_page_component ?
147
- add_page_mounting_code(file_contents, default_export, component_name) :
148
- file_contents;
149
-
150
- restore_examples_without_mounting_code(file_contents, examples_before_replacement);
151
-
152
- return {
153
- contents: file_contents,
154
- loader: "js",
155
- };
127
+ try {
128
+ const is_layout_component = check_if_is_component_type('ui/layouts', build_args);
129
+ const is_page_component = check_if_is_component_type('ui/pages', build_args);
130
+ const is_email_component = check_if_is_component_type('email/', build_args);
131
+ const is_component = is_layout_component || is_page_component || is_email_component;
132
+
133
+ if (is_component) {
134
+ let file_contents = await readFile(get_platform_safe_path(build_args.path), "utf-8");
135
+
136
+ const has_joystick_ui = check_if_has_joystick_ui(file_contents);
137
+ const default_export = get_default_export(file_contents);
138
+ const is_valid_component_file = check_if_valid_component_file(has_joystick_ui, default_export);
139
+ const examples_before_replacement = get_examples_before_replacement(file_contents);
140
+ const component_name = get_component_name(default_export);
141
+
142
+ file_contents = set_placeholders_for_examples(file_contents);
143
+ file_contents = replace_commented_code(file_contents);
144
+ file_contents = component_name && is_layout_component ?
145
+ add_layout_mounting_code(file_contents, default_export, component_name) :
146
+ file_contents;
147
+ file_contents = component_name && is_page_component ?
148
+ add_page_mounting_code(file_contents, default_export, component_name) :
149
+ file_contents;
150
+
151
+ restore_examples_without_mounting_code(file_contents, examples_before_replacement);
152
+
153
+ return {
154
+ contents: file_contents,
155
+ loader: "js",
156
+ };
157
+ }
158
+ } catch (exception) {
159
+ console.warn(exception);
156
160
  }
157
- }).catch((error) => {
158
- console.log('ON LOAD', error);
159
161
  });
160
162
 
161
163
  build.onEnd(() => {
162
164
  return new Promise(async (resolve) => {
163
- for (let i = 0; i < build?.initialOptions?.entryPoints?.length; i += 1) {
164
- const entry_point = build?.initialOptions?.entryPoints[i];
165
- const should_set_component_id = check_if_should_set_component_id(entry_point);
166
- const build_exists = await path_exists(`${build?.initialOptions?.outdir}/${entry_point}`);
167
-
168
- if (should_set_component_id && build_exists) {
169
- let file_contents = await readFile(`${build?.initialOptions?.outdir}/${entry_point}`, "utf-8");
170
- const has_joystick_ui = check_if_has_joystick_ui(file_contents);
171
- const examples_before_replacement = get_examples_before_replacement(file_contents);
172
-
173
- file_contents = set_placeholders_for_examples(file_contents);
174
-
175
- if (has_joystick_ui) {
176
- file_contents = await set_component_id(file_contents);
177
-
178
- for (let i = 0; i < examples_before_replacement?.length; i += 1) {
179
- const example_to_restore = examples_before_replacement[i];
180
- file_contents = file_contents.replace(`%example:${i}%`, example_to_restore);
181
- }
165
+ try {
166
+ for (let i = 0; i < build?.initialOptions?.entryPoints?.length; i += 1) {
167
+ const entry_point = build?.initialOptions?.entryPoints[i];
168
+ const should_set_component_id = check_if_should_set_component_id(entry_point);
169
+ const build_exists = await path_exists(`${build?.initialOptions?.outdir}/${entry_point}`);
170
+
171
+ if (should_set_component_id && build_exists) {
172
+ let file_contents = await readFile(`${build?.initialOptions?.outdir}/${entry_point}`, "utf-8");
173
+ const has_joystick_ui = check_if_has_joystick_ui(file_contents);
174
+ const examples_before_replacement = get_examples_before_replacement(file_contents);
182
175
 
183
- await writeFile(`${build?.initialOptions?.outdir}/${entry_point}`, file_contents);
176
+ file_contents = set_placeholders_for_examples(file_contents);
177
+
178
+ if (has_joystick_ui) {
179
+ file_contents = await set_component_id(file_contents);
180
+
181
+ for (let i = 0; i < examples_before_replacement?.length; i += 1) {
182
+ const example_to_restore = examples_before_replacement[i];
183
+ file_contents = file_contents.replace(`%example:${i}%`, example_to_restore);
184
+ }
185
+
186
+ await writeFile(`${build?.initialOptions?.outdir}/${entry_point}`, file_contents);
187
+ }
184
188
  }
185
189
  }
190
+
191
+ resolve();
192
+ } catch (exception) {
193
+ console.warn(exception);
186
194
  }
187
-
188
- resolve();
189
195
  });
190
- }).catch((error) => {
191
- console.log('ON END', error);
192
196
  });
193
197
  };
194
198
 
@@ -6,16 +6,18 @@ const { readFile } = fs.promises;
6
6
 
7
7
  const generate_file_dependency_map = (build = {}) => {
8
8
  build.onLoad({ filter: /\.js$/ }, async (args) => {
9
- const can_add_to_map = !["node_modules", ".joystick", "?", "commonjsHelpers.js"].some((excluded_path) => {
10
- return get_platform_safe_path(args.path).includes(excluded_path);
11
- });
12
-
13
- if (can_add_to_map) {
14
- const code = await readFile(get_platform_safe_path(args.path), "utf-8");
15
- await update_file_map(get_platform_safe_path(args.path), code);
9
+ try {
10
+ const can_add_to_map = !["node_modules", ".joystick", "?", "commonjsHelpers.js"].some((excluded_path) => {
11
+ return get_platform_safe_path(args.path).includes(excluded_path);
12
+ });
13
+
14
+ if (can_add_to_map) {
15
+ const code = await readFile(get_platform_safe_path(args.path), "utf-8");
16
+ await update_file_map(get_platform_safe_path(args.path), code);
17
+ }
18
+ } catch (exception) {
19
+ console.warn(exception);
16
20
  }
17
- }).catch((error) => {
18
- console.log('GFDM ON LOAD', error);
19
21
  });
20
22
  };
21
23
 
@@ -5,14 +5,18 @@ const { readFile } = fs.promises;
5
5
 
6
6
  const warn_node_environment = (build = {}) => {
7
7
  build.onLoad({ filter: /\.js$/ }, async (args = {}) => {
8
- const code = await readFile(args.path, "utf-8");
8
+ try {
9
+ const code = await readFile(args.path, "utf-8");
9
10
 
10
- if (code?.match(/process.env.NODE_ENV\s+=\s/gi)?.length) {
11
- console.warn(
12
- chalk.yellowBright(
13
- "\n[WARNING] process.env.NODE_ENV should only be set via a CLI flag in development or via external environment variables in production.\n"
14
- )
15
- );
11
+ if (code?.match(/process.env.NODE_ENV\s+=\s/gi)?.length) {
12
+ console.warn(
13
+ chalk.yellowBright(
14
+ "\n[WARNING] process.env.NODE_ENV should only be set via a CLI flag in development or via external environment variables in production.\n"
15
+ )
16
+ );
17
+ }
18
+ } catch (exception) {
19
+ console.warn(exception);
16
20
  }
17
21
  });
18
22
  };