@baeta/generator-sdk 0.0.11 → 0.0.12
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 +12 -0
- package/dist/index.cjs +96 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -7
- package/dist/index.d.ts +20 -7
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @baeta/generator-sdk
|
|
2
2
|
|
|
3
|
+
## 0.0.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
- [#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
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454)]:
|
|
12
|
+
- @baeta/plugin@0.0.23
|
|
13
|
+
- @baeta/util-path@0.0.4
|
|
14
|
+
|
|
3
15
|
## 0.0.11
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4;// lib/config.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5;// lib/config.ts
|
|
2
2
|
var _utilpath = require('@baeta/util-path'); var _utilpath2 = _interopRequireDefault(_utilpath);
|
|
3
3
|
function loadOptions(options) {
|
|
4
4
|
const cwd = _utilpath.posixPath.call(void 0, _nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
@@ -112,12 +112,88 @@ var File = (_class = class {
|
|
|
112
112
|
}
|
|
113
113
|
}, _class);
|
|
114
114
|
|
|
115
|
+
// lib/file-block.ts
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
var FileBlock = (_class2 = class extends File {
|
|
119
|
+
constructor(filename, content, start, end, tag, options) {
|
|
120
|
+
super(filename, content, tag, {
|
|
121
|
+
addEslintDisableHeader: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.addEslintDisableHeader]), () => ( false)),
|
|
122
|
+
addGenerationNoticeHeader: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _10 => _10.addGenerationNoticeHeader]), () => ( false))
|
|
123
|
+
});_class2.prototype.__init4.call(this);;
|
|
124
|
+
this.start = start;
|
|
125
|
+
this.end = end;
|
|
126
|
+
}
|
|
127
|
+
__init4() {this.write = async () => {
|
|
128
|
+
if (this.persisted) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.persisted = true;
|
|
132
|
+
const dir = _utilpath.dirname.call(void 0, this.filename);
|
|
133
|
+
await _promises.mkdir.call(void 0, dir, { recursive: true });
|
|
134
|
+
const [existingContent, fd] = await this.getExistingContent();
|
|
135
|
+
this.addBlockToContent(existingContent);
|
|
136
|
+
const content = await this.buildContent();
|
|
137
|
+
if (fd) {
|
|
138
|
+
await fd.write(content, 0, "utf-8");
|
|
139
|
+
await fd.close();
|
|
140
|
+
} else {
|
|
141
|
+
await _promises.writeFile.call(void 0, this.filename, content, "utf-8");
|
|
142
|
+
}
|
|
143
|
+
}}
|
|
144
|
+
async getExistingContent() {
|
|
145
|
+
try {
|
|
146
|
+
const fd = await _promises.open.call(void 0, this.filename, "r+");
|
|
147
|
+
const existingContent = await fd.readFile("utf-8");
|
|
148
|
+
return [existingContent, fd];
|
|
149
|
+
} catch (err) {
|
|
150
|
+
return ["", null];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
getSlices(existingContent) {
|
|
154
|
+
const startMarkerIndex = existingContent.indexOf(this.start);
|
|
155
|
+
const endMarkerIndex = existingContent.indexOf(this.end);
|
|
156
|
+
if (startMarkerIndex === -1 || endMarkerIndex === -1) {
|
|
157
|
+
return [existingContent, ""];
|
|
158
|
+
}
|
|
159
|
+
return [
|
|
160
|
+
existingContent.slice(0, startMarkerIndex),
|
|
161
|
+
existingContent.slice(endMarkerIndex + this.end.length)
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
addBlockToContent(existingContent) {
|
|
165
|
+
const block = `${this.start}
|
|
166
|
+
${this.content}
|
|
167
|
+
${this.end}`;
|
|
168
|
+
const padding = this.buildPadding(existingContent);
|
|
169
|
+
const [startSlice, endSlice] = this.getSlices(existingContent);
|
|
170
|
+
this.content = startSlice + padding + block + endSlice;
|
|
171
|
+
}
|
|
172
|
+
stripBlock(existingContent) {
|
|
173
|
+
const [startSlice, endSlice] = this.getSlices(existingContent);
|
|
174
|
+
return startSlice + endSlice;
|
|
175
|
+
}
|
|
176
|
+
buildPadding(existingContent) {
|
|
177
|
+
const existingStripped = this.stripBlock(existingContent);
|
|
178
|
+
if (existingStripped === "") {
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
if (existingStripped.endsWith("\n\n")) {
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
if (existingStripped.endsWith("\n")) {
|
|
185
|
+
return "\n";
|
|
186
|
+
}
|
|
187
|
+
return "\n\n";
|
|
188
|
+
}
|
|
189
|
+
}, _class2);
|
|
190
|
+
|
|
115
191
|
// lib/file-manager.ts
|
|
116
|
-
var FileManager = (
|
|
117
|
-
constructor(fileOptions) {;
|
|
192
|
+
var FileManager = (_class3 = class {
|
|
193
|
+
constructor(fileOptions) {;_class3.prototype.__init5.call(this);
|
|
118
194
|
this.fileOptions = fileOptions;
|
|
119
195
|
}
|
|
120
|
-
|
|
196
|
+
__init5() {this.files = []}
|
|
121
197
|
createAndAdd(filename, content, tag) {
|
|
122
198
|
const file = new File(filename, content, tag, this.fileOptions);
|
|
123
199
|
this.add(file);
|
|
@@ -164,7 +240,7 @@ var FileManager = (_class2 = class {
|
|
|
164
240
|
getPersistedFileNames() {
|
|
165
241
|
return this.getPersistedFiles().map((file) => file.filename);
|
|
166
242
|
}
|
|
167
|
-
},
|
|
243
|
+
}, _class3);
|
|
168
244
|
|
|
169
245
|
// lib/module.ts
|
|
170
246
|
var _changecaseall = require('change-case-all');
|
|
@@ -218,15 +294,15 @@ var _micromatch = require('micromatch'); var _micromatch2 = _interopRequireDefau
|
|
|
218
294
|
// lib/watcher-ignore.ts
|
|
219
295
|
|
|
220
296
|
|
|
221
|
-
var WatcherIgnore = (
|
|
222
|
-
constructor(cwd) {;
|
|
297
|
+
var WatcherIgnore = (_class4 = class {
|
|
298
|
+
constructor(cwd) {;_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);_class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this);
|
|
223
299
|
this.cwd = cwd;
|
|
224
300
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
301
|
+
__init6() {this.files = []}
|
|
302
|
+
__init7() {this.regexps = []}
|
|
303
|
+
__init8() {this.functions = []}
|
|
304
|
+
__init9() {this.globs = []}
|
|
305
|
+
__init10() {this.globsMap = /* @__PURE__ */ new Map()}
|
|
230
306
|
ignore(pattern) {
|
|
231
307
|
if (pattern instanceof RegExp) {
|
|
232
308
|
this.regexps.push(pattern);
|
|
@@ -282,25 +358,25 @@ var WatcherIgnore = (_class3 = class {
|
|
|
282
358
|
}
|
|
283
359
|
return false;
|
|
284
360
|
}
|
|
285
|
-
},
|
|
361
|
+
}, _class4);
|
|
286
362
|
|
|
287
363
|
// lib/watcher.ts
|
|
288
364
|
var isMatch = _micromatch2.default.isMatch;
|
|
289
|
-
var Watcher = (
|
|
290
|
-
constructor(cwd, options) {;
|
|
365
|
+
var Watcher = (_class5 = class {
|
|
366
|
+
constructor(cwd, options) {;_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);
|
|
291
367
|
this.cwd = cwd;
|
|
292
368
|
this.options = options;
|
|
293
369
|
this.watcherIgnore = new WatcherIgnore(cwd);
|
|
294
370
|
this.subscription = this.createSubscription();
|
|
295
371
|
}
|
|
296
372
|
|
|
297
|
-
|
|
373
|
+
__init11() {this.listeners = {
|
|
298
374
|
create: [],
|
|
299
375
|
update: [],
|
|
300
376
|
delete: []
|
|
301
377
|
}}
|
|
302
378
|
|
|
303
|
-
|
|
379
|
+
__init12() {this.onEvents = (err, events) => {
|
|
304
380
|
if (err) {
|
|
305
381
|
console.error(err);
|
|
306
382
|
return;
|
|
@@ -343,7 +419,8 @@ var Watcher = (_class4 = class {
|
|
|
343
419
|
close() {
|
|
344
420
|
return this.subscription.unsubscribe();
|
|
345
421
|
}
|
|
346
|
-
},
|
|
422
|
+
}, _class5);
|
|
423
|
+
|
|
347
424
|
|
|
348
425
|
|
|
349
426
|
|
|
@@ -358,5 +435,5 @@ var Watcher = (_class4 = class {
|
|
|
358
435
|
|
|
359
436
|
|
|
360
437
|
|
|
361
|
-
exports.File = File; exports.FileManager = FileManager; exports.GeneratorPluginVersion = GeneratorPluginVersion; exports.Watcher = Watcher; exports.createPluginV1 = createPluginV1; exports.getGeneratorPlugins = getGeneratorPlugins; exports.getModuleCreateName = getModuleCreateName; exports.getModuleGetName = getModuleGetName; exports.getModuleVariableName = getModuleVariableName; exports.isGeneratorPlugin = isGeneratorPlugin; exports.isMatch = isMatch; exports.loadOptions = loadOptions; exports.micromatch = _micromatch2.default;
|
|
438
|
+
exports.File = File; exports.FileBlock = FileBlock; exports.FileManager = FileManager; exports.GeneratorPluginVersion = GeneratorPluginVersion; exports.Watcher = Watcher; exports.createPluginV1 = createPluginV1; exports.getGeneratorPlugins = getGeneratorPlugins; exports.getModuleCreateName = getModuleCreateName; exports.getModuleGetName = getModuleGetName; exports.getModuleVariableName = getModuleVariableName; exports.isGeneratorPlugin = isGeneratorPlugin; exports.isMatch = isMatch; exports.loadOptions = loadOptions; exports.micromatch = _micromatch2.default;
|
|
362
439
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/config.ts","../lib/file.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher.ts","../lib/watcher-ignore.ts"],"names":["GeneratorPluginVersion","path","posixPath","micromatch"],"mappings":";AAAA,SAAS,YAAY,MAAM,WAAW,UAAU,eAAe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ions } from './file';\n\n/**\n * Options for the graphql generator.\n */\nexport interface GeneratorOptions {\n /**\n * Current working directory.\n * @default process.cwd()\n */\n cwd?: string;\n\n /**\n * Glob pattern(s) to load graphql schema files.\n * @default ['src/∗∗/∗.graphql']\n */\n schemas: string[];\n\n /**\n * Directory where modules are defined.\n * @default 'src/modules'\n */\n modulesDir?: string;\n\n /**\n * Name for the generated module definition file. This will contain type definitions and the graphql ast.\n * @default 'typedef.ts'\n */\n moduleDefinitionName?: string;\n\n /**\n * Path for the generated base types file.\n * @default `${modulesDir}/../__generated__/types.ts`\n */\n baseTypesPath?: string;\n\n /**\n * Path where the context type is exported.\n * @example 'src/types/context#Context' // for named export\n * @example 'src/types/context' // for default export\n * @default undefined\n */\n contextType?: string;\n\n /**\n * Path where extensions (ex. auth-extension) are exported. Only default export is supported.\n * @example 'src/extensions'\n * @default undefined\n */\n extensions?: string;\n\n /**\n * Custom scalar mappings.\n * @example { DateTime: 'Date' }\n * @default undefined\n */\n scalars?: Record<string, string>;\n\n /**\n * Options for generated files.\n */\n fileOptions?: FileOptions;\n}\n\nexport interface NormalizedGeneratorOptions {\n cwd: string;\n schemas: string[];\n modulesDir: string;\n moduleDefinitionName: string;\n baseTypesPath: string;\n contextType?: string;\n extensions?: string;\n scalars?: Record<string, string>;\n fileOptions?: FileOptions;\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n const cwd = posixPath(options.cwd ?? process.cwd());\n const schemas = options.schemas ?? ['src/**/*.graphql'];\n const modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n const moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\n const defaultBaseTypesRoot = resolve(modulesDir, '../__generated__/types.ts');\n const baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);\n const baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));\n\n const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);\n const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);\n\n return {\n cwd,\n schemas,\n modulesDir,\n moduleDefinitionName,\n baseTypesPath,\n contextType,\n extensions,\n scalars: options.scalars,\n fileOptions: options.fileOptions,\n };\n}\n\nfunction resolveContextType(root: string, baseTypesRoot: string, contextType?: string) {\n if (!contextType) {\n return;\n }\n\n if (isAbsolute(contextType)) {\n return contextType;\n }\n\n if (contextType[0] === '!') {\n return contextType.slice(1);\n }\n\n const contextTypeRoot = resolve(root, contextType);\n\n return posixPath(relative(join(baseTypesRoot, '../'), contextTypeRoot));\n}\n\nfunction resolveExtensionPath(\n modulesDir: string,\n moduleDefinitionName: string,\n extensionsPath?: string,\n) {\n if (!extensionsPath) {\n return;\n }\n\n if (isAbsolute(extensionsPath)) {\n return extensionsPath;\n }\n\n if (extensionsPath[0] === '!') {\n return extensionsPath.slice(1);\n }\n\n return posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));\n}\n","import { dirname, extname } from '@baeta/util-path';\nimport fs from 'node:fs/promises';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n /**\n * Add generation notice at the beginning of the file.\n * @default true\n */\n addGenerationNoticeHeader?: boolean;\n\n /**\n * Add eslint-disable comment at the beginning of the file.\n * @default true\n */\n addEslintDisableHeader?: boolean;\n\n /**\n * Add custom header at the beginning of the file.\n */\n addHeader?: (name: string, content: string, tag: string) => string;\n\n /**\n * Edit the content of the file before writing it.\n */\n transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n persisted = false;\n\n constructor(\n public filename: string,\n public content: string,\n public tag: string,\n private options?: FileOptions,\n ) {}\n\n write = async () => {\n if (this.persisted) {\n return;\n }\n this.persisted = true;\n\n const dir = dirname(this.filename);\n await fs.mkdir(dir, { recursive: true });\n\n const content = await this.buildContent();\n\n return fs.writeFile(this.filename, content, 'utf-8');\n };\n\n unlink = async () => {\n this.persisted = false;\n return fs.unlink(this.filename);\n };\n\n private async buildContent() {\n const content = this.buildHeader() + this.content;\n\n if (this.options?.transformContent) {\n return this.options.transformContent(this.filename, content, this.tag);\n }\n\n return content;\n }\n\n protected buildHeader() {\n const headerItems: string[] = [];\n\n if (this.options?.addGenerationNoticeHeader !== false) {\n const comment = this.createComment(\n 'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n );\n headerItems.push(comment);\n }\n\n if (this.options?.addEslintDisableHeader !== false) {\n const comment = this.createComment('eslint-disable');\n headerItems.push(comment);\n }\n\n if (this.options?.addHeader) {\n const customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n headerItems.push(customHeader);\n }\n\n if (headerItems.length === 0) {\n return '';\n }\n\n return `${headerItems.join('\\n')}\\n\\n`;\n }\n\n protected createComment(comment: string) {\n const extension = extname(this.filename);\n\n if (['.gql', '.graphql'].includes(extension)) {\n return `# ${comment}`;\n }\n\n return `/* ${comment} */`;\n }\n}\n","import { File, FileOptions } from './file';\n\nexport class FileManager {\n files: File[] = [];\n\n constructor(private fileOptions?: FileOptions) {}\n\n createAndAdd(filename: string, content: string, tag: string) {\n const file = new File(filename, content, tag, this.fileOptions);\n this.add(file);\n return file;\n }\n\n add(...file: File[]) {\n this.files.push(...file);\n }\n\n get(filename: string) {\n return this.files.find((file) => file.filename === filename);\n }\n\n getAll() {\n return this.files;\n }\n\n getByTag(tag: string) {\n return this.files.filter((file) => file.tag === tag);\n }\n\n remove(filename: string) {\n const index = this.files.findIndex((file) => file.filename === filename);\n this.files.splice(index, 1);\n }\n\n removeAll() {\n this.files = [];\n }\n\n removeByTag(tag: string) {\n this.files = this.files.filter((file) => file.tag !== tag);\n }\n\n writeAll() {\n const toWrite = this.files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n writeByTag(tag: string) {\n const files = this.getByTag(tag);\n const toWrite = files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n unlinkAll() {\n return Promise.all(this.files.map((file) => file.unlink())).then(() => {\n // void\n });\n }\n\n getPersistedFiles() {\n return this.files.filter((file) => file.persisted);\n }\n\n getPersistedFileNames() {\n return this.getPersistedFiles().map((file) => file.filename);\n }\n}\n","import { camelCase, pascalCase } from 'change-case-all';\n\nexport function getModuleGetName(name: string) {\n return `get${pascalCase(name)}Module`;\n}\n\nexport function getModuleCreateName(name: string) {\n return `create${pascalCase(name)}Module`;\n}\n\nexport function getModuleVariableName(name: string) {\n return camelCase(`${name}Module`);\n}\n","import { PluginType } from '@baeta/plugin';\nimport { NormalizedGeneratorOptions } from './config';\nimport { Ctx } from './ctx';\nimport { Watcher, WatcherFile } from './watcher';\n\nexport enum GeneratorPluginVersion {\n V1 = 'v1',\n}\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n ctx: Ctx<Store>,\n next: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n options: NormalizedGeneratorOptions,\n watcher: Watcher,\n reload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n name: string;\n actionName: string;\n setup?: GeneratorPluginV1Fn<Store>;\n generate?: GeneratorPluginV1Fn<Store>;\n end?: GeneratorPluginV1Fn<Store>;\n watch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n name: string;\n actionName: string;\n version: GeneratorPluginVersion.V1;\n type: PluginType.Generator;\n setup: GeneratorPluginV1Fn<Store>;\n generate: GeneratorPluginV1Fn<Store>;\n end: GeneratorPluginV1Fn<Store>;\n watch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (ctx, next) => {\n return next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = {}>(\n options: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n return {\n name: options.name,\n actionName: options.actionName,\n version: GeneratorPluginVersion.V1,\n type: PluginType.Generator,\n end: options.end ?? defaultPluginFn,\n generate: options.generate ?? defaultPluginFn,\n setup: options.setup ?? defaultPluginFn,\n watch: options.watch ?? defaultWatchFn,\n };\n}\n\nexport function isGeneratorPlugin(plugin: {\n type: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n return plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n if (!plugins) {\n return [];\n }\n return plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport { AsyncSubscription, Event, EventType, Options, subscribe } from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { MatchPattern, WatcherIgnore } from './watcher-ignore';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n type: EventType;\n path: string;\n relativePath: string;\n}\nexport class Watcher {\n private subscription: AsyncSubscription;\n\n private listeners: Record<EventType, WatcherListener[]> = {\n create: [],\n update: [],\n delete: [],\n };\n\n private watcherIgnore: WatcherIgnore;\n\n constructor(\n private readonly cwd: string,\n private readonly options?: Options,\n ) {\n this.watcherIgnore = new WatcherIgnore(cwd);\n this.subscription = this.createSubscription();\n }\n\n onEvents = (err: Error | null, events: Event[]) => {\n if (err) {\n console.error(err);\n return;\n }\n\n const filteredEvents = events.filter((event) => {\n return !this.watcherIgnore.isIgnored(posixPath(event.path));\n });\n\n for (const event of filteredEvents) {\n for (const listener of this.listeners[event.type]) {\n listener({\n type: event.type,\n path: posixPath(event.path),\n relativePath: posixPath(path.relative(this.cwd, event.path)),\n });\n }\n }\n };\n\n on(event: EventType, listener: WatcherListener) {\n this.listeners[event].push(listener);\n }\n\n off(event: EventType, listener: WatcherListener) {\n this.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n }\n\n ignore(pattern: MatchPattern) {\n this.watcherIgnore.ignore(pattern);\n }\n\n unignore(pattern: MatchPattern) {\n this.watcherIgnore.unignore(pattern);\n }\n\n createSubscription() {\n const promise = subscribe(this.cwd, this.onEvents, this.options);\n\n const unsubscribe = async () => {\n const subscription = await promise;\n await subscription.unsubscribe();\n };\n\n return {\n unsubscribe,\n };\n }\n\n close() {\n return this.subscription.unsubscribe();\n }\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 private files: string[] = [];\n private regexps: RegExp[] = [];\n private functions: MatchFn[] = [];\n\n private globs: MatchFn[] = [];\n private globsMap = new Map<string, MatchFn>();\n\n constructor(private readonly cwd: string) {}\n\n ignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps.push(pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions.push(pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n this.files.push(this.resolveFile(pattern));\n return;\n }\n\n this.globsMap.set(pattern, micromatch.matcher(pattern));\n this.globs = Array.from(this.globsMap.values());\n }\n\n isMicromatch(pattern: string) {\n const result = micromatch.scan(pattern);\n return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n }\n\n resolveFile(file: string) {\n return path.isAbsolute(file) ? file : path.join(this.cwd, file);\n }\n\n unignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps = this.regexps.filter((p) => p !== pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions = this.functions.filter((p) => p !== pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n const file = this.resolveFile(pattern);\n this.files = this.files.filter((p) => p !== file);\n return;\n }\n\n this.globsMap.delete(pattern);\n this.globs = Array.from(this.globsMap.values());\n }\n\n isIgnored(path: string) {\n if (this.files.includes(path)) {\n return true;\n }\n\n if (this.globs.some((f) => f(path))) {\n return true;\n }\n\n if (this.regexps.some((r) => r.test(path))) {\n return true;\n }\n\n if (this.functions.some((f) => f(path))) {\n return true;\n }\n\n return false;\n }\n}\n"]}
|
|
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"],"names":["dirname","GeneratorPluginVersion","path","posixPath","micromatch"],"mappings":";AAAA,SAAS,YAAY,MAAM,WAAW,UAAU,eAAe;AA6ExD,SAAS,YAAY,SAAuD;AACjF,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;AAE7D,QAAM,uBAAuB,QAAQ,YAAY,2BAA2B;AAC5E,QAAM,gBAAgB,QAAQ,KAAK,QAAQ,iBAAiB,oBAAoB;AAChF,QAAM,gBAAgB,UAAU,SAAS,YAAY,aAAa,CAAC;AAEnE,QAAM,cAAc,mBAAmB,KAAK,eAAe,QAAQ,WAAW;AAC9E,QAAM,aAAa,qBAAqB,YAAY,sBAAsB,QAAQ,UAAU;AAE5F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,QAAQ;AAAA,IACjB,aAAa,QAAQ;AAAA,EACvB;AACF;AAEA,SAAS,mBAAmB,MAAc,eAAuB,aAAsB;AACrF,MAAI,CAAC,aAAa;AAChB;AAAA,EACF;AAEA,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,CAAC,MAAM,KAAK;AAC1B,WAAO,YAAY,MAAM,CAAC;AAAA,EAC5B;AAEA,QAAM,kBAAkB,QAAQ,MAAM,WAAW;AAEjD,SAAO,UAAU,SAAS,KAAK,eAAe,KAAK,GAAG,eAAe,CAAC;AACxE;AAEA,SAAS,qBACP,YACA,s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C;AAED,eAAW,SAAS,gBAAgB;AAClC,iBAAW,YAAY,KAAK,UAAU,MAAM,IAAI,GAAG;AACjD,iBAAS;AAAA,UACP,MAAM,MAAM;AAAA,UACZ,MAAMA,WAAU,MAAM,IAAI;AAAA,UAC1B,cAAcA,WAAUD,MAAK,SAAS,KAAK,KAAK,MAAM,IAAI,CAAC;AAAA,QAC7D,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAEA,GAAG,OAAkB,UAA2B;AAC9C,SAAK,UAAU,KAAK,EAAE,KAAK,QAAQ;AAAA,EACrC;AAAA,EAEA,IAAI,OAAkB,UAA2B;AAC/C,SAAK,UAAU,KAAK,IAAI,KAAK,UAAU,KAAK,EAAE,OAAO,CAAC,MAAM,MAAM,QAAQ;AAAA,EAC5E;AAAA,EAEA,OAAO,SAAuB;AAC5B,SAAK,cAAc,OAAO,OAAO;AAAA,EACnC;AAAA,EAEA,SAAS,SAAuB;AAC9B,SAAK,cAAc,SAAS,OAAO;AAAA,EACrC;AAAA,EAEA,qBAAqB;AACnB,UAAM,UAAU,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK,OAAO;AAE/D,UAAM,cAAc,YAAY;AAC9B,YAAM,eAAe,MAAM;AAC3B,YAAM,aAAa,YAAY;AAAA,IACjC;AAEA,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ;AACN,WAAO,KAAK,aAAa,YAAY;AAAA,EACvC;AACF","sourcesContent":["import { isAbsolute, join, posixPath, relative, resolve } from '@baeta/util-path';\nimport { FileOptions } from './file';\n\n/**\n * Options for the graphql generator.\n */\nexport interface GeneratorOptions {\n /**\n * Current working directory.\n * @default process.cwd()\n */\n cwd?: string;\n\n /**\n * Glob pattern(s) to load graphql schema files.\n * @default ['src/∗∗/∗.graphql']\n */\n schemas: string[];\n\n /**\n * Directory where modules are defined.\n * @default 'src/modules'\n */\n modulesDir?: string;\n\n /**\n * Name for the generated module definition file. This will contain type definitions and the graphql ast.\n * @default 'typedef.ts'\n */\n moduleDefinitionName?: string;\n\n /**\n * Path for the generated base types file.\n * @default `${modulesDir}/../__generated__/types.ts`\n */\n baseTypesPath?: string;\n\n /**\n * Path where the context type is exported.\n * @example contextType: 'src/types/context#Context' // for named export\n * @example contextType: 'src/types/context' // for default export\n * @default undefined\n */\n contextType?: string;\n\n /**\n * Path where extensions (ex. auth-extension) are exported. Only default export is supported.\n * @example extensions: 'src/extensions'\n * @default undefined\n */\n extensions?: string;\n\n /**\n * Custom scalar mappings.\n * @example scalars: { DateTime: 'Date' }\n * @default undefined\n */\n scalars?: Record<string, string>;\n\n /**\n * Options for generated files.\n */\n fileOptions?: FileOptions;\n}\n\nexport interface NormalizedGeneratorOptions {\n cwd: string;\n schemas: string[];\n modulesDir: string;\n moduleDefinitionName: string;\n baseTypesPath: string;\n contextType?: string;\n extensions?: string;\n scalars?: Record<string, string>;\n fileOptions?: FileOptions;\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n const cwd = posixPath(options.cwd ?? process.cwd());\n const schemas = options.schemas ?? ['src/**/*.graphql'];\n const modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n const moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\n const defaultBaseTypesRoot = resolve(modulesDir, '../__generated__/types.ts');\n const baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);\n const baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));\n\n const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);\n const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);\n\n return {\n cwd,\n schemas,\n modulesDir,\n moduleDefinitionName,\n baseTypesPath,\n contextType,\n extensions,\n scalars: options.scalars,\n fileOptions: options.fileOptions,\n };\n}\n\nfunction resolveContextType(root: string, baseTypesRoot: string, contextType?: string) {\n if (!contextType) {\n return;\n }\n\n if (isAbsolute(contextType)) {\n return contextType;\n }\n\n if (contextType[0] === '!') {\n return contextType.slice(1);\n }\n\n const contextTypeRoot = resolve(root, contextType);\n\n return posixPath(relative(join(baseTypesRoot, '../'), contextTypeRoot));\n}\n\nfunction resolveExtensionPath(\n modulesDir: string,\n moduleDefinitionName: string,\n extensionsPath?: string,\n) {\n if (!extensionsPath) {\n return;\n }\n\n if (isAbsolute(extensionsPath)) {\n return extensionsPath;\n }\n\n if (extensionsPath[0] === '!') {\n return extensionsPath.slice(1);\n }\n\n return posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));\n}\n","import { dirname, extname } from '@baeta/util-path';\nimport fs from 'node:fs/promises';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n /**\n * Add generation notice at the beginning of the file.\n * @default true\n */\n addGenerationNoticeHeader?: boolean;\n\n /**\n * Add eslint-disable comment at the beginning of the file.\n * @default true\n */\n addEslintDisableHeader?: boolean;\n\n /**\n * Add custom header at the beginning of the file.\n */\n addHeader?: (name: string, content: string, tag: string) => string;\n\n /**\n * Edit the content of the file before writing it.\n */\n transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n persisted = false;\n\n constructor(\n public filename: string,\n public content: string,\n public tag: string,\n private options?: FileOptions,\n ) {}\n\n write = async () => {\n if (this.persisted) {\n return;\n }\n this.persisted = true;\n\n const dir = dirname(this.filename);\n await fs.mkdir(dir, { recursive: true });\n\n const content = await this.buildContent();\n\n return fs.writeFile(this.filename, content, 'utf-8');\n };\n\n unlink = async () => {\n this.persisted = false;\n return fs.unlink(this.filename);\n };\n\n protected async buildContent() {\n const content = this.buildHeader() + this.content;\n\n if (this.options?.transformContent) {\n return this.options.transformContent(this.filename, content, this.tag);\n }\n\n return content;\n }\n\n protected buildHeader() {\n const headerItems: string[] = [];\n\n if (this.options?.addGenerationNoticeHeader !== false) {\n const comment = this.createComment(\n 'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n );\n headerItems.push(comment);\n }\n\n if (this.options?.addEslintDisableHeader !== false) {\n const comment = this.createComment('eslint-disable');\n headerItems.push(comment);\n }\n\n if (this.options?.addHeader) {\n const customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n headerItems.push(customHeader);\n }\n\n if (headerItems.length === 0) {\n return '';\n }\n\n return `${headerItems.join('\\n')}\\n\\n`;\n }\n\n protected createComment(comment: string) {\n const extension = extname(this.filename);\n\n if (['.gql', '.graphql'].includes(extension)) {\n return `# ${comment}`;\n }\n\n return `/* ${comment} */`;\n }\n}\n","import { dirname } from '@baeta/util-path';\nimport { mkdir, open, writeFile } from 'node:fs/promises';\nimport { File, FileOptions } from './file';\n\nexport class FileBlock extends File {\n constructor(\n filename: string,\n content: string,\n protected start: string,\n protected end: string,\n tag: string,\n options?: FileOptions,\n ) {\n super(filename, content, tag, {\n addEslintDisableHeader: options?.addEslintDisableHeader ?? false,\n addGenerationNoticeHeader: options?.addGenerationNoticeHeader ?? false,\n });\n }\n\n write = async () => {\n if (this.persisted) {\n return;\n }\n this.persisted = true;\n\n const dir = dirname(this.filename);\n await mkdir(dir, { recursive: true });\n\n const [existingContent, fd] = await this.getExistingContent();\n this.addBlockToContent(existingContent);\n const content = await this.buildContent();\n\n if (fd) {\n await fd.write(content, 0, 'utf-8');\n await fd.close();\n } else {\n await writeFile(this.filename, content, 'utf-8');\n }\n };\n\n protected async getExistingContent() {\n try {\n const fd = await open(this.filename, 'r+');\n const existingContent = await fd.readFile('utf-8');\n return [existingContent, fd] as const;\n } catch (err) {\n return ['', null] as const;\n }\n }\n\n protected getSlices(existingContent: string) {\n const startMarkerIndex = existingContent.indexOf(this.start);\n const endMarkerIndex = existingContent.indexOf(this.end);\n\n if (startMarkerIndex === -1 || endMarkerIndex === -1) {\n return [existingContent, ''] as const;\n }\n\n return [\n existingContent.slice(0, startMarkerIndex),\n existingContent.slice(endMarkerIndex + this.end.length),\n ] as const;\n }\n\n protected addBlockToContent(existingContent: string) {\n const block = `${this.start}\\n${this.content}\\n${this.end}`;\n const padding = this.buildPadding(existingContent);\n const [startSlice, endSlice] = this.getSlices(existingContent);\n this.content = startSlice + padding + block + endSlice;\n }\n\n protected stripBlock(existingContent: string) {\n const [startSlice, endSlice] = this.getSlices(existingContent);\n return startSlice + endSlice;\n }\n\n protected buildPadding(existingContent: string) {\n const existingStripped = this.stripBlock(existingContent);\n\n if (existingStripped === '') {\n return '';\n }\n\n if (existingStripped.endsWith('\\n\\n')) {\n return '';\n }\n\n if (existingStripped.endsWith('\\n')) {\n return '\\n';\n }\n\n return '\\n\\n';\n }\n}\n","import { File, FileOptions } from './file';\n\nexport class FileManager {\n files: File[] = [];\n\n constructor(public fileOptions?: FileOptions) {}\n\n createAndAdd(filename: string, content: string, tag: string) {\n const file = new File(filename, content, tag, this.fileOptions);\n this.add(file);\n return file;\n }\n\n add(...file: File[]) {\n this.files.push(...file);\n }\n\n get(filename: string) {\n return this.files.find((file) => file.filename === filename);\n }\n\n getAll() {\n return this.files;\n }\n\n getByTag(tag: string) {\n return this.files.filter((file) => file.tag === tag);\n }\n\n remove(filename: string) {\n const index = this.files.findIndex((file) => file.filename === filename);\n this.files.splice(index, 1);\n }\n\n removeAll() {\n this.files = [];\n }\n\n removeByTag(tag: string) {\n this.files = this.files.filter((file) => file.tag !== tag);\n }\n\n writeAll() {\n const toWrite = this.files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n writeByTag(tag: string) {\n const files = this.getByTag(tag);\n const toWrite = files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n unlinkAll() {\n return Promise.all(this.files.map((file) => file.unlink())).then(() => {\n // void\n });\n }\n\n getPersistedFiles() {\n return this.files.filter((file) => file.persisted);\n }\n\n getPersistedFileNames() {\n return this.getPersistedFiles().map((file) => file.filename);\n }\n}\n","import { camelCase, pascalCase } from 'change-case-all';\n\nexport function getModuleGetName(name: string) {\n return `get${pascalCase(name)}Module`;\n}\n\nexport function getModuleCreateName(name: string) {\n return `create${pascalCase(name)}Module`;\n}\n\nexport function getModuleVariableName(name: string) {\n return camelCase(`${name}Module`);\n}\n","import { PluginType } from '@baeta/plugin';\nimport { NormalizedGeneratorOptions } from './config';\nimport { Ctx } from './ctx';\nimport { Watcher, WatcherFile } from './watcher';\n\nexport enum GeneratorPluginVersion {\n V1 = 'v1',\n}\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n ctx: Ctx<Store>,\n next: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n options: NormalizedGeneratorOptions,\n watcher: Watcher,\n reload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n name: string;\n actionName: string;\n setup?: GeneratorPluginV1Fn<Store>;\n generate?: GeneratorPluginV1Fn<Store>;\n end?: GeneratorPluginV1Fn<Store>;\n watch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n name: string;\n actionName: string;\n version: GeneratorPluginVersion.V1;\n type: PluginType.Generator;\n setup: GeneratorPluginV1Fn<Store>;\n generate: GeneratorPluginV1Fn<Store>;\n end: GeneratorPluginV1Fn<Store>;\n watch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (ctx, next) => {\n return next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = {}>(\n options: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n return {\n name: options.name,\n actionName: options.actionName,\n version: GeneratorPluginVersion.V1,\n type: PluginType.Generator,\n end: options.end ?? defaultPluginFn,\n generate: options.generate ?? defaultPluginFn,\n setup: options.setup ?? defaultPluginFn,\n watch: options.watch ?? defaultWatchFn,\n };\n}\n\nexport function isGeneratorPlugin(plugin: {\n type: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n return plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n if (!plugins) {\n return [];\n }\n return plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport { AsyncSubscription, Event, EventType, Options, subscribe } from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { MatchPattern, WatcherIgnore } from './watcher-ignore';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n type: EventType;\n path: string;\n relativePath: string;\n}\nexport class Watcher {\n private subscription: AsyncSubscription;\n\n private listeners: Record<EventType, WatcherListener[]> = {\n create: [],\n update: [],\n delete: [],\n };\n\n private watcherIgnore: WatcherIgnore;\n\n constructor(\n private readonly cwd: string,\n private readonly options?: Options,\n ) {\n this.watcherIgnore = new WatcherIgnore(cwd);\n this.subscription = this.createSubscription();\n }\n\n onEvents = (err: Error | null, events: Event[]) => {\n if (err) {\n console.error(err);\n return;\n }\n\n const filteredEvents = events.filter((event) => {\n return !this.watcherIgnore.isIgnored(posixPath(event.path));\n });\n\n for (const event of filteredEvents) {\n for (const listener of this.listeners[event.type]) {\n listener({\n type: event.type,\n path: posixPath(event.path),\n relativePath: posixPath(path.relative(this.cwd, event.path)),\n });\n }\n }\n };\n\n on(event: EventType, listener: WatcherListener) {\n this.listeners[event].push(listener);\n }\n\n off(event: EventType, listener: WatcherListener) {\n this.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n }\n\n ignore(pattern: MatchPattern) {\n this.watcherIgnore.ignore(pattern);\n }\n\n unignore(pattern: MatchPattern) {\n this.watcherIgnore.unignore(pattern);\n }\n\n createSubscription() {\n const promise = subscribe(this.cwd, this.onEvents, this.options);\n\n const unsubscribe = async () => {\n const subscription = await promise;\n await subscription.unsubscribe();\n };\n\n return {\n unsubscribe,\n };\n }\n\n close() {\n return this.subscription.unsubscribe();\n }\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 private files: string[] = [];\n private regexps: RegExp[] = [];\n private functions: MatchFn[] = [];\n\n private globs: MatchFn[] = [];\n private globsMap = new Map<string, MatchFn>();\n\n constructor(private readonly cwd: string) {}\n\n ignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps.push(pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions.push(pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n this.files.push(this.resolveFile(pattern));\n return;\n }\n\n this.globsMap.set(pattern, micromatch.matcher(pattern));\n this.globs = Array.from(this.globsMap.values());\n }\n\n isMicromatch(pattern: string) {\n const result = micromatch.scan(pattern);\n return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n }\n\n resolveFile(file: string) {\n return path.isAbsolute(file) ? file : path.join(this.cwd, file);\n }\n\n unignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps = this.regexps.filter((p) => p !== pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions = this.functions.filter((p) => p !== pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n const file = this.resolveFile(pattern);\n this.files = this.files.filter((p) => p !== file);\n return;\n }\n\n this.globsMap.delete(pattern);\n this.globs = Array.from(this.globsMap.values());\n }\n\n isIgnored(path: string) {\n if (this.files.includes(path)) {\n return true;\n }\n\n if (this.globs.some((f) => f(path))) {\n return true;\n }\n\n if (this.regexps.some((r) => r.test(path))) {\n return true;\n }\n\n if (this.functions.some((f) => f(path))) {\n return true;\n }\n\n return false;\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventType, Options, Event } from '@parcel/watcher';
|
|
2
2
|
import micromatch from 'micromatch';
|
|
3
3
|
export { default as micromatch } from 'micromatch';
|
|
4
|
+
import * as fs_promises from 'fs/promises';
|
|
4
5
|
import { PluginType } from '@baeta/plugin';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -35,7 +36,7 @@ declare class File {
|
|
|
35
36
|
constructor(filename: string, content: string, tag: string, options?: FileOptions | undefined);
|
|
36
37
|
write: () => Promise<void>;
|
|
37
38
|
unlink: () => Promise<void>;
|
|
38
|
-
|
|
39
|
+
protected buildContent(): Promise<string>;
|
|
39
40
|
protected buildHeader(): string;
|
|
40
41
|
protected createComment(comment: string): string;
|
|
41
42
|
}
|
|
@@ -71,20 +72,20 @@ interface GeneratorOptions {
|
|
|
71
72
|
baseTypesPath?: string;
|
|
72
73
|
/**
|
|
73
74
|
* Path where the context type is exported.
|
|
74
|
-
* @example 'src/types/context#Context' // for named export
|
|
75
|
-
* @example 'src/types/context' // for default export
|
|
75
|
+
* @example contextType: 'src/types/context#Context' // for named export
|
|
76
|
+
* @example contextType: 'src/types/context' // for default export
|
|
76
77
|
* @default undefined
|
|
77
78
|
*/
|
|
78
79
|
contextType?: string;
|
|
79
80
|
/**
|
|
80
81
|
* Path where extensions (ex. auth-extension) are exported. Only default export is supported.
|
|
81
|
-
* @example 'src/extensions'
|
|
82
|
+
* @example extensions: 'src/extensions'
|
|
82
83
|
* @default undefined
|
|
83
84
|
*/
|
|
84
85
|
extensions?: string;
|
|
85
86
|
/**
|
|
86
87
|
* Custom scalar mappings.
|
|
87
|
-
* @example { DateTime: 'Date' }
|
|
88
|
+
* @example scalars: { DateTime: 'Date' }
|
|
88
89
|
* @default undefined
|
|
89
90
|
*/
|
|
90
91
|
scalars?: Record<string, string>;
|
|
@@ -107,7 +108,7 @@ interface NormalizedGeneratorOptions {
|
|
|
107
108
|
declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
|
|
108
109
|
|
|
109
110
|
declare class FileManager {
|
|
110
|
-
|
|
111
|
+
fileOptions?: FileOptions | undefined;
|
|
111
112
|
files: File[];
|
|
112
113
|
constructor(fileOptions?: FileOptions | undefined);
|
|
113
114
|
createAndAdd(filename: string, content: string, tag: string): File;
|
|
@@ -164,6 +165,18 @@ type Ctx<T = unknown> = {
|
|
|
164
165
|
changedFile?: WatcherFile;
|
|
165
166
|
} & T;
|
|
166
167
|
|
|
168
|
+
declare class FileBlock extends File {
|
|
169
|
+
protected start: string;
|
|
170
|
+
protected end: string;
|
|
171
|
+
constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
|
|
172
|
+
write: () => Promise<void>;
|
|
173
|
+
protected getExistingContent(): Promise<readonly [string, fs_promises.FileHandle] | readonly ["", null]>;
|
|
174
|
+
protected getSlices(existingContent: string): readonly [string, string];
|
|
175
|
+
protected addBlockToContent(existingContent: string): void;
|
|
176
|
+
protected stripBlock(existingContent: string): string;
|
|
177
|
+
protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
declare function getModuleGetName(name: string): string;
|
|
168
181
|
declare function getModuleCreateName(name: string): string;
|
|
169
182
|
declare function getModuleVariableName(name: string): string;
|
|
@@ -200,4 +213,4 @@ declare function getGeneratorPlugins(plugins?: Array<{
|
|
|
200
213
|
type: PluginType;
|
|
201
214
|
}>): GeneratorPluginV1<unknown>[];
|
|
202
215
|
|
|
203
|
-
export { type Ctx, File, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type NormalizedGeneratorOptions, Watcher, type WatcherFile, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch, loadOptions };
|
|
216
|
+
export { type Ctx, File, FileBlock, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type NormalizedGeneratorOptions, Watcher, type WatcherFile, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch, loadOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventType, Options, Event } from '@parcel/watcher';
|
|
2
2
|
import micromatch from 'micromatch';
|
|
3
3
|
export { default as micromatch } from 'micromatch';
|
|
4
|
+
import * as fs_promises from 'fs/promises';
|
|
4
5
|
import { PluginType } from '@baeta/plugin';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -35,7 +36,7 @@ declare class File {
|
|
|
35
36
|
constructor(filename: string, content: string, tag: string, options?: FileOptions | undefined);
|
|
36
37
|
write: () => Promise<void>;
|
|
37
38
|
unlink: () => Promise<void>;
|
|
38
|
-
|
|
39
|
+
protected buildContent(): Promise<string>;
|
|
39
40
|
protected buildHeader(): string;
|
|
40
41
|
protected createComment(comment: string): string;
|
|
41
42
|
}
|
|
@@ -71,20 +72,20 @@ interface GeneratorOptions {
|
|
|
71
72
|
baseTypesPath?: string;
|
|
72
73
|
/**
|
|
73
74
|
* Path where the context type is exported.
|
|
74
|
-
* @example 'src/types/context#Context' // for named export
|
|
75
|
-
* @example 'src/types/context' // for default export
|
|
75
|
+
* @example contextType: 'src/types/context#Context' // for named export
|
|
76
|
+
* @example contextType: 'src/types/context' // for default export
|
|
76
77
|
* @default undefined
|
|
77
78
|
*/
|
|
78
79
|
contextType?: string;
|
|
79
80
|
/**
|
|
80
81
|
* Path where extensions (ex. auth-extension) are exported. Only default export is supported.
|
|
81
|
-
* @example 'src/extensions'
|
|
82
|
+
* @example extensions: 'src/extensions'
|
|
82
83
|
* @default undefined
|
|
83
84
|
*/
|
|
84
85
|
extensions?: string;
|
|
85
86
|
/**
|
|
86
87
|
* Custom scalar mappings.
|
|
87
|
-
* @example { DateTime: 'Date' }
|
|
88
|
+
* @example scalars: { DateTime: 'Date' }
|
|
88
89
|
* @default undefined
|
|
89
90
|
*/
|
|
90
91
|
scalars?: Record<string, string>;
|
|
@@ -107,7 +108,7 @@ interface NormalizedGeneratorOptions {
|
|
|
107
108
|
declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
|
|
108
109
|
|
|
109
110
|
declare class FileManager {
|
|
110
|
-
|
|
111
|
+
fileOptions?: FileOptions | undefined;
|
|
111
112
|
files: File[];
|
|
112
113
|
constructor(fileOptions?: FileOptions | undefined);
|
|
113
114
|
createAndAdd(filename: string, content: string, tag: string): File;
|
|
@@ -164,6 +165,18 @@ type Ctx<T = unknown> = {
|
|
|
164
165
|
changedFile?: WatcherFile;
|
|
165
166
|
} & T;
|
|
166
167
|
|
|
168
|
+
declare class FileBlock extends File {
|
|
169
|
+
protected start: string;
|
|
170
|
+
protected end: string;
|
|
171
|
+
constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
|
|
172
|
+
write: () => Promise<void>;
|
|
173
|
+
protected getExistingContent(): Promise<readonly [string, fs_promises.FileHandle] | readonly ["", null]>;
|
|
174
|
+
protected getSlices(existingContent: string): readonly [string, string];
|
|
175
|
+
protected addBlockToContent(existingContent: string): void;
|
|
176
|
+
protected stripBlock(existingContent: string): string;
|
|
177
|
+
protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
|
|
178
|
+
}
|
|
179
|
+
|
|
167
180
|
declare function getModuleGetName(name: string): string;
|
|
168
181
|
declare function getModuleCreateName(name: string): string;
|
|
169
182
|
declare function getModuleVariableName(name: string): string;
|
|
@@ -200,4 +213,4 @@ declare function getGeneratorPlugins(plugins?: Array<{
|
|
|
200
213
|
type: PluginType;
|
|
201
214
|
}>): GeneratorPluginV1<unknown>[];
|
|
202
215
|
|
|
203
|
-
export { type Ctx, File, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type NormalizedGeneratorOptions, Watcher, type WatcherFile, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch, loadOptions };
|
|
216
|
+
export { type Ctx, File, FileBlock, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type NormalizedGeneratorOptions, Watcher, type WatcherFile, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch, loadOptions };
|
package/dist/index.js
CHANGED
|
@@ -112,6 +112,82 @@ var File = class {
|
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
+
// lib/file-block.ts
|
|
116
|
+
import { dirname as dirname2 } from "@baeta/util-path";
|
|
117
|
+
import { mkdir, open, writeFile } from "node:fs/promises";
|
|
118
|
+
var FileBlock = class extends File {
|
|
119
|
+
constructor(filename, content, start, end, tag, options) {
|
|
120
|
+
super(filename, content, tag, {
|
|
121
|
+
addEslintDisableHeader: options?.addEslintDisableHeader ?? false,
|
|
122
|
+
addGenerationNoticeHeader: options?.addGenerationNoticeHeader ?? false
|
|
123
|
+
});
|
|
124
|
+
this.start = start;
|
|
125
|
+
this.end = end;
|
|
126
|
+
}
|
|
127
|
+
write = async () => {
|
|
128
|
+
if (this.persisted) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.persisted = true;
|
|
132
|
+
const dir = dirname2(this.filename);
|
|
133
|
+
await mkdir(dir, { recursive: true });
|
|
134
|
+
const [existingContent, fd] = await this.getExistingContent();
|
|
135
|
+
this.addBlockToContent(existingContent);
|
|
136
|
+
const content = await this.buildContent();
|
|
137
|
+
if (fd) {
|
|
138
|
+
await fd.write(content, 0, "utf-8");
|
|
139
|
+
await fd.close();
|
|
140
|
+
} else {
|
|
141
|
+
await writeFile(this.filename, content, "utf-8");
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
async getExistingContent() {
|
|
145
|
+
try {
|
|
146
|
+
const fd = await open(this.filename, "r+");
|
|
147
|
+
const existingContent = await fd.readFile("utf-8");
|
|
148
|
+
return [existingContent, fd];
|
|
149
|
+
} catch (err) {
|
|
150
|
+
return ["", null];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
getSlices(existingContent) {
|
|
154
|
+
const startMarkerIndex = existingContent.indexOf(this.start);
|
|
155
|
+
const endMarkerIndex = existingContent.indexOf(this.end);
|
|
156
|
+
if (startMarkerIndex === -1 || endMarkerIndex === -1) {
|
|
157
|
+
return [existingContent, ""];
|
|
158
|
+
}
|
|
159
|
+
return [
|
|
160
|
+
existingContent.slice(0, startMarkerIndex),
|
|
161
|
+
existingContent.slice(endMarkerIndex + this.end.length)
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
addBlockToContent(existingContent) {
|
|
165
|
+
const block = `${this.start}
|
|
166
|
+
${this.content}
|
|
167
|
+
${this.end}`;
|
|
168
|
+
const padding = this.buildPadding(existingContent);
|
|
169
|
+
const [startSlice, endSlice] = this.getSlices(existingContent);
|
|
170
|
+
this.content = startSlice + padding + block + endSlice;
|
|
171
|
+
}
|
|
172
|
+
stripBlock(existingContent) {
|
|
173
|
+
const [startSlice, endSlice] = this.getSlices(existingContent);
|
|
174
|
+
return startSlice + endSlice;
|
|
175
|
+
}
|
|
176
|
+
buildPadding(existingContent) {
|
|
177
|
+
const existingStripped = this.stripBlock(existingContent);
|
|
178
|
+
if (existingStripped === "") {
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
if (existingStripped.endsWith("\n\n")) {
|
|
182
|
+
return "";
|
|
183
|
+
}
|
|
184
|
+
if (existingStripped.endsWith("\n")) {
|
|
185
|
+
return "\n";
|
|
186
|
+
}
|
|
187
|
+
return "\n\n";
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
115
191
|
// lib/file-manager.ts
|
|
116
192
|
var FileManager = class {
|
|
117
193
|
constructor(fileOptions) {
|
|
@@ -346,6 +422,7 @@ var Watcher = class {
|
|
|
346
422
|
};
|
|
347
423
|
export {
|
|
348
424
|
File,
|
|
425
|
+
FileBlock,
|
|
349
426
|
FileManager,
|
|
350
427
|
GeneratorPluginVersion,
|
|
351
428
|
Watcher,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/config.ts","../lib/file.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 { FileOptions } from './file';\n\n/**\n * Options for the graphql generator.\n */\nexport interface GeneratorOptions {\n /**\n * Current working directory.\n * @default process.cwd()\n */\n cwd?: string;\n\n /**\n * Glob pattern(s) to load graphql schema files.\n * @default ['src/∗∗/∗.graphql']\n */\n schemas: string[];\n\n /**\n * Directory where modules are defined.\n * @default 'src/modules'\n */\n modulesDir?: string;\n\n /**\n * Name for the generated module definition file. This will contain type definitions and the graphql ast.\n * @default 'typedef.ts'\n */\n moduleDefinitionName?: string;\n\n /**\n * Path for the generated base types file.\n * @default `${modulesDir}/../__generated__/types.ts`\n */\n baseTypesPath?: string;\n\n /**\n * Path where the context type is exported.\n * @example 'src/types/context#Context' // for named export\n * @example 'src/types/context' // for default export\n * @default undefined\n */\n contextType?: string;\n\n /**\n * Path where extensions (ex. auth-extension) are exported. Only default export is supported.\n * @example 'src/extensions'\n * @default undefined\n */\n extensions?: string;\n\n /**\n * Custom scalar mappings.\n * @example { DateTime: 'Date' }\n * @default undefined\n */\n scalars?: Record<string, string>;\n\n /**\n * Options for generated files.\n */\n fileOptions?: FileOptions;\n}\n\nexport interface NormalizedGeneratorOptions {\n cwd: string;\n schemas: string[];\n modulesDir: string;\n moduleDefinitionName: string;\n baseTypesPath: string;\n contextType?: string;\n extensions?: string;\n scalars?: Record<string, string>;\n fileOptions?: FileOptions;\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n const cwd = posixPath(options.cwd ?? process.cwd());\n const schemas = options.schemas ?? ['src/**/*.graphql'];\n const modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n const moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\n const defaultBaseTypesRoot = resolve(modulesDir, '../__generated__/types.ts');\n const baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);\n const baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));\n\n const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);\n const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);\n\n return {\n cwd,\n schemas,\n modulesDir,\n moduleDefinitionName,\n baseTypesPath,\n contextType,\n extensions,\n scalars: options.scalars,\n fileOptions: options.fileOptions,\n };\n}\n\nfunction resolveContextType(root: string, baseTypesRoot: string, contextType?: string) {\n if (!contextType) {\n return;\n }\n\n if (isAbsolute(contextType)) {\n return contextType;\n }\n\n if (contextType[0] === '!') {\n return contextType.slice(1);\n }\n\n const contextTypeRoot = resolve(root, contextType);\n\n return posixPath(relative(join(baseTypesRoot, '../'), contextTypeRoot));\n}\n\nfunction resolveExtensionPath(\n modulesDir: string,\n moduleDefinitionName: string,\n extensionsPath?: string,\n) {\n if (!extensionsPath) {\n return;\n }\n\n if (isAbsolute(extensionsPath)) {\n return extensionsPath;\n }\n\n if (extensionsPath[0] === '!') {\n return extensionsPath.slice(1);\n }\n\n return posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));\n}\n","import { dirname, extname } from '@baeta/util-path';\nimport fs from 'node:fs/promises';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n /**\n * Add generation notice at the beginning of the file.\n * @default true\n */\n addGenerationNoticeHeader?: boolean;\n\n /**\n * Add eslint-disable comment at the beginning of the file.\n * @default true\n */\n addEslintDisableHeader?: boolean;\n\n /**\n * Add custom header at the beginning of the file.\n */\n addHeader?: (name: string, content: string, tag: string) => string;\n\n /**\n * Edit the content of the file before writing it.\n */\n transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n persisted = false;\n\n constructor(\n public filename: string,\n public content: string,\n public tag: string,\n private options?: FileOptions,\n ) {}\n\n write = async () => {\n if (this.persisted) {\n return;\n }\n this.persisted = true;\n\n const dir = dirname(this.filename);\n await fs.mkdir(dir, { recursive: true });\n\n const content = await this.buildContent();\n\n return fs.writeFile(this.filename, content, 'utf-8');\n };\n\n unlink = async () => {\n this.persisted = false;\n return fs.unlink(this.filename);\n };\n\n private async buildContent() {\n const content = this.buildHeader() + this.content;\n\n if (this.options?.transformContent) {\n return this.options.transformContent(this.filename, content, this.tag);\n }\n\n return content;\n }\n\n protected buildHeader() {\n const headerItems: string[] = [];\n\n if (this.options?.addGenerationNoticeHeader !== false) {\n const comment = this.createComment(\n 'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n );\n headerItems.push(comment);\n }\n\n if (this.options?.addEslintDisableHeader !== false) {\n const comment = this.createComment('eslint-disable');\n headerItems.push(comment);\n }\n\n if (this.options?.addHeader) {\n const customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n headerItems.push(customHeader);\n }\n\n if (headerItems.length === 0) {\n return '';\n }\n\n return `${headerItems.join('\\n')}\\n\\n`;\n }\n\n protected createComment(comment: string) {\n const extension = extname(this.filename);\n\n if (['.gql', '.graphql'].includes(extension)) {\n return `# ${comment}`;\n }\n\n return `/* ${comment} */`;\n }\n}\n","import { File, FileOptions } from './file';\n\nexport class FileManager {\n files: File[] = [];\n\n constructor(private fileOptions?: FileOptions) {}\n\n createAndAdd(filename: string, content: string, tag: string) {\n const file = new File(filename, content, tag, this.fileOptions);\n this.add(file);\n return file;\n }\n\n add(...file: File[]) {\n this.files.push(...file);\n }\n\n get(filename: string) {\n return this.files.find((file) => file.filename === filename);\n }\n\n getAll() {\n return this.files;\n }\n\n getByTag(tag: string) {\n return this.files.filter((file) => file.tag === tag);\n }\n\n remove(filename: string) {\n const index = this.files.findIndex((file) => file.filename === filename);\n this.files.splice(index, 1);\n }\n\n removeAll() {\n this.files = [];\n }\n\n removeByTag(tag: string) {\n this.files = this.files.filter((file) => file.tag !== tag);\n }\n\n writeAll() {\n const toWrite = this.files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n writeByTag(tag: string) {\n const files = this.getByTag(tag);\n const toWrite = files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n unlinkAll() {\n return Promise.all(this.files.map((file) => file.unlink())).then(() => {\n // void\n });\n }\n\n getPersistedFiles() {\n return this.files.filter((file) => file.persisted);\n }\n\n getPersistedFileNames() {\n return this.getPersistedFiles().map((file) => file.filename);\n }\n}\n","import { camelCase, pascalCase } from 'change-case-all';\n\nexport function getModuleGetName(name: string) {\n return `get${pascalCase(name)}Module`;\n}\n\nexport function getModuleCreateName(name: string) {\n return `create${pascalCase(name)}Module`;\n}\n\nexport function getModuleVariableName(name: string) {\n return camelCase(`${name}Module`);\n}\n","import { PluginType } from '@baeta/plugin';\nimport { NormalizedGeneratorOptions } from './config';\nimport { Ctx } from './ctx';\nimport { Watcher, WatcherFile } from './watcher';\n\nexport enum GeneratorPluginVersion {\n V1 = 'v1',\n}\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n ctx: Ctx<Store>,\n next: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n options: NormalizedGeneratorOptions,\n watcher: Watcher,\n reload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n name: string;\n actionName: string;\n setup?: GeneratorPluginV1Fn<Store>;\n generate?: GeneratorPluginV1Fn<Store>;\n end?: GeneratorPluginV1Fn<Store>;\n watch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n name: string;\n actionName: string;\n version: GeneratorPluginVersion.V1;\n type: PluginType.Generator;\n setup: GeneratorPluginV1Fn<Store>;\n generate: GeneratorPluginV1Fn<Store>;\n end: GeneratorPluginV1Fn<Store>;\n watch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (ctx, next) => {\n return next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = {}>(\n options: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n return {\n name: options.name,\n actionName: options.actionName,\n version: GeneratorPluginVersion.V1,\n type: PluginType.Generator,\n end: options.end ?? defaultPluginFn,\n generate: options.generate ?? defaultPluginFn,\n setup: options.setup ?? defaultPluginFn,\n watch: options.watch ?? defaultWatchFn,\n };\n}\n\nexport function isGeneratorPlugin(plugin: {\n type: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n return plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n if (!plugins) {\n return [];\n }\n return plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport { AsyncSubscription, Event, EventType, Options, subscribe } from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { MatchPattern, WatcherIgnore } from './watcher-ignore';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n type: EventType;\n path: string;\n relativePath: string;\n}\nexport class Watcher {\n private subscription: AsyncSubscription;\n\n private listeners: Record<EventType, WatcherListener[]> = {\n create: [],\n update: [],\n delete: [],\n };\n\n private watcherIgnore: WatcherIgnore;\n\n constructor(\n private readonly cwd: string,\n private readonly options?: Options,\n ) {\n this.watcherIgnore = new WatcherIgnore(cwd);\n this.subscription = this.createSubscription();\n }\n\n onEvents = (err: Error | null, events: Event[]) => {\n if (err) {\n console.error(err);\n return;\n }\n\n const filteredEvents = events.filter((event) => {\n return !this.watcherIgnore.isIgnored(posixPath(event.path));\n });\n\n for (const event of filteredEvents) {\n for (const listener of this.listeners[event.type]) {\n listener({\n type: event.type,\n path: posixPath(event.path),\n relativePath: posixPath(path.relative(this.cwd, event.path)),\n });\n }\n }\n };\n\n on(event: EventType, listener: WatcherListener) {\n this.listeners[event].push(listener);\n }\n\n off(event: EventType, listener: WatcherListener) {\n this.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n }\n\n ignore(pattern: MatchPattern) {\n this.watcherIgnore.ignore(pattern);\n }\n\n unignore(pattern: MatchPattern) {\n this.watcherIgnore.unignore(pattern);\n }\n\n createSubscription() {\n const promise = subscribe(this.cwd, this.onEvents, this.options);\n\n const unsubscribe = async () => {\n const subscription = await promise;\n await subscription.unsubscribe();\n };\n\n return {\n unsubscribe,\n };\n }\n\n close() {\n return this.subscription.unsubscribe();\n }\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 private files: string[] = [];\n private regexps: RegExp[] = [];\n private functions: MatchFn[] = [];\n\n private globs: MatchFn[] = [];\n private globsMap = new Map<string, MatchFn>();\n\n constructor(private readonly cwd: string) {}\n\n ignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps.push(pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions.push(pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n this.files.push(this.resolveFile(pattern));\n return;\n }\n\n this.globsMap.set(pattern, micromatch.matcher(pattern));\n this.globs = Array.from(this.globsMap.values());\n }\n\n isMicromatch(pattern: string) {\n const result = micromatch.scan(pattern);\n return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n }\n\n resolveFile(file: string) {\n return path.isAbsolute(file) ? file : path.join(this.cwd, file);\n }\n\n unignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps = this.regexps.filter((p) => p !== pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions = this.functions.filter((p) => p !== pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n const file = this.resolveFile(pattern);\n this.files = this.files.filter((p) => p !== file);\n return;\n }\n\n this.globsMap.delete(pattern);\n this.globs = Array.from(this.globsMap.values());\n }\n\n isIgnored(path: string) {\n if (this.files.includes(path)) {\n return true;\n }\n\n if (this.globs.some((f) => f(path))) {\n return true;\n }\n\n if (this.regexps.some((r) => r.test(path))) {\n return true;\n }\n\n if (this.functions.some((f) => f(path))) {\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY,MAAM,WAAW,UAAU,eAAe;AA6ExD,SAAS,YAAY,SAAuD;AACjF,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;AAE7D,QAAM,uBAAuB,QAAQ,YAAY,2BAA2B;AAC5E,QAAM,gBAAgB,QAAQ,KAAK,QAAQ,iBAAiB,oBAAoB;AAChF,QAAM,gBAAgB,UAAU,SAAS,YAAY,aAAa,CAAC;AAEnE,QAAM,cAAc,mBAAmB,KAAK,eAAe,QAAQ,WAAW;AAC9E,QAAM,aAAa,qBAAqB,YAAY,sBAAsB,QAAQ,UAAU;AAE5F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,QAAQ;AAAA,IACjB,aAAa,QAAQ;AAAA,EACvB;AACF;AAEA,SAAS,mBAAmB,MAAc,eAAuB,aAAsB;AACrF,MAAI,CAAC,aAAa;AAChB;AAAA,EACF;AAEA,MAAI,W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AAAA,EAC5E;AAAA,EAEA,OAAO,SAAuB;AAC5B,SAAK,cAAc,OAAO,OAAO;AAAA,EACnC;AAAA,EAEA,SAAS,SAAuB;AAC9B,SAAK,cAAc,SAAS,OAAO;AAAA,EACrC;AAAA,EAEA,qBAAqB;AACnB,UAAM,UAAU,UAAU,KAAK,KAAK,KAAK,UAAU,KAAK,OAAO;AAE/D,UAAM,cAAc,YAAY;AAC9B,YAAM,eAAe,MAAM;AAC3B,YAAM,aAAa,YAAY;AAAA,IACjC;AAEA,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ;AACN,WAAO,KAAK,aAAa,YAAY;AAAA,EACvC;AACF;","names":["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 { isAbsolute, join, posixPath, relative, resolve } from '@baeta/util-path';\nimport { FileOptions } from './file';\n\n/**\n * Options for the graphql generator.\n */\nexport interface GeneratorOptions {\n /**\n * Current working directory.\n * @default process.cwd()\n */\n cwd?: string;\n\n /**\n * Glob pattern(s) to load graphql schema files.\n * @default ['src/∗∗/∗.graphql']\n */\n schemas: string[];\n\n /**\n * Directory where modules are defined.\n * @default 'src/modules'\n */\n modulesDir?: string;\n\n /**\n * Name for the generated module definition file. This will contain type definitions and the graphql ast.\n * @default 'typedef.ts'\n */\n moduleDefinitionName?: string;\n\n /**\n * Path for the generated base types file.\n * @default `${modulesDir}/../__generated__/types.ts`\n */\n baseTypesPath?: string;\n\n /**\n * Path where the context type is exported.\n * @example contextType: 'src/types/context#Context' // for named export\n * @example contextType: 'src/types/context' // for default export\n * @default undefined\n */\n contextType?: string;\n\n /**\n * Path where extensions (ex. auth-extension) are exported. Only default export is supported.\n * @example extensions: 'src/extensions'\n * @default undefined\n */\n extensions?: string;\n\n /**\n * Custom scalar mappings.\n * @example scalars: { DateTime: 'Date' }\n * @default undefined\n */\n scalars?: Record<string, string>;\n\n /**\n * Options for generated files.\n */\n fileOptions?: FileOptions;\n}\n\nexport interface NormalizedGeneratorOptions {\n cwd: string;\n schemas: string[];\n modulesDir: string;\n moduleDefinitionName: string;\n baseTypesPath: string;\n contextType?: string;\n extensions?: string;\n scalars?: Record<string, string>;\n fileOptions?: FileOptions;\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n const cwd = posixPath(options.cwd ?? process.cwd());\n const schemas = options.schemas ?? ['src/**/*.graphql'];\n const modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n const moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\n const defaultBaseTypesRoot = resolve(modulesDir, '../__generated__/types.ts');\n const baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);\n const baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));\n\n const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);\n const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);\n\n return {\n cwd,\n schemas,\n modulesDir,\n moduleDefinitionName,\n baseTypesPath,\n contextType,\n extensions,\n scalars: options.scalars,\n fileOptions: options.fileOptions,\n };\n}\n\nfunction resolveContextType(root: string, baseTypesRoot: string, contextType?: string) {\n if (!contextType) {\n return;\n }\n\n if (isAbsolute(contextType)) {\n return contextType;\n }\n\n if (contextType[0] === '!') {\n return contextType.slice(1);\n }\n\n const contextTypeRoot = resolve(root, contextType);\n\n return posixPath(relative(join(baseTypesRoot, '../'), contextTypeRoot));\n}\n\nfunction resolveExtensionPath(\n modulesDir: string,\n moduleDefinitionName: string,\n extensionsPath?: string,\n) {\n if (!extensionsPath) {\n return;\n }\n\n if (isAbsolute(extensionsPath)) {\n return extensionsPath;\n }\n\n if (extensionsPath[0] === '!') {\n return extensionsPath.slice(1);\n }\n\n return posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));\n}\n","import { dirname, extname } from '@baeta/util-path';\nimport fs from 'node:fs/promises';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n /**\n * Add generation notice at the beginning of the file.\n * @default true\n */\n addGenerationNoticeHeader?: boolean;\n\n /**\n * Add eslint-disable comment at the beginning of the file.\n * @default true\n */\n addEslintDisableHeader?: boolean;\n\n /**\n * Add custom header at the beginning of the file.\n */\n addHeader?: (name: string, content: string, tag: string) => string;\n\n /**\n * Edit the content of the file before writing it.\n */\n transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n persisted = false;\n\n constructor(\n public filename: string,\n public content: string,\n public tag: string,\n private options?: FileOptions,\n ) {}\n\n write = async () => {\n if (this.persisted) {\n return;\n }\n this.persisted = true;\n\n const dir = dirname(this.filename);\n await fs.mkdir(dir, { recursive: true });\n\n const content = await this.buildContent();\n\n return fs.writeFile(this.filename, content, 'utf-8');\n };\n\n unlink = async () => {\n this.persisted = false;\n return fs.unlink(this.filename);\n };\n\n protected async buildContent() {\n const content = this.buildHeader() + this.content;\n\n if (this.options?.transformContent) {\n return this.options.transformContent(this.filename, content, this.tag);\n }\n\n return content;\n }\n\n protected buildHeader() {\n const headerItems: string[] = [];\n\n if (this.options?.addGenerationNoticeHeader !== false) {\n const comment = this.createComment(\n 'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n );\n headerItems.push(comment);\n }\n\n if (this.options?.addEslintDisableHeader !== false) {\n const comment = this.createComment('eslint-disable');\n headerItems.push(comment);\n }\n\n if (this.options?.addHeader) {\n const customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n headerItems.push(customHeader);\n }\n\n if (headerItems.length === 0) {\n return '';\n }\n\n return `${headerItems.join('\\n')}\\n\\n`;\n }\n\n protected createComment(comment: string) {\n const extension = extname(this.filename);\n\n if (['.gql', '.graphql'].includes(extension)) {\n return `# ${comment}`;\n }\n\n return `/* ${comment} */`;\n }\n}\n","import { dirname } from '@baeta/util-path';\nimport { mkdir, open, writeFile } from 'node:fs/promises';\nimport { File, FileOptions } from './file';\n\nexport class FileBlock extends File {\n constructor(\n filename: string,\n content: string,\n protected start: string,\n protected end: string,\n tag: string,\n options?: FileOptions,\n ) {\n super(filename, content, tag, {\n addEslintDisableHeader: options?.addEslintDisableHeader ?? false,\n addGenerationNoticeHeader: options?.addGenerationNoticeHeader ?? false,\n });\n }\n\n write = async () => {\n if (this.persisted) {\n return;\n }\n this.persisted = true;\n\n const dir = dirname(this.filename);\n await mkdir(dir, { recursive: true });\n\n const [existingContent, fd] = await this.getExistingContent();\n this.addBlockToContent(existingContent);\n const content = await this.buildContent();\n\n if (fd) {\n await fd.write(content, 0, 'utf-8');\n await fd.close();\n } else {\n await writeFile(this.filename, content, 'utf-8');\n }\n };\n\n protected async getExistingContent() {\n try {\n const fd = await open(this.filename, 'r+');\n const existingContent = await fd.readFile('utf-8');\n return [existingContent, fd] as const;\n } catch (err) {\n return ['', null] as const;\n }\n }\n\n protected getSlices(existingContent: string) {\n const startMarkerIndex = existingContent.indexOf(this.start);\n const endMarkerIndex = existingContent.indexOf(this.end);\n\n if (startMarkerIndex === -1 || endMarkerIndex === -1) {\n return [existingContent, ''] as const;\n }\n\n return [\n existingContent.slice(0, startMarkerIndex),\n existingContent.slice(endMarkerIndex + this.end.length),\n ] as const;\n }\n\n protected addBlockToContent(existingContent: string) {\n const block = `${this.start}\\n${this.content}\\n${this.end}`;\n const padding = this.buildPadding(existingContent);\n const [startSlice, endSlice] = this.getSlices(existingContent);\n this.content = startSlice + padding + block + endSlice;\n }\n\n protected stripBlock(existingContent: string) {\n const [startSlice, endSlice] = this.getSlices(existingContent);\n return startSlice + endSlice;\n }\n\n protected buildPadding(existingContent: string) {\n const existingStripped = this.stripBlock(existingContent);\n\n if (existingStripped === '') {\n return '';\n }\n\n if (existingStripped.endsWith('\\n\\n')) {\n return '';\n }\n\n if (existingStripped.endsWith('\\n')) {\n return '\\n';\n }\n\n return '\\n\\n';\n }\n}\n","import { File, FileOptions } from './file';\n\nexport class FileManager {\n files: File[] = [];\n\n constructor(public fileOptions?: FileOptions) {}\n\n createAndAdd(filename: string, content: string, tag: string) {\n const file = new File(filename, content, tag, this.fileOptions);\n this.add(file);\n return file;\n }\n\n add(...file: File[]) {\n this.files.push(...file);\n }\n\n get(filename: string) {\n return this.files.find((file) => file.filename === filename);\n }\n\n getAll() {\n return this.files;\n }\n\n getByTag(tag: string) {\n return this.files.filter((file) => file.tag === tag);\n }\n\n remove(filename: string) {\n const index = this.files.findIndex((file) => file.filename === filename);\n this.files.splice(index, 1);\n }\n\n removeAll() {\n this.files = [];\n }\n\n removeByTag(tag: string) {\n this.files = this.files.filter((file) => file.tag !== tag);\n }\n\n writeAll() {\n const toWrite = this.files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n writeByTag(tag: string) {\n const files = this.getByTag(tag);\n const toWrite = files.filter((file) => !file.persisted);\n return Promise.all(toWrite.map((file) => file.write()));\n }\n\n unlinkAll() {\n return Promise.all(this.files.map((file) => file.unlink())).then(() => {\n // void\n });\n }\n\n getPersistedFiles() {\n return this.files.filter((file) => file.persisted);\n }\n\n getPersistedFileNames() {\n return this.getPersistedFiles().map((file) => file.filename);\n }\n}\n","import { camelCase, pascalCase } from 'change-case-all';\n\nexport function getModuleGetName(name: string) {\n return `get${pascalCase(name)}Module`;\n}\n\nexport function getModuleCreateName(name: string) {\n return `create${pascalCase(name)}Module`;\n}\n\nexport function getModuleVariableName(name: string) {\n return camelCase(`${name}Module`);\n}\n","import { PluginType } from '@baeta/plugin';\nimport { NormalizedGeneratorOptions } from './config';\nimport { Ctx } from './ctx';\nimport { Watcher, WatcherFile } from './watcher';\n\nexport enum GeneratorPluginVersion {\n V1 = 'v1',\n}\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n ctx: Ctx<Store>,\n next: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n options: NormalizedGeneratorOptions,\n watcher: Watcher,\n reload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n name: string;\n actionName: string;\n setup?: GeneratorPluginV1Fn<Store>;\n generate?: GeneratorPluginV1Fn<Store>;\n end?: GeneratorPluginV1Fn<Store>;\n watch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n name: string;\n actionName: string;\n version: GeneratorPluginVersion.V1;\n type: PluginType.Generator;\n setup: GeneratorPluginV1Fn<Store>;\n generate: GeneratorPluginV1Fn<Store>;\n end: GeneratorPluginV1Fn<Store>;\n watch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (ctx, next) => {\n return next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = {}>(\n options: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n return {\n name: options.name,\n actionName: options.actionName,\n version: GeneratorPluginVersion.V1,\n type: PluginType.Generator,\n end: options.end ?? defaultPluginFn,\n generate: options.generate ?? defaultPluginFn,\n setup: options.setup ?? defaultPluginFn,\n watch: options.watch ?? defaultWatchFn,\n };\n}\n\nexport function isGeneratorPlugin(plugin: {\n type: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n return plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n if (!plugins) {\n return [];\n }\n return plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport { AsyncSubscription, Event, EventType, Options, subscribe } from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { MatchPattern, WatcherIgnore } from './watcher-ignore';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n type: EventType;\n path: string;\n relativePath: string;\n}\nexport class Watcher {\n private subscription: AsyncSubscription;\n\n private listeners: Record<EventType, WatcherListener[]> = {\n create: [],\n update: [],\n delete: [],\n };\n\n private watcherIgnore: WatcherIgnore;\n\n constructor(\n private readonly cwd: string,\n private readonly options?: Options,\n ) {\n this.watcherIgnore = new WatcherIgnore(cwd);\n this.subscription = this.createSubscription();\n }\n\n onEvents = (err: Error | null, events: Event[]) => {\n if (err) {\n console.error(err);\n return;\n }\n\n const filteredEvents = events.filter((event) => {\n return !this.watcherIgnore.isIgnored(posixPath(event.path));\n });\n\n for (const event of filteredEvents) {\n for (const listener of this.listeners[event.type]) {\n listener({\n type: event.type,\n path: posixPath(event.path),\n relativePath: posixPath(path.relative(this.cwd, event.path)),\n });\n }\n }\n };\n\n on(event: EventType, listener: WatcherListener) {\n this.listeners[event].push(listener);\n }\n\n off(event: EventType, listener: WatcherListener) {\n this.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n }\n\n ignore(pattern: MatchPattern) {\n this.watcherIgnore.ignore(pattern);\n }\n\n unignore(pattern: MatchPattern) {\n this.watcherIgnore.unignore(pattern);\n }\n\n createSubscription() {\n const promise = subscribe(this.cwd, this.onEvents, this.options);\n\n const unsubscribe = async () => {\n const subscription = await promise;\n await subscription.unsubscribe();\n };\n\n return {\n unsubscribe,\n };\n }\n\n close() {\n return this.subscription.unsubscribe();\n }\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 private files: string[] = [];\n private regexps: RegExp[] = [];\n private functions: MatchFn[] = [];\n\n private globs: MatchFn[] = [];\n private globsMap = new Map<string, MatchFn>();\n\n constructor(private readonly cwd: string) {}\n\n ignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps.push(pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions.push(pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n this.files.push(this.resolveFile(pattern));\n return;\n }\n\n this.globsMap.set(pattern, micromatch.matcher(pattern));\n this.globs = Array.from(this.globsMap.values());\n }\n\n isMicromatch(pattern: string) {\n const result = micromatch.scan(pattern);\n return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n }\n\n resolveFile(file: string) {\n return path.isAbsolute(file) ? file : path.join(this.cwd, file);\n }\n\n unignore(pattern: MatchPattern) {\n if (pattern instanceof RegExp) {\n this.regexps = this.regexps.filter((p) => p !== pattern);\n return;\n }\n\n if (typeof pattern === 'function') {\n this.functions = this.functions.filter((p) => p !== pattern);\n return;\n }\n\n if (!this.isMicromatch(pattern)) {\n const file = this.resolveFile(pattern);\n this.files = this.files.filter((p) => p !== file);\n return;\n }\n\n this.globsMap.delete(pattern);\n this.globs = Array.from(this.globsMap.values());\n }\n\n isIgnored(path: string) {\n if (this.files.includes(path)) {\n return true;\n }\n\n if (this.globs.some((f) => f(path))) {\n return true;\n }\n\n if (this.regexps.some((r) => r.test(path))) {\n return true;\n }\n\n if (this.functions.some((f) => f(path))) {\n return true;\n }\n\n return false;\n }\n}\n"],"mappings":";AAAA,SAAS,YAAY,MAAM,WAAW,UAAU,eAAe;AA6ExD,SAAS,YAAY,SAAuD;AACjF,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;AAE7D,QAAM,uBAAuB,QAAQ,YAAY,2BAA2B;AAC5E,QAAM,gBAAgB,QAAQ,KAAK,QAAQ,iBAAiB,oBAAoB;AAChF,QAAM,gBAAgB,UAAU,SAAS,YAAY,aAAa,CAAC;AAEnE,QAAM,cAAc,mBAAmB,KAAK,eAAe,QAAQ,WAAW;AAC9E,QAAM,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KAAK,UAAU,KAAK,OAAO;AAE/D,UAAM,cAAc,YAAY;AAC9B,YAAM,eAAe,MAAM;AAC3B,YAAM,aAAa,YAAY;AAAA,IACjC;AAEA,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ;AACN,WAAO,KAAK,aAAa,YAAY;AAAA,EACvC;AACF;","names":["dirname","dirname","GeneratorPluginVersion","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": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"baeta",
|
|
6
6
|
"graphql",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"types": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@baeta/plugin": "^0.0.
|
|
49
|
-
"@baeta/util-path": "^0.0.
|
|
48
|
+
"@baeta/plugin": "^0.0.23",
|
|
49
|
+
"@baeta/util-path": "^0.0.4",
|
|
50
50
|
"@parcel/watcher": "^2.4.1",
|
|
51
51
|
"change-case-all": "2.1.0",
|
|
52
52
|
"micromatch": "^4.0.5"
|
|
@@ -54,12 +54,12 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@baeta/builder": "^0.0.0",
|
|
56
56
|
"@baeta/tsconfig": "^0.0.0",
|
|
57
|
-
"@types/micromatch": "^4.0.
|
|
58
|
-
"@types/node": "^
|
|
59
|
-
"typescript": "^5.4.
|
|
57
|
+
"@types/micromatch": "^4.0.7",
|
|
58
|
+
"@types/node": "^20.12.7",
|
|
59
|
+
"typescript": "^5.4.5"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
62
|
+
"node": ">=20.0.0"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|