@batijs/cli 0.0.176 → 0.0.177

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 (23) hide show
  1. package/dist/boilerplates/@batijs/auth0/files/$.env.js +19 -0
  2. package/dist/boilerplates/@batijs/auth0/files/$README.md.js +43 -0
  3. package/dist/boilerplates/@batijs/auth0/files/vike.d.ts +11 -0
  4. package/dist/boilerplates/@batijs/express/files/$package.json.js +6 -2
  5. package/dist/boilerplates/@batijs/express/files/express-entry.ts +33 -11
  6. package/dist/boilerplates/@batijs/express/files/vike.d.ts +10 -0
  7. package/dist/boilerplates/@batijs/express/types/express-entry.d.ts +1 -1
  8. package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +0 -6
  9. package/dist/boilerplates/@batijs/firebase-auth/files/firebase/$service-account.json.js +20 -0
  10. package/dist/boilerplates/@batijs/firebase-auth/files/pages/+firebaseApp.ts +2 -1
  11. package/dist/boilerplates/@batijs/firebase-auth/files/{types.ts → vike.d.ts} +0 -9
  12. package/dist/boilerplates/@batijs/h3/files/$package.json.js +10 -2
  13. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +37 -16
  14. package/dist/boilerplates/@batijs/h3/files/vike.d.ts +22 -0
  15. package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +1 -6
  16. package/dist/boilerplates/@batijs/react/files/pages/+config.ts +1 -1
  17. package/dist/boilerplates/@batijs/solid/files/pages/+config.ts +1 -1
  18. package/dist/boilerplates/@batijs/vue/files/pages/+config.ts +1 -1
  19. package/dist/boilerplates/boilerplates.json +11 -0
  20. package/dist/index.js +54 -14
  21. package/package.json +5 -5
  22. package/dist/boilerplates/@batijs/firebase-auth/files/firebase/service-account-example.json +0 -13
  23. package/dist/boilerplates/@batijs/firebase-auth/types/types.d.ts +0 -18
