@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.
- package/dist/lib/build/plugins/bootstrap_component.js +6 -6
- package/dist/lib/build/plugins/generate_file_dependency_map.js +1 -1
- package/dist/lib/build/plugins/warn_node_environment.js +2 -2
- package/package.json +2 -2
- package/src/lib/build/plugins/bootstrap_component.js +59 -55
- package/src/lib/build/plugins/generate_file_dependency_map.js +11 -9
- package/src/lib/build/plugins/warn_node_environment.js +11 -7
|
@@ -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
|
|
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(${
|
|
10
|
+
joystick.mount(${n}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export default ${
|
|
14
|
-
`)
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
5
|
-
"canary_version": "0.0.0-canary.
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
8
|
+
try {
|
|
9
|
+
const code = await readFile(args.path, "utf-8");
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
};
|