@batijs/cli 0.0.140 → 0.0.142

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.
Files changed (49) hide show
  1. package/dist/boilerplates/@batijs/google-analytics/files/$.env.js +16 -0
  2. package/dist/boilerplates/@batijs/prettier/files/.prettierignore +29 -7
  3. package/dist/boilerplates/@batijs/prisma/files/$.env.js +12 -17
  4. package/dist/boilerplates/@batijs/react/files/$package.json.js +20 -14
  5. package/dist/boilerplates/@batijs/react/files/layouts/HeadDefault.tsx +26 -0
  6. package/dist/boilerplates/@batijs/react/files/pages/+config.h.ts +2 -7
  7. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+Page.tsx +4 -2
  8. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+data.ts +22 -0
  9. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+title.ts +7 -0
  10. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+Page.tsx +5 -3
  11. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+data.ts +22 -0
  12. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+title.ts +7 -0
  13. package/dist/boilerplates/@batijs/react/files/pages/star-wars/types.ts +1 -4
  14. package/dist/boilerplates/@batijs/react/types/pages/+config.h.d.ts +9 -9
  15. package/dist/boilerplates/@batijs/react/types/pages/star-wars/@id/+Page.d.ts +1 -4
  16. package/dist/boilerplates/@batijs/react/types/pages/star-wars/@id/+data.d.ts +4 -0
  17. package/dist/boilerplates/@batijs/react/types/pages/star-wars/@id/+title.d.ts +3 -0
  18. package/dist/boilerplates/@batijs/react/types/pages/star-wars/index/+Page.d.ts +1 -4
  19. package/dist/boilerplates/@batijs/react/types/pages/star-wars/index/+data.d.ts +3 -0
  20. package/dist/boilerplates/@batijs/react/types/pages/star-wars/index/+title.d.ts +3 -0
  21. package/dist/boilerplates/@batijs/react/types/pages/star-wars/types.d.ts +1 -4
  22. package/dist/boilerplates/@batijs/react-telefunc/files/pages/todo/+Page.tsx +4 -2
  23. package/dist/boilerplates/@batijs/react-telefunc/files/pages/todo/+data.ts +9 -0
  24. package/dist/boilerplates/@batijs/react-telefunc/types/pages/todo/+Page.d.ts +1 -4
  25. package/dist/boilerplates/@batijs/react-telefunc/types/pages/todo/+data.d.ts +2 -0
  26. package/dist/boilerplates/@batijs/react-trpc/files/pages/todo-trpc/+Page.tsx +4 -2
  27. package/dist/boilerplates/@batijs/react-trpc/files/pages/todo-trpc/+data.ts +9 -0
  28. package/dist/boilerplates/@batijs/react-trpc/types/pages/todo-trpc/+Page.d.ts +1 -4
  29. package/dist/boilerplates/@batijs/react-trpc/types/pages/todo-trpc/+data.d.ts +2 -0
  30. package/dist/boilerplates/@batijs/solid/files/layouts/HeadDefault.tsx +19 -0
  31. package/dist/boilerplates/@batijs/vercel/files/$package.json.js +1 -1
  32. package/dist/boilerplates/@batijs/vue/files/$package.json.js +14 -2
  33. package/dist/boilerplates/@batijs/vue/files/layouts/HeadDefault.vue +4 -9
  34. package/dist/boilerplates/@batijs/vue/files/pages/+onCreateApp.ts +14 -0
  35. package/dist/boilerplates/@batijs/vue/types/pages/+config.h.d.ts +24 -0
  36. package/dist/boilerplates/@batijs/vue/types/pages/+onCreateApp.d.ts +2 -0
  37. package/dist/boilerplates/boilerplates.json +11 -0
  38. package/dist/index.js +22 -14
  39. package/package.json +5 -5
  40. package/dist/boilerplates/@batijs/react/files/pages/star-wars/@id/+onBeforeRender.ts +0 -25
  41. package/dist/boilerplates/@batijs/react/files/pages/star-wars/filterMovieData.ts +0 -7
  42. package/dist/boilerplates/@batijs/react/files/pages/star-wars/index/+onBeforeRender.ts +0 -77
  43. package/dist/boilerplates/@batijs/react/types/pages/star-wars/@id/+onBeforeRender.d.ts +0 -10
  44. package/dist/boilerplates/@batijs/react/types/pages/star-wars/filterMovieData.d.ts +0 -2
  45. package/dist/boilerplates/@batijs/react/types/pages/star-wars/index/+onBeforeRender.d.ts +0 -9
  46. package/dist/boilerplates/@batijs/react-telefunc/files/pages/todo/+onBeforeRender.ts +0 -13
  47. package/dist/boilerplates/@batijs/react-telefunc/types/pages/todo/+onBeforeRender.d.ts +0 -7
  48. package/dist/boilerplates/@batijs/react-trpc/files/pages/todo-trpc/+onBeforeRender.ts +0 -13
  49. package/dist/boilerplates/@batijs/react-trpc/types/pages/todo-trpc/+onBeforeRender.d.ts +0 -7
