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,386 @@
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/modules/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({
57
+ complexityExtension: complexity
58
+ });
59
+ `,
60
+ },
61
+ {
62
+ relativePath: './src/modules/user/user.gql',
63
+ content: `type User {
64
+ id: ID!
65
+ email: String!
66
+ lastName: String!
67
+ profile: String
68
+ givenName: String
69
+ }
70
+
71
+ input UserWhereUniqueInput {
72
+ id: ID!
73
+ }
74
+
75
+ type Query {
76
+ user(where: UserWhereUniqueInput!): User
77
+ users: [User!]
78
+ }
79
+ `,
80
+ },
81
+ {
82
+ relativePath: './src/modules/user/index.ts',
83
+ content: `import { UserModule } from './typedef.ts';
84
+
85
+ const { Query, User } = UserModule;
86
+
87
+ const userQuery = Query.user
88
+ .use(async (next, { args }) => {
89
+ const result = await next();
90
+ console.log('Got user:', result, 'for args:', args);
91
+ return result;
92
+ })
93
+ .resolve(({ args }) => {
94
+ return {
95
+ id: args.where.id,
96
+ email: 'jon.doe@baeta.io',
97
+ lastName: 'Doe',
98
+ givenName: null,
99
+ profile: null,
100
+ };
101
+ });
102
+
103
+ const usersQuery = Query.users.resolve(() => {
104
+ const users = Array.from({ length: 10 }).map((_, i) => ({
105
+ id: i.toString(),
106
+ email: \`jon.doe\${i}@baeta.io\`,
107
+ lastName: \`Doe \${i}\`,
108
+ givenName: null,
109
+ profile: null,
110
+ }));
111
+ return users;
112
+ });
113
+
114
+ export default UserModule.$schema({
115
+ User: User.$fields({
116
+ id: User.id.key('id'),
117
+ email: User.email.key('email'),
118
+ lastName: User.lastName.key('lastName'),
119
+ givenName: User.givenName.key('givenName').undefinedAsNull(),
120
+ profile: User.profile.key('profile').undefinedAsNull(),
121
+ }),
122
+ Query: Query.$fields({
123
+ user: userQuery,
124
+ users: usersQuery,
125
+ }),
126
+ });
127
+ `,
128
+ },
129
+ {
130
+ relativePath: './src/modules/user-photos/user-photos.gql',
131
+ content: `type UserPhoto {
132
+ id: ID!
133
+ userId: ID!
134
+ url: String!
135
+ }
136
+
137
+ extend type User {
138
+ photos: [UserPhoto!]
139
+ }
140
+ `,
141
+ },
142
+ {
143
+ relativePath: './src/modules/user-photos/index.ts',
144
+ content: `import { UserPhotosModule } from './typedef.ts';
145
+
146
+ const { User, UserPhoto } = UserPhotosModule;
147
+
148
+ export default UserPhotosModule.$schema({
149
+ User: User.$fields({
150
+ photos: User.photos.resolve(({ source }) => {
151
+ return Array.from({ length: 10 }).map((_, i) => ({
152
+ id: \`u\${source.id}_p\${i}\`,
153
+ userId: source.id,
154
+ url: \`https://baeta.io/user/\${source.id}/photo/\${i}.png\`,
155
+ }));
156
+ }),
157
+ }),
158
+ UserPhoto: UserPhoto.$fields({
159
+ id: UserPhoto.id.key('id'),
160
+ url: UserPhoto.url.key('url'),
161
+ userId: UserPhoto.userId.key('userId'),
162
+ }),
163
+ });
164
+ `,
165
+ },
166
+ {
167
+ relativePath: './src/modules/types.ts',
168
+ content: `import type { GraphQLResolveInfo } from 'graphql';
169
+ import type { BaseObjectTypes, BaseScalars } from '../__generated__/utility.ts';
170
+ import type { Context } from '../types/context.ts';
171
+
172
+ export interface Scalars extends BaseScalars {}
173
+
174
+ export interface ObjectTypes extends BaseObjectTypes {
175
+ User: {
176
+ id: string;
177
+ email: string;
178
+ lastName: string;
179
+ givenName?: string | null;
180
+ profile?: string | null;
181
+ };
182
+ }
183
+
184
+ export type Ctx = Context;
185
+
186
+ export type Info = GraphQLResolveInfo;
187
+ `,
188
+ },
189
+ {
190
+ relativePath: './baeta.ts',
191
+ content: `import { defineConfig } from '@baeta/cli';
192
+
193
+ export default defineConfig({
194
+ graphql: {
195
+ schemas: ['src/**/*.gql'],
196
+ },
197
+ });
198
+ `,
199
+ },
200
+ {
201
+ relativePath: './.gitignore',
202
+ content: `# Logs
203
+ logs
204
+ *.log
205
+ npm-debug.log*
206
+ yarn-debug.log*
207
+ yarn-error.log*
208
+ lerna-debug.log*
209
+ .pnpm-debug.log*
210
+
211
+ # Diagnostic reports (https://nodejs.org/api/report.html)
212
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
213
+
214
+ # Runtime data
215
+ pids
216
+ *.pid
217
+ *.seed
218
+ *.pid.lock
219
+
220
+ # Directory for instrumented libs generated by jscoverage/JSCover
221
+ lib-cov
222
+
223
+ # Coverage directory used by tools like istanbul
224
+ coverage
225
+ *.lcov
226
+
227
+ # nyc test coverage
228
+ .nyc_output
229
+
230
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
231
+ .grunt
232
+
233
+ # Bower dependency directory (https://bower.io/)
234
+ bower_components
235
+
236
+ # node-waf configuration
237
+ .lock-wscript
238
+
239
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
240
+ build/Release
241
+
242
+ # Dependency directories
243
+ node_modules/
244
+ jspm_packages/
245
+
246
+ # Snowpack dependency directory (https://snowpack.dev/)
247
+ web_modules/
248
+
249
+ # TypeScript cache
250
+ *.tsbuildinfo
251
+
252
+ # Optional npm cache directory
253
+ .npm
254
+
255
+ # Optional eslint cache
256
+ .eslintcache
257
+
258
+ # Optional stylelint cache
259
+ .stylelintcache
260
+
261
+ # Microbundle cache
262
+ .rpt2_cache/
263
+ .rts2_cache_cjs/
264
+ .rts2_cache_es/
265
+ .rts2_cache_umd/
266
+
267
+ # Optional REPL history
268
+ .node_repl_history
269
+
270
+ # Output of 'npm pack'
271
+ *.tgz
272
+
273
+ # Yarn Integrity file
274
+ .yarn-integrity
275
+
276
+ # dotenv environment variable files
277
+ .env
278
+ .env.development.local
279
+ .env.test.local
280
+ .env.production.local
281
+ .env.local
282
+
283
+ # parcel-bundler cache (https://parceljs.org/)
284
+ .cache
285
+ .parcel-cache
286
+
287
+ # Next.js build output
288
+ .next
289
+ out
290
+
291
+ # Nuxt.js build / generate output
292
+ .nuxt
293
+ dist
294
+
295
+ # Gatsby files
296
+ .cache/
297
+ # Comment in the public line in if your project uses Gatsby and not Next.js
298
+ # https://nextjs.org/blog/next-9-1#public-directory-support
299
+ # public
300
+
301
+ # vuepress build output
302
+ .vuepress/dist
303
+
304
+ # vuepress v2.x temp and cache directory
305
+ .temp
306
+ .cache
307
+
308
+ # vitepress build output
309
+ **/.vitepress/dist
310
+
311
+ # vitepress cache directory
312
+ **/.vitepress/cache
313
+
314
+ # Docusaurus cache and generated files
315
+ .docusaurus
316
+
317
+ # Serverless directories
318
+ .serverless/
319
+
320
+ # FuseBox cache
321
+ .fusebox/
322
+
323
+ # DynamoDB Local files
324
+ .dynamodb/
325
+
326
+ # TernJS port file
327
+ .tern-port
328
+
329
+ # Stores VSCode versions used for testing VSCode extensions
330
+ .vscode-test
331
+
332
+ # yarn v2
333
+ .yarn/cache
334
+ .yarn/unplugged
335
+ .yarn/build-state.yml
336
+ .yarn/install-state.gz
337
+ .pnp.*
338
+ `,
339
+ },
340
+ ];
341
+ }
342
+
343
+ function makePackageJson(
344
+ appName: string,
345
+ runtime: JavaScriptRuntime,
346
+ packageJson: {
347
+ name: string;
348
+ scripts: Record<string, string | undefined>;
349
+ dependencies: Record<string, string | undefined>;
350
+ devDependencies: Record<string, string | undefined>;
351
+ },
352
+ ) {
353
+ const meta = structuredClone(packageJson);
354
+
355
+ for (const [dep, version] of Object.entries(dependenciesVersions)) {
356
+ if (dep in meta.dependencies) {
357
+ meta.dependencies[dep] = version;
358
+ } else if (dep in packageJson.devDependencies) {
359
+ meta.devDependencies[dep] = version;
360
+ }
361
+ }
362
+
363
+ if (runtime === 'node') {
364
+ meta.devDependencies['@types/bun'] = undefined;
365
+ meta.devDependencies['@types/deno'] = undefined;
366
+ }
367
+
368
+ if (runtime === 'bun') {
369
+ meta.scripts.start = `baeta generate --watch --run='bun --watch --inspect src/app.ts'`;
370
+ meta.devDependencies['@types/node'] = undefined;
371
+ meta.devDependencies['@types/deno'] = undefined;
372
+ }
373
+
374
+ if (runtime === 'deno') {
375
+ meta.scripts.start = `baeta generate --watch --run='deno --watch --allow-env --allow-read --allow-net src/app.ts'`;
376
+ meta.devDependencies['@types/node'] = undefined;
377
+ meta.devDependencies['@types/bun'] = undefined;
378
+ }
379
+
380
+ meta.name = appName;
381
+
382
+ return {
383
+ relativePath: './package.json',
384
+ content: JSON.stringify(meta, null, 2),
385
+ };
386
+ }
@@ -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/index.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/index.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/index.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
+ }
package/CHANGELOG.md DELETED
@@ -1,39 +0,0 @@
1
- # create-baeta
2
-
3
- ## 1.0.9
4
-
5
- ### Patch Changes
6
-
7
- - [`583014f`](https://github.com/andreisergiu98/baeta/commit/583014f0bac810b25d9a8226bda2df4c9039f5e3) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Update dependencies
8
-
9
- ## 1.0.8
10
-
11
- ### Patch Changes
12
-
13
- - [#189](https://github.com/andreisergiu98/baeta/pull/189) [`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add jsdocs
14
-
15
- - [#165](https://github.com/andreisergiu98/baeta/pull/165) [`1334c2a`](https://github.com/andreisergiu98/baeta/commit/1334c2a866676c88f0f3d380b22133d81c4e98bc) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - mark as stable
16
-
17
- ## 0.0.4
18
-
19
- ### Patch Changes
20
-
21
- - [`770fef4`](https://github.com/andreisergiu98/baeta/commit/770fef4974fd8926886162424f326c4cda2ad21b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - fix package entrypoint
22
-
23
- ## 0.0.3
24
-
25
- ### Patch Changes
26
-
27
- - [`bcbfb49`](https://github.com/andreisergiu98/baeta/commit/bcbfb49b16daf5d6f195ba273f52b1aa89602c1c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - fix yoga entrypoint for bun and deno
28
-
29
- ## 0.0.2
30
-
31
- ### Patch Changes
32
-
33
- - [#184](https://github.com/andreisergiu98/baeta/pull/184) [`bf2d1a3`](https://github.com/andreisergiu98/baeta/commit/bf2d1a326235e5f34e723a5acc81cd7b974b913b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add runtime selector
34
-
35
- ## 0.0.1
36
-
37
- ### Patch Changes
38
-
39
- - [#182](https://github.com/andreisergiu98/baeta/pull/182) [`9a0f100`](https://github.com/andreisergiu98/baeta/commit/9a0f1003a9579406809c80e6fe123e54fb86e5ac) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add create baeta package