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

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 o from"fs";import f from"esbuild";import r from"../path_exists.js";const{readFile:s,writeFile:a}=o.promises,m=async(i="")=>{if(await r(i)){const t=await s(i,"utf-8"),e=await f.transform(t,{minify:!0});await a(i,e.code)}};var d=m;export{d as default};
1
+ import f from"fs";import r from"esbuild";import a from"../path_exists.js";const{readFile:s,writeFile:m}=f.promises,n=async(i="")=>{if(await a(i)){const o=await s(i,"utf-8"),t=await r.transform(o,{minify:!0}).catch(e=>{console.warn(e)});t?.code&&await m(i,t.code)}};var w=n;export{w as default};
@@ -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 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 (
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"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(${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
- `),O=(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"chalk";import k from"fs";import r from"../../get_platform_safe_path.js";i
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)||[],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};
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 +1 @@
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
+ import p from"fs";import o 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 e=>{if(!["node_modules",".joystick","?","commonjsHelpers.js"].some(t=>o(e.path).includes(t))){const t=await n(o(e.path),"utf-8");await m(o(e.path),t)}})};var c=s;export{c as default};
@@ -1,3 +1,3 @@
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(`
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(`
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
- `))}catch(e){console.warn(e)}})};var l=s;export{l as default};
3
+ `))})};var c=a;export{c 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.1637",
5
- "canary_version": "0.0.0-canary.1636",
4
+ "version": "0.0.0-canary.1639",
5
+ "canary_version": "0.0.0-canary.1638",
6
6
  "description": "The CLI for Joystick.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
@@ -7,8 +7,13 @@ const { readFile, writeFile } = fs.promises;
7
7
  const minify_file = async (path = "") => {
8
8
  if (await path_exists(path)) {
9
9
  const file = await readFile(path, "utf-8");
10
- const minified = await esbuild.transform(file, { minify: true });
11
- await writeFile(path, minified.code);
10
+ const minified = await esbuild.transform(file, { minify: true }).catch((error) => {
11
+ console.warn(error);
12
+ });
13
+
14
+ if (minified?.code) {
15
+ await writeFile(path, minified.code);
16
+ }
12
17
  }
13
18
  };
14
19
 
@@ -124,74 +124,66 @@ 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
- 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);
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
+ };
160
156
  }
161
157
  });
162
158
 
163
159
  build.onEnd(() => {
164
160
  return new Promise(async (resolve) => {
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);
175
-
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);
161
+ for (let i = 0; i < build?.initialOptions?.entryPoints?.length; i += 1) {
162
+ const entry_point = build?.initialOptions?.entryPoints[i];
163
+ const should_set_component_id = check_if_should_set_component_id(entry_point);
164
+ const build_exists = await path_exists(`${build?.initialOptions?.outdir}/${entry_point}`);
165
+
166
+ if (should_set_component_id && build_exists) {
167
+ let file_contents = await readFile(`${build?.initialOptions?.outdir}/${entry_point}`, "utf-8");
168
+ const has_joystick_ui = check_if_has_joystick_ui(file_contents);
169
+ const examples_before_replacement = get_examples_before_replacement(file_contents);
170
+
171
+ file_contents = set_placeholders_for_examples(file_contents);
172
+
173
+ if (has_joystick_ui) {
174
+ file_contents = await set_component_id(file_contents);
175
+
176
+ for (let i = 0; i < examples_before_replacement?.length; i += 1) {
177
+ const example_to_restore = examples_before_replacement[i];
178
+ file_contents = file_contents.replace(`%example:${i}%`, example_to_restore);
187
179
  }
180
+
181
+ await writeFile(`${build?.initialOptions?.outdir}/${entry_point}`, file_contents);
188
182
  }
189
183
  }
190
-
191
- resolve();
192
- } catch (exception) {
193
- console.warn(exception);
194
184
  }
185
+
186
+ resolve();
195
187
  });
196
188
  });
197
189
  };
@@ -6,17 +6,13 @@ const { readFile } = fs.promises;
6
6
 
7
7
  const generate_file_dependency_map = (build = {}) => {
8
8
  build.onLoad({ filter: /\.js$/ }, async (args) => {
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);
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);
20
16
  }
21
17
  });
22
18
  };
@@ -5,18 +5,14 @@ const { readFile } = fs.promises;
5
5
 
6
6
  const warn_node_environment = (build = {}) => {
7
7
  build.onLoad({ filter: /\.js$/ }, async (args = {}) => {
8
- try {
9
- const code = await readFile(args.path, "utf-8");
8
+ const code = await readFile(args.path, "utf-8");
10
9
 
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);
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
+ );
20
16
  }
21
17
  });
22
18
  };