@@ -0,0 +1,16 @@
1
+ // files/$.env.ts
2
+ import { appendToEnv } from "@batijs/core";
3
+ async function getEnv(props) {
4
+ const envContent = await props.readfile?.();
5
+ return appendToEnv(
6
+ envContent,
7
+ "PUBLIC_ENV__GOOGLE_ANALYTICS",
8
+ "G-XXXXXXXXXX",
9
+ `Google Analytics
10
+
11
+ See the documentation https://support.google.com/analytics/answer/9304153?hl=en#zippy=%2Cweb`
12
+ );
13
+ }
14
+ export {
15
+ getEnv as default
16
+ };
@@ -5,6 +5,7 @@ npm-debug.log*
5
5
  yarn-debug.log*
6
6
  yarn-error.log*
7
7
  lerna-debug.log*
8
+ .pnpm-debug.log*
8
9
 
9
10
  # Diagnostic reports (https://nodejs.org/api/report.html)
10
11
  report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
@@ -41,8 +42,8 @@ build/Release
41
42
  node_modules/
42
43
  jspm_packages/
43
44
 
44
- # TypeScript v1 declaration files
45
- typings/
45
+ # Snowpack dependency directory (https://snowpack.dev/)
46
+ web_modules/
46
47
 
47
48
  # TypeScript cache
48
49
  *.tsbuildinfo
@@ -53,6 +54,9 @@ typings/
53
54
  # Optional eslint cache
54
55
  .eslintcache
55
56
 
57
+ # Optional stylelint cache
58
+ .stylelintcache
59
+
56
60
  # Microbundle cache
57
61
  .rpt2_cache/
58
62
  .rts2_cache_cjs/
@@ -68,15 +72,20 @@ typings/
68
72
  # Yarn Integrity file
69
73
  .yarn-integrity
70
74
 
71
- # dotenv environment variables file
75
+ # dotenv environment variable files
72
76
  .env
73
- .env.test
77
+ .env.development.local
78
+ .env.test.local
79
+ .env.production.local
80
+ .env.local
74
81
 
75
82
  # parcel-bundler cache (https://parceljs.org/)
76
83
  .cache
84
+ .parcel-cache
77
85
 
78
86
  # Next.js build output
79
87
  .next
88
+ out
80
89
 
81
90
  # Nuxt.js build / generate output
82
91
  .nuxt
@@ -84,13 +93,19 @@ dist
84
93
 
85
94
  # Gatsby files
86
95
  .cache/
87
- # Comment in the public line in if your project uses Gatsby and *not* Next.js
96
+ # Comment in the public line in if your project uses Gatsby and not Next.js
88
97
  # https://nextjs.org/blog/next-9-1#public-directory-support
89
98
  # public
90
99
 
91
100
  # vuepress build output
92
101
  .vuepress/dist
93
102
 
103
+ # vuepress v2.x temp and cache directory
104
+ .temp
105
+
106
+ # Docusaurus cache and generated files
107
+ .docusaurus
108
+
94
109
  # Serverless directories
95
110
  .serverless/
96
111
 
@@ -103,5 +118,12 @@ dist
103
118
  # TernJS port file
104
119
  .tern-port
105
120
 
106
- # IDEs
107
- .idea/
121
+ # Stores VSCode versions used for testing VSCode extensions
122
+ .vscode-test
123
+
124
+ # yarn v2
125
+ .yarn/cache
126
+ .yarn/unplugged
127
+ .yarn/build-state.yml
128
+ .yarn/install-state.gz
129
+ .pnp.*
@@ -1,24 +1,19 @@
1
1
  // files/$.env.ts
2
- import "@batijs/core";
2
+ import { appendToEnv } from "@batijs/core";
3
3
  async function getEnv(props) {
4
- let envContent = await props.readfile?.() ?? "";
5
- if (envContent.endsWith("\n\n")) {
6
- } else if (envContent.endsWith("\n")) {
7
- envContent = envContent + "\n";
8
- } else if (envContent) {
9
- envContent = envContent + "\n\n";
10
- }
11
- const prismaContent = `# Prisma
4
+ const envContent = await props.readfile?.();
5
+ return appendToEnv(
6
+ envContent,
7
+ "DATABASE_URL",
8
+ "postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public",
9
+ `Prisma
12
10
 
13
- # Environment variables declared in this file are automatically made available to Prisma.
14
- # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
11
+ Environment variables declared in this file are automatically made available to Prisma.
12
+ See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
15
13
 
16
- # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
17
- # See the documentation for all the connection string options: https://pris.ly/d/connection-strings
18
-
19
- DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
20
- `;
21
- return envContent + prismaContent;
14
+ Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
15
+ See the documentation for all the connection string options: https://pris.ly/d/connection-strings`
16
+ );
22
17
  }