@@ -0,0 +1,19 @@
1
+ // files/$.env.ts
2
+ import { appendToEnv, randomBytes } from "@batijs/core";
3
+ async function getEnv(props) {
4
+ const auth0ClientId = process.env.TEST_AUTH0_CLIENT_ID;
5
+ const auth0BaseUrl = process.env.TEST_AUTH0_ISSUER_BASE_URL;
6
+ let envContent = await props.readfile?.();
7
+ envContent = appendToEnv(
8
+ envContent,
9
+ "SECRET",
10
+ randomBytes(32).toString("hex"),
11
+ "Randomly generated by Bati CLI, used by Auth0"
12
+ );
13
+ envContent = appendToEnv(envContent, "CLIENT_ID", auth0ClientId ?? "", "Auth0 Client ID");
14
+ envContent = appendToEnv(envContent, "ISSUER_BASE_URL", auth0BaseUrl ?? "", "Auth0 base URL");
15
+ return envContent;
16
+ }
17
+ export {
18
+ getEnv as default
19
+ };
@@ -0,0 +1,43 @@
1
+ // files/$README.md.ts
2
+ import { loadReadme } from "@batijs/core";
3
+ async function getReadme(props) {
4
+ const content = await loadReadme(props);
5
+ const todo = `
6
+ ## *Auth0*
7
+ - Sign up or login to an Auth0 account, then go to [your Dashboard](https://manage.auth0.com/dashboard/)
8
+ - Create Application -> Regular Web Application
9
+ - What technology are you using for your project? -> Node.js (Express) -> Integrate Now
10
+ - Configure Auth0:
11
+ - Allowed Callback URL: http://localhost:3000/api/auth/callback
12
+ - Allowed Logout URLs: http://localhost:3000
13
+ - Save Changes
14
+ - Copy your \`clientID\` and \`issuerBaseURL\` and paste it in \`.env\` file like this:
15
+
16
+ \`\`\`env
17
+ // .env
18
+ SECRET=<random string>
19
+ CLIENT_ID=<Client ID>
20
+ ISSUER_BASE_URL=https://<your-auth0-domain>.<eu>.auth0.com
21
+ \`\`\`
22
+
23
+ > [!NOTE]
24
+ > Environment variables that are automatically made available to Auth0 :
25
+ > - \`SECRET\`
26
+ > - \`ISSUER_BASE_URL\`
27
+ > - \`BASE_URL\`
28
+ > - \`CLIENT_ID\`
29
+ > - \`CLIENT_SECRET\`
30
+
31
+ > [!NOTE]
32
+ > Login route is \`http://localhost:3000/api/auth/login\`.
33
+ > Logout route is \`http://localhost:3000/api/auth/logout\`.
34
+
35
+ - Read more [Auth0 Express SDK Quickstarts: Login](https://auth0.com/docs/quickstart/webapp/express)
36
+ - Read more [Auth0 Express SDK Quickstarts: Add Login to your Express App](https://auth0.com/docs/quickstart/webapp/express/interactive)
37
+ `;
38
+ content.addTodo(todo);
39
+ return content.finalize();
40
+ }
41
+ export {
42
+ getReadme as default
43
+ };
@@ -0,0 +1,11 @@
1
+ import type { RequestContext } from "express-openid-connect";
2
+
3
+ declare global {
4
+ namespace Vike {
5
+ interface PageContext {
6
+ user?: RequestContext["user"] | null;
7
+ }
8
+ }
9
+ }
10
+
11
+ export {};
@@ -51,7 +51,9 @@ var require_package = __commonJS({
51
51
  "@types/express": "^4.17.21",
52
52
  "@types/node": "^18.19.14",
53
53
  "cookie-parser": "^1.4.6",
54
+ dotenv: "^16.4.5",
54
55
  express: "^4.19.2",
56
+ "express-openid-connect": "^2.17.1",
55
57
  "firebase-admin": "^12.0.0",
56
58
  telefunc: "^0.1.71",
57
59
  tsx: "^4.7.2",
@@ -109,7 +111,8 @@ async function getPackageJson(props) {
109
111
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
110
112
  devDependencies: [
111
113
  "@types/express",
112
- ...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : []
114
+ ...props.meta.BATI.has("firebase-auth") ? ["@types/cookie-parser"] : [],
115
+ ...props.meta.BATI.has("auth0") ? ["dotenv"] : []
113
116
  ],
114
117
  dependencies: [
115
118
  "@hattip/adapter-node",
@@ -118,7 +121,8 @@ async function getPackageJson(props) {
118
121
  "vite",
119
122
  "vike",
120
123
  ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : [],
121
- ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : []
124
+ ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : [],
125
+ ...props.meta.BATI.has("auth0") ? ["express-openid-connect"] : []
122
126
  ]
123
127
  });
124
128
  }
@@ -1,3 +1,5 @@
1
+ // BATI.has("auth0")
2
+ import "dotenv/config";
1
3
  import { dirname } from "node:path";
2
4
  import { fileURLToPath } from "node:url";
3
5
  import CredentialsProvider from "@auth/core/providers/credentials";
@@ -7,6 +9,7 @@ import { createMiddleware } from "@hattip/adapter-node";
7
9
  import * as trpcExpress from "@trpc/server/adapters/express";
8
10
  import cookieParser from "cookie-parser";
9
11
  import express, { type Request } from "express";
12
+ import { auth, type ConfigParams } from "express-openid-connect";
10
13
  import { getAuth } from "firebase-admin/auth";
11
14
  import { telefunc } from "telefunc";
12
15
  import { VikeAuth } from "vike-authjs";
@@ -16,6 +19,8 @@ const __filename = fileURLToPath(import.meta.url);
16
19
  const __dirname = dirname(__filename);
17
20
  const isProduction = process.env.NODE_ENV === "production";
18
21
  const root = __dirname;
22
+ const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
23
+ const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
19
24
 
20
25
  startServer();
21
26
 
@@ -32,7 +37,7 @@ async function startServer() {
32
37
  const viteDevMiddleware = (
33
38
  await vite.createServer({
34
39
  root,
35
- server: { middlewareMode: true },
40
+ server: { middlewareMode: true, hmr: { port: hmrPort } },
36
41
  })
37
42
  ).middlewares;
38
43
  app.use(viteDevMiddleware);
@@ -88,7 +93,7 @@ async function startServer() {
88
93
  const user = await auth.getUser(decodedIdToken.sub);
89
94
  req.user = user;
90
95
  } catch (error) {
91
- console.error("verifySessionCookie:", error);
96
+ console.debug("verifySessionCookie:", error);
92
97
  req.user = null;
93
98
  }
94
99
 
@@ -123,6 +128,21 @@ async function startServer() {
123
128
  });
124
129
  }
125
130
 
