@joystick.js/cli-canary 0.0.0-canary.1637 → 0.0.0-canary.1638
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/minify_file.js +1 -1
- 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/minify_file.js +3 -1
- package/src/lib/build/plugins/bootstrap_component.js +51 -59
- package/src/lib/build/plugins/generate_file_dependency_map.js +7 -11
- package/src/lib/build/plugins/warn_node_environment.js +7 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import r from"fs";import a from"esbuild";import f from"../path_exists.js";const{readFile:s,writeFile:m}=r.promises,n=async(i="")=>{if(await f(i)){const t=await s(i,"utf-8"),o=await a.transform(t,{minify:!0}).catch(e=>{console.warn(e)});await m(i,o.code)}};var d=n;export{d 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
|
|
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(${
|
|
10
|
+
joystick.mount(${_}, window.__joystick_ssr_props__ || {}, document.getElementById('app'));
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export default ${
|
|
14
|
-
`),O=(t="",o="",
|
|
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 ${
|
|
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 ${_};
|
|
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
|
|
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
|
|
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
|
-
`))}
|
|
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.
|
|
5
|
-
"canary_version": "0.0.0-canary.
|
|
4
|
+
"version": "0.0.0-canary.1638",
|
|
5
|
+
"canary_version": "0.0.0-canary.1637",
|
|
6
6
|
"description": "The CLI for Joystick.",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
@@ -7,7 +7,9 @@ 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 })
|
|
10
|
+
const minified = await esbuild.transform(file, { minify: true }).catch((error) => {
|
|
11
|
+
console.warn(error);
|
|
12
|
+
});
|
|
11
13
|
await writeFile(path, minified.code);
|
|
12
14
|
}
|
|
13
15
|
};
|
|
@@ -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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
file_contents
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
file_contents
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
9
|
-
const code = await readFile(args.path, "utf-8");
|
|
8
|
+
const code = await readFile(args.path, "utf-8");
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
};
|