create-baeta 1.0.9 → 2.0.0-next.0

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