@blinkk/root 1.0.0-alpha.1 → 1.0.0-alpha.11
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/bin/root.js +34 -16
- package/dist/{chunk-4SVK7R4Z.js → chunk-ZV52A6YZ.js} +42 -22
- package/dist/chunk-ZV52A6YZ.js.map +1 -0
- package/dist/cli.d.ts +10 -4
- package/dist/cli.js +540 -199
- package/dist/cli.js.map +1 -1
- package/dist/config-ea7b8b9c.d.ts +81 -0
- package/dist/core.d.ts +7 -6
- package/dist/core.js +3 -3
- package/dist/core.js.map +1 -1
- package/dist/render.d.ts +9 -16
- package/dist/render.js +238 -86
- package/dist/render.js.map +1 -1
- package/package.json +19 -22
- package/dist/chunk-4SVK7R4Z.js.map +0 -1
- package/dist/config-5b8f6033.d.ts +0 -15
package/bin/root.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import {createRequire} from 'node:module';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {fileURLToPath} from 'node:url';
|
|
3
6
|
import {Command} from 'commander';
|
|
4
|
-
import {build, dev, start} from '../dist/cli.js';
|
|
7
|
+
import {build, dev, preview, start} from '../dist/cli.js';
|
|
8
|
+
import {bgGreen, black} from 'kleur/colors';
|
|
5
9
|
|
|
6
|
-
const
|
|
7
|
-
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const packageJson = require(path.join(__dirname, '../package.json'));
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
.
|
|
11
|
-
.description('generates a static build')
|
|
12
|
-
.action(build);
|
|
13
|
-
program
|
|
14
|
-
.command('dev [path]')
|
|
15
|
-
.description('starts the server in development mode')
|
|
16
|
-
.action(dev);
|
|
17
|
-
program
|
|
18
|
-
.command('start [path]')
|
|
19
|
-
.description('starts the server in production mode')
|
|
20
|
-
.action(start);
|
|
14
|
+
async function main() {
|
|
15
|
+
console.log(`🌱 ${bgGreen(black(' root.js '))} v${packageJson.version}`);
|
|
21
16
|
|
|
22
|
-
program
|
|
17
|
+
const program = new Command('root');
|
|
18
|
+
program.version(packageJson.version);
|
|
19
|
+
program
|
|
20
|
+
.command('build [path]')
|
|
21
|
+
.description('generates a static build')
|
|
22
|
+
.option('--ssr-only', 'produce a ssr-only build')
|
|
23
|
+
.option('--mode <mode>', 'see: https://vitejs.dev/guide/env-and-mode.html#modes', 'production')
|
|
24
|
+
.action(build);
|
|
25
|
+
program
|
|
26
|
+
.command('dev [path]')
|
|
27
|
+
.description('starts the server in development mode')
|
|
28
|
+
.action(dev);
|
|
29
|
+
program
|
|
30
|
+
.command('preview [path]')
|
|
31
|
+
.description('starts the server in preview mode')
|
|
32
|
+
.action(preview);
|
|
33
|
+
program
|
|
34
|
+
.command('start [path]')
|
|
35
|
+
.description('starts the server in production mode')
|
|
36
|
+
.action(start);
|
|
37
|
+
await program.parseAsync(process.argv);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
main();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/components/error-page.tsx
|
|
2
|
-
import {
|
|
2
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
3
3
|
function ErrorPage(props) {
|
|
4
4
|
const error = props.error;
|
|
5
5
|
let message = void 0;
|
|
@@ -10,7 +10,18 @@ function ErrorPage(props) {
|
|
|
10
10
|
message = String(error);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
return /* @__PURE__ */
|
|
13
|
+
return /* @__PURE__ */ jsx("div", {
|
|
14
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
15
|
+
children: [
|
|
16
|
+
/* @__PURE__ */ jsx("p", {
|
|
17
|
+
children: "An error occured during route handling or page rendering."
|
|
18
|
+
}),
|
|
19
|
+
message && /* @__PURE__ */ jsx("pre", {
|
|
20
|
+
children: message
|
|
21
|
+
})
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
});
|
|
14
25
|
}
|
|
15
26
|
|
|
16
27
|
// src/core/components/head.ts
|
|
@@ -23,7 +34,10 @@ function Head(props) {
|
|
|
23
34
|
context = useContext(HEAD_CONTEXT);
|
|
24
35
|
} catch (err) {
|
|
25
36
|
console.log(err);
|
|
26
|
-
throw new Error(
|
|
37
|
+
throw new Error(
|
|
38
|
+
"<Head> component is not supported in the browser, or during suspense renders.",
|
|
39
|
+
{ cause: err }
|
|
40
|
+
);
|
|
27
41
|
}
|
|
28
42
|
context.push(props.children);
|
|
29
43
|
return null;
|
|
@@ -38,7 +52,10 @@ function Script(props) {
|
|
|
38
52
|
try {
|
|
39
53
|
context = useContext2(SCRIPT_CONTEXT);
|
|
40
54
|
} catch (err) {
|
|
41
|
-
throw new Error(
|
|
55
|
+
throw new Error(
|
|
56
|
+
"<Script> component is not supported in the browser, or during suspense renders.",
|
|
57
|
+
{ cause: err }
|
|
58
|
+
);
|
|
42
59
|
}
|
|
43
60
|
context.push(props);
|
|
44
61
|
return null;
|
|
@@ -49,21 +66,6 @@ import path from "node:path";
|
|
|
49
66
|
import { createContext as createContext3 } from "preact";
|
|
50
67
|
import { useContext as useContext3 } from "preact/hooks";
|
|
51
68
|
var I18N_CONTEXT = createContext3(null);
|
|
52
|
-
function t(str, params) {
|
|
53
|
-
const context = useContext3(I18N_CONTEXT);
|
|
54
|
-
if (!context) {
|
|
55
|
-
throw new Error("could not find i18n context");
|
|
56
|
-
}
|
|
57
|
-
const translations = (context == null ? void 0 : context.translations) || {};
|
|
58
|
-
let translation = translations[str] || str;
|
|
59
|
-
if (params) {
|
|
60
|
-
for (const key in params) {
|
|
61
|
-
const val = String(params[key] || "");
|
|
62
|
-
translation = translation.replaceAll(`{${key}}`, val);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return translation;
|
|
66
|
-
}
|
|
67
69
|
function getTranslations(locale) {
|
|
68
70
|
const translations = {};
|
|
69
71
|
const translationsFiles = import.meta.glob(["/translations/*.json"], {
|
|
@@ -79,6 +81,24 @@ function getTranslations(locale) {
|
|
|
79
81
|
});
|
|
80
82
|
return translations[locale] || {};
|
|
81
83
|
}
|
|
84
|
+
function useTranslations() {
|
|
85
|
+
const context = useContext3(I18N_CONTEXT);
|
|
86
|
+
if (!context) {
|
|
87
|
+
throw new Error("could not find i18n context");
|
|
88
|
+
}
|
|
89
|
+
const translations = (context == null ? void 0 : context.translations) || {};
|
|
90
|
+
const t = (str, params) => {
|
|
91
|
+
let translation = translations[str] || str || "";
|
|
92
|
+
if (params) {
|
|
93
|
+
for (const key of Object.keys(params)) {
|
|
94
|
+
const val = String(params[key] || "");
|
|
95
|
+
translation = translation.replaceAll(`{${key}}`, val);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return translation;
|
|
99
|
+
};
|
|
100
|
+
return t;
|
|
101
|
+
}
|
|
82
102
|
|
|
83
103
|
export {
|
|
84
104
|
ErrorPage,
|
|
@@ -87,7 +107,7 @@ export {
|
|
|
87
107
|
SCRIPT_CONTEXT,
|
|
88
108
|
Script,
|
|
89
109
|
I18N_CONTEXT,
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
getTranslations,
|
|
111
|
+
useTranslations
|
|
92
112
|
};
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
113
|
+
//# sourceMappingURL=chunk-ZV52A6YZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/components/error-page.tsx","../src/core/components/head.ts","../src/core/components/script.ts","../src/core/i18n.ts"],"sourcesContent":["export interface ErrorPageProps {\n error: unknown;\n}\n\nexport function ErrorPage(props: ErrorPageProps) {\n const error = props.error;\n\n let message = undefined;\n if (import.meta.env.DEV) {\n if (error instanceof Error) {\n message = error.stack;\n } else {\n message = String(error);\n }\n }\n\n return (\n <div>\n <div>\n <p>An error occured during route handling or page rendering.</p>\n {message && <pre>{message}</pre>}\n </div>\n </div>\n );\n}\n","import {ComponentChildren, createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const HEAD_CONTEXT = createContext<ComponentChildren[]>([]);\n\nexport interface HeadProps {\n children?: ComponentChildren;\n}\n\n/**\n * The <Head> component can be used for injecting elements into the HTML head\n * tag from any part of a page.\n */\nexport function Head(props: HeadProps) {\n let context: ComponentChildren[];\n try {\n context = useContext(HEAD_CONTEXT);\n } catch (err) {\n console.log(err);\n throw new Error(\n '<Head> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n context.push(props.children);\n return null;\n}\n","import {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const SCRIPT_CONTEXT = createContext<ScriptProps[]>([]);\n\nexport interface ScriptProps {\n src: string;\n type?: string;\n}\n\n/**\n * The <Script> component is used for rendering any custom script modules. At\n * the moment, the system only pre-renders and bundles files that are in the\n * `/bundles` folder at the root of the project.\n */\nexport function Script(props: ScriptProps) {\n let context: ScriptProps[];\n try {\n context = useContext(SCRIPT_CONTEXT);\n } catch (err) {\n throw new Error(\n '<Script> component is not supported in the browser, or during suspense renders.',\n {cause: err}\n );\n }\n context.push(props);\n return null;\n}\n","import path from 'node:path';\nimport {createContext} from 'preact';\nimport {useContext} from 'preact/hooks';\n\nexport const I18N_CONTEXT = createContext<I18nContext | null>(null);\n\nexport interface I18nContext {\n locale: string;\n translations: Record<string, string>;\n}\n\nexport function getTranslations(locale: string): Record<string, string> {\n const translations: Record<string, Record<string, string>> = {};\n const translationsFiles = import.meta.glob(['/translations/*.json'], {\n eager: true,\n }) as Record<string, {default?: Record<string, string>}>;\n Object.keys(translationsFiles).forEach((translationPath) => {\n const parts = path.parse(translationPath);\n const locale = parts.name;\n const module = translationsFiles[translationPath];\n if (module && module.default) {\n translations[locale] = module.default;\n }\n });\n return translations[locale] || {};\n}\n\nexport function useTranslations() {\n const context = useContext(I18N_CONTEXT);\n if (!context) {\n throw new Error('could not find i18n context');\n }\n const translations = context?.translations || {};\n const t = (str: string, params?: Record<string, string>) => {\n let translation = translations[str] || str || '';\n if (params) {\n for (const key of Object.keys(params)) {\n const val = String(params[key] || '');\n translation = translation.replaceAll(`{${key}}`, val);\n }\n }\n return translation;\n };\n return t;\n}\n"],"mappings":";AAkBM,SACE,KADF;AAdC,SAAS,UAAU,OAAuB;AAC/C,QAAM,QAAQ,MAAM;AAEpB,MAAI,UAAU;AACd,MAAI,YAAY,IAAI,KAAK;AACvB,QAAI,iBAAiB,OAAO;AAC1B,gBAAU,MAAM;AAAA,IAClB,OAAO;AACL,gBAAU,OAAO,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SACE,oBAAC;AAAA,IACC,+BAAC;AAAA,MACC;AAAA,4BAAC;AAAA,UAAE;AAAA,SAAyD;AAAA,QAC3D,WAAW,oBAAC;AAAA,UAAK;AAAA,SAAQ;AAAA;AAAA,KAC5B;AAAA,GACF;AAEJ;;;ACxBA,SAA2B,qBAAoB;AAC/C,SAAQ,kBAAiB;AAElB,IAAM,eAAe,cAAmC,CAAC,CAAC;AAU1D,SAAS,KAAK,OAAkB;AACrC,MAAI;AACJ,MAAI;AACF,cAAU,WAAW,YAAY;AAAA,EACnC,SAAS,KAAP;AACA,YAAQ,IAAI,GAAG;AACf,UAAM,IAAI;AAAA,MACR;AAAA,MACA,EAAC,OAAO,IAAG;AAAA,IACb;AAAA,EACF;AACA,UAAQ,KAAK,MAAM,QAAQ;AAC3B,SAAO;AACT;;;AC1BA,SAAQ,iBAAAA,sBAAoB;AAC5B,SAAQ,cAAAC,mBAAiB;AAElB,IAAM,iBAAiBD,eAA6B,CAAC,CAAC;AAYtD,SAAS,OAAO,OAAoB;AACzC,MAAI;AACJ,MAAI;AACF,cAAUC,YAAW,cAAc;AAAA,EACrC,SAAS,KAAP;AACA,UAAM,IAAI;AAAA,MACR;AAAA,MACA,EAAC,OAAO,IAAG;AAAA,IACb;AAAA,EACF;AACA,UAAQ,KAAK,KAAK;AAClB,SAAO;AACT;;;AC3BA,OAAO,UAAU;AACjB,SAAQ,iBAAAC,sBAAoB;AAC5B,SAAQ,cAAAC,mBAAiB;AAElB,IAAM,eAAeD,eAAkC,IAAI;AAO3D,SAAS,gBAAgB,QAAwC;AACtE,QAAM,eAAuD,CAAC;AAC9D,QAAM,oBAAoB,YAAY,KAAK,CAAC,sBAAsB,GAAG;AAAA,IACnE,OAAO;AAAA,EACT,CAAC;AACD,SAAO,KAAK,iBAAiB,EAAE,QAAQ,CAAC,oBAAoB;AAC1D,UAAM,QAAQ,KAAK,MAAM,eAAe;AACxC,UAAME,UAAS,MAAM;AACrB,UAAM,SAAS,kBAAkB;AACjC,QAAI,UAAU,OAAO,SAAS;AAC5B,mBAAaA,WAAU,OAAO;AAAA,IAChC;AAAA,EACF,CAAC;AACD,SAAO,aAAa,WAAW,CAAC;AAClC;AAEO,SAAS,kBAAkB;AAChC,QAAM,UAAUD,YAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACA,QAAM,gBAAe,mCAAS,iBAAgB,CAAC;AAC/C,QAAM,IAAI,CAAC,KAAa,WAAoC;AAC1D,QAAI,cAAc,aAAa,QAAQ,OAAO;AAC9C,QAAI,QAAQ;AACV,iBAAW,OAAO,OAAO,KAAK,MAAM,GAAG;AACrC,cAAM,MAAM,OAAO,OAAO,QAAQ,EAAE;AACpC,sBAAc,YAAY,WAAW,IAAI,QAAQ,GAAG;AAAA,MACtD;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;","names":["createContext","useContext","createContext","useContext","locale"]}
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
declare function dev(
|
|
1
|
+
declare function dev(rootProjectDir?: string): Promise<void>;
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface BuildOptions {
|
|
4
|
+
ssrOnly?: boolean;
|
|
5
|
+
mode?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function build(rootProjectDir?: string, options?: BuildOptions): Promise<void>;
|
|
4
8
|
|
|
5
|
-
declare function
|
|
9
|
+
declare function preview(rootProjectDir?: string): Promise<void>;
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
declare function start(rootProjectDir?: string): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { build, dev, preview, start };
|