@baeta/generator-sdk 2.0.0-next.1 → 2.0.0-next.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @baeta/generator-sdk
2
2
 
3
+ ## 2.0.0-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix broken types
8
+
9
+ - Updated dependencies []:
10
+ - @baeta/util-path@2.0.0-next.2
11
+ - @baeta/plugin@2.0.0-next.2
12
+
3
13
  ## 2.0.0-next.1
4
14
 
5
15
  ### Patch Changes
@@ -0,0 +1,244 @@
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
+ * Disable generation notice at the beginning of the file.
13
+ * @defaultValue false
14
+ */
15
+ disableGenerationNoticeHeader?: boolean;
16
+ /**
17
+ * Disable eslint-disable comment at the beginning of the file.
18
+ * @defaultValue false
19
+ */
20
+ disableEslintHeader?: boolean;
21
+ /**
22
+ * Disable biome comment at the beginning of the file.
23
+ * @defaultValue false
24
+ */
25
+ disableBiomeHeader?: boolean;
26
+ /**
27
+ * Allow overwriting the file.
28
+ * @defaultValue true
29
+ */
30
+ allowOverwrite?: boolean;
31
+ /**
32
+ * Add custom header at the beginning of the file.
33
+ */
34
+ addHeader?: (name: string, content: string, tag: string) => string;
35
+ /**
36
+ * Edit the content of the file before writing it.
37
+ */
38
+ transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
39
+ }
40
+ declare class File {
41
+ persisted: boolean;
42
+ filename: string;
43
+ content: string;
44
+ tag: string;
45
+ private options?;
46
+ constructor(filename: string, content: string, tag: string, options?: FileOptions);
47
+ write: () => Promise<void>;
48
+ unlink: () => Promise<void>;
49
+ protected buildContent(): Promise<string>;
50
+ protected buildHeader(): string;
51
+ protected createComment(comment: string): string;
52
+ }
53
+
54
+ /**
55
+ * Interface for custom schema loaders.
56
+ */
57
+ type GraphQlLoaderAny = any;
58
+ interface Loader<TOptions = GraphQlLoaderAny> {
59
+ load(pointer: string, options?: TOptions): Promise<GraphQlLoaderAny[] | null | never>;
60
+ loadSync?(pointer: string, options?: TOptions): GraphQlLoaderAny[] | null | never;
61
+ }
62
+ /**
63
+ * Options for the Baeta Generator.
64
+ */
65
+ interface GeneratorOptions {
66
+ /**
67
+ * Current working directory for resolving relative paths.
68
+ * @defaultValue process.cwd()
69
+ */
70
+ cwd?: string;
71
+ /**
72
+ * Glob pattern(s) to locate GraphQL schema files.
73
+ * @defaultValue ```ts
74
+ * ['src/∗∗/∗.gql', 'src/∗∗/∗.graphql']
75
+ * ```
76
+ */
77
+ schemas: string[];
78
+ /**
79
+ * Root directory where GraphQL modules are defined.
80
+ * @defaultValue 'src/modules'
81
+ */
82
+ modulesDir?: string;
83
+ /**
84
+ * Filename for the generated module definition file.
85
+ * Contains type definitions and the GraphQL AST.
86
+ * @defaultValue 'typedef.ts'
87
+ */
88
+ moduleDefinitionName?: string;
89
+ /**
90
+ * Output path for the generated type files.
91
+ * @defaultValue ```ts
92
+ * `${modulesDir}/../__generated__/types.ts`
93
+ * ```
94
+ */
95
+ typesDir?: string;
96
+ /**
97
+ * Configuration options for generated files.
98
+ */
99
+ fileOptions?: FileOptions;
100
+ /**
101
+ * Custom schema loaders for processing schema files.
102
+ */
103
+ loaders?: Loader[];
104
+ /**
105
+ * File extension to use in generated import statements.
106
+ * Set to false to omit extensions.
107
+ * @defaultValue '.ts'
108
+ */
109
+ importExtension?: '.js' | '.ts' | false;
110
+ }
111
+ interface NormalizedGeneratorOptions {
112
+ cwd: string;
113
+ schemas: string[];
114
+ modulesDir: string;
115
+ moduleDefinitionName: string;
116
+ typesDir: string;
117
+ fileOptions?: FileOptions;
118
+ loaders?: Loader[];
119
+ importExtension: '.js' | '.ts' | '';
120
+ }
121
+ declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
122
+
123
+ declare class FileManager {
124
+ files: File[];
125
+ fileOptions?: FileOptions;
126
+ constructor(fileOptions?: FileOptions);
127
+ createAndAdd(filename: string, content: string, tag: string, options?: FileOptions): File;
128
+ add(...file: File[]): void;
129
+ get(filename: string): File | undefined;
130
+ getAll(): File[];
131
+ getByTag(tag: string): File[];
132
+ remove(filename: string): void;
133
+ removeAll(): void;
134
+ removeByTag(tag: string): void;
135
+ writeAll(): Promise<void[]>;
136
+ writeByTag(tag: string): Promise<void[]>;
137
+ unlinkAll(): Promise<void>;
138
+ getPersistedFiles(): File[];
139
+ }
140
+
141
+ type MatchFn = (testString: string) => boolean;
142
+ type MatchPattern = string | RegExp | MatchFn;
143
+ declare class WatcherIgnore {
144
+ private readonly cwd;
145
+ private files;
146
+ private regexps;
147
+ private functions;
148
+ private globs;
149
+ private globsMap;
150
+ constructor(cwd: string);
151
+ ignore(pattern: MatchPattern): void;
152
+ isMicromatch(pattern: string): boolean;
153
+ resolveFile(file: string): string;
154
+ unignore(pattern: MatchPattern): void;
155
+ isIgnored(path: string): boolean;
156
+ }
157
+
158
+ declare const isMatch: (string: string, pattern: string | readonly string[], options?: micromatch.Options) => boolean;
159
+ type WatcherListener = (path: WatcherFile) => void;
160
+ interface WatcherFile {
161
+ type: EventType;
162
+ path: string;
163
+ relativePath: string;
164
+ }
165
+ declare class Watcher {
166
+ private readonly cwd;
167
+ private readonly options?;
168
+ private subscription;
169
+ private listeners;
170
+ private watcherIgnore;
171
+ constructor(cwd: string, options?: Options);
172
+ onEvents: (err: Error | null, events: Event[]) => void;
173
+ on(event: EventType, listener: WatcherListener): void;
174
+ off(event: EventType, listener: WatcherListener): void;
175
+ ignore(pattern: MatchPattern): void;
176
+ unignore(pattern: MatchPattern): void;
177
+ createSubscription(): {
178
+ unsubscribe: () => Promise<void>;
179
+ };
180
+ close(): Promise<void>;
181
+ }
182
+
183
+ type Ctx<T = unknown> = {
184
+ fileManager: FileManager;
185
+ didSetup: string[];
186
+ didGenerate: string[];
187
+ didEnd: string[];
188
+ pluginNames: string[];
189
+ generatorOptions: NormalizedGeneratorOptions;
190
+ watching: boolean;
191
+ changedFile?: WatcherFile;
192
+ } & T;
193
+
194
+ declare class FileBlock extends File {
195
+ filename: string;
196
+ content: string;
197
+ start: string;
198
+ end: string;
199
+ tag: string;
200
+ constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
201
+ write: () => Promise<void>;
202
+ unlink: () => Promise<void>;
203
+ protected getExistingContent(): Promise<readonly [string, fs_promises.FileHandle] | readonly ["", null]>;
204
+ protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
205
+ protected addBlockToContent(existingContent: string): string;
206
+ protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
207
+ }
208
+
209
+ declare function getModuleExportName(name: string): string;
210
+
211
+ declare const GeneratorPluginVersion: {
212
+ readonly V1: "v1";
213
+ };
214
+ type GeneratorPluginVersion = (typeof GeneratorPluginVersion)[keyof typeof GeneratorPluginVersion];
215
+ type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
216
+ type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;
217
+ type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions, watcher: Watcher, reload: GeneratorPluginV1ReloadFn) => void;
218
+ type GeneratorPluginV1Factory<Store = unknown> = {
219
+ name: string;
220
+ actionName: string;
221
+ setup?: GeneratorPluginV1Fn<Store>;
222
+ generate?: GeneratorPluginV1Fn<Store>;
223
+ end?: GeneratorPluginV1Fn<Store>;
224
+ watch?: GeneratorPluginV1WatchOptions;
225
+ };
226
+ interface GeneratorPluginV1<Store = unknown> {
227
+ name: string;
228
+ actionName: string;
229
+ version: typeof GeneratorPluginVersion.V1;
230
+ type: typeof PluginType.Generator;
231
+ setup: GeneratorPluginV1Fn<Store>;
232
+ generate: GeneratorPluginV1Fn<Store>;
233
+ end: GeneratorPluginV1Fn<Store>;
234
+ watch: GeneratorPluginV1WatchOptions;
235
+ }
236
+ declare function createPluginV1<Store = unknown>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
237
+ declare function isGeneratorPlugin(plugin: {
238
+ type: PluginType;
239
+ }): plugin is GeneratorPluginV1<unknown>;
240
+ declare function getGeneratorPlugins(plugins?: Array<{
241
+ type: PluginType;
242
+ }>): GeneratorPluginV1<unknown>[];
243
+
244
+ 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, getModuleExportName, isGeneratorPlugin, isMatch, loadOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/generator-sdk",
3
- "version": "2.0.0-next.1",
3
+ "version": "2.0.0-next.2",
4
4
  "keywords": [
5
5
  "baeta",
6
6
  "graphql",
@@ -43,8 +43,8 @@
43
43
  "types": "tsc --noEmit"
44
44
  },
45
45
  "dependencies": {
46
- "@baeta/plugin": "^2.0.0-next.1",
47
- "@baeta/util-path": "^2.0.0-next.1",
46
+ "@baeta/plugin": "^2.0.0-next.2",
47
+ "@baeta/util-path": "^2.0.0-next.2",
48
48
  "@parcel/watcher": "^2.5.1",
49
49
  "change-case-all": "2.1.0",
50
50
  "micromatch": "^4.0.8"