@baeta/generator-sdk 1.0.1 → 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.
package/dist/index.js CHANGED
@@ -1,71 +1,48 @@
1
1
  // lib/config.ts
2
- import { isAbsolute, join, posixPath, relative, resolve } from "@baeta/util-path";
2
+ import { posixPath, resolve } from "@baeta/util-path";
3
3
  function loadOptions(options) {
4
4
  const cwd = posixPath(options.cwd ?? process.cwd());
5
5
  const schemas = options.schemas ?? ["src/**/*.graphql"];
6
6
  const modulesDir = posixPath(resolve(cwd, options.modulesDir || "src/modules"));
7
7
  const moduleDefinitionName = options.moduleDefinitionName || "typedef.ts";
8
- const defaultBaseTypesRoot = resolve(modulesDir, "../__generated__/types.ts");
9
- const baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);
10
- const baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));
11
- const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);
12
- const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);
8
+ const defaultTypesDir = resolve(modulesDir, "../__generated__/");
9
+ const typesDir = resolve(cwd, options.typesDir || defaultTypesDir);
13
10
  return {
14
11
  cwd,
15
12
  schemas,
16
13
  modulesDir,
17
14
  moduleDefinitionName,
18
- baseTypesPath,
19
- contextType,
20
- extensions,
21
- scalars: options.scalars,
15
+ typesDir,
22
16
  fileOptions: options.fileOptions,
23
17
  loaders: options.loaders,
24
- importExtension: options.importExtension === false ? void 0 : options.importExtension ?? ".ts"
18
+ importExtension: options.importExtension === false ? "" : options.importExtension ?? ".ts"
25
19
  };
26
20
  }
27
- function resolveContextType(root, baseTypesRoot, contextType) {
28
- if (!contextType) {
29
- return;
30
- }
31
- if (isAbsolute(contextType)) {
32
- return contextType;
33
- }
34
- if (contextType[0] === "!") {
35
- return contextType.slice(1);
36
- }
37
- const contextTypeRoot = resolve(root, contextType);
38
- return posixPath(relative(join(baseTypesRoot, "../"), contextTypeRoot));
39
- }
40
- function resolveExtensionPath(modulesDir, moduleDefinitionName, extensionsPath) {
41
- if (!extensionsPath) {
42
- return;
43
- }
44
- if (isAbsolute(extensionsPath)) {
45
- return extensionsPath;
46
- }
47
- if (extensionsPath[0] === "!") {
48
- return extensionsPath.slice(1);
49
- }
50
- return posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));
51
- }
52
21
 
53
22
  // lib/file.ts
54
- import fs from "node:fs/promises";
23
+ import fs from "fs/promises";
55
24
  import { dirname, extname } from "@baeta/util-path";