131
+ if (BATI.has("auth0")) {
132
+ const config: ConfigParams = {
133
+ authRequired: false, // Controls whether authentication is required for all routes
134
+ auth0Logout: true, // Uses Auth0 logout feature
135
+ baseURL: process.env.BASE_URL?.startsWith("http") ? process.env.BASE_URL : `http://localhost:${port}`, // The URL where the application is served
136
+ routes: {
137
+ login: "/api/auth/login", // Custom login route, default is : "/login"
138
+ logout: "/api/auth/logout", // Custom logout route, default is : "/logout"
139
+ callback: "/api/auth/callback", // Custom callback route, default is "/callback"
140
+ },
141
+ };
142
+
143
+ app.use(auth(config));
144
+ }
145
+
126
146
  if (BATI.has("trpc")) {
127
147
  /**
128
148
  * tRPC route
@@ -177,24 +197,26 @@ async function startServer() {
177
197
  * @link {@see https://vike.dev}
178
198
  **/
179
199
  app.all("*", async (req: Request, res, next) => {
180
- const pageContextInit = BATI.has("firebase-auth")
181
- ? { urlOriginal: req.originalUrl, user: req.user }
182
- : { urlOriginal: req.originalUrl };
200
+ const pageContextInit = BATI.has("auth0")
201
+ ? { urlOriginal: req.originalUrl, user: req.oidc.user }
202
+ : BATI.has("firebase-auth")
203
+ ? { urlOriginal: req.originalUrl, user: req.user }
204
+ : { urlOriginal: req.originalUrl };
183
205
 
184
206
  const pageContext = await renderPage(pageContextInit);
185
- const { httpResponse } = pageContext
207
+ const { httpResponse } = pageContext;
186
208
 
187
209
  if (!httpResponse) {
188
- return next()
210
+ return next();
189
211
  } else {
190
212
  const { statusCode, headers } = httpResponse;
191
- headers.forEach(([name, value]) => res.setHeader(name, value))
192
- res.status(statusCode)
213
+ headers.forEach(([name, value]) => res.setHeader(name, value));
214
+ res.status(statusCode);
193
215
  httpResponse.pipe(res);
194
216
  }
195
217
  });
196
218
 
197
- app.listen(process.env.PORT ? parseInt(process.env.PORT) : 3000, () => {
198
- console.log("Server listening on http://localhost:3000");
219
+ app.listen(port, () => {
220
+ console.log(`Server listening on http://localhost:${port}`);
199
221
  });
200
222
  }
@@ -0,0 +1,10 @@
1
+ import type { UserRecord } from "firebase-admin/auth";
2
+
3
+ //# BATI.has("firebase-auth")
4
+ declare module "express" {
5
+ interface Request {
6
+ user?: UserRecord | null;
7
+ }
8
+ }
9
+
10
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ import "dotenv/config";
@@ -62,9 +62,6 @@ var require_package = __commonJS({
62
62
  }
63
63
  },
64
64
  exports: {
65
- "./types": {
66
- types: "./dist/types/types.d.ts"
67
- },
68
65
  "./libs/firebaseAdmin": {
69
66
  types: "./dist/types/libs/firebaseAdmin.d.ts"
70
67
  },
@@ -83,9 +80,6 @@ var require_package = __commonJS({
83
80
  },
84
81
  typesVersions: {
85
82
  "*": {
86
- types: [
87
- "./dist/types/types.d.ts"
88
- ],
89
83
  "libs/firebaseAdmin": [
90
84
  "./dist/types/libs/firebaseAdmin.d.ts"
91
85
  ],
@@ -0,0 +1,20 @@
1
+ // files/firebase/$service-account.json.ts
2
+ async function getPackageJson() {
3
+ const firebaseAccountStringified = process.env.TEST_FIREBASE_ACCOUNT;
4
+ return firebaseAccountStringified ? JSON.parse(firebaseAccountStringified) : {
5
+ type: "",
6
+ project_id: "",
7
+ private_key_id: "",
8
+ private_key: "",
9
+ client_email: "",
10
+ client_id: "",
11
+ auth_uri: "",
12
+ token_uri: "",
13
+ auth_provider_x509_cert_url: "",
14
+ client_x509_cert_url: "",
15
+ universe_domain: ""
16
+ };
17
+ }
18
+ export {
19
+ getPackageJson as default
20
+ };
@@ -2,7 +2,8 @@
2
2
  import { deleteApp, getApp, getApps, initializeApp, type FirebaseApp } from "firebase/app";
3
3
  import { getAuth, inMemoryPersistence } from "firebase/auth";
4
4
 
5
- // Your web app's Firebase configuration
5
+ // TODO: Fill your web app's Firebase configuration
6
+ // See https://firebase.google.com/docs/web/learn-more?hl=fr#config-object
6
7
  const firebaseConfig = {
7
8
  apiKey: "",
8
9
  authDomain: "",
@@ -2,14 +2,6 @@ import type { UserRecord } from "firebase-admin/auth";
2
2
  import type { FirebaseApp } from "firebase/app";
3
3
 
4
4
  declare global {
5
- /*{ @if (it.BATI.has("express")) }*/
6
- // eslint-disable-next-line
7
- namespace Express {
8
- interface Request {
9
- user?: UserRecord | null;
10
- }
11
- }
12
- /*{ /if }*/
13
5
  // eslint-disable-next-line
14
6
  namespace Vike {
15
7
  interface PageContext {
@@ -21,5 +13,4 @@ declare global {
21
13
  }
22
14
  }
23
15
 
24
- // Tell TypeScript that this file isn't an ambient module
25
16
  export {};
@@ -47,8 +47,12 @@ var require_package = __commonJS({
47
47
  "@batijs/trpc": "workspace:^",
48
48
  "@hattip/polyfills": "^0.0.45",
49
49
  "@trpc/server": "^10.45.2",
50
+ "@types/express": "^4.17.21",
50
51
  "@types/node": "^18.19.14",
51
52
  "@types/serve-static": "^1.15.7",
53
+ dotenv: "^16.4.5",
54
+ express: "^4.19.2",
55
+ "express-openid-connect": "^2.17.1",
52
56
  "firebase-admin": "^12.0.0",
53
57
  h3: "~1.11.1",
54
58
  "serve-static": "^1.15.0",
@@ -106,7 +110,10 @@ async function getPackageJson(props) {
106
110
  }
107
111
  });
108
112
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)), {
109
- devDependencies: ["@types/serve-static"],
113
+ devDependencies: [
114
+ "@types/serve-static",
115
+ ...props.meta.BATI.has("auth0") ? ["@types/express", "dotenv"] : []
116
+ ],
110
117
  dependencies: [
111
118
  "@hattip/polyfills",
112
119
  "h3",
@@ -114,7 +121,8 @@ async function getPackageJson(props) {
114
121
  "tsx",
115
122
  "vike",
116
123
  "vite",
117
- ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : []
124
+ ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : [],
125
+ ...props.meta.BATI.has("auth0") ? ["express", "express-openid-connect"] : []
118
126
  ]
119
127
  });
120
128
  }
@@ -1,3 +1,5 @@
1
+ // BATI.has("auth0")
2
+ import "dotenv/config";
1
3
  import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
2
4
  import { dirname } from "node:path";
3
5
  import { fileURLToPath } from "node:url";
@@ -8,7 +10,9 @@ import installCrypto from "@hattip/polyfills/crypto";
8
10
  import installGetSetCookie from "@hattip/polyfills/get-set-cookie";
9
11
  import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
10
12
  import { nodeHTTPRequestHandler, type NodeHTTPCreateContextFnOptions } from "@trpc/server/adapters/node-http";
11
- import { getAuth, type UserRecord } from "firebase-admin/auth";
13
+ import express from "express";
14
+ import { auth, type ConfigParams } from "express-openid-connect";
15
+ import { getAuth } from "firebase-admin/auth";
12
16
  import {
13
17
  createApp,
14
18
  createRouter,
@@ -38,14 +42,8 @@ const __filename = fileURLToPath(import.meta.url);
38
42
  const __dirname = dirname(__filename);
39
43
  const isProduction = process.env.NODE_ENV === "production";
40
44
  const root = __dirname;
41
-
42
- /*{ @if (it.BATI.has("firebase-auth")) }*/
43
- declare module "h3" {
44
- interface H3EventContext {
45
- user: UserRecord | null;
46
- }
47
- }
48
- /*{ /if }*/
45
+ const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
46
+ const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
49
47
 
50
48
  startServer();
51
49
 
@@ -62,7 +60,7 @@ async function startServer() {
62
60
  const viteDevMiddleware = (
63
61
  await vite.createServer({
64
62
  root,
65
- server: { middlewareMode: true },
63
+ server: { middlewareMode: true, hmr: { port: hmrPort } },
66
64
  })
67
65
  ).middlewares;
68
66
  app.use(fromNodeMiddleware(viteDevMiddleware));
@@ -122,7 +120,7 @@ async function startServer() {
122
120
  const user = await auth.getUser(decodedIdToken.sub);
123
121
  event.context.user = user;
124
122
  } catch (error) {
125
- console.error("verifySessionCookie:", error);
123
+ console.debug("verifySessionCookie:", error);
126
124
  event.context.user = null;
127
125
  }
128
126
  }
@@ -176,6 +174,23 @@ async function startServer() {
176
174
  );
177
175
  }
178
176
 
177
+ if (BATI.has("auth0")) {
178
+ const config: ConfigParams = {
179
+ authRequired: false, // Controls whether authentication is required for all routes
180
+ auth0Logout: true, // Uses Auth0 logout feature
181
+ baseURL: process.env.BASE_URL?.startsWith("http") ? process.env.BASE_URL : `http://localhost:${port}`, // The URL where the application is served
182
+ routes: {
183
+ login: "/api/auth/login", // Custom login route, default is "/login"
184
+ logout: "/api/auth/logout", // Custom logout route, default is "/logout"
185
+ callback: "/api/auth/callback", // Custom callback route, default is "/callback"
186
+ },
187
+ };
188
+
189
+ const expressApp = express();
190
+
191
+ app.use(fromNodeMiddleware(expressApp.use(auth(config))));
192
+ }
193
+
179
194
  if (BATI.has("trpc")) {
180
195
  /**
181
196
  * tRPC route
@@ -234,12 +249,18 @@ async function startServer() {
234
249
  router.use(
235
250
  "/**",
236
251
  eventHandler(async (event) => {
237
- const pageContextInit = BATI.has("firebase-auth")
252
+ const pageContextInit = BATI.has("auth0")
238
253
  ? {
239
254
  urlOriginal: event.node.req.originalUrl || event.node.req.url!,
240
- user: event.context.user,
255
+ user: event.node.req.oidc.user,
241
256
  }
242
- : { urlOriginal: event.node.req.originalUrl || event.node.req.url! };
257
+ : BATI.has("firebase-auth")
258
+ ? {
259
+ urlOriginal: event.node.req.originalUrl || event.node.req.url!,
260
+ user: event.context.user,
261
+ }
262
+ : { urlOriginal: event.node.req.originalUrl || event.node.req.url! };
263
+
243
264
  const pageContext = await renderPage(pageContextInit);
244
265
  const response = pageContext.httpResponse;
245
266
 
@@ -252,9 +273,9 @@ async function startServer() {
252
273
 
253
274
  app.use(router);
254
275
 
255
- const server = createServer(toNodeListener(app)).listen(process.env.PORT || 3000);
276
+ const server = createServer(toNodeListener(app)).listen(port);
256
277
 
257
278
  server.on("listening", () => {
258
- console.log(`Server listening on http://localhost:${process.env.PORT || 3000}`);
279
+ console.log(`Server listening on http://localhost:${port}`);
259
280
  });
260
281
  }
@@ -0,0 +1,22 @@
1
+ import type { RequestContext, ResponseContext } from "express-openid-connect";
2
+ import type { UserRecord } from "firebase-admin/auth";
3
+
4
+ //# BATI.has("auth0")
5
+ declare module "node:http" {
6
+ interface IncomingMessage {
7
+ oidc: RequestContext;
8
+ }
9
+
10
+ interface ServerResponse {
11
+ oidc: ResponseContext;
12
+ }
13
+ }
14
+
15
+ //# BATI.has("firebase-auth")
16
+ declare module "h3" {
17
+ interface H3EventContext {
18
+ user: UserRecord | null;
19
+ }
20
+ }
21
+
22
+ export {};
@@ -1,6 +1 @@
1
- import { type UserRecord } from "firebase-admin/auth";
2
- declare module "h3" {
3
- interface H3EventContext {
4
- user: UserRecord | null;
5
- }
6
- }
1
+ import "dotenv/config";
@@ -7,7 +7,7 @@ import Layout from "../layouts/LayoutDefault";
7
7
  export default {
8
8
  Layout,
9
9
  Head,
10
- /*{ @if (it.BATI.has("firebase-auth")) }*/
10
+ /*{ @if (it.BATI.has("auth0") || it.BATI.has("firebase-auth")) }*/
11
11
  passToClient: ["user"],
12
12
  /*{ /if }*/
13
13
  // <title>
@@ -8,7 +8,7 @@ export default {
8
8
  Layout,
9
9
  Head,
10
10
  // <title>
11
- /*{ @if (it.BATI.has("firebase-auth")) }*/
11
+ /*{ @if (it.BATI.has("auth0") || it.BATI.has("firebase-auth")) }*/
12
12
  passToClient: ["user"],
13
13
  /*{ /if }*/
14
14
  title: "My Vike App",
@@ -8,7 +8,7 @@ export default {
8
8
  Layout,
9
9
  Head,
10
10
  // <title>
11
- /*{ @if (it.BATI.has("firebase-auth")) }*/
11
+ /*{ @if (it.BATI.has("auth0") || it.BATI.has("firebase-auth")) }*/
12
12
  passToClient: ["user"],
13
13
  /*{ /if }*/
14
14
  title: "My Vike App",
@@ -1,4 +1,15 @@
1
1
  [
2
+ {
3
+ "config": {
4
+ "if": {
5
+ "flag": "auth0"
6
+ }
7
+ },
8
+ "folder": "@batijs/auth0",
9
+ "subfolders": [
10
+ "files"
11
+ ]
12
+ },
2
13
  {
3
14
  "config": {
4
15
  "if": {
package/dist/index.js CHANGED
@@ -457,9 +457,40 @@ async function runMain(cmd, opts = {}) {
457
457
 
458
458
  // ../build/dist/index.js
459
459
  import { existsSync } from "fs";
460
- import { mkdir, opendir, readFile, writeFile } from "fs/promises";
460
+ import { mkdir, opendir, readFile as readFile2, writeFile } from "fs/promises";
461
461
  import path from "path";
462
- import { transformAndFormat } from "@batijs/core";
462
+ import { transformAndFormat as transformAndFormat2 } from "@batijs/core";
463
+ import { readFile } from "fs/promises";
464
+ import { parseModule, transformAndFormat } from "@batijs/core";
465
+ async function mergeDts({
466
+ target,
467
+ fileContent,
468
+ filepath,
469
+ meta
470
+ }) {
471
+ const previousCode = await readFile(target, { encoding: "utf-8" });
472
+ const previousAst = parseModule(previousCode);
473
+ const currentAst = parseModule(fileContent);
474
+ for (const imp of previousAst.imports.$items) {
475
+ currentAst.imports[imp.local] = imp;
476
+ }
477
+ const index = currentAst.$ast.body.findIndex(
478
+ (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration"
479
+ );
480
+ for (const node of previousAst.$ast.body) {
481
+ if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration") {
482
+ continue;
483
+ }
484
+ if (index === -1) {
485
+ currentAst.$ast.body.push(node);
486
+ } else {
487
+ currentAst.$ast.body.splice(index, 0, node);
488
+ }
489
+ }
490
+ return transformAndFormat(currentAst.generate().code, meta, {
491
+ filepath
492
+ });
493
+ }
463
494
  function queue() {
464
495
  const tasks = [];
465
496
  return {
@@ -535,7 +566,7 @@ async function importTransformer(p) {
535
566
  async function main(options, meta) {
536
567
  const sources = Array.isArray(options.source) ? options.source : [options.source];
537
568
  const targets = /* @__PURE__ */ new Set();
538
- const simpleCopyQ = queue();
569
+ const priorityQ = queue();
539
570
  const transformAndWriteQ = queue();
540
571
  for (const source of sources) {
541
572
  for await (const p of walk(source)) {
@@ -546,13 +577,13 @@ async function main(options, meta) {
546
577
  } else if (parsed.name.startsWith("$") && parsed.ext.match(/\.tsx?$/)) {
547
578
  throw new Error(
548
579
  `Typescript file needs to be compiled before it can be executed: '${p}'.
549
- Please report this issue to https://github.com/magne4000/bati`
580
+ Please report this issue to https://github.com/batijs/bati`
550
581
  );
551
582
  } else if (parsed.name.startsWith("$") && parsed.ext.match(/\.jsx?$/)) {
552
583
  transformAndWriteQ.add(async () => {
553
584
  const transformer = await importTransformer(p);
554
585
  const rf = () => {
555
- return readFile(target, { encoding: "utf-8" });
586
+ return readFile2(target, { encoding: "utf-8" });
556
587
  };
557
588
  const fileContent = transformFileAfterExec(
558
589
  target,
@@ -569,27 +600,36 @@ Please report this issue to https://github.com/magne4000/bati`
569
600
  }
570
601
  });
571
602
  } else {
572
- transformAndWriteQ.add(async () => {
573
- const code = await readFile(p, { encoding: "utf-8" });
574
- const fileContent = await transformAndFormat(code, meta, {
575
- filepath: path.relative(source, p)
603
+ priorityQ.add(async () => {
604
+ const code = await readFile2(p, { encoding: "utf-8" });
605
+ const filepath = path.relative(source, p);
606
+ let fileContent = await transformAndFormat2(code, meta, {
607
+ filepath
576
608
  });
609
+ if (p.endsWith(".d.ts") && targets.has(target)) {
610
+ fileContent = await mergeDts({
611
+ fileContent,
612
+ target,
613
+ meta,
614
+ filepath
615
+ });
616
+ }
577
617
  if (fileContent) {
578
- await safeWriteFile(target, fileContent);
618
+ await safeWriteFile(target, fileContent.trimStart());
579
619
  targets.add(target);
580
620
  }
581
621
  });
582
622
  }
583
623
  }
584
624
  }
585
- await simpleCopyQ.run();
625
+ await priorityQ.run();
586
626
  await transformAndWriteQ.run();
587
627
  }
588
628
 
589
629
  // package.json
590
630
  var package_default = {
591
631
  name: "@batijs/cli",
592
- version: "0.0.176",
632
+ version: "0.0.177",
593
633
  type: "module",
594
634
  scripts: {
595
635
  "check-types": "tsc --noEmit",
@@ -637,7 +677,7 @@ import { execRules } from "@batijs/features/rules";
637
677
  import { existsSync as existsSync2 } from "fs";
638
678
  import { fileURLToPath } from "url";
639
679
  import { dirname, join, parse } from "path";
640
- import { access, constants, lstat, readdir, readFile as readFile2 } from "fs/promises";
680
+ import { access, constants, lstat, readdir, readFile as readFile3 } from "fs/promises";
641
681
 
642
682
  // ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
643
683
  import * as tty from "tty";
@@ -1575,7 +1615,7 @@ function boilerplatesDir() {
1575
1615
  throw new Error("Missing boilerplates.json file. Run `pnpm run build`");
1576
1616
  }
1577
1617
  async function parseBoilerplates(dir) {
1578
- return JSON.parse(await readFile2(join(dir, "boilerplates.json"), "utf-8"));
1618
+ return JSON.parse(await readFile3(join(dir, "boilerplates.json"), "utf-8"));
1579
1619
  }
1580
1620
  function toArg(flag, description) {
1581
1621
  if (!flag)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/cli",
3
- "version": "0.0.176",
3
+ "version": "0.0.177",
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.2",
20
20
  "typescript": "^5.4.5",
21
21
  "vite": "^5.2.8",
22
- "@batijs/build": "0.0.176",
23
- "@batijs/compile": "0.0.176"
22
+ "@batijs/build": "0.0.177",
23
+ "@batijs/compile": "0.0.177"
24
24
  },
25
25
  "dependencies": {
26
- "@batijs/core": "0.0.176",
27
- "@batijs/features": "0.0.176"
26
+ "@batijs/core": "0.0.177",
27
+ "@batijs/features": "0.0.177"
28
28
  },
29
29
  "bin": "./dist/index.js",
30
30
  "exports": {
@@ -1,13 +0,0 @@
1
- {
2
- "type": "",
3
- "project_id": "",
4
- "private_key_id": "",
5
- "private_key": "",
6
- "client_email": "",
7
- "client_id": "",
8
- "auth_uri": "",
9
- "token_uri": "",
10
- "auth_provider_x509_cert_url": "",
11
- "client_x509_cert_url": "",
12
- "universe_domain": ""
13
- }
@@ -1,18 +0,0 @@
1
- import type { UserRecord } from "firebase-admin/auth";
2
- import type { FirebaseApp } from "firebase/app";
3
- declare global {
4
- namespace Express {
5
- interface Request {
6
- user?: UserRecord | null;
7
- }
8
- }
9
- namespace Vike {
10
- interface PageContext {
11
- user?: UserRecord | null;
12
- }
13
- interface Config {
14
- firebaseApp?: FirebaseApp;
15
- }
16
- }
17
- }
18
- export {};