create-baeta 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,346 @@
1
+ import tsconfig from '../../../tools/tsconfig/tsconfig.json';
2
+ import type { JavaScriptRuntime } from '../lib/constants.ts';
3
+ import type { TemplateFile } from '../lib/template-file.ts';
4
+ import dependenciesVersions from '../versions.json';
5
+
6
+ export type PackageJson = {
7
+ name: string;
8
+ scripts: Record<string, string | undefined>;
9
+ dependencies: Record<string, string | undefined>;
10
+ devDependencies: Record<string, string | undefined>;
11
+ };
12
+
13
+ export function makeSharedTemplate(
14
+ appName: string,
15
+ runtime: JavaScriptRuntime,
16
+ packageJson: PackageJson,
17
+ ): TemplateFile[] {
18
+ return [
19
+ makePackageJson(appName, runtime, packageJson),
20
+ {
21
+ relativePath: './tsconfig.json',
22
+ content: JSON.stringify(
23
+ {
24
+ ...tsconfig,
25
+ compilerOptions: {
26
+ ...tsconfig.compilerOptions,
27
+ rootDir: 'src',
28
+ outDir: 'dist',
29
+ noEmit: true,
30
+ emitDeclarationOnly: false,
31
+ },
32
+ exclude: ['baeta.ts'],
33
+ },
34
+ null,
35
+ 2,
36
+ ),
37
+ },
38
+ {
39
+ relativePath: './src/lib/extensions.ts',
40
+ content: `import { createExtensions } from '@baeta/core';
41
+ import { complexityExtension } from '@baeta/extension-complexity';
42
+ import type { Context } from '../types/context.ts';
43
+
44
+ const complexity = complexityExtension<Context>({
45
+ defaultComplexity: 1,
46
+ defaultListMultiplier: 10,
47
+ async limit(ctx) {
48
+ return {
49
+ depth: 10,
50
+ breadth: 50,
51
+ complexity: 1000,
52
+ };
53
+ },
54
+ });
55
+
56
+ export default createExtensions(complexity);
57
+ `,
58
+ },
59
+ {
60
+ relativePath: './src/modules/user/user.gql',
61
+ content: `type User {
62
+ id: ID!
63
+ email: String!
64
+ lastName: String!
65
+ profile: String
66
+ givenName: String
67
+ }
68
+
69
+ input UserWhereUniqueInput {
70
+ id: ID!
71
+ }
72
+
73
+ type Query {
74
+ user(where: UserWhereUniqueInput!): User
75
+ users: [User!]
76
+ }
77
+ `,
78
+ },
79
+ {
80
+ relativePath: './src/modules/user/user.resolvers.ts',
81
+ content: `import { getUserModule } from './typedef.ts';
82
+
83
+ const { Query } = getUserModule();
84
+
85
+ Query.user(({ args }) => {
86
+ return {
87
+ id: args.where.id,
88
+ email: 'jon.doe@baeta.io',
89
+ lastName: 'Doe',
90
+ };
91
+ });
92
+
93
+ Query.user.$use(async ({ args }, next) => {
94
+ const result = await next();
95
+ console.log('Got user:', result, 'for args:', args);
96
+ return result;
97
+ });
98
+
99
+ Query.users(() => {
100
+ const users = Array.from({ length: 10 }).map((_, i) => ({
101
+ id: i.toString(),
102
+ email: \`jon.doe\${i}@baeta.io\`,
103
+ lastName: \`Doe \${i}\`,
104
+ }));
105
+ return users;
106
+ });
107
+ `,
108
+ },
109
+ {
110
+ relativePath: './src/modules/user-photos/user-photos.gql',
111
+ content: `type UserPhoto {
112
+ id: ID!
113
+ userId: ID!
114
+ url: String!
115
+ }
116
+
117
+ extend type User {
118
+ photos: [UserPhoto!]
119
+ }
120
+ `,
121
+ },
122
+ {
123
+ relativePath: './src/modules/user-photos/user-photos.resolvers.ts',
124
+ content: `import { getUserPhotosModule } from './typedef.ts';
125
+
126
+ const { User } = getUserPhotosModule();
127
+
128
+ User.photos(({ root }) => {
129
+ return Array.from({ length: 10 }).map((_, i) => ({
130
+ id: \`u\${root.id}_p\${i}\`,
131
+ userId: root.id,
132
+ url: \`https://baeta.io/user/\${root.id}/photo/\${i}.png\`,
133
+ }));
134
+ });
135
+ `,
136
+ },
137
+ {
138
+ relativePath: './baeta.ts',
139
+ content: `import { defineConfig } from '@baeta/cli';
140
+ import { autoloadPlugin } from '@baeta/plugin-autoload';
141
+
142
+ export default defineConfig({
143
+ graphql: {
144
+ schemas: ['src/**/*.gql'],
145
+ contextType: 'src/types/context#Context',
146
+ extensions: 'src/lib/extensions.ts',
147
+ },
148
+ compiler: {
149
+ src: 'src/app.ts',
150
+ dist: 'dist',
151
+ bundleWorkspaces: true,
152
+ esbuild: {
153
+ format: 'esm',
154
+ },
155
+ },
156
+ plugins: [autoloadPlugin()],
157
+ });
158
+ `,
159
+ },
160
+ {
161
+ relativePath: './.gitignore',
162
+ content: `# Logs
163
+ logs
164
+ *.log
165
+ npm-debug.log*
166
+ yarn-debug.log*
167
+ yarn-error.log*
168
+ lerna-debug.log*
169
+ .pnpm-debug.log*
170
+
171
+ # Diagnostic reports (https://nodejs.org/api/report.html)
172
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
173
+
174
+ # Runtime data
175
+ pids
176
+ *.pid
177
+ *.seed
178
+ *.pid.lock
179
+
180
+ # Directory for instrumented libs generated by jscoverage/JSCover
181
+ lib-cov
182
+
183
+ # Coverage directory used by tools like istanbul
184
+ coverage
185
+ *.lcov
186
+
187
+ # nyc test coverage
188
+ .nyc_output
189
+
190
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
191
+ .grunt
192
+
193
+ # Bower dependency directory (https://bower.io/)
194
+ bower_components
195
+
196
+ # node-waf configuration
197
+ .lock-wscript
198
+
199
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
200
+ build/Release
201
+
202
+ # Dependency directories
203
+ node_modules/
204
+ jspm_packages/
205
+
206
+ # Snowpack dependency directory (https://snowpack.dev/)
207
+ web_modules/
208
+
209
+ # TypeScript cache
210
+ *.tsbuildinfo
211
+
212
+ # Optional npm cache directory
213
+ .npm
214
+
215
+ # Optional eslint cache
216
+ .eslintcache
217
+
218
+ # Optional stylelint cache
219
+ .stylelintcache
220
+
221
+ # Microbundle cache
222
+ .rpt2_cache/
223
+ .rts2_cache_cjs/
224
+ .rts2_cache_es/
225
+ .rts2_cache_umd/
226
+
227
+ # Optional REPL history
228
+ .node_repl_history
229
+
230
+ # Output of 'npm pack'
231
+ *.tgz
232
+
233
+ # Yarn Integrity file
234
+ .yarn-integrity
235
+
236
+ # dotenv environment variable files
237
+ .env
238
+ .env.development.local
239
+ .env.test.local
240
+ .env.production.local
241
+ .env.local
242
+
243
+ # parcel-bundler cache (https://parceljs.org/)
244
+ .cache
245
+ .parcel-cache
246
+
247
+ # Next.js build output
248
+ .next
249
+ out
250
+
251
+ # Nuxt.js build / generate output
252
+ .nuxt
253
+ dist
254
+
255
+ # Gatsby files
256
+ .cache/
257
+ # Comment in the public line in if your project uses Gatsby and not Next.js
258
+ # https://nextjs.org/blog/next-9-1#public-directory-support
259
+ # public
260
+
261
+ # vuepress build output
262
+ .vuepress/dist
263
+
264
+ # vuepress v2.x temp and cache directory
265
+ .temp
266
+ .cache
267
+
268
+ # vitepress build output
269
+ **/.vitepress/dist
270
+
271
+ # vitepress cache directory
272
+ **/.vitepress/cache
273
+
274
+ # Docusaurus cache and generated files
275
+ .docusaurus
276
+
277
+ # Serverless directories
278
+ .serverless/
279
+
280
+ # FuseBox cache
281
+ .fusebox/
282
+
283
+ # DynamoDB Local files
284
+ .dynamodb/
285
+
286
+ # TernJS port file
287
+ .tern-port
288
+
289
+ # Stores VSCode versions used for testing VSCode extensions
290
+ .vscode-test
291
+
292
+ # yarn v2
293
+ .yarn/cache
294
+ .yarn/unplugged
295
+ .yarn/build-state.yml
296
+ .yarn/install-state.gz
297
+ .pnp.*
298
+ `,
299
+ },
300
+ ];
301
+ }
302
+
303
+ function makePackageJson(
304
+ appName: string,
305
+ runtime: JavaScriptRuntime,
306
+ packageJson: {
307
+ name: string;
308
+ scripts: Record<string, string | undefined>;
309
+ dependencies: Record<string, string | undefined>;
310
+ devDependencies: Record<string, string | undefined>;
311
+ },
312
+ ) {
313
+ const meta = structuredClone(packageJson);
314
+
315
+ for (const [dep, version] of Object.entries(dependenciesVersions)) {
316
+ if (dep in meta.dependencies) {
317
+ meta.dependencies[dep] = version;
318
+ } else if (dep in packageJson.devDependencies) {
319
+ meta.devDependencies[dep] = version;
320
+ }
321
+ }
322
+
323
+ if (runtime === 'node') {
324
+ meta.devDependencies['@types/bun'] = undefined;
325
+ meta.devDependencies['@types/deno'] = undefined;
326
+ }
327
+
328
+ if (runtime === 'bun') {
329
+ meta.scripts.start = `baeta generate --watch --run='bun --watch --inspect src/app.ts'`;
330
+ meta.devDependencies['@types/node'] = undefined;
331
+ meta.devDependencies['@types/deno'] = undefined;
332
+ }
333
+
334
+ if (runtime === 'deno') {
335
+ meta.scripts.start = `baeta generate --watch --run='deno --watch --allow-env --allow-read --allow-net src/app.ts'`;
336
+ meta.devDependencies['@types/node'] = undefined;
337
+ meta.devDependencies['@types/bun'] = undefined;
338
+ }
339
+
340
+ meta.name = appName;
341
+
342
+ return {
343
+ relativePath: './package.json',
344
+ content: JSON.stringify(meta, null, 2),
345
+ };
346
+ }
@@ -0,0 +1,133 @@
1
+ import type { JavaScriptRuntime } from '../lib/constants.ts';
2
+ import type { TemplateFile } from '../lib/template-file.ts';
3
+ import yogaPackageJson from '../meta/yoga/package.json';
4
+ import { makeSharedTemplate } from './shared.ts';
5
+
6
+ export async function makeYogaTemplate(
7
+ appName: string,
8
+ runtime: JavaScriptRuntime,
9
+ ): Promise<TemplateFile[]> {
10
+ return [
11
+ ...makeSharedTemplate(appName, runtime, yogaPackageJson),
12
+ ...makeRuntimeFiles(runtime),
13
+ {
14
+ relativePath: './src/types/context.ts',
15
+ content: `export type Context = {
16
+ appVersion: string;
17
+ };
18
+
19
+ // biome-ignore lint/complexity/noBannedTypes: Empty context
20
+ export type ServerContext = {};
21
+ `,
22
+ },
23
+ ];
24
+ }
25
+
26
+ function makeRuntimeFiles(runtime: JavaScriptRuntime): TemplateFile[] {
27
+ switch (runtime) {
28
+ case 'bun':
29
+ return makeBunFiles();
30
+ case 'deno':
31
+ return makeDenoFiles();
32
+ case 'node':
33
+ return makeNodeFiles();
34
+ default:
35
+ return [] satisfies never[];
36
+ }
37
+ }
38
+
39
+ function makeBunFiles(): TemplateFile[] {
40
+ return [
41
+ {
42
+ relativePath: './src/app.ts',
43
+ content: `import { createApplication } from '@baeta/core';
44
+ import { createYoga } from 'graphql-yoga';
45
+ import { modules } from './modules/autoload.ts';
46
+ import type { Context, ServerContext } from './types/context.ts';
47
+
48
+ const baeta = createApplication({
49
+ modules,
50
+ });
51
+
52
+ export const yoga = createYoga<ServerContext, Context>({
53
+ schema: baeta.schema,
54
+ context: {
55
+ appVersion: '1.0.0',
56
+ },
57
+ });
58
+
59
+ Bun.serve({
60
+ fetch: yoga.fetch,
61
+ port: 4000,
62
+ });
63
+
64
+ console.log(\`🚀 Server ready at http://localhost:4000\${yoga.graphqlEndpoint}\`);
65
+ `,
66
+ },
67
+ ];
68
+ }
69
+
70
+ function makeDenoFiles(): TemplateFile[] {
71
+ return [
72
+ {
73
+ relativePath: './src/app.ts',
74
+ content: `import { createApplication } from '@baeta/core';
75
+ import { createYoga } from 'graphql-yoga';
76
+ import { modules } from './modules/autoload.ts';
77
+ import type { Context, ServerContext } from './types/context.ts';
78
+
79
+ const baeta = createApplication({
80
+ modules,
81
+ });
82
+
83
+ export const yoga = createYoga<ServerContext, Context>({
84
+ schema: baeta.schema,
85
+ context: {
86
+ appVersion: '1.0.0',
87
+ },
88
+ });
89
+
90
+ Deno.serve(
91
+ {
92
+ port: 4000,
93
+ onListen() {
94
+ console.log(\`🚀 Server ready at http://localhost:4000\${yoga.graphqlEndpoint}\`);
95
+ },
96
+ },
97
+ yoga.fetch,
98
+ );
99
+ `,
100
+ },
101
+ ];
102
+ }
103
+
104
+ function makeNodeFiles(): TemplateFile[] {
105
+ return [
106
+ {
107
+ relativePath: './src/app.ts',
108
+ content: `import { createServer } from 'node:http';
109
+ import { createApplication } from '@baeta/core';
110
+ import { createYoga } from 'graphql-yoga';
111
+ import { modules } from './modules/autoload.ts';
112
+ import type { Context, ServerContext } from './types/context.ts';
113
+
114
+ const baeta = createApplication({
115
+ modules,
116
+ });
117
+
118
+ export const yoga = createYoga<ServerContext, Context>({
119
+ schema: baeta.schema,
120
+ context: {
121
+ appVersion: '1.0.0',
122
+ },
123
+ });
124
+
125
+ const server = createServer(yoga);
126
+
127
+ server.listen(4000, () => {
128
+ console.log(\`🚀 Server ready at http://localhost:4000\${yoga.graphqlEndpoint}\`);
129
+ });
130
+ `,
131
+ },
132
+ ];
133
+ }