@baeta/generator-sdk 0.0.10 → 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 +24 -0
- package/dist/index.cjs +161 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -6
- package/dist/index.d.ts +79 -6
- package/dist/index.js +147 -17
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
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
|
+
|
|
15
|
+
## 0.0.11
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#117](https://github.com/andreisergiu98/baeta/pull/117) [`18db339`](https://github.com/andreisergiu98/baeta/commit/18db339719aa309c619372d2161c5fdbc08fa316) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add comments to config types
|
|
20
|
+
|
|
21
|
+
- [#119](https://github.com/andreisergiu98/baeta/pull/119) [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [[`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a)]:
|
|
24
|
+
- @baeta/plugin@0.0.22
|
|
25
|
+
- @baeta/util-path@0.0.3
|
|
26
|
+
|
|
3
27
|
## 0.0.10
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
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/
|
|
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
|
+
function loadOptions(options) {
|
|
4
|
+
const cwd = _utilpath.posixPath.call(void 0, _nullishCoalesce(options.cwd, () => ( process.cwd())));
|
|
5
|
+
const schemas = _nullishCoalesce(options.schemas, () => ( ["src/**/*.graphql"]));
|
|
6
|
+
const modulesDir = _utilpath.posixPath.call(void 0, _utilpath.resolve.call(void 0, cwd, options.modulesDir || "src/modules"));
|
|
7
|
+
const moduleDefinitionName = options.moduleDefinitionName || "typedef.ts";
|
|
8
|
+
const defaultBaseTypesRoot = _utilpath.resolve.call(void 0, modulesDir, "../__generated__/types.ts");
|
|
9
|
+
const baseTypesRoot = _utilpath.resolve.call(void 0, cwd, options.baseTypesPath || defaultBaseTypesRoot);
|
|
10
|
+
const baseTypesPath = _utilpath.posixPath.call(void 0, _utilpath.relative.call(void 0, modulesDir, baseTypesRoot));
|
|
11
|
+
const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);
|
|
12
|
+
const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);
|
|
13
|
+
return {
|
|
14
|
+
cwd,
|
|
15
|
+
schemas,
|
|
16
|
+
modulesDir,
|
|
17
|
+
moduleDefinitionName,
|
|
18
|
+
baseTypesPath,
|
|
19
|
+
contextType,
|
|
20
|
+
extensions,
|
|
21
|
+
scalars: options.scalars,
|
|
22
|
+
fileOptions: options.fileOptions
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveContextType(root, baseTypesRoot, contextType) {
|
|
26
|
+
if (!contextType) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (_utilpath.isAbsolute.call(void 0, contextType)) {
|
|
30
|
+
return contextType;
|
|
31
|
+
}
|
|
32
|
+
if (contextType[0] === "!") {
|
|
33
|
+
return contextType.slice(1);
|
|
34
|
+
}
|
|
35
|
+
const contextTypeRoot = _utilpath.resolve.call(void 0, root, contextType);
|
|
36
|
+
return _utilpath.posixPath.call(void 0, _utilpath.relative.call(void 0, _utilpath.join.call(void 0, baseTypesRoot, "../"), contextTypeRoot));
|
|
37
|
+
}
|
|
38
|
+
function resolveExtensionPath(modulesDir, moduleDefinitionName, extensionsPath) {
|
|
39
|
+
if (!extensionsPath) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (_utilpath.isAbsolute.call(void 0, extensionsPath)) {
|
|
43
|
+
return extensionsPath;
|
|
44
|
+
}
|
|
45
|
+
if (extensionsPath[0] === "!") {
|
|
46
|
+
return extensionsPath.slice(1);
|
|
47
|
+
}
|
|
48
|
+
return _utilpath.posixPath.call(void 0, _utilpath.relative.call(void 0, _utilpath.join.call(void 0, modulesDir, moduleDefinitionName), extensionsPath));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// lib/file.ts
|
|
52
|
+
|
|
3
53
|
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
|
|
4
54
|
var File = (_class = class {
|
|
5
55
|
constructor(filename, content, tag, options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
@@ -31,28 +81,30 @@ var File = (_class = class {
|
|
|
31
81
|
return content;
|
|
32
82
|
}
|
|
33
83
|
buildHeader() {
|
|
34
|
-
const ext = _utilpath.extname.call(void 0, this.filename);
|
|
35
84
|
const headerItems = [];
|
|
36
|
-
if (_optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"This file was generated by baeta. Do not edit it directly.",
|
|
40
|
-
ext
|
|
41
|
-
)}
|
|
42
|
-
`
|
|
85
|
+
if (_optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.addGenerationNoticeHeader]) !== false) {
|
|
86
|
+
const comment = this.createComment(
|
|
87
|
+
"This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator."
|
|
43
88
|
);
|
|
89
|
+
headerItems.push(comment);
|
|
44
90
|
}
|
|
45
|
-
if (_optionalChain([this, 'access', _5 => _5.options, 'optionalAccess', _6 => _6.
|
|
46
|
-
|
|
91
|
+
if (_optionalChain([this, 'access', _5 => _5.options, 'optionalAccess', _6 => _6.addEslintDisableHeader]) !== false) {
|
|
92
|
+
const comment = this.createComment("eslint-disable");
|
|
93
|
+
headerItems.push(comment);
|
|
47
94
|
}
|
|
48
95
|
if (_optionalChain([this, 'access', _7 => _7.options, 'optionalAccess', _8 => _8.addHeader])) {
|
|
49
|
-
|
|
96
|
+
const customHeader = this.options.addHeader(this.filename, this.content, this.tag);
|
|
97
|
+
headerItems.push(customHeader);
|
|
98
|
+
}
|
|
99
|
+
if (headerItems.length === 0) {
|
|
100
|
+
return "";
|
|
50
101
|
}
|
|
51
102
|
return `${headerItems.join("\n")}
|
|
52
103
|
|
|
53
104
|
`;
|
|
54
105
|
}
|
|
55
|
-
createComment(comment
|
|
106
|
+
createComment(comment) {
|
|
107
|
+
const extension = _utilpath.extname.call(void 0, this.filename);
|
|
56
108
|
if ([".gql", ".graphql"].includes(extension)) {
|
|
57
109
|
return `# ${comment}`;
|
|
58
110
|
}
|
|
@@ -60,12 +112,88 @@ var File = (_class = class {
|
|
|
60
112
|
}
|
|
61
113
|
}, _class);
|
|
62
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
|
+
|
|
63
191
|
// lib/file-manager.ts
|
|
64
|
-
var FileManager = (
|
|
65
|
-
constructor(fileOptions) {;
|
|
192
|
+
var FileManager = (_class3 = class {
|
|
193
|
+
constructor(fileOptions) {;_class3.prototype.__init5.call(this);
|
|
66
194
|
this.fileOptions = fileOptions;
|
|
67
195
|
}
|
|
68
|
-
|
|
196
|
+
__init5() {this.files = []}
|
|
69
197
|
createAndAdd(filename, content, tag) {
|
|
70
198
|
const file = new File(filename, content, tag, this.fileOptions);
|
|
71
199
|
this.add(file);
|
|
@@ -112,7 +240,7 @@ var FileManager = (_class2 = class {
|
|
|
112
240
|
getPersistedFileNames() {
|
|
113
241
|
return this.getPersistedFiles().map((file) => file.filename);
|
|
114
242
|
}
|
|
115
|
-
},
|
|
243
|
+
}, _class3);
|
|
116
244
|
|
|
117
245
|
// lib/module.ts
|
|
118
246
|
var _changecaseall = require('change-case-all');
|
|
@@ -166,15 +294,15 @@ var _micromatch = require('micromatch'); var _micromatch2 = _interopRequireDefau
|
|
|
166
294
|
// lib/watcher-ignore.ts
|
|
167
295
|
|
|
168
296
|
|
|
169
|
-
var WatcherIgnore = (
|
|
170
|
-
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);
|
|
171
299
|
this.cwd = cwd;
|
|
172
300
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
301
|
+
__init6() {this.files = []}
|
|
302
|
+
__init7() {this.regexps = []}
|
|
303
|
+
__init8() {this.functions = []}
|
|
304
|
+
__init9() {this.globs = []}
|
|
305
|
+
__init10() {this.globsMap = /* @__PURE__ */ new Map()}
|
|
178
306
|
ignore(pattern) {
|
|
179
307
|
if (pattern instanceof RegExp) {
|
|
180
308
|
this.regexps.push(pattern);
|
|
@@ -230,25 +358,25 @@ var WatcherIgnore = (_class3 = class {
|
|
|
230
358
|
}
|
|
231
359
|
return false;
|
|
232
360
|
}
|
|
233
|
-
},
|
|
361
|
+
}, _class4);
|
|
234
362
|
|
|
235
363
|
// lib/watcher.ts
|
|
236
364
|
var isMatch = _micromatch2.default.isMatch;
|
|
237
|
-
var Watcher = (
|
|
238
|
-
constructor(cwd, options) {;
|
|
365
|
+
var Watcher = (_class5 = class {
|
|
366
|
+
constructor(cwd, options) {;_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);
|
|
239
367
|
this.cwd = cwd;
|
|
240
368
|
this.options = options;
|
|
241
369
|
this.watcherIgnore = new WatcherIgnore(cwd);
|
|
242
370
|
this.subscription = this.createSubscription();
|
|
243
371
|
}
|
|
244
372
|
|
|
245
|
-
|
|
373
|
+
__init11() {this.listeners = {
|
|
246
374
|
create: [],
|
|
247
375
|
update: [],
|
|
248
376
|
delete: []
|
|
249
377
|
}}
|
|
250
378
|
|
|
251
|
-
|
|
379
|
+
__init12() {this.onEvents = (err, events) => {
|
|
252
380
|
if (err) {
|
|
253
381
|
console.error(err);
|
|
254
382
|
return;
|
|
@@ -291,7 +419,9 @@ var Watcher = (_class4 = class {
|
|
|
291
419
|
close() {
|
|
292
420
|
return this.subscription.unsubscribe();
|
|
293
421
|
}
|
|
294
|
-
},
|
|
422
|
+
}, _class5);
|
|
423
|
+
|
|
424
|
+
|
|
295
425
|
|
|
296
426
|
|
|
297
427
|
|
|
@@ -305,5 +435,5 @@ var Watcher = (_class4 = class {
|
|
|
305
435
|
|
|
306
436
|
|
|
307
437
|
|
|
308
|
-
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.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;
|
|
309
439
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/file.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher.ts","../lib/watcher-ignore.ts"],"names":["GeneratorPluginVersion","path","micromatch"],"mappings":";AAAA,SAAS,SAAS,eAAe;AACjC,OAAO,QAAQ;AASR,IAAM,OAAN,MAAW;AAAA,EAGhB,YACS,UACA,SACA,KACC,SACR;AAJO;AACA;AACA;AACC;AAAA,EACP;AAAA,EAPH,YAAY;AAAA,EASZ,QAAQ,YAAY;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eAAW,SAAS,gBAAgB;AAClC,iBAAW,YAAY,KAAK,UAAU,MAAM,IAAI,GAAG;AACjD,iBAAS;AAAA,UACP,MAAM,MAAM;AAAA,UACZ,MAAM,UAAU,MAAM,IAAI;AAAA,UAC1B,cAAc,UAAUD,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 { dirname, extname } from '@baeta/util-path';\nimport fs from 'fs/promises';\n\nexport interface FileOptions {\n eslintDisable?: boolean;\n generationNotice?: boolean;\n addHeader?: (name: string, content: string, tag: string) => string;\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 ext = extname(this.filename);\n\n const headerItems: string[] = [];\n\n if (this.options?.generationNotice !== false) {\n headerItems.push(\n `${this.createComment(\n 'This file was generated by baeta. Do not edit it directly.',\n ext,\n )}\\n`,\n );\n }\n\n if (this.options?.eslintDisable !== false) {\n headerItems.push(this.createComment('eslint-disable', ext));\n }\n\n if (this.options?.addHeader) {\n headerItems.push(this.options.addHeader(this.filename, this.content, this.tag));\n }\n\n return `${headerItems.join('\\n')}\\n\\n`;\n }\n\n protected createComment(comment: string, extension: string) {\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,S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AU;AAC9C,aAAO,CAAC,KAAK,cAAc,UAAUD,WAAU,MAAM,IAAI,CAAC;AAAA,IAC5D,CAAC;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,12 +1,30 @@
|
|
|
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
|
|
|
7
|
+
/**
|
|
8
|
+
* Options for generated files.
|
|
9
|
+
*/
|
|
6
10
|
interface FileOptions {
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Add generation notice at the beginning of the file.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
addGenerationNoticeHeader?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Add eslint-disable comment at the beginning of the file.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
addEslintDisableHeader?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Add custom header at the beginning of the file.
|
|
23
|
+
*/
|
|
9
24
|
addHeader?: (name: string, content: string, tag: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Edit the content of the file before writing it.
|
|
27
|
+
*/
|
|
10
28
|
transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
|
|
11
29
|
}
|
|
12
30
|
declare class File {
|
|
@@ -18,20 +36,62 @@ declare class File {
|
|
|
18
36
|
constructor(filename: string, content: string, tag: string, options?: FileOptions | undefined);
|
|
19
37
|
write: () => Promise<void>;
|
|
20
38
|
unlink: () => Promise<void>;
|
|
21
|
-
|
|
39
|
+
protected buildContent(): Promise<string>;
|
|
22
40
|
protected buildHeader(): string;
|
|
23
|
-
protected createComment(comment: string
|
|
41
|
+
protected createComment(comment: string): string;
|
|
24
42
|
}
|
|
25
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Options for the graphql generator.
|
|
46
|
+
*/
|
|
26
47
|
interface GeneratorOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Current working directory.
|
|
50
|
+
* @default process.cwd()
|
|
51
|
+
*/
|
|
27
52
|
cwd?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Glob pattern(s) to load graphql schema files.
|
|
55
|
+
* @default ['src/∗∗/∗.graphql']
|
|
56
|
+
*/
|
|
28
57
|
schemas: string[];
|
|
58
|
+
/**
|
|
59
|
+
* Directory where modules are defined.
|
|
60
|
+
* @default 'src/modules'
|
|
61
|
+
*/
|
|
29
62
|
modulesDir?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Name for the generated module definition file. This will contain type definitions and the graphql ast.
|
|
65
|
+
* @default 'typedef.ts'
|
|
66
|
+
*/
|
|
30
67
|
moduleDefinitionName?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Path for the generated base types file.
|
|
70
|
+
* @default `${modulesDir}/../__generated__/types.ts`
|
|
71
|
+
*/
|
|
31
72
|
baseTypesPath?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Path where the context type is exported.
|
|
75
|
+
* @example contextType: 'src/types/context#Context' // for named export
|
|
76
|
+
* @example contextType: 'src/types/context' // for default export
|
|
77
|
+
* @default undefined
|
|
78
|
+
*/
|
|
32
79
|
contextType?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Path where extensions (ex. auth-extension) are exported. Only default export is supported.
|
|
82
|
+
* @example extensions: 'src/extensions'
|
|
83
|
+
* @default undefined
|
|
84
|
+
*/
|
|
33
85
|
extensions?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Custom scalar mappings.
|
|
88
|
+
* @example scalars: { DateTime: 'Date' }
|
|
89
|
+
* @default undefined
|
|
90
|
+
*/
|
|
34
91
|
scalars?: Record<string, string>;
|
|
92
|
+
/**
|
|
93
|
+
* Options for generated files.
|
|
94
|
+
*/
|
|
35
95
|
fileOptions?: FileOptions;
|
|
36
96
|
}
|
|
37
97
|
interface NormalizedGeneratorOptions {
|
|
@@ -45,9 +105,10 @@ interface NormalizedGeneratorOptions {
|
|
|
45
105
|
scalars?: Record<string, string>;
|
|
46
106
|
fileOptions?: FileOptions;
|
|
47
107
|
}
|
|
108
|
+
declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
|
|
48
109
|
|
|
49
110
|
declare class FileManager {
|
|
50
|
-
|
|
111
|
+
fileOptions?: FileOptions | undefined;
|
|
51
112
|
files: File[];
|
|
52
113
|
constructor(fileOptions?: FileOptions | undefined);
|
|
53
114
|
createAndAdd(filename: string, content: string, tag: string): File;
|
|
@@ -104,6 +165,18 @@ type Ctx<T = unknown> = {
|
|
|
104
165
|
changedFile?: WatcherFile;
|
|
105
166
|
} & T;
|
|
106
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
|
+
|
|
107
180
|
declare function getModuleGetName(name: string): string;
|
|
108
181
|
declare function getModuleCreateName(name: string): string;
|
|
109
182
|
declare function getModuleVariableName(name: string): string;
|
|
@@ -140,4 +213,4 @@ declare function getGeneratorPlugins(plugins?: Array<{
|
|
|
140
213
|
type: PluginType;
|
|
141
214
|
}>): GeneratorPluginV1<unknown>[];
|
|
142
215
|
|
|
143
|
-
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 };
|
|
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,12 +1,30 @@
|
|
|
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
|
|
|
7
|
+
/**
|
|
8
|
+
* Options for generated files.
|
|
9
|
+
*/
|
|
6
10
|
interface FileOptions {
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Add generation notice at the beginning of the file.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
addGenerationNoticeHeader?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Add eslint-disable comment at the beginning of the file.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
addEslintDisableHeader?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Add custom header at the beginning of the file.
|
|
23
|
+
*/
|
|
9
24
|
addHeader?: (name: string, content: string, tag: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Edit the content of the file before writing it.
|
|
27
|
+
*/
|
|
10
28
|
transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
|
|
11
29
|
}
|
|
12
30
|
declare class File {
|
|
@@ -18,20 +36,62 @@ declare class File {
|
|
|
18
36
|
constructor(filename: string, content: string, tag: string, options?: FileOptions | undefined);
|
|
19
37
|
write: () => Promise<void>;
|
|
20
38
|
unlink: () => Promise<void>;
|
|
21
|
-
|
|
39
|
+
protected buildContent(): Promise<string>;
|
|
22
40
|
protected buildHeader(): string;
|
|
23
|
-
protected createComment(comment: string
|
|
41
|
+
protected createComment(comment: string): string;
|
|
24
42
|
}
|
|
25
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Options for the graphql generator.
|
|
46
|
+
*/
|
|
26
47
|
interface GeneratorOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Current working directory.
|
|
50
|
+
* @default process.cwd()
|
|
51
|
+
*/
|
|
27
52
|
cwd?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Glob pattern(s) to load graphql schema files.
|
|
55
|
+
* @default ['src/∗∗/∗.graphql']
|
|
56
|
+
*/
|
|
28
57
|
schemas: string[];
|
|
58
|
+
/**
|
|
59
|
+
* Directory where modules are defined.
|
|
60
|
+
* @default 'src/modules'
|
|
61
|
+
*/
|
|
29
62
|
modulesDir?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Name for the generated module definition file. This will contain type definitions and the graphql ast.
|
|
65
|
+
* @default 'typedef.ts'
|
|
66
|
+
*/
|
|
30
67
|
moduleDefinitionName?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Path for the generated base types file.
|
|
70
|
+
* @default `${modulesDir}/../__generated__/types.ts`
|
|
71
|
+
*/
|
|
31
72
|
baseTypesPath?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Path where the context type is exported.
|
|
75
|
+
* @example contextType: 'src/types/context#Context' // for named export
|
|
76
|
+
* @example contextType: 'src/types/context' // for default export
|
|
77
|
+
* @default undefined
|
|
78
|
+
*/
|
|
32
79
|
contextType?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Path where extensions (ex. auth-extension) are exported. Only default export is supported.
|
|
82
|
+
* @example extensions: 'src/extensions'
|
|
83
|
+
* @default undefined
|
|
84
|
+
*/
|
|
33
85
|
extensions?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Custom scalar mappings.
|
|
88
|
+
* @example scalars: { DateTime: 'Date' }
|
|
89
|
+
* @default undefined
|
|
90
|
+
*/
|
|
34
91
|
scalars?: Record<string, string>;
|
|
92
|
+
/**
|
|
93
|
+
* Options for generated files.
|
|
94
|
+
*/
|
|
35
95
|
fileOptions?: FileOptions;
|
|
36
96
|
}
|
|
37
97
|
interface NormalizedGeneratorOptions {
|
|
@@ -45,9 +105,10 @@ interface NormalizedGeneratorOptions {
|
|
|
45
105
|
scalars?: Record<string, string>;
|
|
46
106
|
fileOptions?: FileOptions;
|
|
47
107
|
}
|
|
108
|
+
declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
|
|
48
109
|
|
|
49
110
|
declare class FileManager {
|
|
50
|
-
|
|
111
|
+
fileOptions?: FileOptions | undefined;
|
|
51
112
|
files: File[];
|
|
52
113
|
constructor(fileOptions?: FileOptions | undefined);
|
|
53
114
|
createAndAdd(filename: string, content: string, tag: string): File;
|
|
@@ -104,6 +165,18 @@ type Ctx<T = unknown> = {
|
|
|
104
165
|
changedFile?: WatcherFile;
|
|
105
166
|
} & T;
|
|
106
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
|
+
|
|
107
180
|
declare function getModuleGetName(name: string): string;
|
|
108
181
|
declare function getModuleCreateName(name: string): string;
|
|
109
182
|
declare function getModuleVariableName(name: string): string;
|
|
@@ -140,4 +213,4 @@ declare function getGeneratorPlugins(plugins?: Array<{
|
|
|
140
213
|
type: PluginType;
|
|
141
214
|
}>): GeneratorPluginV1<unknown>[];
|
|
142
215
|
|
|
143
|
-
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 };
|
|
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
|
@@ -1,6 +1,56 @@
|
|
|
1
|
+
// lib/config.ts
|
|
2
|
+
import { isAbsolute, join, posixPath, relative, resolve } from "@baeta/util-path";
|
|
3
|
+
function loadOptions(options) {
|
|
4
|
+
const cwd = posixPath(options.cwd ?? process.cwd());
|
|
5
|
+
const schemas = options.schemas ?? ["src/**/*.graphql"];
|
|
6
|
+
const modulesDir = posixPath(resolve(cwd, options.modulesDir || "src/modules"));
|
|
7
|
+
const moduleDefinitionName = options.moduleDefinitionName || "typedef.ts";
|
|
8
|
+
const defaultBaseTypesRoot = resolve(modulesDir, "../__generated__/types.ts");
|
|
9
|
+
const baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);
|
|
10
|
+
const baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));
|
|
11
|
+
const contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);
|
|
12
|
+
const extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);
|
|
13
|
+
return {
|
|
14
|
+
cwd,
|
|
15
|
+
schemas,
|
|
16
|
+
modulesDir,
|
|
17
|
+
moduleDefinitionName,
|
|
18
|
+
baseTypesPath,
|
|
19
|
+
contextType,
|
|
20
|
+
extensions,
|
|
21
|
+
scalars: options.scalars,
|
|
22
|
+
fileOptions: options.fileOptions
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveContextType(root, baseTypesRoot, contextType) {
|
|
26
|
+
if (!contextType) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (isAbsolute(contextType)) {
|
|
30
|
+
return contextType;
|
|
31
|
+
}
|
|
32
|
+
if (contextType[0] === "!") {
|
|
33
|
+
return contextType.slice(1);
|
|
34
|
+
}
|
|
35
|
+
const contextTypeRoot = resolve(root, contextType);
|
|
36
|
+
return posixPath(relative(join(baseTypesRoot, "../"), contextTypeRoot));
|
|
37
|
+
}
|
|
38
|
+
function resolveExtensionPath(modulesDir, moduleDefinitionName, extensionsPath) {
|
|
39
|
+
if (!extensionsPath) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (isAbsolute(extensionsPath)) {
|
|
43
|
+
return extensionsPath;
|
|
44
|
+
}
|
|
45
|
+
if (extensionsPath[0] === "!") {
|
|
46
|
+
return extensionsPath.slice(1);
|
|
47
|
+
}
|
|
48
|
+
return posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));
|
|
49
|
+
}
|
|
50
|
+
|
|
1
51
|
// lib/file.ts
|
|
2
52
|
import { dirname, extname } from "@baeta/util-path";
|
|
3
|
-
import fs from "fs/promises";
|
|
53
|
+
import fs from "node:fs/promises";
|
|
4
54
|
var File = class {
|
|
5
55
|
constructor(filename, content, tag, options) {
|
|
6
56
|
this.filename = filename;
|
|
@@ -31,28 +81,30 @@ var File = class {
|
|
|
31
81
|
return content;
|
|
32
82
|
}
|
|
33
83
|
buildHeader() {
|
|
34
|
-
const ext = extname(this.filename);
|
|
35
84
|
const headerItems = [];
|
|
36
|
-
if (this.options?.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"This file was generated by baeta. Do not edit it directly.",
|
|
40
|
-
ext
|
|
41
|
-
)}
|
|
42
|
-
`
|
|
85
|
+
if (this.options?.addGenerationNoticeHeader !== false) {
|
|
86
|
+
const comment = this.createComment(
|
|
87
|
+
"This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator."
|
|
43
88
|
);
|
|
89
|
+
headerItems.push(comment);
|
|
44
90
|
}
|
|
45
|
-
if (this.options?.
|
|
46
|
-
|
|
91
|
+
if (this.options?.addEslintDisableHeader !== false) {
|
|
92
|
+
const comment = this.createComment("eslint-disable");
|
|
93
|
+
headerItems.push(comment);
|
|
47
94
|
}
|
|
48
95
|
if (this.options?.addHeader) {
|
|
49
|
-
|
|
96
|
+
const customHeader = this.options.addHeader(this.filename, this.content, this.tag);
|
|
97
|
+
headerItems.push(customHeader);
|
|
98
|
+
}
|
|
99
|
+
if (headerItems.length === 0) {
|
|
100
|
+
return "";
|
|
50
101
|
}
|
|
51
102
|
return `${headerItems.join("\n")}
|
|
52
103
|
|
|
53
104
|
`;
|
|
54
105
|
}
|
|
55
|
-
createComment(comment
|
|
106
|
+
createComment(comment) {
|
|
107
|
+
const extension = extname(this.filename);
|
|
56
108
|
if ([".gql", ".graphql"].includes(extension)) {
|
|
57
109
|
return `# ${comment}`;
|
|
58
110
|
}
|
|
@@ -60,6 +112,82 @@ var File = class {
|
|
|
60
112
|
}
|
|
61
113
|
};
|
|
62
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
|
+
|
|
63
191
|
// lib/file-manager.ts
|
|
64
192
|
var FileManager = class {
|
|
65
193
|
constructor(fileOptions) {
|
|
@@ -159,7 +287,7 @@ function getGeneratorPlugins(plugins) {
|
|
|
159
287
|
}
|
|
160
288
|
|
|
161
289
|
// lib/watcher.ts
|
|
162
|
-
import path2, { posixPath } from "@baeta/util-path";
|
|
290
|
+
import path2, { posixPath as posixPath2 } from "@baeta/util-path";
|
|
163
291
|
import { subscribe } from "@parcel/watcher";
|
|
164
292
|
import micromatch2 from "micromatch";
|
|
165
293
|
|
|
@@ -254,14 +382,14 @@ var Watcher = class {
|
|
|
254
382
|
return;
|
|
255
383
|
}
|
|
256
384
|
const filteredEvents = events.filter((event) => {
|
|
257
|
-
return !this.watcherIgnore.isIgnored(
|
|
385
|
+
return !this.watcherIgnore.isIgnored(posixPath2(event.path));
|
|
258
386
|
});
|
|
259
387
|
for (const event of filteredEvents) {
|
|
260
388
|
for (const listener of this.listeners[event.type]) {
|
|
261
389
|
listener({
|
|
262
390
|
type: event.type,
|
|
263
|
-
path:
|
|
264
|
-
relativePath:
|
|
391
|
+
path: posixPath2(event.path),
|
|
392
|
+
relativePath: posixPath2(path2.relative(this.cwd, event.path))
|
|
265
393
|
});
|
|
266
394
|
}
|
|
267
395
|
}
|
|
@@ -294,6 +422,7 @@ var Watcher = class {
|
|
|
294
422
|
};
|
|
295
423
|
export {
|
|
296
424
|
File,
|
|
425
|
+
FileBlock,
|
|
297
426
|
FileManager,
|
|
298
427
|
GeneratorPluginVersion,
|
|
299
428
|
Watcher,
|
|
@@ -304,6 +433,7 @@ export {
|
|
|
304
433
|
getModuleVariableName,
|
|
305
434
|
isGeneratorPlugin,
|
|
306
435
|
isMatch,
|
|
436
|
+
loadOptions,
|
|
307
437
|
micromatch2 as micromatch
|
|
308
438
|
};
|
|
309
439
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../lib/file.ts","../lib/file-manager.ts","../lib/module.ts","../lib/plugin.ts","../lib/watcher.ts","../lib/watcher-ignore.ts"],"sourcesContent":["import { dirname, extname } from '@baeta/util-path';\nimport fs from 'fs/promises';\n\nexport interface FileOptions {\n eslintDisable?: boolean;\n generationNotice?: boolean;\n addHeader?: (name: string, content: string, tag: string) => string;\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 ext = extname(this.filename);\n\n const headerItems: string[] = [];\n\n if (this.options?.generationNotice !== false) {\n headerItems.push(\n `${this.createComment(\n 'This file was generated by baeta. Do not edit it directly.',\n ext,\n )}\\n`,\n );\n }\n\n if (this.options?.eslintDisable !== false) {\n headerItems.push(this.createComment('eslint-disable', ext));\n }\n\n if (this.options?.addHeader) {\n headerItems.push(this.options.addHeader(this.filename, this.content, this.tag));\n }\n\n return `${headerItems.join('\\n')}\\n\\n`;\n }\n\n protected createComment(comment: string, extension: string) {\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,SAAS,eAAe;AACjC,OAAO,QAAQ;AASR,IAAM,OAAN,MAAW;AAAA,EAGhB,YACS,UACA,SACA,KACC,SACR;AAJO;AACA;AACA;AACC;AAAA,EACP;AAAA,EAPH,YAAY;AAAA,EASZ,QAAQ,YAAY;AAClB,QAAI,KAAK,WAAW;AAClB;AAAA,IACF;AACA,SAAK,YAAY;AAEjB,UAAM,MAAM,QAAQ,KAAK,QAAQ;AACjC,UAAM,GAAG,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAE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cAAc,UAAUC,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;","names":["GeneratorPluginVersion","path","micromatch","path","micromatch","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,aAA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B,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;","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,21 +45,21 @@
|
|
|
45
45
|
"types": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@baeta/plugin": "^0.0.
|
|
49
|
-
"@baeta/util-path": "^0.0.
|
|
50
|
-
"@parcel/watcher": "^2.4.
|
|
48
|
+
"@baeta/plugin": "^0.0.23",
|
|
49
|
+
"@baeta/util-path": "^0.0.4",
|
|
50
|
+
"@parcel/watcher": "^2.4.1",
|
|
51
51
|
"change-case-all": "2.1.0",
|
|
52
52
|
"micromatch": "^4.0.5"
|
|
53
53
|
},
|
|
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.
|
|
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"
|