56
25
  var File = class {
26
+ persisted = false;
27
+ filename;
28
+ content;
29
+ tag;
30
+ options;
57
31
  constructor(filename, content, tag, options) {
58
32
  this.filename = filename;
59
33
  this.content = content;
60
34
  this.tag = tag;
61
35
  this.options = options;
62
36
  }
63
- persisted = false;
64
37
  write = async () => {
65
38
  if (this.persisted) {
66
39
  return;
67
40
  }
68
41
  this.persisted = true;
42
+ if (this.options?.allowOverwrite === false) {
43
+ const exists = await fs.stat(this.filename).then((res) => res.isFile()).catch(() => false);
44
+ if (exists) return;
45
+ }
69
46
  const dir = dirname(this.filename);
70
47
  await fs.mkdir(dir, { recursive: true });
71
48
  const content = await this.buildContent();
@@ -84,16 +61,20 @@ var File = class {
84
61
  }
85
62
  buildHeader() {
86
63
  const headerItems = [];
87
- if (this.options?.addGenerationNoticeHeader !== false) {
64
+ if (this.options?.disableGenerationNoticeHeader !== true) {
88
65
  const comment = this.createComment(
89
66
  "This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator."
90
67
  );
91
68
  headerItems.push(comment);
92
69
  }
93
- if (this.options?.addEslintDisableHeader !== false) {
70
+ if (this.options?.disableEslintHeader !== true) {
94
71
  const comment = this.createComment("eslint-disable");
95
72
  headerItems.push(comment);
96
73
  }
74
+ if (this.options?.disableBiomeHeader !== true) {
75
+ const comment = this.createComment("@biome-ignore-all: generated file");
76
+ headerItems.push(comment);
77
+ }
97
78
  if (this.options?.addHeader) {
98
79
  const customHeader = this.options.addHeader(this.filename, this.content, this.tag);
99
80
  headerItems.push(customHeader);
@@ -115,13 +96,19 @@ var File = class {
115
96
  };
116
97
 
117
98
  // lib/file-block.ts
118
- import { mkdir, open, writeFile } from "node:fs/promises";
99
+ import { mkdir, open, writeFile } from "fs/promises";
119
100
  import { dirname as dirname2 } from "@baeta/util-path";
120
101
  var FileBlock = class extends File {
102
+ filename;
103
+ content;
104
+ start;
105
+ end;
106
+ tag;
121
107
  constructor(filename, content, start, end, tag, options) {
122
108
  super(filename, content, tag, {
123
- addEslintDisableHeader: options?.addEslintDisableHeader ?? false,
124
- addGenerationNoticeHeader: options?.addGenerationNoticeHeader ?? false
109
+ disableBiomeHeader: options?.disableBiomeHeader ?? true,
110
+ disableEslintHeader: options?.disableEslintHeader ?? true,
111
+ disableGenerationNoticeHeader: options?.disableGenerationNoticeHeader ?? true
125
112
  });
126
113
  this.filename = filename;
127
114
  this.content = content;
@@ -162,7 +149,7 @@ var FileBlock = class extends File {
162
149
  const fd = await open(this.filename, "r+");
163
150
  const existingContent = await fd.readFile("utf-8");
164
151
  return [existingContent, fd];
165
- } catch (err) {
152
+ } catch {
166
153
  return ["", null];
167
154
  }
168
155
  }
@@ -202,12 +189,13 @@ ${this.end}`;
202
189
 
203
190
  // lib/file-manager.ts
204
191
  var FileManager = class {
192
+ files = [];
193
+ fileOptions;
205
194
  constructor(fileOptions) {
206
195
  this.fileOptions = fileOptions;
207
196
  }
208
- files = [];
209
- createAndAdd(filename, content, tag) {
210
- const file = new File(filename, content, tag, this.fileOptions);
197
+ createAndAdd(filename, content, tag, options) {
198
+ const file = new File(filename, content, tag, { ...this.fileOptions, ...options });
211
199
  this.add(file);
212
200
  return file;
213
201
  }
@@ -252,24 +240,17 @@ var FileManager = class {
252
240
  };
253
241
 
254
242
  // lib/module.ts
255
- import { camelCase, pascalCase } from "change-case-all";
256
- function getModuleGetName(name) {
257
- return `get${pascalCase(name)}Module`;
258
- }
259
- function getModuleCreateName(name) {
260
- return `create${pascalCase(name)}Module`;
261
- }
262
- function getModuleVariableName(name) {
263
- return camelCase(`${name}Module`);
243
+ import { pascalCase } from "change-case-all";
244
+ function getModuleExportName(name) {
245
+ return `${pascalCase(name)}Module`;
264
246
  }
265
247
 
266
248
  // lib/plugin.ts
267
249
  import { PluginType } from "@baeta/plugin";
268
- var GeneratorPluginVersion = /* @__PURE__ */ ((GeneratorPluginVersion2) => {
269
- GeneratorPluginVersion2["V1"] = "v1";
270
- return GeneratorPluginVersion2;
271
- })(GeneratorPluginVersion || {});
272
- var defaultPluginFn = async (ctx, next) => {
250
+ var GeneratorPluginVersion = {
251
+ V1: "v1"
252
+ };
253
+ var defaultPluginFn = async (_ctx, next) => {
273
254
  return next();
274
255
  };
275
256
  var defaultWatchFn = () => ({ include: [], ignore: [] });
@@ -277,7 +258,7 @@ function createPluginV1(options) {
277
258
  return {
278
259
  name: options.name,
279
260
  actionName: options.actionName,
280
- version: "v1" /* V1 */,
261
+ version: GeneratorPluginVersion.V1,
281
262
  type: PluginType.Generator,
282
263
  end: options.end ?? defaultPluginFn,
283
264
  generate: options.generate ?? defaultPluginFn,
@@ -306,14 +287,15 @@ import micromatch2 from "micromatch";
306
287
  import path from "@baeta/util-path";
307
288
  import micromatch from "micromatch";
308
289
  var WatcherIgnore = class {
309
- constructor(cwd) {
310
- this.cwd = cwd;
311
- }
290
+ cwd;
312
291
  files = [];
313
292
  regexps = [];
314
293
  functions = [];
315
294
  globs = [];
316
295
  globsMap = /* @__PURE__ */ new Map();
296
+ constructor(cwd) {
297
+ this.cwd = cwd;
298
+ }
317
299
  ignore(pattern) {
318
300
  if (pattern instanceof RegExp) {
319
301
  this.regexps.push(pattern);
@@ -374,12 +356,8 @@ var WatcherIgnore = class {
374
356
  // lib/watcher.ts
375
357
  var isMatch = micromatch2.isMatch;
376
358
  var Watcher = class {
377
- constructor(cwd, options) {
378
- this.cwd = cwd;
379
- this.options = options;
380
- this.watcherIgnore = new WatcherIgnore(cwd);
381
- this.subscription = this.createSubscription();
382
- }
359
+ cwd;
360
+ options;
383
361
  subscription;
384
362
  listeners = {
385
363
  create: [],
@@ -387,6 +365,12 @@ var Watcher = class {
387
365
  delete: []
388
366
  };
389
367
  watcherIgnore;
368
+ constructor(cwd, options) {
369
+ this.cwd = cwd;
370
+ this.options = options;
371
+ this.watcherIgnore = new WatcherIgnore(cwd);
372
+ this.subscription = this.createSubscription();
373
+ }
390
374
  onEvents = (err, events) => {
391
375
  if (err) {
392
376
  console.error(err);
@@ -440,9 +424,7 @@ export {
440
424
  WatcherIgnore,
441
425
  createPluginV1,
442
426
  getGeneratorPlugins,
443
- getModuleCreateName,
444
- getModuleGetName,
445
- getModuleVariableName,
427
+ getModuleExportName,
446
428
  isGeneratorPlugin,
447
429
  isMatch,
448
430
  loadOptions,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/config.ts","../lib/file.ts","../lib/file-block.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher.ts","../lib/watcher-ignore.ts"],"sourcesContent":["import { isAbsolute, join, posixPath, relative, resolve } from '@baeta/util-path';\nimport type { FileOptions } from './file.ts';\n\n/**\n * Interface for custom schema loaders.\n */\n// biome-ignore lint/suspicious/noExplicitAny: We don't want to import graphql for this type\nexport interface Loader<TOptions = any> {\n\t// biome-ignore lint/suspicious/noExplicitAny: Same reason as above\n\tload(pointer: string, options?: TOptions): Promise<any[] | null | never>;\n\t// biome-ignore lint/suspicious/noExplicitAny: Same reason as above\n\tloadSync?(pointer: string, options?: TOptions): any[] | null | never;\n}\n\n/**\n * Options for the Baeta Generator.\n */\nexport interface GeneratorOptions {\n\t/**\n\t * Current working directory for resolving relative paths.\n\t * @defaultValue process.cwd()\n\t */\n\tcwd?: string;\n\n\t/**\n\t * Glob pattern(s) to locate GraphQL schema files.\n\t * @defaultValue ```ts\n\t * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']\n\t * ```\n\t */\n\tschemas: string[];\n\n\t/**\n\t * Root directory where GraphQL modules are defined.\n\t * @defaultValue 'src/modules'\n\t */\n\tmodulesDir?: string;\n\n\t/**\n\t * Filename for the generated module definition file.\n\t * Contains type definitions and the GraphQL AST.\n\t * @defaultValue 'typedef.ts'\n\t */\n\tmoduleDefinitionName?: string;\n\n\t/**\n\t * Output path for the generated base types file.\n\t * @defaultValue ```ts\n\t * `${modulesDir}/../__generated__/types.ts`\n\t * ```\n\t */\n\tbaseTypesPath?: string;\n\n\t/**\n\t * Path to the context type definition.\n\t * Supports both named and default exports.\n\t * @example contextType: 'src/types/context.ts#Context' // for named export\n\t * @example contextType: 'src/types/context.ts' // for default export\n\t * @defaultValue undefined\n\t */\n\tcontextType?: string;\n\n\t/**\n\t * Path to Baeta Extensions (ex. auth-extension).\n\t * Only default export is supported.\n\t * @example extensions: 'src/extensions.ts'\n\t * @defaultValue undefined\n\t */\n\textensions?: string;\n\n\t/**\n\t * Custom scalar type mappings.\n\t * Maps GraphQL scalar types to TypeScript types.\n\t * Supports global types and imports.\n\t * @example { DateTime: 'Date', JSON: 'Record<string, unknown>' }\t * @defaultValue undefined\n\t */\n\tscalars?: Record<string, string>;\n\n\t/**\n\t * Configuration options for generated files.\n\t */\n\tfileOptions?: FileOptions;\n\n\t/**\n\t * Custom schema loaders for processing schema files.\n\t */\n\tloaders?: Loader[];\n\n\t/**\n\t * File extension to use in generated import statements.\n\t * Set to false to omit extensions.\n\t * @defaultValue '.ts'\n\t */\n\timportExtension?: '.js' | '.ts' | false;\n}\n\nexport interface NormalizedGeneratorOptions {\n\tcwd: string;\n\tschemas: string[];\n\tmodulesDir: string;\n\tmoduleDefinitionName: string;\n\tbaseTypesPath: string;\n\tcontextType?: string;\n\textensions?: string;\n\tscalars?: Record<string, string>;\n\tfileOptions?: FileOptions;\n\tloaders?: Loader[];\n\timportExtension?: '.js' | '.ts';\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n\tconst cwd = posixPath(options.cwd ?? process.cwd());\n\tconst schemas = options.schemas ?? ['src/**/*.graphql'];\n\tconst modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n\tconst moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\n\tconst defaultBaseTypesRoot = resolve(modulesDir, '../__generated__/types.ts');\n\tconst baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);\n\tconst baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));\n\n\tconst contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);\n\tconst extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);\n\n\treturn {\n\t\tcwd,\n\t\tschemas,\n\t\tmodulesDir,\n\t\tmoduleDefinitionName,\n\t\tbaseTypesPath,\n\t\tcontextType,\n\t\textensions,\n\t\tscalars: options.scalars,\n\t\tfileOptions: options.fileOptions,\n\t\tloaders: options.loaders,\n\t\timportExtension:\n\t\t\toptions.importExtension === false ? undefined : (options.importExtension ?? '.ts'),\n\t};\n}\n\nfunction resolveContextType(root: string, baseTypesRoot: string, contextType?: string) {\n\tif (!contextType) {\n\t\treturn;\n\t}\n\n\tif (isAbsolute(contextType)) {\n\t\treturn contextType;\n\t}\n\n\tif (contextType[0] === '!') {\n\t\treturn contextType.slice(1);\n\t}\n\n\tconst contextTypeRoot = resolve(root, contextType);\n\n\treturn posixPath(relative(join(baseTypesRoot, '../'), contextTypeRoot));\n}\n\nfunction resolveExtensionPath(\n\tmodulesDir: string,\n\tmoduleDefinitionName: string,\n\textensionsPath?: string,\n) {\n\tif (!extensionsPath) {\n\t\treturn;\n\t}\n\n\tif (isAbsolute(extensionsPath)) {\n\t\treturn extensionsPath;\n\t}\n\n\tif (extensionsPath[0] === '!') {\n\t\treturn extensionsPath.slice(1);\n\t}\n\n\treturn posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));\n}\n","import fs from 'node:fs/promises';\nimport { dirname, extname } from '@baeta/util-path';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n\t/**\n\t * Add generation notice at the beginning of the file.\n\t * @defaultValue true\n\t */\n\taddGenerationNoticeHeader?: boolean;\n\n\t/**\n\t * Add eslint-disable comment at the beginning of the file.\n\t * @defaultValue true\n\t */\n\taddEslintDisableHeader?: boolean;\n\n\t/**\n\t * Add custom header at the beginning of the file.\n\t */\n\taddHeader?: (name: string, content: string, tag: string) => string;\n\n\t/**\n\t * Edit the content of the file before writing it.\n\t */\n\ttransformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n\tpersisted = false;\n\n\tconstructor(\n\t\tpublic filename: string,\n\t\tpublic content: string,\n\t\tpublic tag: string,\n\t\tprivate options?: FileOptions,\n\t) {}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait fs.mkdir(dir, { recursive: true });\n\n\t\tconst content = await this.buildContent();\n\n\t\treturn fs.writeFile(this.filename, content, 'utf-8');\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\t\treturn fs.unlink(this.filename);\n\t};\n\n\tprotected async buildContent() {\n\t\tconst content = this.buildHeader() + this.content;\n\n\t\tif (this.options?.transformContent) {\n\t\t\treturn this.options.transformContent(this.filename, content, this.tag);\n\t\t}\n\n\t\treturn content;\n\t}\n\n\tprotected buildHeader() {\n\t\tconst headerItems: string[] = [];\n\n\t\tif (this.options?.addGenerationNoticeHeader !== false) {\n\t\t\tconst comment = this.createComment(\n\t\t\t\t'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n\t\t\t);\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addEslintDisableHeader !== false) {\n\t\t\tconst comment = this.createComment('eslint-disable');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addHeader) {\n\t\t\tconst customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n\t\t\theaderItems.push(customHeader);\n\t\t}\n\n\t\tif (headerItems.length === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `${headerItems.join('\\n')}\\n\\n`;\n\t}\n\n\tprotected createComment(comment: string) {\n\t\tconst extension = extname(this.filename);\n\n\t\tif (['.gql', '.graphql'].includes(extension)) {\n\t\t\treturn `# ${comment}`;\n\t\t}\n\n\t\treturn `/* ${comment} */`;\n\t}\n}\n","import { mkdir, open, writeFile } from 'node:fs/promises';\nimport { dirname } from '@baeta/util-path';\nimport { File, type FileOptions } from './file.ts';\n\nexport class FileBlock extends File {\n\tconstructor(\n\t\tpublic filename: string,\n\t\tpublic content: string,\n\t\tpublic start: string,\n\t\tpublic end: string,\n\t\tpublic tag: string,\n\t\toptions?: FileOptions,\n\t) {\n\t\tsuper(filename, content, tag, {\n\t\t\taddEslintDisableHeader: options?.addEslintDisableHeader ?? false,\n\t\t\taddGenerationNoticeHeader: options?.addGenerationNoticeHeader ?? false,\n\t\t});\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait mkdir(dir, { recursive: true });\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tthis.content = this.addBlockToContent(existingContent);\n\t\tconst content = await this.buildContent();\n\n\t\tif (fd) {\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(content, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t} else {\n\t\t\tawait writeFile(this.filename, content, 'utf-8');\n\t\t}\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tif (fd) {\n\t\t\tconst [start, end] = this.getSlices(existingContent);\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(start + end, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t}\n\t};\n\n\tprotected async getExistingContent() {\n\t\ttry {\n\t\t\tconst fd = await open(this.filename, 'r+');\n\t\t\tconst existingContent = await fd.readFile('utf-8');\n\t\t\treturn [existingContent, fd] as const;\n\t\t} catch (err) {\n\t\t\treturn ['', null] as const;\n\t\t}\n\t}\n\n\tprotected getSlices(existingContent: string) {\n\t\tconst startMarkerIndex = existingContent.indexOf(this.start);\n\t\tconst endMarkerIndex = existingContent.lastIndexOf(this.end);\n\n\t\tif (startMarkerIndex === -1 || endMarkerIndex === -1) {\n\t\t\treturn [existingContent, '', false] as const;\n\t\t}\n\n\t\treturn [\n\t\t\texistingContent.slice(0, startMarkerIndex),\n\t\t\texistingContent.slice(endMarkerIndex + this.end.length),\n\t\t\ttrue,\n\t\t] as const;\n\t}\n\n\tprotected addBlockToContent(existingContent: string) {\n\t\tconst block = `${this.start}\\n${this.content}\\n${this.end}`;\n\t\tconst [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);\n\t\tconst padding = hasMarkers ? '' : this.buildPadding(existingContent);\n\t\treturn startSlice + padding + block + endSlice;\n\t}\n\n\tprotected buildPadding(existingContent: string) {\n\t\tif (existingContent === '') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n\\n')) {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n')) {\n\t\t\treturn '\\n';\n\t\t}\n\n\t\treturn '\\n\\n';\n\t}\n}\n","import { File, type FileOptions } from './file.ts';\n\nexport class FileManager {\n\tfiles: File[] = [];\n\n\tconstructor(public fileOptions?: FileOptions) {}\n\n\tcreateAndAdd(filename: string, content: string, tag: string) {\n\t\tconst file = new File(filename, content, tag, this.fileOptions);\n\t\tthis.add(file);\n\t\treturn file;\n\t}\n\n\tadd(...file: File[]) {\n\t\tthis.files.push(...file);\n\t}\n\n\tget(filename: string) {\n\t\treturn this.files.find((file) => file.filename === filename);\n\t}\n\n\tgetAll() {\n\t\treturn this.files;\n\t}\n\n\tgetByTag(tag: string) {\n\t\treturn this.files.filter((file) => file.tag === tag);\n\t}\n\n\tremove(filename: string) {\n\t\tconst index = this.files.findIndex((file) => file.filename === filename);\n\t\tthis.files.splice(index, 1);\n\t}\n\n\tremoveAll() {\n\t\tthis.files = [];\n\t}\n\n\tremoveByTag(tag: string) {\n\t\tthis.files = this.files.filter((file) => file.tag !== tag);\n\t}\n\n\twriteAll() {\n\t\tconst toWrite = this.files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\twriteByTag(tag: string) {\n\t\tconst files = this.getByTag(tag);\n\t\tconst toWrite = files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\tunlinkAll() {\n\t\treturn Promise.all(this.files.map((file) => file.unlink())).then(() => {\n\t\t\t// void\n\t\t});\n\t}\n\n\tgetPersistedFiles() {\n\t\treturn this.files.filter((file) => file.persisted);\n\t}\n}\n","import { camelCase, pascalCase } from 'change-case-all';\n\nexport function getModuleGetName(name: string) {\n\treturn `get${pascalCase(name)}Module`;\n}\n\nexport function getModuleCreateName(name: string) {\n\treturn `create${pascalCase(name)}Module`;\n}\n\nexport function getModuleVariableName(name: string) {\n\treturn camelCase(`${name}Module`);\n}\n","import { PluginType } from '@baeta/plugin';\nimport type { NormalizedGeneratorOptions } from './config.ts';\nimport type { Ctx } from './ctx.ts';\nimport type { Watcher, WatcherFile } from './watcher.ts';\n\nexport enum GeneratorPluginVersion {\n\tV1 = 'v1',\n}\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n\tctx: Ctx<Store>,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n\toptions: NormalizedGeneratorOptions,\n\twatcher: Watcher,\n\treload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n\tname: string;\n\tactionName: string;\n\tsetup?: GeneratorPluginV1Fn<Store>;\n\tgenerate?: GeneratorPluginV1Fn<Store>;\n\tend?: GeneratorPluginV1Fn<Store>;\n\twatch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n\tname: string;\n\tactionName: string;\n\tversion: GeneratorPluginVersion.V1;\n\ttype: PluginType.Generator;\n\tsetup: GeneratorPluginV1Fn<Store>;\n\tgenerate: GeneratorPluginV1Fn<Store>;\n\tend: GeneratorPluginV1Fn<Store>;\n\twatch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (ctx, next) => {\n\treturn next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = unknown>(\n\toptions: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n\treturn {\n\t\tname: options.name,\n\t\tactionName: options.actionName,\n\t\tversion: GeneratorPluginVersion.V1,\n\t\ttype: PluginType.Generator,\n\t\tend: options.end ?? defaultPluginFn,\n\t\tgenerate: options.generate ?? defaultPluginFn,\n\t\tsetup: options.setup ?? defaultPluginFn,\n\t\twatch: options.watch ?? defaultWatchFn,\n\t};\n}\n\nexport function isGeneratorPlugin(plugin: {\n\ttype: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n\treturn plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n\tif (!plugins) {\n\t\treturn [];\n\t}\n\treturn plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport {\n\ttype AsyncSubscription,\n\ttype Event,\n\ttype EventType,\n\ttype Options,\n\tsubscribe,\n} from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { type MatchPattern, WatcherIgnore } from './watcher-ignore.ts';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n\ttype: EventType;\n\tpath: string;\n\trelativePath: string;\n}\nexport class Watcher {\n\tprivate subscription: AsyncSubscription;\n\n\tprivate listeners: Record<EventType, WatcherListener[]> = {\n\t\tcreate: [],\n\t\tupdate: [],\n\t\tdelete: [],\n\t};\n\n\tprivate watcherIgnore: WatcherIgnore;\n\n\tconstructor(\n\t\tprivate readonly cwd: string,\n\t\tprivate readonly options?: Options,\n\t) {\n\t\tthis.watcherIgnore = new WatcherIgnore(cwd);\n\t\tthis.subscription = this.createSubscription();\n\t}\n\n\tonEvents = (err: Error | null, events: Event[]) => {\n\t\tif (err) {\n\t\t\tconsole.error(err);\n\t\t\treturn;\n\t\t}\n\n\t\tconst filteredEvents = events.filter((event) => {\n\t\t\treturn !this.watcherIgnore.isIgnored(posixPath(event.path));\n\t\t});\n\n\t\tfor (const event of filteredEvents) {\n\t\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\t\tlistener({\n\t\t\t\t\ttype: event.type,\n\t\t\t\t\tpath: posixPath(event.path),\n\t\t\t\t\trelativePath: posixPath(path.relative(this.cwd, event.path)),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\ton(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event].push(listener);\n\t}\n\n\toff(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.ignore(pattern);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.unignore(pattern);\n\t}\n\n\tcreateSubscription() {\n\t\tconst promise = subscribe(this.cwd, this.onEvents, this.options);\n\n\t\tconst unsubscribe = async () => {\n\t\t\tconst subscription = await promise;\n\t\t\tawait subscription.unsubscribe();\n\t\t};\n\n\t\treturn {\n\t\t\tunsubscribe,\n\t\t};\n\t}\n\n\tclose() {\n\t\treturn this.subscription.unsubscribe();\n\t}\n}\n","import path from '@baeta/util-path';\nimport micromatch from 'micromatch';\n\nexport type MatchFn = (testString: string) => boolean;\nexport type MatchPattern = string | RegExp | MatchFn;\n\nexport class WatcherIgnore {\n\tprivate files: string[] = [];\n\tprivate regexps: RegExp[] = [];\n\tprivate functions: MatchFn[] = [];\n\n\tprivate globs: MatchFn[] = [];\n\tprivate globsMap = new Map<string, MatchFn>();\n\n\tconstructor(private readonly cwd: string) {}\n\n\tignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tthis.files.push(this.resolveFile(pattern));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.set(pattern, micromatch.matcher(pattern));\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisMicromatch(pattern: string) {\n\t\tconst result = micromatch.scan(pattern);\n\t\treturn result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n\t}\n\n\tresolveFile(file: string) {\n\t\treturn path.isAbsolute(file) ? file : path.join(this.cwd, file);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps = this.regexps.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions = this.functions.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tconst file = this.resolveFile(pattern);\n\t\t\tthis.files = this.files.filter((p) => p !== file);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.delete(pattern);\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisIgnored(path: string) {\n\t\tif (this.files.includes(path)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.globs.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.regexps.some((r)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Q,MAAM,GAAG;AACjB;AAAA,IACD;AAEA,UAAM,iBAAiB,OAAO,OAAO,CAAC,UAAU;AAC/C,aAAO,CAAC,KAAK,cAAc,UAAUC,WAAU,MAAM,IAAI,CAAC;AAAA,IAC3D,CAAC;AAED,eAAW,SAAS,gBAAgB;AACnC,iBAAW,YAAY,KAAK,UAAU,MAAM,IAAI,GAAG;AAClD,iBAAS;AAAA,UACR,MAAM,MAAM;AAAA,UACZ,MAAMA,WAAU,MAAM,IAAI;AAAA,UAC1B,cAAcA,WAAUC,MAAK,SAAS,KAAK,KAAK,MAAM,IAAI,CAAC;AAAA,QAC5D,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAEA,GAAG,OAAkB,UAA2B;AAC/C,SAAK,UAAU,KAAK,EAAE,KAAK,QAAQ;AAAA,EACpC;AAAA,EAEA,IAAI,OAAkB,UAA2B;AAChD,SAAK,UAAU,KAAK,IAAI,KAAK,UAAU,KAAK,EAAE,OAAO,CAAC,MAAM,MAAM,QAAQ;AAAA,EAC3E;AAAA,EAEA,OAAO,SAAuB;AAC7B,SAAK,cAAc,OAAO,OAAO;AAAA,EAClC;AAAA,EAEA,SAAS,SAAuB;AAC/B,SAAK,cAAc,SAAS,OAAO;AAAA,EACpC;AAAA,EAEA,qBAAqB;AACpB,UAAM,UAAU,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK,OAAO;AAE/D,UAAM,cAAc,YAAY;AAC/B,YAAM,eAAe,MAAM;AAC3B,YAAM,aAAa,YAAY;AAAA,IAChC;AAEA,WAAO;AAAA,MACN;AAAA,IACD;AAAA,EACD;AAAA,EAEA,QAAQ;AACP,WAAO,KAAK,aAAa,YAAY;AAAA,EACtC;AACD;","names":["dirname","dirname","GeneratorPluginVersion","path","posixPath","micromatch","path","micromatch","posixPath","path"]}
1
+ {"version":3,"sources":["../lib/config.ts","../lib/file.ts","../lib/file-block.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher.ts","../lib/watcher-ignore.ts"],"sourcesContent":["import { posixPath, resolve } from '@baeta/util-path';\nimport type { FileOptions } from './file.ts';\n\n/**\n * Interface for custom schema loaders.\n */\n// biome-ignore lint/suspicious/noExplicitAny: We don't want to import graphql for this type\ntype GraphQlLoaderAny = any;\nexport interface Loader<TOptions = GraphQlLoaderAny> {\n\tload(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;\n\tloadSync?(pointer: string, options?: TOptions): GraphQlLoaderAny[] | null | never;\n}\n\n/**\n * Options for the Baeta Generator.\n */\nexport interface GeneratorOptions {\n\t/**\n\t * Current working directory for resolving relative paths.\n\t * @defaultValue process.cwd()\n\t */\n\tcwd?: string;\n\n\t/**\n\t * Glob pattern(s) to locate GraphQL schema files.\n\t * @defaultValue ```ts\n\t * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']\n\t * ```\n\t */\n\tschemas: string[];\n\n\t/**\n\t * Root directory where GraphQL modules are defined.\n\t * @defaultValue 'src/modules'\n\t */\n\tmodulesDir?: string;\n\n\t/**\n\t * Filename for the generated module definition file.\n\t * Contains type definitions and the GraphQL AST.\n\t * @defaultValue 'typedef.ts'\n\t */\n\tmoduleDefinitionName?: string;\n\n\t/**\n\t * Output path for the generated type files.\n\t * @defaultValue ```ts\n\t * `${modulesDir}/../__generated__/types.ts`\n\t * ```\n\t */\n\ttypesDir?: string;\n\n\t/**\n\t * Configuration options for generated files.\n\t */\n\tfileOptions?: FileOptions;\n\n\t/**\n\t * Custom schema loaders for processing schema files.\n\t */\n\tloaders?: Loader[];\n\n\t/**\n\t * File extension to use in generated import statements.\n\t * Set to false to omit extensions.\n\t * @defaultValue '.ts'\n\t */\n\timportExtension?: '.js' | '.ts' | false;\n}\n\nexport interface NormalizedGeneratorOptions {\n\tcwd: string;\n\tschemas: string[];\n\tmodulesDir: string;\n\tmoduleDefinitionName: string;\n\ttypesDir: string;\n\tfileOptions?: FileOptions;\n\tloaders?: Loader[];\n\timportExtension: '.js' | '.ts' | '';\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n\tconst cwd = posixPath(options.cwd ?? process.cwd());\n\tconst schemas = options.schemas ?? ['src/**/*.graphql'];\n\tconst modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n\tconst moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\tconst defaultTypesDir = resolve(modulesDir, '../__generated__/');\n\tconst typesDir = resolve(cwd, options.typesDir || defaultTypesDir);\n\n\treturn {\n\t\tcwd,\n\t\tschemas,\n\t\tmodulesDir,\n\t\tmoduleDefinitionName,\n\t\ttypesDir,\n\t\tfileOptions: options.fileOptions,\n\t\tloaders: options.loaders,\n\t\timportExtension: options.importExtension === false ? '' : (options.importExtension ?? '.ts'),\n\t};\n}\n","import fs from 'node:fs/promises';\nimport { dirname, extname } from '@baeta/util-path';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n\t/**\n\t * Disable generation notice at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableGenerationNoticeHeader?: boolean;\n\n\t/**\n\t * Disable eslint-disable comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableEslintHeader?: boolean;\n\n\t/**\n\t * Disable biome comment at the beginning of the file.\n\t * @defaultValue false\n\t */\n\tdisableBiomeHeader?: boolean;\n\n\t/**\n\t * Allow overwriting the file.\n\t * @defaultValue true\n\t */\n\tallowOverwrite?: boolean;\n\n\t/**\n\t * Add custom header at the beginning of the file.\n\t */\n\taddHeader?: (name: string, content: string, tag: string) => string;\n\n\t/**\n\t * Edit the content of the file before writing it.\n\t */\n\ttransformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n\tpersisted = false;\n\tfilename: string;\n\tcontent: string;\n\ttag: string;\n\tprivate options?: FileOptions;\n\n\tconstructor(filename: string, content: string, tag: string, options?: FileOptions) {\n\t\tthis.filename = filename;\n\t\tthis.content = content;\n\t\tthis.tag = tag;\n\t\tthis.options = options;\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tif (this.options?.allowOverwrite === false) {\n\t\t\tconst exists = await fs\n\t\t\t\t.stat(this.filename)\n\t\t\t\t.then((res) => res.isFile())\n\t\t\t\t.catch(() => false);\n\t\t\tif (exists) return;\n\t\t}\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait fs.mkdir(dir, { recursive: true });\n\n\t\tconst content = await this.buildContent();\n\n\t\treturn fs.writeFile(this.filename, content, 'utf-8');\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\t\treturn fs.unlink(this.filename);\n\t};\n\n\tprotected async buildContent() {\n\t\tconst content = this.buildHeader() + this.content;\n\n\t\tif (this.options?.transformContent) {\n\t\t\treturn this.options.transformContent(this.filename, content, this.tag);\n\t\t}\n\n\t\treturn content;\n\t}\n\n\tprotected buildHeader() {\n\t\tconst headerItems: string[] = [];\n\n\t\tif (this.options?.disableGenerationNoticeHeader !== true) {\n\t\t\tconst comment = this.createComment(\n\t\t\t\t'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n\t\t\t);\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableEslintHeader !== true) {\n\t\t\tconst comment = this.createComment('eslint-disable');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.disableBiomeHeader !== true) {\n\t\t\tconst comment = this.createComment('@biome-ignore-all: generated file');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addHeader) {\n\t\t\tconst customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n\t\t\theaderItems.push(customHeader);\n\t\t}\n\n\t\tif (headerItems.length === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `${headerItems.join('\\n')}\\n\\n`;\n\t}\n\n\tprotected createComment(comment: string) {\n\t\tconst extension = extname(this.filename);\n\n\t\tif (['.gql', '.graphql'].includes(extension)) {\n\t\t\treturn `# ${comment}`;\n\t\t}\n\n\t\treturn `/* ${comment} */`;\n\t}\n}\n","import { mkdir, open, writeFile } from 'node:fs/promises';\nimport { dirname } from '@baeta/util-path';\nimport { File, type FileOptions } from './file.ts';\n\nexport class FileBlock extends File {\n\tpublic filename: string;\n\tpublic content: string;\n\tpublic start: string;\n\tpublic end: string;\n\tpublic tag: string;\n\tconstructor(\n\t\tfilename: string,\n\t\tcontent: string,\n\t\tstart: string,\n\t\tend: string,\n\t\ttag: string,\n\t\toptions?: FileOptions,\n\t) {\n\t\tsuper(filename, content, tag, {\n\t\t\tdisableBiomeHeader: options?.disableBiomeHeader ?? true,\n\t\t\tdisableEslintHeader: options?.disableEslintHeader ?? true,\n\t\t\tdisableGenerationNoticeHeader: options?.disableGenerationNoticeHeader ?? true,\n\t\t});\n\t\tthis.filename = filename;\n\t\tthis.content = content;\n\t\tthis.start = start;\n\t\tthis.end = end;\n\t\tthis.tag = tag;\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait mkdir(dir, { recursive: true });\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tthis.content = this.addBlockToContent(existingContent);\n\t\tconst content = await this.buildContent();\n\n\t\tif (fd) {\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(content, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t} else {\n\t\t\tawait writeFile(this.filename, content, 'utf-8');\n\t\t}\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tif (fd) {\n\t\t\tconst [start, end] = this.getSlices(existingContent);\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(start + end, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t}\n\t};\n\n\tprotected async getExistingContent() {\n\t\ttry {\n\t\t\tconst fd = await open(this.filename, 'r+');\n\t\t\tconst existingContent = await fd.readFile('utf-8');\n\t\t\treturn [existingContent, fd] as const;\n\t\t} catch {\n\t\t\treturn ['', null] as const;\n\t\t}\n\t}\n\n\tprotected getSlices(existingContent: string) {\n\t\tconst startMarkerIndex = existingContent.indexOf(this.start);\n\t\tconst endMarkerIndex = existingContent.lastIndexOf(this.end);\n\n\t\tif (startMarkerIndex === -1 || endMarkerIndex === -1) {\n\t\t\treturn [existingContent, '', false] as const;\n\t\t}\n\n\t\treturn [\n\t\t\texistingContent.slice(0, startMarkerIndex),\n\t\t\texistingContent.slice(endMarkerIndex + this.end.length),\n\t\t\ttrue,\n\t\t] as const;\n\t}\n\n\tprotected addBlockToContent(existingContent: string) {\n\t\tconst block = `${this.start}\\n${this.content}\\n${this.end}`;\n\t\tconst [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);\n\t\tconst padding = hasMarkers ? '' : this.buildPadding(existingContent);\n\t\treturn startSlice + padding + block + endSlice;\n\t}\n\n\tprotected buildPadding(existingContent: string) {\n\t\tif (existingContent === '') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n\\n')) {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n')) {\n\t\t\treturn '\\n';\n\t\t}\n\n\t\treturn '\\n\\n';\n\t}\n}\n","import { File, type FileOptions } from './file.ts';\n\nexport class FileManager {\n\tfiles: File[] = [];\n\tfileOptions?: FileOptions;\n\n\tconstructor(fileOptions?: FileOptions) {\n\t\tthis.fileOptions = fileOptions;\n\t}\n\n\tcreateAndAdd(filename: string, content: string, tag: string, options?: FileOptions) {\n\t\tconst file = new File(filename, content, tag, { ...this.fileOptions, ...options });\n\t\tthis.add(file);\n\t\treturn file;\n\t}\n\n\tadd(...file: File[]) {\n\t\tthis.files.push(...file);\n\t}\n\n\tget(filename: string) {\n\t\treturn this.files.find((file) => file.filename === filename);\n\t}\n\n\tgetAll() {\n\t\treturn this.files;\n\t}\n\n\tgetByTag(tag: string) {\n\t\treturn this.files.filter((file) => file.tag === tag);\n\t}\n\n\tremove(filename: string) {\n\t\tconst index = this.files.findIndex((file) => file.filename === filename);\n\t\tthis.files.splice(index, 1);\n\t}\n\n\tremoveAll() {\n\t\tthis.files = [];\n\t}\n\n\tremoveByTag(tag: string) {\n\t\tthis.files = this.files.filter((file) => file.tag !== tag);\n\t}\n\n\twriteAll() {\n\t\tconst toWrite = this.files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\twriteByTag(tag: string) {\n\t\tconst files = this.getByTag(tag);\n\t\tconst toWrite = files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\tunlinkAll() {\n\t\treturn Promise.all(this.files.map((file) => file.unlink())).then(() => {\n\t\t\t// void\n\t\t});\n\t}\n\n\tgetPersistedFiles() {\n\t\treturn this.files.filter((file) => file.persisted);\n\t}\n}\n","import { pascalCase } from 'change-case-all';\n\nexport function getModuleExportName(name: string) {\n\treturn `${pascalCase(name)}Module`;\n}\n","import { PluginType } from '@baeta/plugin';\nimport type { NormalizedGeneratorOptions } from './config.ts';\nimport type { Ctx } from './ctx.ts';\nimport type { Watcher, WatcherFile } from './watcher.ts';\n\nexport const GeneratorPluginVersion = {\n\tV1: 'v1',\n} as const;\n\nexport type GeneratorPluginVersion =\n\t(typeof GeneratorPluginVersion)[keyof typeof GeneratorPluginVersion];\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n\tctx: Ctx<Store>,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n\toptions: NormalizedGeneratorOptions,\n\twatcher: Watcher,\n\treload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n\tname: string;\n\tactionName: string;\n\tsetup?: GeneratorPluginV1Fn<Store>;\n\tgenerate?: GeneratorPluginV1Fn<Store>;\n\tend?: GeneratorPluginV1Fn<Store>;\n\twatch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n\tname: string;\n\tactionName: string;\n\tversion: typeof GeneratorPluginVersion.V1;\n\ttype: typeof PluginType.Generator;\n\tsetup: GeneratorPluginV1Fn<Store>;\n\tgenerate: GeneratorPluginV1Fn<Store>;\n\tend: GeneratorPluginV1Fn<Store>;\n\twatch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (_ctx, next) => {\n\treturn next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = unknown>(\n\toptions: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n\treturn {\n\t\tname: options.name,\n\t\tactionName: options.actionName,\n\t\tversion: GeneratorPluginVersion.V1,\n\t\ttype: PluginType.Generator,\n\t\tend: options.end ?? defaultPluginFn,\n\t\tgenerate: options.generate ?? defaultPluginFn,\n\t\tsetup: options.setup ?? defaultPluginFn,\n\t\twatch: options.watch ?? defaultWatchFn,\n\t};\n}\n\nexport function isGeneratorPlugin(plugin: {\n\ttype: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n\treturn plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n\tif (!plugins) {\n\t\treturn [];\n\t}\n\treturn plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport {\n\ttype AsyncSubscription,\n\ttype Event,\n\ttype EventType,\n\ttype Options,\n\tsubscribe,\n} from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { type MatchPattern, WatcherIgnore } from './watcher-ignore.ts';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n\ttype: EventType;\n\tpath: string;\n\trelativePath: string;\n}\nexport class Watcher {\n\tprivate readonly cwd: string;\n\tprivate readonly options?: Options;\n\n\tprivate subscription: AsyncSubscription;\n\n\tprivate listeners: Record<EventType, WatcherListener[]> = {\n\t\tcreate: [],\n\t\tupdate: [],\n\t\tdelete: [],\n\t};\n\n\tprivate watcherIgnore: WatcherIgnore;\n\n\tconstructor(cwd: string, options?: Options) {\n\t\tthis.cwd = cwd;\n\t\tthis.options = options;\n\t\tthis.watcherIgnore = new WatcherIgnore(cwd);\n\t\tthis.subscription = this.createSubscription();\n\t}\n\n\tonEvents = (err: Error | null, events: Event[]) => {\n\t\tif (err) {\n\t\t\tconsole.error(err);\n\t\t\treturn;\n\t\t}\n\n\t\tconst filteredEvents = events.filter((event) => {\n\t\t\treturn !this.watcherIgnore.isIgnored(posixPath(event.path));\n\t\t});\n\n\t\tfor (const event of filteredEvents) {\n\t\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\t\tlistener({\n\t\t\t\t\ttype: event.type,\n\t\t\t\t\tpath: posixPath(event.path),\n\t\t\t\t\trelativePath: posixPath(path.relative(this.cwd, event.path)),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\ton(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event].push(listener);\n\t}\n\n\toff(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.ignore(pattern);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.unignore(pattern);\n\t}\n\n\tcreateSubscription() {\n\t\tconst promise = subscribe(this.cwd, this.onEvents, this.options);\n\n\t\tconst unsubscribe = async () => {\n\t\t\tconst subscription = await promise;\n\t\t\tawait subscription.unsubscribe();\n\t\t};\n\n\t\treturn {\n\t\t\tunsubscribe,\n\t\t};\n\t}\n\n\tclose() {\n\t\treturn this.subscription.unsubscribe();\n\t}\n}\n","import path from '@baeta/util-path';\nimport micromatch from 'micromatch';\n\nexport type MatchFn = (testString: string) => boolean;\nexport type MatchPattern = string | RegExp | MatchFn;\n\nexport class WatcherIgnore {\n\tprivate readonly cwd: string;\n\tprivate files: string[] = [];\n\tprivate regexps: RegExp[] = [];\n\tprivate functions: MatchFn[] = [];\n\n\tprivate globs: MatchFn[] = [];\n\tprivate globsMap = new Map<string, MatchFn>();\n\n\tconstructor(cwd: string) {\n\t\tthis.cwd = cwd;\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tthis.files.push(this.resolveFile(pattern));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.set(pattern, micromatch.matcher(pattern));\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisMicromatch(pattern: string) {\n\t\tconst result = micromatch.scan(pattern);\n\t\treturn result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n\t}\n\n\tresolveFile(file: string) {\n\t\treturn path.isAbsolute(file) ? file : path.join(this.cwd, file);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps = this.regexps.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions = this.functions.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tconst file = this.resolveFile(pattern);\n\t\t\tthis.files = this.files.filter((p) => p !== file);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.delete(pattern);\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisIgnored(path: string) {\n\t\tif (this.files.includes(path)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.globs.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.regexps.some((r) => r.test(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.functions.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n}\n"],"mappings":";AAAA,SAAS,WAAW,eAAe;AAiF5B,SAAS,YAAY,SAAuD;AAClF,QAAM,MAAM,UAAU,QAAQ,OAAO,QAAQ,IAAI,CAAC;AAClD,QAAM,UAAU,QAAQ,WAAW,CAAC,kBAAkB;AACtD,QAAM,aAAa,UAAU,QAAQ,KAAK,QAAQ,cAAc,aAAa,CAAC;AAC9E,QAAM,uBAAuB,QAAQ,wBAAwB;AAC7D,QAAM,kBAAkB,QAAQ,YAAY,mBAAmB;AAC/D,QAAM,WAAW,QAAQ,KAAK,QAAQ,YAAY,eAAe;AAEjE,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,QAAQ;AAAA,IACrB,SAAS,QAAQ;AAAA,IACjB,iBAAiB,QAAQ,oBAAoB,QAAQ,KAAM,QAAQ,mBAAmB;AAAA,EACvF;AACD;;;ACnGA,OAAO,QAAQ;AACf,SAAS,SAAS,eAAe;AAyC1B,IAAM,OAAN,MAAW;AAAA,EACjB,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA,EAER,YAAY,UAAkB,SAAiB,KAAa,SAAuB;AAClF,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,MAAM;AACX,SAAK,UAAU;AAAA,EAChB;AAAA,EAEA,QAAQ,YAAY;AACnB,QAAI,KAAK,WAAW;AACnB;AAAA,IACD;AACA,SAAK,YAAY;AAEjB,QAAI,KAAK,SAAS,mBAAmB,OAAO;AAC3C,YAAM,SAAS,MAAM,GACnB,KAAK,KAAK,QAAQ,EAClB,KAAK,CAAC,QAAQ,I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,UACR,MAAM,MAAM;AAAA,UACZ,MAAMA,WAAU,MAAM,IAAI;AAAA,UAC1B,cAAcA,WAAUC,MAAK,SAAS,KAAK,KAAK,MAAM,IAAI,CAAC;AAAA,QAC5D,CAAC;AAAA,MACF;AAAA,IACD;AAAA,EACD;AAAA,EAEA,GAAG,OAAkB,UAA2B;AAC/C,SAAK,UAAU,KAAK,EAAE,KAAK,QAAQ;AAAA,EACpC;AAAA,EAEA,IAAI,OAAkB,UAA2B;AAChD,SAAK,UAAU,KAAK,IAAI,KAAK,UAAU,KAAK,EAAE,OAAO,CAAC,MAAM,MAAM,QAAQ;AAAA,EAC3E;AAAA,EAEA,OAAO,SAAuB;AAC7B,SAAK,cAAc,OAAO,OAAO;AAAA,EAClC;AAAA,EAEA,SAAS,SAAuB;AAC/B,SAAK,cAAc,SAAS,OAAO;AAAA,EACpC;AAAA,EAEA,qBAAqB;AACpB,UAAM,UAAU,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK,OAAO;AAE/D,UAAM,cAAc,YAAY;AAC/B,YAAM,eAAe,MAAM;AAC3B,YAAM,aAAa,YAAY;AAAA,IAChC;AAEA,WAAO;AAAA,MACN;AAAA,IACD;AAAA,EACD;AAAA,EAEA,QAAQ;AACP,WAAO,KAAK,aAAa,YAAY;AAAA,EACtC;AACD;","names":["dirname","dirname","path","posixPath","micromatch","path","micromatch","posixPath","path"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/generator-sdk",
3
- "version": "1.0.1",
3
+ "version": "2.0.0-next.0",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -27,8 +27,8 @@
27
27
  "type": "module",
28
28
  "exports": {
29
29
  ".": {
30
- "types": "./dist/index.d.ts",
31
- "default": "./dist/index.js"
30
+ "types": "./index.ts",
31
+ "default": "./index.ts"
32
32
  }
33
33
  },
34
34
  "types": "dist/index.d.ts",
@@ -43,21 +43,21 @@
43
43
  "types": "tsc --noEmit"
44
44
  },
45
45
  "dependencies": {
46
- "@baeta/plugin": "^1.0.1",
47
- "@baeta/util-path": "^1.0.1",
46
+ "@baeta/plugin": "workspace:^",
47
+ "@baeta/util-path": "workspace:^",
48
48
  "@parcel/watcher": "^2.5.1",
49
49
  "change-case-all": "2.1.0",
50
50
  "micromatch": "^4.0.8"
51
51
  },
52
52
  "devDependencies": {
53
- "@baeta/builder": "^0.0.0",
54
- "@baeta/tsconfig": "^0.0.0",
53
+ "@baeta/builder": "workspace:^",
54
+ "@baeta/tsconfig": "workspace:^",
55
55
  "@types/micromatch": "^4.0.9",
56
- "@types/node": "^22.13.10",
57
- "typescript": "^5.8.2"
56
+ "@types/node": "^22.18.11",
57
+ "typescript": "^5.9.3"
58
58
  },
59
59
  "engines": {
60
- "node": ">=22.12.0"
60
+ "node": ">=22.20.0"
61
61
  },
62
62
  "publishConfig": {
63
63
  "access": "public",
@@ -68,15 +68,6 @@
68
68
  }
69
69
  }
70
70
  },
71
- "ava": {
72
- "extensions": {
73
- "ts": "module"
74
- },
75
- "nodeArguments": [
76
- "--no-warnings",
77
- "--experimental-transform-types"
78
- ]
79
- },
80
71
  "typedocOptions": {
81
72
  "entryPoints": [
82
73
  "./index.ts"
@@ -90,4 +81,4 @@
90
81
  "alphabetical-ignoring-documents"
91
82
  ]
92
83
  }
93
- }
84
+ }
package/CHANGELOG.md DELETED
@@ -1,235 +0,0 @@
1
- # @baeta/generator-sdk
2
-
3
- ## 1.0.1
4
-
5
- ### Patch Changes
6
-
7
- - [`583014f`](https://github.com/andreisergiu98/baeta/commit/583014f0bac810b25d9a8226bda2df4c9039f5e3) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Update dependencies
8
-
9
- - Updated dependencies [[`583014f`](https://github.com/andreisergiu98/baeta/commit/583014f0bac810b25d9a8226bda2df4c9039f5e3)]:
10
- - @baeta/plugin@1.0.1
11
- - @baeta/util-path@1.0.1
12
-
13
- ## 1.0.0
14
-
15
- ### Major Changes
16
-
17
- - [#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
18
-
19
- ### Patch Changes
20
-
21
- - [#189](https://github.com/andreisergiu98/baeta/pull/189) [`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add jsdocs
22
-
23
- - Updated dependencies [[`d500378`](https://github.com/andreisergiu98/baeta/commit/d500378198e0a9c48298c4242913bca8ad348228), [`1334c2a`](https://github.com/andreisergiu98/baeta/commit/1334c2a866676c88f0f3d380b22133d81c4e98bc)]:
24
- - @baeta/plugin@1.0.0
25
- - @baeta/util-path@1.0.0
26
-
27
- ## 0.1.5
28
-
29
- ### Patch Changes
30
-
31
- - [#184](https://github.com/andreisergiu98/baeta/pull/184) [`bf2d1a3`](https://github.com/andreisergiu98/baeta/commit/bf2d1a326235e5f34e723a5acc81cd7b974b913b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - generate with .ts extension by default
32
-
33
- ## 0.1.4
34
-
35
- ### Patch Changes
36
-
37
- - [`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add readme
38
-
39
- - Updated dependencies [[`b59db50`](https://github.com/andreisergiu98/baeta/commit/b59db501a83275ab2d964933080e688a3a5d8820)]:
40
- - @baeta/plugin@0.1.4
41
- - @baeta/util-path@0.1.4
42
-
43
- ## 0.1.3
44
-
45
- ### Patch Changes
46
-
47
- - [#180](https://github.com/andreisergiu98/baeta/pull/180) [`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Raise minimum required NodeJS version to 22.12.0. Drop CommonJS builds in favor of the require_esm feature from NodeJS 22.12.0 onwards.
48
-
49
- - [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
50
-
51
- - Updated dependencies [[`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72), [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857)]:
52
- - @baeta/plugin@0.1.3
53
- - @baeta/util-path@0.1.3
54
-
55
- ## 0.1.2
56
-
57
- ### Patch Changes
58
-
59
- - [`e3fb6f8`](https://github.com/andreisergiu98/baeta/commit/e3fb6f877b4b20e248ad79cbaa3655cabe973f6b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - revert fileblock instead of removing the file
60
-
61
- - [#170](https://github.com/andreisergiu98/baeta/pull/170) [`59bbb9c`](https://github.com/andreisergiu98/baeta/commit/59bbb9c4baaf716f27dc251fe7aeb0231e6c5321) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
62
-
63
- - Updated dependencies [[`59bbb9c`](https://github.com/andreisergiu98/baeta/commit/59bbb9c4baaf716f27dc251fe7aeb0231e6c5321)]:
64
- - @baeta/plugin@0.1.2
65
- - @baeta/util-path@0.1.2
66
-
67
- ## 0.1.1
68
-
69
- ### Patch Changes
70
-
71
- - [`7f1958c`](https://github.com/andreisergiu98/baeta/commit/7f1958c44d1b9bed473e48c875fdaa7020c434fa) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - allow custom extension for generated file imports
72
-
73
- - [#157](https://github.com/andreisergiu98/baeta/pull/157) [`b9638eb`](https://github.com/andreisergiu98/baeta/commit/b9638eb9fb713507efa9821b4f04cc7896a997b1) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - stricter linting, better type safety
74
-
75
- - [`fd3a5d2`](https://github.com/andreisergiu98/baeta/commit/fd3a5d27b497aca4b8807155e801b1c1197c5fe2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - handle cloudflare cache in cloudflare plugin
76
-
77
- - [`9d8d6a1`](https://github.com/andreisergiu98/baeta/commit/9d8d6a15d63579a2e0bdaa07b7efdcf10aff2492) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - remove all loaders apart from graphql file loader, and let users define extra loaders if needed
78
-
79
- - [`a3f0e5d`](https://github.com/andreisergiu98/baeta/commit/a3f0e5d03fc9ef21a87d3ec6bf264d0e9707636a) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - fix exports order in package.json
80
-
81
- - [#161](https://github.com/andreisergiu98/baeta/pull/161) [`cca37dd`](https://github.com/andreisergiu98/baeta/commit/cca37dd7135a2852f1f6e287c46911306bdc8da0) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
82
-
83
- - Updated dependencies [[`a3f0e5d`](https://github.com/andreisergiu98/baeta/commit/a3f0e5d03fc9ef21a87d3ec6bf264d0e9707636a), [`cca37dd`](https://github.com/andreisergiu98/baeta/commit/cca37dd7135a2852f1f6e287c46911306bdc8da0)]:
84
- - @baeta/plugin@0.1.1
85
- - @baeta/util-path@0.1.1
86
-
87
- ## 0.1.0
88
-
89
- ### Minor Changes
90
-
91
- - [#156](https://github.com/andreisergiu98/baeta/pull/156) [`01f3c20`](https://github.com/andreisergiu98/baeta/commit/01f3c20365539fad6e8a8694c59a8e86c95784e8) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise engine requirement to node >= 22
92
-
93
- ### Patch Changes
94
-
95
- - [#152](https://github.com/andreisergiu98/baeta/pull/152) [`d538c79`](https://github.com/andreisergiu98/baeta/commit/d538c7905e6ba96d9f294e2d528f9252e83acbe7) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update formatter
96
-
97
- - [#145](https://github.com/andreisergiu98/baeta/pull/145) [`08428d4`](https://github.com/andreisergiu98/baeta/commit/08428d4f03b79cab9c116ff7b3a3cf9a0b2620f2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
98
-
99
- - Updated dependencies [[`01f3c20`](https://github.com/andreisergiu98/baeta/commit/01f3c20365539fad6e8a8694c59a8e86c95784e8), [`d538c79`](https://github.com/andreisergiu98/baeta/commit/d538c7905e6ba96d9f294e2d528f9252e83acbe7), [`08428d4`](https://github.com/andreisergiu98/baeta/commit/08428d4f03b79cab9c116ff7b3a3cf9a0b2620f2)]:
100
- - @baeta/plugin@0.1.0
101
- - @baeta/util-path@0.1.0
102
-
103
- ## 0.0.14
104
-
105
- ### Patch Changes
106
-
107
- - [#139](https://github.com/andreisergiu98/baeta/pull/139) [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
108
-
109
- - [#139](https://github.com/andreisergiu98/baeta/pull/139) [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update typescript
110
-
111
- - Updated dependencies [[`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4), [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4)]:
112
- - @baeta/plugin@0.0.25
113
- - @baeta/util-path@0.0.6
114
-
115
- ## 0.0.13
116
-
117
- ### Patch Changes
118
-
119
- - [#128](https://github.com/andreisergiu98/baeta/pull/128) [`534917a`](https://github.com/andreisergiu98/baeta/commit/534917a18e7ed5d788a90a0335a5370d6af8f4a4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
120
-
121
- - Updated dependencies [[`534917a`](https://github.com/andreisergiu98/baeta/commit/534917a18e7ed5d788a90a0335a5370d6af8f4a4)]:
122
- - @baeta/plugin@0.0.24
123
- - @baeta/util-path@0.0.5
124
-
125
- ## 0.0.12
126
-
127
- ### Patch Changes
128
-
129
- - [#121](https://github.com/andreisergiu98/baeta/pull/121) [`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Update Node to v20
130
-
131
- - [#51](https://github.com/andreisergiu98/baeta/pull/51) [`d94ee47`](https://github.com/andreisergiu98/baeta/commit/d94ee47bc485c541ff011290c4ac6ef0c145c83f) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add native support for file monifications
132
-
133
- - Updated dependencies [[`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454)]:
134
- - @baeta/plugin@0.0.23
135
- - @baeta/util-path@0.0.4
136
-
137
- ## 0.0.11
138
-
139
- ### Patch Changes
140
-
141
- - [#117](https://github.com/andreisergiu98/baeta/pull/117) [`18db339`](https://github.com/andreisergiu98/baeta/commit/18db339719aa309c619372d2161c5fdbc08fa316) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add comments to config types
142
-
143
- - [#119](https://github.com/andreisergiu98/baeta/pull/119) [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
144
-
145
- - Updated dependencies [[`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a)]:
146
- - @baeta/plugin@0.0.22
147
- - @baeta/util-path@0.0.3
148
-
149
- ## 0.0.10
150
-
151
- ### Patch Changes
152
-
153
- - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
154
-
155
- - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies and builder
156
-
157
- - [#106](https://github.com/andreisergiu98/baeta/pull/106) [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add compatibility with windows
158
-
159
- - Updated dependencies [[`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e)]:
160
- - @baeta/plugin@0.0.21
161
- - @baeta/util-path@0.0.2
162
-
163
- ## 0.0.9
164
-
165
- ### Patch Changes
166
-
167
- - [#81](https://github.com/andreisergiu98/baeta/pull/81) [`3ff5e54`](https://github.com/andreisergiu98/baeta/commit/3ff5e54f31cf42ba2264b12309338d6e78710722) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add file transformation function from config
168
-
169
- - [#69](https://github.com/andreisergiu98/baeta/pull/69) [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
170
-
171
- - [#91](https://github.com/andreisergiu98/baeta/pull/91) [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
172
-
173
- - Updated dependencies [[`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37), [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546)]:
174
- - @baeta/plugin@0.0.20
175
-
176
- ## 0.0.8
177
-
178
- ### Patch Changes
179
-
180
- - [#66](https://github.com/andreisergiu98/baeta/pull/66) [`9a4a021`](https://github.com/andreisergiu98/baeta/commit/9a4a0214351b70295ce4f7eecaa8c49ab0e1325b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - replace chokidar with @parcel/watcher
181
-
182
- ## 0.0.7
183
-
184
- ### Patch Changes
185
-
186
- - Updated dependencies [[`6a2dd11`](https://github.com/andreisergiu98/baeta/commit/6a2dd110d6ffd2bff25d9c4501faebb052e0cd40)]:
187
- - @baeta/plugin@0.0.19
188
-
189
- ## 0.0.6
190
-
191
- ### Patch Changes
192
-
193
- - [#47](https://github.com/andreisergiu98/baeta/pull/47) [`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
194
-
195
- - [#43](https://github.com/andreisergiu98/baeta/pull/43) [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump dependencies
196
-
197
- - Updated dependencies [[`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9), [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2)]:
198
- - @baeta/plugin@0.0.18
199
-
200
- ## 0.0.5
201
-
202
- ### Patch Changes
203
-
204
- - [#40](https://github.com/andreisergiu98/baeta/pull/40) [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - avoid rewriting persisted files
205
-
206
- - [#40](https://github.com/andreisergiu98/baeta/pull/40) [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - normalize config
207
-
208
- ## 0.0.4
209
-
210
- ### Patch Changes
211
-
212
- - [`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - create cli sdk
213
- release prisma plugin
214
- update dependencies
215
- refactor generator plugins
216
- - Updated dependencies [[`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4)]:
217
- - @baeta/plugin@0.0.17
218
-
219
- ## 0.0.3
220
-
221
- ### Patch Changes
222
-
223
- - [`02936ae`](https://github.com/andreisergiu98/baeta/commit/02936aeb606c75a2a79b6ce4524851c6c62afb82) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump packages
224
-
225
- - Updated dependencies [[`02936ae`](https://github.com/andreisergiu98/baeta/commit/02936aeb606c75a2a79b6ce4524851c6c62afb82)]:
226
- - @baeta/plugin@0.0.16
227
-
228
- ## 0.0.2
229
-
230
- ### Patch Changes
231
-
232
- - [#25](https://github.com/andreisergiu98/baeta/pull/25) [`c2c5875`](https://github.com/andreisergiu98/baeta/commit/c2c5875f8356e166f34a20b3e4384f9bce093e61) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - refactor cli and plugins
233
-
234
- - Updated dependencies [[`c2c5875`](https://github.com/andreisergiu98/baeta/commit/c2c5875f8356e166f34a20b3e4384f9bce093e61)]:
235
- - @baeta/plugin@0.0.15
package/dist/index.d.ts DELETED
@@ -1,259 +0,0 @@
1
- import { EventType, Options, Event } from '@parcel/watcher';
2
- import micromatch from 'micromatch';
3
- export { default as micromatch } from 'micromatch';
4
- import * as fs_promises from 'fs/promises';
5
- import { PluginType } from '@baeta/plugin';
6
-
7
- /**
8
- * Options for generated files.
9
- */
10
- interface FileOptions {
11
- /**
12
- * Add generation notice at the beginning of the file.
13
- * @defaultValue true
14
- */
15
- addGenerationNoticeHeader?: boolean;
16
- /**
17
- * Add eslint-disable comment at the beginning of the file.
18
- * @defaultValue true
19
- */
20
- addEslintDisableHeader?: boolean;
21
- /**
22
- * Add custom header at the beginning of the file.
23
- */
24
- addHeader?: (name: string, content: string, tag: string) => string;
25
- /**
26
- * Edit the content of the file before writing it.
27
- */
28
- transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
29
- }
30
- declare class File {
31
- filename: string;
32
- content: string;
33
- tag: string;
34
- private options?;
35
- persisted: boolean;
36
- constructor(filename: string, content: string, tag: string, options?: FileOptions | undefined);
37
- write: () => Promise<void>;
38
- unlink: () => Promise<void>;
39
- protected buildContent(): Promise<string>;
40
- protected buildHeader(): string;
41
- protected createComment(comment: string): string;
42
- }
43
-
44
- /**
45
- * Interface for custom schema loaders.
46
- */
47
- interface Loader<TOptions = any> {
48
- load(pointer: string, options?: TOptions): Promise<any[] | null | never>;
49
- loadSync?(pointer: string, options?: TOptions): any[] | null | never;
50
- }
51
- /**
52
- * Options for the Baeta Generator.
53
- */
54
- interface GeneratorOptions {
55
- /**
56
- * Current working directory for resolving relative paths.
57
- * @defaultValue process.cwd()
58
- */
59
- cwd?: string;
60
- /**
61
- * Glob pattern(s) to locate GraphQL schema files.
62
- * @defaultValue ```ts
63
- * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']
64
- * ```
65
- */
66
- schemas: string[];
67
- /**
68
- * Root directory where GraphQL modules are defined.
69
- * @defaultValue 'src/modules'
70
- */
71
- modulesDir?: string;
72
- /**
73
- * Filename for the generated module definition file.
74
- * Contains type definitions and the GraphQL AST.
75
- * @defaultValue 'typedef.ts'
76
- */
77
- moduleDefinitionName?: string;
78
- /**
79
- * Output path for the generated base types file.
80
- * @defaultValue ```ts
81
- * `${modulesDir}/../__generated__/types.ts`
82
- * ```
83
- */
84
- baseTypesPath?: string;
85
- /**
86
- * Path to the context type definition.
87
- * Supports both named and default exports.
88
- * @example contextType: 'src/types/context.ts#Context' // for named export
89
- * @example contextType: 'src/types/context.ts' // for default export
90
- * @defaultValue undefined
91
- */
92
- contextType?: string;
93
- /**
94
- * Path to Baeta Extensions (ex. auth-extension).
95
- * Only default export is supported.
96
- * @example extensions: 'src/extensions.ts'
97
- * @defaultValue undefined
98
- */
99
- extensions?: string;
100
- /**
101
- * Custom scalar type mappings.
102
- * Maps GraphQL scalar types to TypeScript types.
103
- * Supports global types and imports.
104
- * @example { DateTime: 'Date', JSON: 'Record<string, unknown>' } * @defaultValue undefined
105
- */
106
- scalars?: Record<string, string>;
107
- /**
108
- * Configuration options for generated files.
109
- */
110
- fileOptions?: FileOptions;
111
- /**
112
- * Custom schema loaders for processing schema files.
113
- */
114
- loaders?: Loader[];
115
- /**
116
- * File extension to use in generated import statements.
117
- * Set to false to omit extensions.
118
- * @defaultValue '.ts'
119
- */
120
- importExtension?: '.js' | '.ts' | false;
121
- }
122
- interface NormalizedGeneratorOptions {
123
- cwd: string;
124
- schemas: string[];
125
- modulesDir: string;
126
- moduleDefinitionName: string;
127
- baseTypesPath: string;
128
- contextType?: string;
129
- extensions?: string;
130
- scalars?: Record<string, string>;
131
- fileOptions?: FileOptions;
132
- loaders?: Loader[];
133
- importExtension?: '.js' | '.ts';
134
- }
135
- declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
136
-
137
- declare class FileManager {
138
- fileOptions?: FileOptions | undefined;
139
- files: File[];
140
- constructor(fileOptions?: FileOptions | undefined);
141
- createAndAdd(filename: string, content: string, tag: string): File;
142
- add(...file: File[]): void;
143
- get(filename: string): File | undefined;
144
- getAll(): File[];
145
- getByTag(tag: string): File[];
146
- remove(filename: string): void;
147
- removeAll(): void;
148
- removeByTag(tag: string): void;
149
- writeAll(): Promise<void[]>;
150
- writeByTag(tag: string): Promise<void[]>;
151
- unlinkAll(): Promise<void>;
152
- getPersistedFiles(): File[];
153
- }
154
-
155
- type MatchFn = (testString: string) => boolean;
156
- type MatchPattern = string | RegExp | MatchFn;
157
- declare class WatcherIgnore {
158
- private readonly cwd;
159
- private files;
160
- private regexps;
161
- private functions;
162
- private globs;
163
- private globsMap;
164
- constructor(cwd: string);
165
- ignore(pattern: MatchPattern): void;
166
- isMicromatch(pattern: string): boolean;
167
- resolveFile(file: string): string;
168
- unignore(pattern: MatchPattern): void;
169
- isIgnored(path: string): boolean;
170
- }
171
-
172
- declare const isMatch: (string: string, pattern: string | readonly string[], options?: micromatch.Options) => boolean;
173
- type WatcherListener = (path: WatcherFile) => void;
174
- interface WatcherFile {
175
- type: EventType;
176
- path: string;
177
- relativePath: string;
178
- }
179
- declare class Watcher {
180
- private readonly cwd;
181
- private readonly options?;
182
- private subscription;
183
- private listeners;
184
- private watcherIgnore;
185
- constructor(cwd: string, options?: Options | undefined);
186
- onEvents: (err: Error | null, events: Event[]) => void;
187
- on(event: EventType, listener: WatcherListener): void;
188
- off(event: EventType, listener: WatcherListener): void;
189
- ignore(pattern: MatchPattern): void;
190
- unignore(pattern: MatchPattern): void;
191
- createSubscription(): {
192
- unsubscribe: () => Promise<void>;
193
- };
194
- close(): Promise<void>;
195
- }
196
-
197
- type Ctx<T = unknown> = {
198
- fileManager: FileManager;
199
- didSetup: string[];
200
- didGenerate: string[];
201
- didEnd: string[];
202
- pluginNames: string[];
203
- generatorOptions: NormalizedGeneratorOptions;
204
- watching: boolean;
205
- changedFile?: WatcherFile;
206
- } & T;
207
-
208
- declare class FileBlock extends File {
209
- filename: string;
210
- content: string;
211
- start: string;
212
- end: string;
213
- tag: string;
214
- constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
215
- write: () => Promise<void>;
216
- unlink: () => Promise<void>;
217
- protected getExistingContent(): Promise<readonly [string, fs_promises.FileHandle] | readonly ["", null]>;
218
- protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
219
- protected addBlockToContent(existingContent: string): string;
220
- protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
221
- }
222
-
223
- declare function getModuleGetName(name: string): string;
224
- declare function getModuleCreateName(name: string): string;
225
- declare function getModuleVariableName(name: string): string;
226
-
227
- declare enum GeneratorPluginVersion {
228
- V1 = "v1"
229
- }
230
- type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
231
- type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;
232
- type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions, watcher: Watcher, reload: GeneratorPluginV1ReloadFn) => void;
233
- type GeneratorPluginV1Factory<Store = unknown> = {
234
- name: string;
235
- actionName: string;
236
- setup?: GeneratorPluginV1Fn<Store>;
237
- generate?: GeneratorPluginV1Fn<Store>;
238
- end?: GeneratorPluginV1Fn<Store>;
239
- watch?: GeneratorPluginV1WatchOptions;
240
- };
241
- interface GeneratorPluginV1<Store = unknown> {
242
- name: string;
243
- actionName: string;
244
- version: GeneratorPluginVersion.V1;
245
- type: PluginType.Generator;
246
- setup: GeneratorPluginV1Fn<Store>;
247
- generate: GeneratorPluginV1Fn<Store>;
248
- end: GeneratorPluginV1Fn<Store>;
249
- watch: GeneratorPluginV1WatchOptions;
250
- }
251
- declare function createPluginV1<Store = unknown>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
252
- declare function isGeneratorPlugin(plugin: {
253
- type: PluginType;
254
- }): plugin is GeneratorPluginV1<unknown>;
255
- declare function getGeneratorPlugins(plugins?: Array<{
256
- type: PluginType;
257
- }>): GeneratorPluginV1<unknown>[];
258
-
259
- export { type Ctx, File, FileBlock, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type Loader, type MatchFn, type MatchPattern, type NormalizedGeneratorOptions, Watcher, type WatcherFile, WatcherIgnore, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch, loadOptions };