23
18
  export {
24
19
  getEnv as default
@@ -55,8 +55,8 @@ var require_package = __commonJS({
55
55
  "react-dom": "^18.2.0",
56
56
  tailwindcss: "^3.4.1",
57
57
  typescript: "^5.3.3",
58
- vike: "^0.4.156",
59
- "vike-react": "^0.3.8",
58
+ vike: "^0.4.159",
59
+ "vike-react": "^0.4.0",
60
60
  vite: "^5.0.11"
61
61
  },
62
62
  dependencies: {
@@ -101,20 +101,23 @@ var require_package = __commonJS({
101
101
  "./pages/star-wars/types": {
102
102
  types: "./dist/types/pages/star-wars/types.d.ts"
103
103
  },
104
- "./pages/star-wars/filterMovieData": {
105
- types: "./dist/types/pages/star-wars/filterMovieData.d.ts"
104
+ "./pages/star-wars/@id/+data": {
105
+ types: "./dist/types/pages/star-wars/@id/+data.d.ts"
106
106
  },
107
107
  "./pages/star-wars/@id/+Page": {
108
108
  types: "./dist/types/pages/star-wars/@id/+Page.d.ts"
109
109
  },
110
- "./pages/star-wars/@id/+onBeforeRender": {
111
- types: "./dist/types/pages/star-wars/@id/+onBeforeRender.d.ts"
110
+ "./pages/star-wars/@id/+title": {
111
+ types: "./dist/types/pages/star-wars/@id/+title.d.ts"
112
+ },
113
+ "./pages/star-wars/index/+data": {
114
+ types: "./dist/types/pages/star-wars/index/+data.d.ts"
112
115
  },
113
116
  "./pages/star-wars/index/+Page": {
114
117
  types: "./dist/types/pages/star-wars/index/+Page.d.ts"
115
118
  },
116
- "./pages/star-wars/index/+onBeforeRender": {
117
- types: "./dist/types/pages/star-wars/index/+onBeforeRender.d.ts"
119
+ "./pages/star-wars/index/+title": {
120
+ types: "./dist/types/pages/star-wars/index/+title.d.ts"
118
121
  }
119
122
  },
120
123
  typesVersions: {
@@ -149,20 +152,23 @@ var require_package = __commonJS({
149
152
  "pages/star-wars/types": [
150
153
  "./dist/types/pages/star-wars/types.d.ts"
151
154
  ],
152
- "pages/star-wars/filterMovieData": [
153
- "./dist/types/pages/star-wars/filterMovieData.d.ts"
155
+ "pages/star-wars/@id/+data": [
156
+ "./dist/types/pages/star-wars/@id/+data.d.ts"
154
157
  ],
155
158
  "pages/star-wars/@id/+Page": [
156
159
  "./dist/types/pages/star-wars/@id/+Page.d.ts"
157
160
  ],
158
- "pages/star-wars/@id/+onBeforeRender": [
159
- "./dist/types/pages/star-wars/@id/+onBeforeRender.d.ts"
161
+ "pages/star-wars/@id/+title": [
162
+ "./dist/types/pages/star-wars/@id/+title.d.ts"
163
+ ],
164
+ "pages/star-wars/index/+data": [
165
+ "./dist/types/pages/star-wars/index/+data.d.ts"
160
166
  ],
161
167
  "pages/star-wars/index/+Page": [
162
168
  "./dist/types/pages/star-wars/index/+Page.d.ts"
163
169
  ],
164
- "pages/star-wars/index/+onBeforeRender": [
165
- "./dist/types/pages/star-wars/index/+onBeforeRender.d.ts"
170
+ "pages/star-wars/index/+title": [
171
+ "./dist/types/pages/star-wars/index/+title.d.ts"
166
172
  ]
167
173
  }
168
174
  }
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import logoUrl from "../assets/logo.svg";
2
3
 
3
4
  // Default <head> (can be overridden by pages)
4
5
 
@@ -7,15 +8,40 @@ export default function HeadDefault() {
7
8
  return (
8
9
  <>
9
10
  <meta name="viewport" content="width=device-width, initial-scale=1" />
11
+ <meta name="description" content="Demo showcasing Vike" />
12
+ <link rel="icon" href={logoUrl} />
10
13
  {/* See https://plausible.io/docs/plausible-script */}
11
14
  {/* TODO: update data-domain */}
12
15
  <script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.js"></script>
13
16
  </>
14
17
  );
18
+ } else if (BATI.has("google-analytics")) {
19
+ return (
20
+ <>
21
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
22
+ <meta name="description" content="Demo showcasing Vike" />
23
+ <link rel="icon" href={logoUrl} />
24
+ <script
25
+ async
26
+ src={`https://www.googletagmanager.com/gtag/js?id=${import.meta.env.PUBLIC_ENV__GOOGLE_ANALYTICS}`}
27
+ ></script>
28
+ <script
29
+ dangerouslySetInnerHTML={{
30
+ __html: `window.dataLayer = window.dataLayer || [];
31
+ function gtag(){dataLayer.push(arguments);}
32
+ gtag('js', new Date());
33
+
34
+ gtag('config', '${import.meta.env.PUBLIC_ENV__GOOGLE_ANALYTICS}');`,
35
+ }}
36
+ ></script>
37
+ </>
38
+ );
15
39
  } else {
16
40
  return (
17
41
  <>
18
42
  <meta name="viewport" content="width=device-width, initial-scale=1" />
43
+ <meta name="description" content="Demo showcasing Vike" />
44
+ <link rel="icon" href={logoUrl} />
19
45
  </>
20
46
  );
21
47
  }
@@ -1,8 +1,7 @@
1
+ import vikeReact from "vike-react";
1
2
  import type { Config } from "vike/types";
2
- import Layout from "../layouts/LayoutDefault";
3
3
  import Head from "../layouts/HeadDefault";
4
- import logoUrl from "../assets/logo.svg";
5
- import vikeReact from "vike-react";
4
+ import Layout from "../layouts/LayoutDefault";
6
5
 
7
6
  // Default config (can be overridden by pages)
8
7
  export default {
@@ -10,9 +9,5 @@ export default {
10
9
  Head,
11
10
  // <title>
12
11
  title: "My Vike App",
13
- // <meta name="description">
14
- description: "Demo showcasing Vike",
15
- // <link rel="icon" href="${favicon}" />
16
- favicon: logoUrl,
17
12
  extends: vikeReact,
18
13
  } satisfies Config;
@@ -1,7 +1,9 @@
1
1
  import React from "react";
2
- import type { MovieDetails } from "../types";
2
+ import { useData } from "vike-react/useData";
3
+ import type { Data } from "./+data";
3
4
 
4
- export default function Page({ movie }: { movie: MovieDetails }) {
5
+ export default function Page() {
6
+ const movie = useData<Data>();
5
7
  return (
6
8
  <>
7
9
  <h1>{movie.title}</h1>
@@ -0,0 +1,22 @@
1
+ // https://vike.dev/data
2
+
3
+ import fetch from "cross-fetch";
4
+ import type { PageContextServer } from "vike/types";
5
+ import type { MovieDetails } from "../types";
6
+
7
+ export type Data = Awaited<ReturnType<typeof data>>;
8
+
9
+ export const data = async (pageContext: PageContextServer) => {
10
+ const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
11
+ let movie = (await response.json()) as MovieDetails;
12
+ // We remove data we don't need because the data is passed to
13
+ // the client; we should minimize what is sent over the network.
14
+ movie = minimize(movie);
15
+ return movie;
16
+ };
17
+
18
+ function minimize(movie: MovieDetails): MovieDetails {
19
+ const { id, title, release_date, director, producer } = movie;
20
+ movie = { id, title, release_date, director, producer };
21
+ return movie;
22
+ }
@@ -0,0 +1,7 @@
1
+ import type { PageContext } from "vike/types";
2
+ import type { Data } from "./+data";
3
+
4
+ export function title(pageContext: PageContext<Data>) {
5
+ const movie = pageContext.data;
6
+ return movie.title;
7
+ }
@@ -1,7 +1,9 @@
1
1
  import React from "react";
2
- import type { Movie } from "../types";
2
+ import { useData } from "vike-react/useData";
3
+ import type { Data } from "./+data";
3
4
 
4
- export default function Page({ movies }: { movies: Movie[] }) {
5
+ export default function Page() {
6
+ const movies = useData<Data>();
5
7
  return (
6
8
  <>
7
9
  <h1>Star Wars Movies</h1>
@@ -13,7 +15,7 @@ export default function Page({ movies }: { movies: Movie[] }) {
13
15
  ))}
14
16
  </ol>
15
17
  <p>
16
- Source: <a href="https://star-wars.brillout.com">star-wars.brillout.com</a>.
18
+ Source: <a href="https://brillout.github.io/star-wars">brillout.github.io/star-wars</a>.
17
19
  </p>
18
20
  </>
19
21
  );
@@ -0,0 +1,22 @@
1
+ // https://vike.dev/data
2
+
3
+ import fetch from "cross-fetch";
4
+ import type { Movie, MovieDetails } from "../types";
5
+
6
+ export type Data = Awaited<ReturnType<typeof data>>;
7
+
8
+ export const data = async () => {
9
+ const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
10
+ const moviesData = (await response.json()) as MovieDetails[];
11
+ // We remove data we don't need because the data is passed to the client; we should
12
+ // minimize what is sent over the network.
13
+ const movies = minimize(moviesData);
14
+ return movies;
15
+ };
16
+
17
+ function minimize(movies: MovieDetails[]): Movie[] {
18
+ return movies.map((movie) => {
19
+ const { title, release_date, id } = movie;
20
+ return { title, release_date, id };
21
+ });
22
+ }
@@ -0,0 +1,7 @@
1
+ import type { PageContext } from "vike/types";
2
+ import type { Data } from "./+data";
3
+
4
+ export function title(pageContext: PageContext<Data>) {
5
+ const movies = pageContext.data;
6
+ return `${movies.length} Star Wars Movies`;
7
+ }
@@ -4,10 +4,7 @@ export type Movie = {
4
4
  release_date: string;
5
5
  };
6
6
 
7
- export type MovieDetails = {
8
- id: string;
9
- title: string;
10
- release_date: string;
7
+ export type MovieDetails = Movie & {
11
8
  director: string;
12
9
  producer: string;
13
10
  };
@@ -1,15 +1,12 @@
1
- import Layout from "../layouts/LayoutDefault";
2
1
  import Head from "../layouts/HeadDefault";
2
+ import Layout from "../layouts/LayoutDefault";
3
3
  declare const _default: {
4
4
  Layout: typeof Layout;
5
5
  Head: typeof Head;
6
6
  title: string;
7
- description: string;
8
- favicon: string;
9
7
  extends: {
10
8
  onRenderHtml: "import:vike-react/renderer/onRenderHtml:onRenderHtml";
11
9
  onRenderClient: "import:vike-react/renderer/onRenderClient:onRenderClient";
12
- passToClient: string[];
13
10
  clientRouting: true;
14
11
  hydrationCanBeAborted: true;
15
12
  meta: {
@@ -30,19 +27,16 @@ declare const _default: {
30
27
  client: true;
31
28
  };
32
29
  };
33
- description: {
34
- env: {
35
- server: true;
36
- };
37
- };
38
30
  favicon: {
39
31
  env: {
40
32
  server: true;
33
+ client: true;
41
34
  };
42
35
  };
43
36
  lang: {
44
37
  env: {
45
38
  server: true;
39
+ client: true;
46
40
  };
47
41
  };
48
42
  ssr: {
@@ -62,6 +56,12 @@ declare const _default: {
62
56
  server: true;
63
57
  };
64
58
  };
59
+ Wrapper: {
60
+ env: {
61
+ client: true;
62
+ server: true;
63
+ };
64
+ };
65
65
  };
66
66
  };
67
67
  };
@@ -1,4 +1 @@
1
- import type { MovieDetails } from "../types";
2
- export default function Page({ movie }: {
3
- movie: MovieDetails;
4
- }): import("react/jsx-runtime").JSX.Element;
1
+ export default function Page(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ import type { PageContextServer } from "vike/types";
2
+ import type { MovieDetails } from "../types";
3
+ export type Data = Awaited<ReturnType<typeof data>>;
4
+ export declare const data: (pageContext: PageContextServer) => Promise<MovieDetails>;
@@ -0,0 +1,3 @@
1
+ import type { PageContext } from "vike/types";
2
+ import type { Data } from "./+data";
3
+ export declare function title(pageContext: PageContext<Data>): string;
@@ -1,4 +1 @@
1
- import type { Movie } from "../types";
2
- export default function Page({ movies }: {
3
- movies: Movie[];
4
- }): import("react/jsx-runtime").JSX.Element;
1
+ export default function Page(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { Movie } from "../types";
2
+ export type Data = Awaited<ReturnType<typeof data>>;
3
+ export declare const data: () => Promise<Movie[]>;
@@ -0,0 +1,3 @@
1
+ import type { PageContext } from "vike/types";
2
+ import type { Data } from "./+data";
3
+ export declare function title(pageContext: PageContext<Data>): string;
@@ -3,10 +3,7 @@ export type Movie = {
3
3
  title: string;
4
4
  release_date: string;
5
5
  };
6
- export type MovieDetails = {
7
- id: string;
8
- title: string;
9
- release_date: string;
6
+ export type MovieDetails = Movie & {
10
7
  director: string;
11
8
  producer: string;
12
9
  };
@@ -1,8 +1,10 @@
1
- import type { TodoItem } from "@batijs/shared-db/database/todoItems";
2
1
  import React, { useState } from "react";
2
+ import { useData } from "vike-react/useData";
3
+ import type { Data } from "./+data";
3
4
  import { TodoList } from "./TodoList";
4
5
 
5
- export default function Page({ todoItemsInitial }: { todoItemsInitial: TodoItem[] }) {
6
+ export default function Page() {
7
+ const todoItemsInitial = useData<Data>();
6
8
  return (
7
9
  <>
8
10
  <h1>To-do List</h1>
@@ -0,0 +1,9 @@
1
+ // https://vike.dev/data
2
+ import { todoItems } from "@batijs/shared-db/database/todoItems";
3
+
4
+ export type Data = ReturnType<typeof data>;
5
+
6
+ export default function data() {
7
+ const todoItemsInitial = todoItems;
8
+ return todoItemsInitial;
9
+ }
@@ -1,4 +1 @@
1
- import type { TodoItem } from "@batijs/shared-db/database/todoItems";
2
- export default function Page({ todoItemsInitial }: {
3
- todoItemsInitial: TodoItem[];
4
- }): import("react/jsx-runtime").JSX.Element;
1
+ export default function Page(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export type Data = ReturnType<typeof data>;
2
+ export default function data(): import("@batijs/shared-db/database/todoItems").TodoItem[];
@@ -1,8 +1,10 @@
1
- import type { TodoItem } from "@batijs/shared-db/database/todoItems";
2
1
  import React, { useState } from "react";
2
+ import { useData } from "vike-react/useData";
3
+ import type { Data } from "./+data";
3
4
  import { TodoList } from "./TodoList";
4
5
 
5
- export default function Page({ todoItemsInitial }: { todoItemsInitial: TodoItem[] }) {
6
+ export default function Page() {
7
+ const todoItemsInitial = useData<Data>();
6
8
  return (
7
9
  <>
8
10
  <h1>To-do List</h1>
@@ -0,0 +1,9 @@
1
+ // https://vike.dev/data
2
+ import { todoItems } from "@batijs/shared-db/database/todoItems";
3
+
4
+ export type Data = ReturnType<typeof data>;
5
+
6
+ export default function data() {
7
+ const todoItemsInitial = todoItems;
8
+ return todoItemsInitial;
9
+ }
@@ -1,4 +1 @@
1
- import type { TodoItem } from "@batijs/shared-db/database/todoItems";
2
- export default function Page({ todoItemsInitial }: {
3
- todoItemsInitial: TodoItem[];
4
- }): import("react/jsx-runtime").JSX.Element;
1
+ export default function Page(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export type Data = ReturnType<typeof data>;
2
+ export default function data(): import("@batijs/shared-db/database/todoItems").TodoItem[];
@@ -1,3 +1,5 @@
1
+ /* eslint-disable solid/no-innerhtml */
2
+
1
3
  // Default <head> (can be overridden by pages)
2
4
 
3
5
  import logoUrl from "../assets/logo.svg";
@@ -12,6 +14,23 @@ export default function HeadDefault() {
12
14
  <script defer data-domain="yourdomain.com" src="https://plausible.io/js/script.js" />
13
15
  </>
14
16
  );
17
+ } else if (BATI.has("google-analytics")) {
18
+ return (
19
+ <>
20
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
21
+ <script
22
+ async
23
+ src={`https://www.googletagmanager.com/gtag/js?id=${import.meta.env.PUBLIC_ENV__GOOGLE_ANALYTICS}`}
24
+ />
25
+ <script
26
+ innerHTML={`window.dataLayer = window.dataLayer || [];
27
+ function gtag(){dataLayer.push(arguments);}
28
+ gtag('js', new Date());
29
+
30
+ gtag('config', '${import.meta.env.PUBLIC_ENV__GOOGLE_ANALYTICS}');`}
31
+ />
32
+ </>
33
+ );
15
34
  } else {
16
35
  return (
17
36
  <>
@@ -46,7 +46,7 @@ var require_package = __commonJS({
46
46
  "@vite-plugin-vercel/vike": "^2.0.0",
47
47
  vike: "^0.4.156",
48
48
  vite: "^5.0.11",
49
- "vite-plugin-vercel": "^2.0.0"
49
+ "vite-plugin-vercel": "^3.0.1"
50
50
  },
51
51
  dependencies: {
52
52
  "@batijs/core": "workspace:*"
@@ -52,9 +52,10 @@ var require_package = __commonJS({
52
52
  typescript: "^5.3.3",
53
53
  "unplugin-vue-markdown": "^0.25.2",
54
54
  vike: "^0.4.156",
55
- "vike-vue": "^0.5.3",
55
+ "vike-vue": "^0.5.4",
56
56
  vite: "^5.0.11",
57
- vue: "^3.4.13"
57
+ vue: "^3.4.13",
58
+ "vue-gtag": "^2.0.1"
58
59
  },
59
60
  dependencies: {
60
61
  "@batijs/core": "workspace:*"
@@ -71,6 +72,9 @@ var require_package = __commonJS({
71
72
  "./pages/+config.h": {
72
73
  types: "./dist/types/pages/+config.h.d.ts"
73
74
  },
75
+ "./pages/+onCreateApp": {
76
+ types: "./dist/types/pages/+onCreateApp.d.ts"
77
+ },
74
78
  "./pages/+onPageTransitionEnd": {
75
79
  types: "./dist/types/pages/+onPageTransitionEnd.d.ts"
76
80
  },
@@ -95,6 +99,9 @@ var require_package = __commonJS({
95
99
  "pages/+config.h": [
96
100
  "./dist/types/pages/+config.h.d.ts"
97
101
  ],
102
+ "pages/+onCreateApp": [
103
+ "./dist/types/pages/+onCreateApp.d.ts"
104
+ ],
98
105
  "pages/+onPageTransitionEnd": [
99
106
  "./dist/types/pages/+onPageTransitionEnd.d.ts"
100
107
  ],
@@ -134,6 +141,11 @@ async function getPackageJson(props) {
134
141
  devDependencies: ["eslint-plugin-vue"]
135
142
  });
136
143
  }
144
+ if (props.meta.BATI.has("google-analytics")) {
145
+ addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
146
+ dependencies: ["vue-gtag"]
147
+ });
148
+ }
137
149
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
138
150
  devDependencies: ["vite"],
139
151
  dependencies: [
@@ -1,17 +1,12 @@
1
1
  <!-- Default <head> (can be overridden by pages) -->
2
2
 
3
3
  <template>
4
- <meta
5
- name="viewport"
6
- content="width=device-width, initial-scale=1"
7
- >
4
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
5
 
9
6
  <!-- BATI.has("plausible.io") -->
10
7
  <!-- See https://plausible.io/docs/plausible-script -->
11
8
  <!-- TODO: update data-domain -->
12
- <component :is="'script'" defer
13
- data-domain="yourdomain.com"
14
- src="https://plausible.io/js/script.js" />
9
+ <component :is="'script'" defer data-domain="yourdomain.com" src="https://plausible.io/js/script.js" />
15
10
  </template>
16
- <script setup lang="ts">
17
- </script>
11
+
12
+ <script setup lang="ts"></script>
@@ -0,0 +1,14 @@
1
+ import type { OnCreateAppSync } from "vike-vue";
2
+ import VueGtag from "vue-gtag";
3
+
4
+ // BATI.has("google-analytics")
5
+ export const onCreateApp: OnCreateAppSync = (pageContext): ReturnType<OnCreateAppSync> => {
6
+ const { app } = pageContext;
7
+
8
+ // See https://matteo-gabriele.gitbook.io/vue-gtag/
9
+ app.use(VueGtag, {
10
+ config: {
11
+ id: import.meta.env.PUBLIC_ENV__GOOGLE_ANALYTICS,
12
+ },
13
+ });
14
+ };
@@ -42,6 +42,7 @@ declare const _default: {
42
42
  lang: {
43
43
  env: {
44
44
  server: true;
45
+ client: true;
45
46
  };
46
47
  };
47
48
  ssr: {
@@ -61,6 +62,29 @@ declare const _default: {
61
62
  client: true;
62
63
  };
63
64
  };
65
+ onCreateApp: {
66
+ env: {
67
+ server: true;
68
+ client: true;
69
+ };
70
+ };
71
+ onCreateAppPinia: {
72
+ env: {
73
+ server: true;
74
+ client: true;
75
+ };
76
+ };
77
+ onAfterRenderSSRApp: {
78
+ env: {
79
+ server: true;
80
+ };
81
+ };
82
+ onBeforeMountApp: {
83
+ env: {
84
+ server: false;
85
+ client: true;
86
+ };
87
+ };
64
88
  };
65
89
  };
66
90
  };
@@ -0,0 +1,2 @@
1
+ import type { OnCreateAppSync } from "vike-vue";
2
+ export declare const onCreateApp: OnCreateAppSync;
@@ -44,6 +44,17 @@
44
44
  "files"
45
45
  ]
46
46
  },
47
+ {
48
+ "config": {
49
+ "if": {
50
+ "flag": "google-analytics"
51
+ }
52
+ },
53
+ "folder": "@batijs/google-analytics",
54
+ "subfolders": [
55
+ "files"
56
+ ]
57
+ },
47
58
  {
48
59
  "config": {
49
60
  "if": {
package/dist/index.js CHANGED
@@ -499,20 +499,28 @@ function transformFileAfterExec(filepath, fileContent) {
499
499
  if (fileContent === void 0 || fileContent === null)
500
500
  return null;
501
501
  const parsed = path.parse(filepath);
502
- const ext = parsed.ext || parsed.name;
503
- switch (ext) {
504
- case ".ts":
505
- case ".js":
506
- case ".tsx":
507
- case ".jsx":
508
- case ".env":
509
- case ".html":
510
- return fileContent;
511
- case ".json":
512
- return JSON.stringify(fileContent, null, 2);
513
- default:
514
- throw new Error(`Unsupported extension ${ext} (${filepath})`);
502
+ const toTest = [parsed.base, parsed.ext, parsed.name].filter(Boolean);
503
+ for (const ext of toTest) {
504
+ switch (ext) {
505
+ case ".ts":
506
+ case ".js":
507
+ case ".tsx":
508
+ case ".jsx":
509
+ case ".env":
510
+ case ".env.local":
511
+ case ".env.development":
512
+ case ".env.development.local":
513
+ case ".env.test":
514
+ case ".env.test.local":
515
+ case ".env.production":
516
+ case ".env.production.local":
517
+ case ".html":
518
+ return fileContent;
519
+ case ".json":
520
+ return JSON.stringify(fileContent, null, 2);
521
+ }
515
522
  }
523
+ throw new Error(`Unsupported file extension ${parsed.base} (${filepath})`);
516
524
  }
517
525
  async function importTransformer(p) {
518
526
  const importFile = isWin ? "file://" + p : p;
@@ -576,7 +584,7 @@ Please report this issue to https://github.com/magne4000/bati`
576
584
  // package.json
577
585
  var package_default = {
578
586
  name: "@batijs/cli",
579
- version: "0.0.140",
587
+ version: "0.0.142",
580
588
  type: "module",
581
589
  scripts: {
582
590
  "check-types": "tsc --noEmit",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/cli",
3
- "version": "0.0.140",
3
+ "version": "0.0.142",
4
4
  "type": "module",
5
5
  "keywords": [],
6
6
  "description": "Next-gen scaffolder. Get started with fully-functional apps, and choose any tool you want",
@@ -19,12 +19,12 @@
19
19
  "tsup": "^8.0.1",
20
20
  "typescript": "^5.3.3",
21
21
  "vite": "^5.0.11",
22
- "@batijs/compile": "0.0.140",
23
- "@batijs/build": "0.0.140"
22
+ "@batijs/build": "0.0.142",
23
+ "@batijs/compile": "0.0.142"
24
24
  },
25
25
  "dependencies": {
26
- "@batijs/core": "0.0.140",
27
- "@batijs/features": "0.0.140"
26
+ "@batijs/core": "0.0.142",
27
+ "@batijs/features": "0.0.142"
28
28
  },
29
29
  "bin": "./dist/index.js",
30
30
  "exports": {
@@ -1,25 +0,0 @@
1
- import fetch from "cross-fetch";
2
- import type { PageContextBuiltInServer } from "vike/types";
3
- import { filterMovieData } from "../filterMovieData";
4
- import type { MovieDetails } from "../types";
5
-
6
- export default async function onBeforeRender(pageContext: PageContextBuiltInServer) {
7
- const response = await fetch(`https://star-wars.brillout.com/api/films/${pageContext.routeParams.id}.json`);
8
- let movie = (await response.json()) as MovieDetails;
9
-
10
- // We remove data we don't need because we pass `pageContext.movie` to
11
- // the client; we want to minimize what is sent over the network.
12
- movie = filterMovieData(movie);
13
-
14
- const { title } = movie;
15
-
16
- return {
17
- pageContext: {
18
- pageProps: {
19
- movie,
20
- },
21
- // The page's <title>
22
- title,
23
- },
24
- };
25
- }
@@ -1,7 +0,0 @@
1
- import type { MovieDetails } from "./types";
2
-
3
- export function filterMovieData(movie: MovieDetails & Record<string, unknown>): MovieDetails {
4
- const { id, title, release_date, director, producer } = movie;
5
- movie = { id, title, release_date, director, producer };
6
- return movie;
7
- }
@@ -1,77 +0,0 @@
1
- import fetch from "cross-fetch";
2
- //import { filterMovieData } from '../filterMovieData'
3
- import type { Movie, MovieDetails } from "../types";
4
-
5
- export default async function onBeforeRender() {
6
- const movies = await getStarWarsMovies();
7
- return {
8
- pageContext: {
9
- pageProps: {
10
- // We remove data we don't need because we pass `pageContext.movies` to
11
- // the client; we want to minimize what is sent over the network.
12
- movies: filterMoviesData(movies),
13
- },
14
- // The page's <title>
15
- title: getTitle(movies),
16
- },
17
- };
18
- }
19
-
20
- async function getStarWarsMovies(): Promise<MovieDetails[]> {
21
- const response = await fetch("https://star-wars.brillout.com/api/films.json");
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- let movies: MovieDetails[] = ((await response.json()) as any).results;
24
- movies = movies.map((movie: MovieDetails, i: number) => ({
25
- ...movie,
26
- id: String(i + 1),
27
- }));
28
- return movies;
29
- }
30
-
31
- function filterMoviesData(movies: MovieDetails[]): Movie[] {
32
- return movies.map((movie: MovieDetails) => {
33
- const { title, release_date, id } = movie;
34
- return { title, release_date, id };
35
- });
36
- }
37
-
38
- /*
39
- async function prerender() {
40
- const movies = await getStarWarsMovies()
41
- return [
42
- {
43
- url: '/star-wars',
44
- // We already provide `pageContext` here so that Vike
45
- // will *not* have to call the `onBeforeRender()` hook defined
46
- // above in this file.
47
- pageContext: {
48
- pageProps: {
49
- movies: filterMoviesData(movies)
50
- },
51
- documentProps: { title: getTitle(movies) }
52
- }
53
- },
54
- ...movies.map((movie) => {
55
- const url = `/star-wars/${movie.id}`
56
- return {
57
- url,
58
- // Note that we can also provide the `pageContext` of other pages.
59
- // This means that Vike will not call any
60
- // `onBeforeRender()` hook and the Star Wars API will be called
61
- // only once (in this `prerender()` hook).
62
- pageContext: {
63
- pageProps: {
64
- movie: filterMovieData(movie)
65
- },
66
- documentProps: { title: movie.title }
67
- }
68
- }
69
- })
70
- ]
71
- }
72
- */
73
-
74
- function getTitle(movies: Movie[] | MovieDetails[]): string {
75
- const title = `${movies.length} Star Wars Movies`;
76
- return title;
77
- }
@@ -1,10 +0,0 @@
1
- import type { PageContextBuiltInServer } from "vike/types";
2
- import type { MovieDetails } from "../types";
3
- export default function onBeforeRender(pageContext: PageContextBuiltInServer): Promise<{
4
- pageContext: {
5
- pageProps: {
6
- movie: MovieDetails;
7
- };
8
- title: string;
9
- };
10
- }>;
@@ -1,2 +0,0 @@
1
- import type { MovieDetails } from "./types";
2
- export declare function filterMovieData(movie: MovieDetails & Record<string, unknown>): MovieDetails;
@@ -1,9 +0,0 @@
1
- import type { Movie } from "../types";
2
- export default function onBeforeRender(): Promise<{
3
- pageContext: {
4
- pageProps: {
5
- movies: Movie[];
6
- };
7
- title: string;
8
- };
9
- }>;
@@ -1,13 +0,0 @@
1
- // https://vike.dev/onBeforeRender
2
- import { todoItems } from "@batijs/shared-db/database/todoItems";
3
-
4
- export default function onBeforeRender() {
5
- const todoItemsInitial = todoItems;
6
- return {
7
- pageContext: {
8
- pageProps: {
9
- todoItemsInitial,
10
- },
11
- },
12
- };
13
- }
@@ -1,7 +0,0 @@
1
- export default function onBeforeRender(): {
2
- pageContext: {
3
- pageProps: {
4
- todoItemsInitial: import("@batijs/shared-db/database/todoItems").TodoItem[];
5
- };
6
- };
7
- };
@@ -1,13 +0,0 @@
1
- // https://vike.dev/onBeforeRender
2
- import { todoItems } from "@batijs/shared-db/database/todoItems";
3
-
4
- export default function onBeforeRender() {
5
- const todoItemsInitial = todoItems;
6
- return {
7
- pageContext: {
8
- pageProps: {
9
- todoItemsInitial,
10
- },
11
- },
12
- };
13
- }
@@ -1,7 +0,0 @@
1
- export default function onBeforeRender(): {
2
- pageContext: {
3
- pageProps: {
4
- todoItemsInitial: import("@batijs/shared-db/database/todoItems").TodoItem[];
5
- };
6
- };
7
- };