create-baeta 2.0.0-next.2 → 2.0.0-next.8

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.
@@ -0,0 +1,832 @@
1
+ import { logger } from "@docusaurus/logger";
2
+ import path from "node:path";
3
+ import shell from "shelljs";
4
+ import supportsColor from "supports-color";
5
+ import fs from "fs-extra";
6
+ import prompts from "prompts";
7
+
8
+ //#region lib/constants.ts
9
+ const defaultPackageManager = "npm";
10
+ const lockfileNames = {
11
+ npm: "package-lock.json",
12
+ yarn: "yarn.lock",
13
+ pnpm: "pnpm-lock.yaml",
14
+ bun: "bun.lockb"
15
+ };
16
+ const packageManagers = Object.keys(lockfileNames);
17
+ const runtimes = [
18
+ "node",
19
+ "deno",
20
+ "bun"
21
+ ];
22
+ const defaultJavaScriptRuntime = "node";
23
+ const templates = ["yoga", "apollo"];
24
+
25
+ //#endregion
26
+ //#region lib/app-name.ts
27
+ async function getAppName(reqName, rootDir) {
28
+ async function validateAppName(appName) {
29
+ if (!appName) return "An app name is required.";
30
+ const dest = path.resolve(rootDir, appName);
31
+ if (await fs.pathExists(dest)) return logger.interpolate`Directory already exists at path=${dest}!`;
32
+ return true;
33
+ }
34
+ if (reqName) {
35
+ const res = await validateAppName(reqName);
36
+ if (typeof res === "string") throw new TypeError(res);
37
+ return reqName;
38
+ }
39
+ return prompts({
40
+ type: "text",
41
+ name: "appName",
42
+ message: "What should we name this app?",
43
+ initial: "baeta-app",
44
+ validate: validateAppName
45
+ }, { onCancel() {
46
+ logger.error("An app name is required.");
47
+ process.exit(1);
48
+ } }).then((result) => result.appName);
49
+ }
50
+
51
+ //#endregion
52
+ //#region lib/package-manager.ts
53
+ async function findPackageManagerFromLockFile(rootDir) {
54
+ for (const packageManager of packageManagers) {
55
+ const lockFilePath = path.join(rootDir, lockfileNames[packageManager]);
56
+ if (await fs.pathExists(lockFilePath)) return packageManager;
57
+ }
58
+ }
59
+ function findPackageManagerFromUserAgent() {
60
+ return packageManagers.find((packageManager) => process.env.npm_config_user_agent?.startsWith(packageManager));
61
+ }
62
+ async function askForPackageManagerChoice() {
63
+ const hasYarn = shell.exec("yarn --version", { silent: true }).code === 0;
64
+ const hasPnpm = shell.exec("pnpm --version", { silent: true }).code === 0;
65
+ const hasBun = shell.exec("bun --version", { silent: true }).code === 0;
66
+ if (!hasYarn && !hasPnpm && !hasBun) return "npm";
67
+ return await prompts({
68
+ type: "select",
69
+ name: "packageManager",
70
+ message: "Select a package manager...",
71
+ choices: [
72
+ "npm",
73
+ hasYarn && "yarn",
74
+ hasPnpm && "pnpm",
75
+ hasBun && "bun"
76
+ ].filter((p) => p !== false).map((p) => ({
77
+ title: p,
78
+ value: p
79
+ }))
80
+ }, { onCancel() {
81
+ logger.info`Falling back to name=${defaultPackageManager}`;
82
+ } }).then((result) => result.packageManager) ?? defaultPackageManager;
83
+ }
84
+ async function getPackageManager(dest, { packageManager, skipInstall }) {
85
+ if (packageManager && !packageManagers.includes(packageManager)) throw new Error(`Invalid package manager choice ${packageManager}. Must be one of ${packageManagers.join(", ")}`);
86
+ const fromLockfile = await findPackageManagerFromLockFile(dest);
87
+ if (fromLockfile) return fromLockfile;
88
+ if (packageManager) return packageManager;
89
+ const fromLockfileInCwd = await findPackageManagerFromLockFile(".");
90
+ if (fromLockfileInCwd) return fromLockfileInCwd;
91
+ const fromUserAgent = findPackageManagerFromUserAgent();
92
+ if (fromUserAgent) return fromUserAgent;
93
+ if (skipInstall) return defaultPackageManager;
94
+ return askForPackageManagerChoice();
95
+ }
96
+ function getInstallCommand(pkgManager) {
97
+ if (pkgManager === "yarn") return "yarn";
98
+ if (pkgManager === "bun") return "bun install";
99
+ return `${pkgManager} install --color always`;
100
+ }
101
+
102
+ //#endregion
103
+ //#region lib/runtime.ts
104
+ async function getRuntime() {
105
+ const hasBun = shell.exec("bun --version", { silent: true }).code === 0;
106
+ const hasDeno = shell.exec("deno --version", { silent: true }).code === 0;
107
+ if (!hasDeno && !hasBun) return "node";
108
+ return await prompts({
109
+ type: "select",
110
+ name: "runtime",
111
+ message: "Select a runtime...",
112
+ choices: [
113
+ "node",
114
+ hasBun && "bun",
115
+ hasDeno && "deno"
116
+ ].filter((p) => p !== false).map((p) => ({
117
+ title: p,
118
+ value: p
119
+ }))
120
+ }, { onCancel() {
121
+ logger.info`Falling back to name=${defaultJavaScriptRuntime}`;
122
+ } }).then((result) => result.runtime) ?? defaultJavaScriptRuntime;
123
+ }
124
+
125
+ //#endregion
126
+ //#region meta/apollo/package.json
127
+ var package_default$1 = {
128
+ name: "@baeta/template-apollo",
129
+ version: "0.0.0",
130
+ "private": true,
131
+ type: "module",
132
+ scripts: {
133
+ "build": "baeta generate",
134
+ "start": "baeta generate --watch --run='node --watch --enable-source-maps --inspect src/app.ts'"
135
+ },
136
+ dependencies: {
137
+ "@apollo/server": "^5.2.0",
138
+ "@baeta/core": "workspace:^",
139
+ "@baeta/errors": "workspace:^",
140
+ "@baeta/extension-complexity": "workspace:^",
141
+ "graphql": "^16.12.0"
142
+ },
143
+ devDependencies: {
144
+ "@baeta/cli": "workspace:^",
145
+ "@types/bun": "^1.3.3",
146
+ "@types/deno": "^2.5.0",
147
+ "@types/node": "^22.19.1",
148
+ "typescript": "^5.9.3"
149
+ }
150
+ };
151
+
152
+ //#endregion
153
+ //#region ../../tools/tsconfig/tsconfig.json
154
+ var compilerOptions = {
155
+ "target": "es2024",
156
+ "lib": ["es2024"],
157
+ "noEmit": true,
158
+ "types": [],
159
+ "module": "esnext",
160
+ "moduleResolution": "bundler",
161
+ "strict": true,
162
+ "noImplicitAny": true,
163
+ "erasableSyntaxOnly": true,
164
+ "isolatedModules": true,
165
+ "esModuleInterop": true,
166
+ "verbatimModuleSyntax": true,
167
+ "allowImportingTsExtensions": true,
168
+ "allowSyntheticDefaultImports": true,
169
+ "skipLibCheck": true,
170
+ "forceConsistentCasingInFileNames": true
171
+ };
172
+ var tsconfig_default = {
173
+ $schema: "https://json.schemastore.org/tsconfig",
174
+ compilerOptions
175
+ };
176
+
177
+ //#endregion
178
+ //#region versions.json
179
+ var versions_default = {
180
+ "@baeta/cli": "2.0.0-next.8",
181
+ "@baeta/core": "2.0.0-next.8",
182
+ "create-baeta": "2.0.0-next.8",
183
+ "@baeta/directives": "2.0.0-next.8",
184
+ "@baeta/env": "2.0.0-next.8",
185
+ "@baeta/errors": "2.0.0-next.8",
186
+ "@baeta/extension-auth": "2.0.0-next.8",
187
+ "@baeta/extension-cache": "2.0.0-next.8",
188
+ "@baeta/extension-cache-cloudflare": "2.0.0-next.8",
189
+ "@baeta/extension-cache-keyv": "2.0.0-next.8",
190
+ "@baeta/extension-cache-redis": "2.0.0-next.8",
191
+ "@baeta/extension-cache-upstash": "2.0.0-next.8",
192
+ "@baeta/extension-complexity": "2.0.0-next.8",
193
+ "@baeta/generator": "2.0.0-next.3",
194
+ "@baeta/generator-sdk": "2.0.0-next.3",
195
+ "@baeta/plugin": "2.0.0-next.2",
196
+ "@baeta/plugin-cloudflare": "2.0.0-next.8",
197
+ "@baeta/plugin-directives": "2.0.0-next.8",
198
+ "@baeta/plugin-exec": "2.0.0-next.8",
199
+ "@baeta/plugin-gitignore": "2.0.0-next.8",
200
+ "@baeta/plugin-graphql": "2.0.0-next.8",
201
+ "@baeta/plugin-pagination": "2.0.0-next.8",
202
+ "@baeta/plugin-prisma": "2.0.0-next.8",
203
+ "@baeta/subscriptions-cloudflare": "0.2.0-next.2",
204
+ "@baeta/subscriptions-pubsub": "2.0.0-next.8",
205
+ "@baeta/util-encoding": "2.0.0-next.2",
206
+ "@baeta/util-env": "2.0.0-next.2",
207
+ "@baeta/util-log": "2.0.0-next.2",
208
+ "@baeta/util-path": "2.0.0-next.2"
209
+ };
210
+
211
+ //#endregion
212
+ //#region templates/shared.ts
213
+ function makeSharedTemplate(appName, runtime, packageJson) {
214
+ return [
215
+ makePackageJson(appName, runtime, packageJson),
216
+ {
217
+ relativePath: "./tsconfig.json",
218
+ content: JSON.stringify({
219
+ ...tsconfig_default,
220
+ compilerOptions: {
221
+ ...compilerOptions,
222
+ rootDir: "src",
223
+ outDir: "dist",
224
+ noEmit: true,
225
+ emitDeclarationOnly: false
226
+ },
227
+ exclude: ["baeta.ts"]
228
+ }, null, 2)
229
+ },
230
+ {
231
+ relativePath: "./src/modules/extensions.ts",
232
+ content: `import { createExtensions } from '@baeta/core';
233
+ import { complexityExtension } from '@baeta/extension-complexity';
234
+ import type { Context } from '../types/context.ts';
235
+
236
+ const complexity = complexityExtension<Context>({
237
+ defaultComplexity: 1,
238
+ defaultListMultiplier: 10,
239
+ async limit(ctx) {
240
+ return {
241
+ depth: 10,
242
+ breadth: 50,
243
+ complexity: 1000,
244
+ };
245
+ },
246
+ });
247
+
248
+ export default createExtensions({
249
+ complexityExtension: complexity
250
+ });
251
+ `
252
+ },
253
+ {
254
+ relativePath: "./src/modules/user/user.gql",
255
+ content: `type User {
256
+ id: ID!
257
+ email: String!
258
+ lastName: String!
259
+ profile: String
260
+ givenName: String
261
+ }
262
+
263
+ input UserWhereUniqueInput {
264
+ id: ID!
265
+ }
266
+
267
+ type Query {
268
+ user(where: UserWhereUniqueInput!): User
269
+ users: [User!]
270
+ }
271
+ `
272
+ },
273
+ {
274
+ relativePath: "./src/modules/user/index.ts",
275
+ content: `import { UserModule } from './typedef.ts';
276
+
277
+ const { Query, User } = UserModule;
278
+
279
+ const userQuery = Query.user
280
+ .$use(async (next, { args }) => {
281
+ const result = await next();
282
+ console.log('Got user:', result, 'for args:', args);
283
+ return result;
284
+ })
285
+ .resolve(({ args }) => {
286
+ return {
287
+ id: args.where.id,
288
+ email: 'jon.doe@baeta.io',
289
+ lastName: 'Doe',
290
+ givenName: null,
291
+ profile: null,
292
+ };
293
+ });
294
+
295
+ const usersQuery = Query.users.resolve(() => {
296
+ const users = Array.from({ length: 10 }).map((_, i) => ({
297
+ id: i.toString(),
298
+ email: \`jon.doe\${i}@baeta.io\`,
299
+ lastName: \`Doe \${i}\`,
300
+ givenName: null,
301
+ profile: null,
302
+ }));
303
+ return users;
304
+ });
305
+
306
+ export default UserModule.$schema({
307
+ User: User.$fields({
308
+ id: User.id.key('id'),
309
+ email: User.email.key('email'),
310
+ lastName: User.lastName.key('lastName'),
311
+ givenName: User.givenName.key('givenName').undefinedAsNull(),
312
+ profile: User.profile.key('profile').undefinedAsNull(),
313
+ }),
314
+ Query: Query.$fields({
315
+ user: userQuery,
316
+ users: usersQuery,
317
+ }),
318
+ });
319
+ `
320
+ },
321
+ {
322
+ relativePath: "./src/modules/user-photos/user-photos.gql",
323
+ content: `type UserPhoto {
324
+ id: ID!
325
+ userId: ID!
326
+ url: String!
327
+ }
328
+
329
+ extend type User {
330
+ photos: [UserPhoto!]
331
+ }
332
+ `
333
+ },
334
+ {
335
+ relativePath: "./src/modules/user-photos/index.ts",
336
+ content: `import { UserPhotosModule } from './typedef.ts';
337
+
338
+ const { User, UserPhoto } = UserPhotosModule;
339
+
340
+ export default UserPhotosModule.$schema({
341
+ User: User.$fields({
342
+ photos: User.photos.resolve(({ source }) => {
343
+ return Array.from({ length: 10 }).map((_, i) => ({
344
+ id: \`u\${source.id}_p\${i}\`,
345
+ userId: source.id,
346
+ url: \`https://baeta.io/user/\${source.id}/photo/\${i}.png\`,
347
+ }));
348
+ }),
349
+ }),
350
+ UserPhoto: UserPhoto.$fields({
351
+ id: UserPhoto.id.key('id'),
352
+ url: UserPhoto.url.key('url'),
353
+ userId: UserPhoto.userId.key('userId'),
354
+ }),
355
+ });
356
+ `
357
+ },
358
+ {
359
+ relativePath: "./src/modules/types.ts",
360
+ content: `import type { GraphQLResolveInfo } from 'graphql';
361
+ import type { BaseObjectTypes, BaseScalars } from '../__generated__/utility.ts';
362
+ import type { Context } from '../types/context.ts';
363
+
364
+ export interface Scalars extends BaseScalars {}
365
+
366
+ export interface ObjectTypes extends BaseObjectTypes {
367
+ User: {
368
+ id: string;
369
+ email: string;
370
+ lastName: string;
371
+ givenName?: string | null;
372
+ profile?: string | null;
373
+ };
374
+ }
375
+
376
+ export type Ctx = Context;
377
+
378
+ export type Info = GraphQLResolveInfo;
379
+ `
380
+ },
381
+ {
382
+ relativePath: "./baeta.ts",
383
+ content: `import { defineConfig } from '@baeta/cli';
384
+
385
+ export default defineConfig({
386
+ graphql: {
387
+ schemas: ['src/**/*.gql'],
388
+ },
389
+ });
390
+ `
391
+ },
392
+ {
393
+ relativePath: "./.gitignore",
394
+ content: `# Logs
395
+ logs
396
+ *.log
397
+ npm-debug.log*
398
+ yarn-debug.log*
399
+ yarn-error.log*
400
+ lerna-debug.log*
401
+ .pnpm-debug.log*
402
+
403
+ # Diagnostic reports (https://nodejs.org/api/report.html)
404
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
405
+
406
+ # Runtime data
407
+ pids
408
+ *.pid
409
+ *.seed
410
+ *.pid.lock
411
+
412
+ # Directory for instrumented libs generated by jscoverage/JSCover
413
+ lib-cov
414
+
415
+ # Coverage directory used by tools like istanbul
416
+ coverage
417
+ *.lcov
418
+
419
+ # nyc test coverage
420
+ .nyc_output
421
+
422
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
423
+ .grunt
424
+
425
+ # Bower dependency directory (https://bower.io/)
426
+ bower_components
427
+
428
+ # node-waf configuration
429
+ .lock-wscript
430
+
431
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
432
+ build/Release
433
+
434
+ # Dependency directories
435
+ node_modules/
436
+ jspm_packages/
437
+
438
+ # Snowpack dependency directory (https://snowpack.dev/)
439
+ web_modules/
440
+
441
+ # TypeScript cache
442
+ *.tsbuildinfo
443
+
444
+ # Optional npm cache directory
445
+ .npm
446
+
447
+ # Optional eslint cache
448
+ .eslintcache
449
+
450
+ # Optional stylelint cache
451
+ .stylelintcache
452
+
453
+ # Microbundle cache
454
+ .rpt2_cache/
455
+ .rts2_cache_cjs/
456
+ .rts2_cache_es/
457
+ .rts2_cache_umd/
458
+
459
+ # Optional REPL history
460
+ .node_repl_history
461
+
462
+ # Output of 'npm pack'
463
+ *.tgz
464
+
465
+ # Yarn Integrity file
466
+ .yarn-integrity
467
+
468
+ # dotenv environment variable files
469
+ .env
470
+ .env.development.local
471
+ .env.test.local
472
+ .env.production.local
473
+ .env.local
474
+
475
+ # parcel-bundler cache (https://parceljs.org/)
476
+ .cache
477
+ .parcel-cache
478
+
479
+ # Next.js build output
480
+ .next
481
+ out
482
+
483
+ # Nuxt.js build / generate output
484
+ .nuxt
485
+ dist
486
+
487
+ # Gatsby files
488
+ .cache/
489
+ # Comment in the public line in if your project uses Gatsby and not Next.js
490
+ # https://nextjs.org/blog/next-9-1#public-directory-support
491
+ # public
492
+
493
+ # vuepress build output
494
+ .vuepress/dist
495
+
496
+ # vuepress v2.x temp and cache directory
497
+ .temp
498
+ .cache
499
+
500
+ # vitepress build output
501
+ **/.vitepress/dist
502
+
503
+ # vitepress cache directory
504
+ **/.vitepress/cache
505
+
506
+ # Docusaurus cache and generated files
507
+ .docusaurus
508
+
509
+ # Serverless directories
510
+ .serverless/
511
+
512
+ # FuseBox cache
513
+ .fusebox/
514
+
515
+ # DynamoDB Local files
516
+ .dynamodb/
517
+
518
+ # TernJS port file
519
+ .tern-port
520
+
521
+ # Stores VSCode versions used for testing VSCode extensions
522
+ .vscode-test
523
+
524
+ # yarn v2
525
+ .yarn/cache
526
+ .yarn/unplugged
527
+ .yarn/build-state.yml
528
+ .yarn/install-state.gz
529
+ .pnp.*
530
+ `
531
+ }
532
+ ];
533
+ }
534
+ function makePackageJson(appName, runtime, packageJson) {
535
+ const meta = structuredClone(packageJson);
536
+ for (const [dep, version$2] of Object.entries(versions_default)) if (dep in meta.dependencies) meta.dependencies[dep] = version$2;
537
+ else if (dep in packageJson.devDependencies) meta.devDependencies[dep] = version$2;
538
+ if (runtime === "node") {
539
+ meta.devDependencies["@types/bun"] = void 0;
540
+ meta.devDependencies["@types/deno"] = void 0;
541
+ }
542
+ if (runtime === "bun") {
543
+ meta.scripts.start = `baeta generate --watch --run='bun --watch --inspect src/app.ts'`;
544
+ meta.devDependencies["@types/node"] = void 0;
545
+ meta.devDependencies["@types/deno"] = void 0;
546
+ }
547
+ if (runtime === "deno") {
548
+ meta.scripts.start = `baeta generate --watch --run='deno --watch --allow-env --allow-read --allow-net src/app.ts'`;
549
+ meta.devDependencies["@types/node"] = void 0;
550
+ meta.devDependencies["@types/bun"] = void 0;
551
+ }
552
+ meta.name = appName;
553
+ return {
554
+ relativePath: "./package.json",
555
+ content: JSON.stringify(meta, null, 2)
556
+ };
557
+ }
558
+
559
+ //#endregion
560
+ //#region templates/apollo.ts
561
+ async function makeApolloTemplate(appName, runtime) {
562
+ return [
563
+ ...makeSharedTemplate(appName, runtime, package_default$1),
564
+ {
565
+ relativePath: "./src/types/context.ts",
566
+ content: `export type Context = {
567
+ userId?: string;
568
+ };
569
+ `
570
+ },
571
+ {
572
+ relativePath: "./src/app.ts",
573
+ content: `import { ApolloServer } from '@apollo/server';
574
+ import { startStandaloneServer } from '@apollo/server/standalone';
575
+ import { createApplication } from '@baeta/core';
576
+ import modules from './modules/index.ts';
577
+ import type { Context } from './types/context.ts';
578
+
579
+ const baeta = createApplication({
580
+ modules,
581
+ });
582
+
583
+ const server = new ApolloServer<Context>({
584
+ schema: baeta.schema,
585
+ });
586
+
587
+ const { url } = await startStandaloneServer(server, {
588
+ listen: { port: 4000 },
589
+ });
590
+
591
+ console.log(\`🚀 Server ready at: \${url}\`);
592
+ `
593
+ }
594
+ ];
595
+ }
596
+
597
+ //#endregion
598
+ //#region meta/yoga/package.json
599
+ var package_default = {
600
+ name: "@baeta/template-yoga",
601
+ version: "0.0.0",
602
+ "private": true,
603
+ type: "module",
604
+ scripts: {
605
+ "build": "baeta generate",
606
+ "start": "baeta generate --watch --run='node --watch --enable-source-maps --inspect src/app.ts'"
607
+ },
608
+ dependencies: {
609
+ "@baeta/core": "workspace:^",
610
+ "@baeta/errors": "workspace:^",
611
+ "@baeta/extension-complexity": "workspace:^",
612
+ "graphql": "^16.12.0",
613
+ "graphql-yoga": "^5.17.0"
614
+ },
615
+ devDependencies: {
616
+ "@baeta/cli": "workspace:^",
617
+ "@types/bun": "^1.3.3",
618
+ "@types/deno": "^2.5.0",
619
+ "@types/node": "^22.19.1",
620
+ "typescript": "^5.9.3"
621
+ }
622
+ };
623
+
624
+ //#endregion
625
+ //#region templates/yoga.ts
626
+ async function makeYogaTemplate(appName, runtime) {
627
+ return [
628
+ ...makeSharedTemplate(appName, runtime, package_default),
629
+ ...makeRuntimeFiles(runtime),
630
+ {
631
+ relativePath: "./src/types/context.ts",
632
+ content: `export type Context = {
633
+ appVersion: string;
634
+ };
635
+
636
+ export type ServerContext = {};
637
+ `
638
+ }
639
+ ];
640
+ }
641
+ function makeRuntimeFiles(runtime) {
642
+ switch (runtime) {
643
+ case "bun": return makeBunFiles();
644
+ case "deno": return makeDenoFiles();
645
+ case "node": return makeNodeFiles();
646
+ default: return [];
647
+ }
648
+ }
649
+ function makeBunFiles() {
650
+ return [{
651
+ relativePath: "./src/app.ts",
652
+ content: `import { createApplication } from '@baeta/core';
653
+ import { createYoga } from 'graphql-yoga';
654
+ import modules from './modules/index.ts';
655
+ import type { Context, ServerContext } from './types/context.ts';
656
+
657
+ const baeta = createApplication({
658
+ modules,
659
+ });
660
+
661
+ export const yoga = createYoga<ServerContext, Context>({
662
+ schema: baeta.schema,
663
+ context: {
664
+ appVersion: '1.0.0',
665
+ },
666
+ });
667
+
668
+ Bun.serve({
669
+ fetch: yoga.fetch,
670
+ port: 4000,
671
+ });
672
+
673
+ console.log(\`🚀 Server ready at http://localhost:4000\${yoga.graphqlEndpoint}\`);
674
+ `
675
+ }];
676
+ }
677
+ function makeDenoFiles() {
678
+ return [{
679
+ relativePath: "./src/app.ts",
680
+ content: `import { createApplication } from '@baeta/core';
681
+ import { createYoga } from 'graphql-yoga';
682
+ import modules from './modules/index.ts';
683
+ import type { Context, ServerContext } from './types/context.ts';
684
+
685
+ const baeta = createApplication({
686
+ modules,
687
+ });
688
+
689
+ export const yoga = createYoga<ServerContext, Context>({
690
+ schema: baeta.schema,
691
+ context: {
692
+ appVersion: '1.0.0',
693
+ },
694
+ });
695
+
696
+ Deno.serve(
697
+ {
698
+ port: 4000,
699
+ onListen() {
700
+ console.log(\`🚀 Server ready at http://localhost:4000\${yoga.graphqlEndpoint}\`);
701
+ },
702
+ },
703
+ yoga.fetch,
704
+ );
705
+ `
706
+ }];
707
+ }
708
+ function makeNodeFiles() {
709
+ return [{
710
+ relativePath: "./src/app.ts",
711
+ content: `import { createServer } from 'node:http';
712
+ import { createApplication } from '@baeta/core';
713
+ import { createYoga } from 'graphql-yoga';
714
+ import modules from './modules/index.ts';
715
+ import type { Context, ServerContext } from './types/context.ts';
716
+
717
+ const baeta = createApplication({
718
+ modules,
719
+ });
720
+
721
+ export const yoga = createYoga<ServerContext, Context>({
722
+ schema: baeta.schema,
723
+ context: {
724
+ appVersion: '1.0.0',
725
+ },
726
+ });
727
+
728
+ const server = createServer(yoga);
729
+
730
+ server.listen(4000, () => {
731
+ console.log(\`🚀 Server ready at http://localhost:4000\${yoga.graphqlEndpoint}\`);
732
+ });
733
+ `
734
+ }];
735
+ }
736
+
737
+ //#endregion
738
+ //#region lib/templates.ts
739
+ function createTemplateChoices() {
740
+ return templates.map((template) => ({
741
+ title: template,
742
+ value: template
743
+ }));
744
+ }
745
+ async function askTemplateChoice() {
746
+ return prompts({
747
+ type: "select",
748
+ name: "template",
749
+ message: "Select a template below...",
750
+ choices: createTemplateChoices()
751
+ }, { onCancel() {
752
+ logger.error("A choice is required.");
753
+ process.exit(1);
754
+ } }).then((result) => {
755
+ return result.template;
756
+ });
757
+ }
758
+ async function getTemplate(reqTemplate) {
759
+ const template = (reqTemplate ? templates.find((t) => t === reqTemplate) : null) ?? await askTemplateChoice();
760
+ if (!template) throw new Error("Template not found");
761
+ return template;
762
+ }
763
+ function getTemplateFiles(template, appName, runtime) {
764
+ switch (template) {
765
+ case "yoga": return makeYogaTemplate(appName, runtime);
766
+ case "apollo": return makeApolloTemplate(appName, runtime);
767
+ default: return [];
768
+ }
769
+ }
770
+ async function copyTemplate(appName, runtime, template, dest) {
771
+ const promises = (await getTemplateFiles(template, appName, runtime)).map((file) => {
772
+ const filePath = path.join(dest, file.relativePath);
773
+ return fs.ensureDir(path.dirname(filePath)).then(() => fs.writeFile(filePath, file.content));
774
+ });
775
+ await Promise.all(promises);
776
+ }
777
+
778
+ //#endregion
779
+ //#region lib/handler.ts
780
+ async function handler(args) {
781
+ const appName = await getAppName(args.appName, args.rootDir);
782
+ const dest = path.resolve(args.rootDir, appName);
783
+ const template = await getTemplate(args.template);
784
+ const runtime = await getRuntime();
785
+ logger.info("Creating new Baeta project...");
786
+ try {
787
+ await copyTemplate(appName, runtime, template, dest);
788
+ } catch (err) {
789
+ logger.error`Copying Baeta template name=${template} failed!`;
790
+ throw err;
791
+ }
792
+ const pkgManager = await getPackageManager(dest, args);
793
+ const runCommand = pkgManager === "npm" || pkgManager === "bun" ? "run " : "";
794
+ const start = `${pkgManager} start`;
795
+ const build = `${pkgManager} ${runCommand}build`;
796
+ const cd = `cd ${dest}`;
797
+ const install = `${pkgManager} install`;
798
+ if (!args.skipInstall) {
799
+ shell.cd(dest);
800
+ logger.info`Installing dependencies with name=${pkgManager}...`;
801
+ if (shell.exec(getInstallCommand(pkgManager), { env: {
802
+ ...process.env,
803
+ ...supportsColor.stdout ? { FORCE_COLOR: "1" } : {}
804
+ } }).code !== 0) {
805
+ console.error("Dependency installation failed.");
806
+ logger.error("Dependency installation failed.");
807
+ logger.info`The app directory has already been created, and you can retry by typing:
808
+
809
+ code=${cd}
810
+ code=${install}`;
811
+ process.exit(0);
812
+ }
813
+ }
814
+ logger.success`Created name=${dest}.`;
815
+ logger.info`Inside that directory, you can run several commands:
816
+
817
+ code=${start}
818
+ Starts the development server.
819
+
820
+ code=${build}
821
+ Generates the Baeta application.
822
+
823
+ We recommend that you begin by typing:
824
+
825
+ code=${cd}
826
+ code=${start}
827
+ `;
828
+ }
829
+
830
+ //#endregion
831
+ export { getInstallCommand as a, defaultJavaScriptRuntime as c, packageManagers as d, runtimes as f, getRuntime as i, defaultPackageManager as l, copyTemplate as n, getPackageManager as o, templates as p, getTemplate as r, getAppName as s, handler as t, lockfileNames as u };
832
+ //# sourceMappingURL=handler-DJjeIx4h.js.map