@baeta/generator-sdk 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/package.json +15 -10
- package/dist/index.cjs +0 -450
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -232
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @baeta/generator-sdk
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#180](https://github.com/andreisergiu98/baeta/pull/180) [`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Raise minimum required NodeJS version to 22.12.0. Drop CommonJS builds in favor of the require_esm feature from NodeJS 22.12.0 onwards.
|
|
8
|
+
|
|
9
|
+
- [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - raise es target to 2024
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`483c709`](https://github.com/andreisergiu98/baeta/commit/483c70932f815fd114732c00b74f9488d7924c72), [`de6e89c`](https://github.com/andreisergiu98/baeta/commit/de6e89c1b592e280967c73a4137d24ee56ef1857)]:
|
|
12
|
+
- @baeta/plugin@0.1.3
|
|
13
|
+
- @baeta/util-path@0.1.3
|
|
14
|
+
|
|
3
15
|
## 0.1.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baeta/generator-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"baeta",
|
|
6
6
|
"graphql",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"types": "./dist/index.d.ts",
|
|
31
|
-
"
|
|
32
|
-
"require": "./dist/index.cjs"
|
|
31
|
+
"default": "./dist/index.js"
|
|
33
32
|
}
|
|
34
33
|
},
|
|
35
34
|
"types": "dist/index.d.ts",
|
|
@@ -44,8 +43,8 @@
|
|
|
44
43
|
"types": "tsc --noEmit"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@baeta/plugin": "^0.1.
|
|
48
|
-
"@baeta/util-path": "^0.1.
|
|
46
|
+
"@baeta/plugin": "^0.1.3",
|
|
47
|
+
"@baeta/util-path": "^0.1.3",
|
|
49
48
|
"@parcel/watcher": "^2.5.0",
|
|
50
49
|
"change-case-all": "2.1.0",
|
|
51
50
|
"micromatch": "^4.0.8"
|
|
@@ -54,19 +53,18 @@
|
|
|
54
53
|
"@baeta/builder": "^0.0.0",
|
|
55
54
|
"@baeta/tsconfig": "^0.0.0",
|
|
56
55
|
"@types/micromatch": "^4.0.9",
|
|
57
|
-
"@types/node": "^22.
|
|
58
|
-
"typescript": "^5.
|
|
56
|
+
"@types/node": "^22.10.1",
|
|
57
|
+
"typescript": "^5.7.2"
|
|
59
58
|
},
|
|
60
59
|
"engines": {
|
|
61
|
-
"node": ">=22.
|
|
60
|
+
"node": ">=22.12.0"
|
|
62
61
|
},
|
|
63
62
|
"publishConfig": {
|
|
64
63
|
"access": "public",
|
|
65
64
|
"exports": {
|
|
66
65
|
".": {
|
|
67
66
|
"types": "./dist/index.d.ts",
|
|
68
|
-
"
|
|
69
|
-
"require": "./dist/index.cjs"
|
|
67
|
+
"default": "./dist/index.js"
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
},
|
|
@@ -78,5 +76,12 @@
|
|
|
78
76
|
"--no-warnings",
|
|
79
77
|
"--experimental-transform-types"
|
|
80
78
|
]
|
|
79
|
+
},
|
|
80
|
+
"typedocOptions": {
|
|
81
|
+
"entryPoints": [
|
|
82
|
+
"./index.ts"
|
|
83
|
+
],
|
|
84
|
+
"readme": "none",
|
|
85
|
+
"tsconfig": "./tsconfig.json"
|
|
81
86
|
}
|
|
82
87
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,450 +0,0 @@
|
|
|
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
|
-
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
|
-
loaders: options.loaders,
|
|
24
|
-
importExtension: options.importExtension
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function resolveContextType(root, baseTypesRoot, contextType) {
|
|
28
|
-
if (!contextType) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (_utilpath.isAbsolute.call(void 0, contextType)) {
|
|
32
|
-
return contextType;
|
|
33
|
-
}
|
|
34
|
-
if (contextType[0] === "!") {
|
|
35
|
-
return contextType.slice(1);
|
|
36
|
-
}
|
|
37
|
-
const contextTypeRoot = _utilpath.resolve.call(void 0, root, contextType);
|
|
38
|
-
return _utilpath.posixPath.call(void 0, _utilpath.relative.call(void 0, _utilpath.join.call(void 0, baseTypesRoot, "../"), contextTypeRoot));
|
|
39
|
-
}
|
|
40
|
-
function resolveExtensionPath(modulesDir, moduleDefinitionName, extensionsPath) {
|
|
41
|
-
if (!extensionsPath) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (_utilpath.isAbsolute.call(void 0, extensionsPath)) {
|
|
45
|
-
return extensionsPath;
|
|
46
|
-
}
|
|
47
|
-
if (extensionsPath[0] === "!") {
|
|
48
|
-
return extensionsPath.slice(1);
|
|
49
|
-
}
|
|
50
|
-
return _utilpath.posixPath.call(void 0, _utilpath.relative.call(void 0, _utilpath.join.call(void 0, modulesDir, moduleDefinitionName), extensionsPath));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// lib/file.ts
|
|
54
|
-
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
|
|
55
|
-
|
|
56
|
-
var File = (_class = class {
|
|
57
|
-
constructor(filename, content, tag, options) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
58
|
-
this.filename = filename;
|
|
59
|
-
this.content = content;
|
|
60
|
-
this.tag = tag;
|
|
61
|
-
this.options = options;
|
|
62
|
-
}
|
|
63
|
-
__init() {this.persisted = false}
|
|
64
|
-
__init2() {this.write = async () => {
|
|
65
|
-
if (this.persisted) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
this.persisted = true;
|
|
69
|
-
const dir = _utilpath.dirname.call(void 0, this.filename);
|
|
70
|
-
await _promises2.default.mkdir(dir, { recursive: true });
|
|
71
|
-
const content = await this.buildContent();
|
|
72
|
-
return _promises2.default.writeFile(this.filename, content, "utf-8");
|
|
73
|
-
}}
|
|
74
|
-
__init3() {this.unlink = async () => {
|
|
75
|
-
this.persisted = false;
|
|
76
|
-
return _promises2.default.unlink(this.filename);
|
|
77
|
-
}}
|
|
78
|
-
async buildContent() {
|
|
79
|
-
const content = this.buildHeader() + this.content;
|
|
80
|
-
if (_optionalChain([this, 'access', _ => _.options, 'optionalAccess', _2 => _2.transformContent])) {
|
|
81
|
-
return this.options.transformContent(this.filename, content, this.tag);
|
|
82
|
-
}
|
|
83
|
-
return content;
|
|
84
|
-
}
|
|
85
|
-
buildHeader() {
|
|
86
|
-
const headerItems = [];
|
|
87
|
-
if (_optionalChain([this, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.addGenerationNoticeHeader]) !== false) {
|
|
88
|
-
const comment = this.createComment(
|
|
89
|
-
"This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator."
|
|
90
|
-
);
|
|
91
|
-
headerItems.push(comment);
|
|
92
|
-
}
|
|
93
|
-
if (_optionalChain([this, 'access', _5 => _5.options, 'optionalAccess', _6 => _6.addEslintDisableHeader]) !== false) {
|
|
94
|
-
const comment = this.createComment("eslint-disable");
|
|
95
|
-
headerItems.push(comment);
|
|
96
|
-
}
|
|
97
|
-
if (_optionalChain([this, 'access', _7 => _7.options, 'optionalAccess', _8 => _8.addHeader])) {
|
|
98
|
-
const customHeader = this.options.addHeader(this.filename, this.content, this.tag);
|
|
99
|
-
headerItems.push(customHeader);
|
|
100
|
-
}
|
|
101
|
-
if (headerItems.length === 0) {
|
|
102
|
-
return "";
|
|
103
|
-
}
|
|
104
|
-
return `${headerItems.join("\n")}
|
|
105
|
-
|
|
106
|
-
`;
|
|
107
|
-
}
|
|
108
|
-
createComment(comment) {
|
|
109
|
-
const extension = _utilpath.extname.call(void 0, this.filename);
|
|
110
|
-
if ([".gql", ".graphql"].includes(extension)) {
|
|
111
|
-
return `# ${comment}`;
|
|
112
|
-
}
|
|
113
|
-
return `/* ${comment} */`;
|
|
114
|
-
}
|
|
115
|
-
}, _class);
|
|
116
|
-
|
|
117
|
-
// lib/file-block.ts
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var FileBlock = (_class2 = class extends File {
|
|
121
|
-
constructor(filename, content, start, end, tag, options) {
|
|
122
|
-
super(filename, content, tag, {
|
|
123
|
-
addEslintDisableHeader: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.addEslintDisableHeader]), () => ( false)),
|
|
124
|
-
addGenerationNoticeHeader: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _10 => _10.addGenerationNoticeHeader]), () => ( false))
|
|
125
|
-
});_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);;
|
|
126
|
-
this.filename = filename;
|
|
127
|
-
this.content = content;
|
|
128
|
-
this.start = start;
|
|
129
|
-
this.end = end;
|
|
130
|
-
this.tag = tag;
|
|
131
|
-
}
|
|
132
|
-
__init4() {this.write = async () => {
|
|
133
|
-
if (this.persisted) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
this.persisted = true;
|
|
137
|
-
const dir = _utilpath.dirname.call(void 0, this.filename);
|
|
138
|
-
await _promises.mkdir.call(void 0, dir, { recursive: true });
|
|
139
|
-
const [existingContent, fd] = await this.getExistingContent();
|
|
140
|
-
this.content = this.addBlockToContent(existingContent);
|
|
141
|
-
const content = await this.buildContent();
|
|
142
|
-
if (fd) {
|
|
143
|
-
await fd.truncate(0);
|
|
144
|
-
await fd.write(content, 0, "utf-8");
|
|
145
|
-
await fd.close();
|
|
146
|
-
} else {
|
|
147
|
-
await _promises.writeFile.call(void 0, this.filename, content, "utf-8");
|
|
148
|
-
}
|
|
149
|
-
}}
|
|
150
|
-
__init5() {this.unlink = async () => {
|
|
151
|
-
this.persisted = false;
|
|
152
|
-
const [existingContent, fd] = await this.getExistingContent();
|
|
153
|
-
if (fd) {
|
|
154
|
-
const [start, end] = this.getSlices(existingContent);
|
|
155
|
-
await fd.truncate(0);
|
|
156
|
-
await fd.write(start + end, 0, "utf-8");
|
|
157
|
-
await fd.close();
|
|
158
|
-
}
|
|
159
|
-
}}
|
|
160
|
-
async getExistingContent() {
|
|
161
|
-
try {
|
|
162
|
-
const fd = await _promises.open.call(void 0, this.filename, "r+");
|
|
163
|
-
const existingContent = await fd.readFile("utf-8");
|
|
164
|
-
return [existingContent, fd];
|
|
165
|
-
} catch (err) {
|
|
166
|
-
return ["", null];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
getSlices(existingContent) {
|
|
170
|
-
const startMarkerIndex = existingContent.indexOf(this.start);
|
|
171
|
-
const endMarkerIndex = existingContent.lastIndexOf(this.end);
|
|
172
|
-
if (startMarkerIndex === -1 || endMarkerIndex === -1) {
|
|
173
|
-
return [existingContent, "", false];
|
|
174
|
-
}
|
|
175
|
-
return [
|
|
176
|
-
existingContent.slice(0, startMarkerIndex),
|
|
177
|
-
existingContent.slice(endMarkerIndex + this.end.length),
|
|
178
|
-
true
|
|
179
|
-
];
|
|
180
|
-
}
|
|
181
|
-
addBlockToContent(existingContent) {
|
|
182
|
-
const block = `${this.start}
|
|
183
|
-
${this.content}
|
|
184
|
-
${this.end}`;
|
|
185
|
-
const [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);
|
|
186
|
-
const padding = hasMarkers ? "" : this.buildPadding(existingContent);
|
|
187
|
-
return startSlice + padding + block + endSlice;
|
|
188
|
-
}
|
|
189
|
-
buildPadding(existingContent) {
|
|
190
|
-
if (existingContent === "") {
|
|
191
|
-
return "";
|
|
192
|
-
}
|
|
193
|
-
if (existingContent.endsWith("\n\n")) {
|
|
194
|
-
return "";
|
|
195
|
-
}
|
|
196
|
-
if (existingContent.endsWith("\n")) {
|
|
197
|
-
return "\n";
|
|
198
|
-
}
|
|
199
|
-
return "\n\n";
|
|
200
|
-
}
|
|
201
|
-
}, _class2);
|
|
202
|
-
|
|
203
|
-
// lib/file-manager.ts
|
|
204
|
-
var FileManager = (_class3 = class {
|
|
205
|
-
constructor(fileOptions) {;_class3.prototype.__init6.call(this);
|
|
206
|
-
this.fileOptions = fileOptions;
|
|
207
|
-
}
|
|
208
|
-
__init6() {this.files = []}
|
|
209
|
-
createAndAdd(filename, content, tag) {
|
|
210
|
-
const file = new File(filename, content, tag, this.fileOptions);
|
|
211
|
-
this.add(file);
|
|
212
|
-
return file;
|
|
213
|
-
}
|
|
214
|
-
add(...file) {
|
|
215
|
-
this.files.push(...file);
|
|
216
|
-
}
|
|
217
|
-
get(filename) {
|
|
218
|
-
return this.files.find((file) => file.filename === filename);
|
|
219
|
-
}
|
|
220
|
-
getAll() {
|
|
221
|
-
return this.files;
|
|
222
|
-
}
|
|
223
|
-
getByTag(tag) {
|
|
224
|
-
return this.files.filter((file) => file.tag === tag);
|
|
225
|
-
}
|
|
226
|
-
remove(filename) {
|
|
227
|
-
const index = this.files.findIndex((file) => file.filename === filename);
|
|
228
|
-
this.files.splice(index, 1);
|
|
229
|
-
}
|
|
230
|
-
removeAll() {
|
|
231
|
-
this.files = [];
|
|
232
|
-
}
|
|
233
|
-
removeByTag(tag) {
|
|
234
|
-
this.files = this.files.filter((file) => file.tag !== tag);
|
|
235
|
-
}
|
|
236
|
-
writeAll() {
|
|
237
|
-
const toWrite = this.files.filter((file) => !file.persisted);
|
|
238
|
-
return Promise.all(toWrite.map((file) => file.write()));
|
|
239
|
-
}
|
|
240
|
-
writeByTag(tag) {
|
|
241
|
-
const files = this.getByTag(tag);
|
|
242
|
-
const toWrite = files.filter((file) => !file.persisted);
|
|
243
|
-
return Promise.all(toWrite.map((file) => file.write()));
|
|
244
|
-
}
|
|
245
|
-
unlinkAll() {
|
|
246
|
-
return Promise.all(this.files.map((file) => file.unlink())).then(() => {
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
getPersistedFiles() {
|
|
250
|
-
return this.files.filter((file) => file.persisted);
|
|
251
|
-
}
|
|
252
|
-
}, _class3);
|
|
253
|
-
|
|
254
|
-
// lib/module.ts
|
|
255
|
-
var _changecaseall = require('change-case-all');
|
|
256
|
-
function getModuleGetName(name) {
|
|
257
|
-
return `get${_changecaseall.pascalCase.call(void 0, name)}Module`;
|
|
258
|
-
}
|
|
259
|
-
function getModuleCreateName(name) {
|
|
260
|
-
return `create${_changecaseall.pascalCase.call(void 0, name)}Module`;
|
|
261
|
-
}
|
|
262
|
-
function getModuleVariableName(name) {
|
|
263
|
-
return _changecaseall.camelCase.call(void 0, `${name}Module`);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// lib/plugin.ts
|
|
267
|
-
var _plugin = require('@baeta/plugin');
|
|
268
|
-
var GeneratorPluginVersion = /* @__PURE__ */ ((GeneratorPluginVersion2) => {
|
|
269
|
-
GeneratorPluginVersion2["V1"] = "v1";
|
|
270
|
-
return GeneratorPluginVersion2;
|
|
271
|
-
})(GeneratorPluginVersion || {});
|
|
272
|
-
var defaultPluginFn = async (ctx, next) => {
|
|
273
|
-
return next();
|
|
274
|
-
};
|
|
275
|
-
var defaultWatchFn = () => ({ include: [], ignore: [] });
|
|
276
|
-
function createPluginV1(options) {
|
|
277
|
-
return {
|
|
278
|
-
name: options.name,
|
|
279
|
-
actionName: options.actionName,
|
|
280
|
-
version: "v1" /* V1 */,
|
|
281
|
-
type: _plugin.PluginType.Generator,
|
|
282
|
-
end: _nullishCoalesce(options.end, () => ( defaultPluginFn)),
|
|
283
|
-
generate: _nullishCoalesce(options.generate, () => ( defaultPluginFn)),
|
|
284
|
-
setup: _nullishCoalesce(options.setup, () => ( defaultPluginFn)),
|
|
285
|
-
watch: _nullishCoalesce(options.watch, () => ( defaultWatchFn))
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
function isGeneratorPlugin(plugin) {
|
|
289
|
-
return plugin.type === _plugin.PluginType.Generator;
|
|
290
|
-
}
|
|
291
|
-
function getGeneratorPlugins(plugins) {
|
|
292
|
-
if (!plugins) {
|
|
293
|
-
return [];
|
|
294
|
-
}
|
|
295
|
-
return plugins.filter(isGeneratorPlugin);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// lib/watcher.ts
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
var _watcher = require('@parcel/watcher');
|
|
303
|
-
var _micromatch = require('micromatch'); var _micromatch2 = _interopRequireDefault(_micromatch);
|
|
304
|
-
|
|
305
|
-
// lib/watcher-ignore.ts
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
var WatcherIgnore = (_class4 = class {
|
|
309
|
-
constructor(cwd) {;_class4.prototype.__init7.call(this);_class4.prototype.__init8.call(this);_class4.prototype.__init9.call(this);_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);
|
|
310
|
-
this.cwd = cwd;
|
|
311
|
-
}
|
|
312
|
-
__init7() {this.files = []}
|
|
313
|
-
__init8() {this.regexps = []}
|
|
314
|
-
__init9() {this.functions = []}
|
|
315
|
-
__init10() {this.globs = []}
|
|
316
|
-
__init11() {this.globsMap = /* @__PURE__ */ new Map()}
|
|
317
|
-
ignore(pattern) {
|
|
318
|
-
if (pattern instanceof RegExp) {
|
|
319
|
-
this.regexps.push(pattern);
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
if (typeof pattern === "function") {
|
|
323
|
-
this.functions.push(pattern);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
if (!this.isMicromatch(pattern)) {
|
|
327
|
-
this.files.push(this.resolveFile(pattern));
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
this.globsMap.set(pattern, _micromatch2.default.matcher(pattern));
|
|
331
|
-
this.globs = Array.from(this.globsMap.values());
|
|
332
|
-
}
|
|
333
|
-
isMicromatch(pattern) {
|
|
334
|
-
const result = _micromatch2.default.scan(pattern);
|
|
335
|
-
return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;
|
|
336
|
-
}
|
|
337
|
-
resolveFile(file) {
|
|
338
|
-
return _utilpath2.default.isAbsolute(file) ? file : _utilpath2.default.join(this.cwd, file);
|
|
339
|
-
}
|
|
340
|
-
unignore(pattern) {
|
|
341
|
-
if (pattern instanceof RegExp) {
|
|
342
|
-
this.regexps = this.regexps.filter((p) => p !== pattern);
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (typeof pattern === "function") {
|
|
346
|
-
this.functions = this.functions.filter((p) => p !== pattern);
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
if (!this.isMicromatch(pattern)) {
|
|
350
|
-
const file = this.resolveFile(pattern);
|
|
351
|
-
this.files = this.files.filter((p) => p !== file);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
this.globsMap.delete(pattern);
|
|
355
|
-
this.globs = Array.from(this.globsMap.values());
|
|
356
|
-
}
|
|
357
|
-
isIgnored(path3) {
|
|
358
|
-
if (this.files.includes(path3)) {
|
|
359
|
-
return true;
|
|
360
|
-
}
|
|
361
|
-
if (this.globs.some((f) => f(path3))) {
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
|
-
if (this.regexps.some((r) => r.test(path3))) {
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
if (this.functions.some((f) => f(path3))) {
|
|
368
|
-
return true;
|
|
369
|
-
}
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
}, _class4);
|
|
373
|
-
|
|
374
|
-
// lib/watcher.ts
|
|
375
|
-
var isMatch = _micromatch2.default.isMatch;
|
|
376
|
-
var Watcher = (_class5 = class {
|
|
377
|
-
constructor(cwd, options) {;_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);
|
|
378
|
-
this.cwd = cwd;
|
|
379
|
-
this.options = options;
|
|
380
|
-
this.watcherIgnore = new WatcherIgnore(cwd);
|
|
381
|
-
this.subscription = this.createSubscription();
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
__init12() {this.listeners = {
|
|
385
|
-
create: [],
|
|
386
|
-
update: [],
|
|
387
|
-
delete: []
|
|
388
|
-
}}
|
|
389
|
-
|
|
390
|
-
__init13() {this.onEvents = (err, events) => {
|
|
391
|
-
if (err) {
|
|
392
|
-
console.error(err);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const filteredEvents = events.filter((event) => {
|
|
396
|
-
return !this.watcherIgnore.isIgnored(_utilpath.posixPath.call(void 0, event.path));
|
|
397
|
-
});
|
|
398
|
-
for (const event of filteredEvents) {
|
|
399
|
-
for (const listener of this.listeners[event.type]) {
|
|
400
|
-
listener({
|
|
401
|
-
type: event.type,
|
|
402
|
-
path: _utilpath.posixPath.call(void 0, event.path),
|
|
403
|
-
relativePath: _utilpath.posixPath.call(void 0, _utilpath2.default.relative(this.cwd, event.path))
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}}
|
|
408
|
-
on(event, listener) {
|
|
409
|
-
this.listeners[event].push(listener);
|
|
410
|
-
}
|
|
411
|
-
off(event, listener) {
|
|
412
|
-
this.listeners[event] = this.listeners[event].filter((l) => l !== listener);
|
|
413
|
-
}
|
|
414
|
-
ignore(pattern) {
|
|
415
|
-
this.watcherIgnore.ignore(pattern);
|
|
416
|
-
}
|
|
417
|
-
unignore(pattern) {
|
|
418
|
-
this.watcherIgnore.unignore(pattern);
|
|
419
|
-
}
|
|
420
|
-
createSubscription() {
|
|
421
|
-
const promise = _watcher.subscribe.call(void 0, this.cwd, this.onEvents, this.options);
|
|
422
|
-
const unsubscribe = async () => {
|
|
423
|
-
const subscription = await promise;
|
|
424
|
-
await subscription.unsubscribe();
|
|
425
|
-
};
|
|
426
|
-
return {
|
|
427
|
-
unsubscribe
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
close() {
|
|
431
|
-
return this.subscription.unsubscribe();
|
|
432
|
-
}
|
|
433
|
-
}, _class5);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
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;
|
|
450
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/baeta/baeta/packages/generator-sdk/dist/index.cjs","../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":["GeneratorPluginVersion","path","micromatch"],"mappings":"AAAA;ACAA,gGAA+D;AAiGxD,SAAS,WAAA,CAAY,OAAA,EAAuD;AAClF,EAAA,MAAM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C,UAAA;AACA,UAAA;AACA,UAAA;AACA,QAAA;AACF,MAAA;AACD,IAAA;AACD,EAAA;AAEqB,EAAA;AACf,IAAA;AACN,EAAA;AAEI,EAAA;AACE,IAAA;AACN,EAAA;AAEO,EAAA;AACD,IAAA;AACN,EAAA;AAES,EAAA;AACH,IAAA;AACN,EAAA;AAEA,EAAA;AACO,IAAA;AAEA,IAAA;AACC,MAAA;AACA,MAAA;AACP,IAAA;AAEO,IAAA;AACN,MAAA;AACD,IAAA;AACD,EAAA;AAEQ,EAAA;AACA,IAAA;AACR,EAAA;AACD;APoVY;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/baeta/baeta/packages/generator-sdk/dist/index.cjs","sourcesContent":[null,"import { isAbsolute, join, posixPath, relative, resolve } from '@baeta/util-path';\nimport type { FileOptions } from './file.ts';\n\n// biome-ignore lint/suspicious/noExplicitAny: We don't want to import graphql for this type\nexport interface Loader<TOptions = any> {\n\t// biome-ignore lint/suspicious/noExplicitAny: Same reason as above\n\tload(pointer: string, options?: TOptions): Promise<any[] | null | never>;\n\t// biome-ignore lint/suspicious/noExplicitAny: Same reason as above\n\tloadSync?(pointer: string, options?: TOptions): any[] | null | never;\n}\n\n/**\n * Options for the graphql generator.\n */\nexport interface GeneratorOptions {\n\t/**\n\t * Current working directory.\n\t * @default process.cwd()\n\t */\n\tcwd?: string;\n\n\t/**\n\t * Glob pattern(s) to load graphql schema files.\n\t * @default ['src/∗∗/∗.graphql']\n\t */\n\tschemas: string[];\n\n\t/**\n\t * Directory where modules are defined.\n\t * @default 'src/modules'\n\t */\n\tmodulesDir?: string;\n\n\t/**\n\t * Name for the generated module definition file. This will contain type definitions and the graphql ast.\n\t * @default 'typedef.ts'\n\t */\n\tmoduleDefinitionName?: string;\n\n\t/**\n\t * Path for the generated base types file.\n\t * @default `${modulesDir}/../__generated__/types.ts`\n\t */\n\tbaseTypesPath?: string;\n\n\t/**\n\t * Path where the context type is exported.\n\t * @example contextType: 'src/types/context#Context' // for named export\n\t * @example contextType: 'src/types/context' // for default export\n\t * @default undefined\n\t */\n\tcontextType?: string;\n\n\t/**\n\t * Path where extensions (ex. auth-extension) are exported. Only default export is supported.\n\t * @example extensions: 'src/extensions'\n\t * @default undefined\n\t */\n\textensions?: string;\n\n\t/**\n\t * Custom scalar mappings.\n\t * @example scalars: { DateTime: 'Date' }\n\t * @default undefined\n\t */\n\tscalars?: Record<string, string>;\n\n\t/**\n\t * Options for generated files.\n\t */\n\tfileOptions?: FileOptions;\n\n\t/**\n\t * Additional schema loaders to be used for \"schemas\" option.\n\t */\n\tloaders?: Loader[];\n\n\t/**\n\t * File extension for generated import statements.\n\t */\n\timportExtension?: '.js' | '.ts';\n}\n\nexport interface NormalizedGeneratorOptions {\n\tcwd: string;\n\tschemas: string[];\n\tmodulesDir: string;\n\tmoduleDefinitionName: string;\n\tbaseTypesPath: string;\n\tcontextType?: string;\n\textensions?: string;\n\tscalars?: Record<string, string>;\n\tfileOptions?: FileOptions;\n\tloaders?: Loader[];\n\timportExtension?: '.js' | '.ts';\n}\n\nexport function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions {\n\tconst cwd = posixPath(options.cwd ?? process.cwd());\n\tconst schemas = options.schemas ?? ['src/**/*.graphql'];\n\tconst modulesDir = posixPath(resolve(cwd, options.modulesDir || 'src/modules'));\n\tconst moduleDefinitionName = options.moduleDefinitionName || 'typedef.ts';\n\n\tconst defaultBaseTypesRoot = resolve(modulesDir, '../__generated__/types.ts');\n\tconst baseTypesRoot = resolve(cwd, options.baseTypesPath || defaultBaseTypesRoot);\n\tconst baseTypesPath = posixPath(relative(modulesDir, baseTypesRoot));\n\n\tconst contextType = resolveContextType(cwd, baseTypesRoot, options.contextType);\n\tconst extensions = resolveExtensionPath(modulesDir, moduleDefinitionName, options.extensions);\n\n\treturn {\n\t\tcwd,\n\t\tschemas,\n\t\tmodulesDir,\n\t\tmoduleDefinitionName,\n\t\tbaseTypesPath,\n\t\tcontextType,\n\t\textensions,\n\t\tscalars: options.scalars,\n\t\tfileOptions: options.fileOptions,\n\t\tloaders: options.loaders,\n\t\timportExtension: options.importExtension,\n\t};\n}\n\nfunction resolveContextType(root: string, baseTypesRoot: string, contextType?: string) {\n\tif (!contextType) {\n\t\treturn;\n\t}\n\n\tif (isAbsolute(contextType)) {\n\t\treturn contextType;\n\t}\n\n\tif (contextType[0] === '!') {\n\t\treturn contextType.slice(1);\n\t}\n\n\tconst contextTypeRoot = resolve(root, contextType);\n\n\treturn posixPath(relative(join(baseTypesRoot, '../'), contextTypeRoot));\n}\n\nfunction resolveExtensionPath(\n\tmodulesDir: string,\n\tmoduleDefinitionName: string,\n\textensionsPath?: string,\n) {\n\tif (!extensionsPath) {\n\t\treturn;\n\t}\n\n\tif (isAbsolute(extensionsPath)) {\n\t\treturn extensionsPath;\n\t}\n\n\tif (extensionsPath[0] === '!') {\n\t\treturn extensionsPath.slice(1);\n\t}\n\n\treturn posixPath(relative(join(modulesDir, moduleDefinitionName), extensionsPath));\n}\n","import fs from 'node:fs/promises';\nimport { dirname, extname } from '@baeta/util-path';\n\n/**\n * Options for generated files.\n */\nexport interface FileOptions {\n\t/**\n\t * Add generation notice at the beginning of the file.\n\t * @default true\n\t */\n\taddGenerationNoticeHeader?: boolean;\n\n\t/**\n\t * Add eslint-disable comment at the beginning of the file.\n\t * @default true\n\t */\n\taddEslintDisableHeader?: boolean;\n\n\t/**\n\t * Add custom header at the beginning of the file.\n\t */\n\taddHeader?: (name: string, content: string, tag: string) => string;\n\n\t/**\n\t * Edit the content of the file before writing it.\n\t */\n\ttransformContent?: (name: string, content: string, tag: string) => string | Promise<string>;\n}\n\nexport class File {\n\tpersisted = false;\n\n\tconstructor(\n\t\tpublic filename: string,\n\t\tpublic content: string,\n\t\tpublic tag: string,\n\t\tprivate options?: FileOptions,\n\t) {}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait fs.mkdir(dir, { recursive: true });\n\n\t\tconst content = await this.buildContent();\n\n\t\treturn fs.writeFile(this.filename, content, 'utf-8');\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\t\treturn fs.unlink(this.filename);\n\t};\n\n\tprotected async buildContent() {\n\t\tconst content = this.buildHeader() + this.content;\n\n\t\tif (this.options?.transformContent) {\n\t\t\treturn this.options.transformContent(this.filename, content, this.tag);\n\t\t}\n\n\t\treturn content;\n\t}\n\n\tprotected buildHeader() {\n\t\tconst headerItems: string[] = [];\n\n\t\tif (this.options?.addGenerationNoticeHeader !== false) {\n\t\t\tconst comment = this.createComment(\n\t\t\t\t'This file was generated by Baeta. Do not edit it directly. All changes will be overwritten by the generator.',\n\t\t\t);\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addEslintDisableHeader !== false) {\n\t\t\tconst comment = this.createComment('eslint-disable');\n\t\t\theaderItems.push(comment);\n\t\t}\n\n\t\tif (this.options?.addHeader) {\n\t\t\tconst customHeader = this.options.addHeader(this.filename, this.content, this.tag);\n\t\t\theaderItems.push(customHeader);\n\t\t}\n\n\t\tif (headerItems.length === 0) {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn `${headerItems.join('\\n')}\\n\\n`;\n\t}\n\n\tprotected createComment(comment: string) {\n\t\tconst extension = extname(this.filename);\n\n\t\tif (['.gql', '.graphql'].includes(extension)) {\n\t\t\treturn `# ${comment}`;\n\t\t}\n\n\t\treturn `/* ${comment} */`;\n\t}\n}\n","import { mkdir, open, writeFile } from 'node:fs/promises';\nimport { dirname } from '@baeta/util-path';\nimport { File, type FileOptions } from './file.ts';\n\nexport class FileBlock extends File {\n\tconstructor(\n\t\tpublic filename: string,\n\t\tpublic content: string,\n\t\tpublic start: string,\n\t\tpublic end: string,\n\t\tpublic tag: string,\n\t\toptions?: FileOptions,\n\t) {\n\t\tsuper(filename, content, tag, {\n\t\t\taddEslintDisableHeader: options?.addEslintDisableHeader ?? false,\n\t\t\taddGenerationNoticeHeader: options?.addGenerationNoticeHeader ?? false,\n\t\t});\n\t}\n\n\twrite = async () => {\n\t\tif (this.persisted) {\n\t\t\treturn;\n\t\t}\n\t\tthis.persisted = true;\n\n\t\tconst dir = dirname(this.filename);\n\t\tawait mkdir(dir, { recursive: true });\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tthis.content = this.addBlockToContent(existingContent);\n\t\tconst content = await this.buildContent();\n\n\t\tif (fd) {\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(content, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t} else {\n\t\t\tawait writeFile(this.filename, content, 'utf-8');\n\t\t}\n\t};\n\n\tunlink = async () => {\n\t\tthis.persisted = false;\n\n\t\tconst [existingContent, fd] = await this.getExistingContent();\n\n\t\tif (fd) {\n\t\t\tconst [start, end] = this.getSlices(existingContent);\n\t\t\tawait fd.truncate(0);\n\t\t\tawait fd.write(start + end, 0, 'utf-8');\n\t\t\tawait fd.close();\n\t\t}\n\t};\n\n\tprotected async getExistingContent() {\n\t\ttry {\n\t\t\tconst fd = await open(this.filename, 'r+');\n\t\t\tconst existingContent = await fd.readFile('utf-8');\n\t\t\treturn [existingContent, fd] as const;\n\t\t} catch (err) {\n\t\t\treturn ['', null] as const;\n\t\t}\n\t}\n\n\tprotected getSlices(existingContent: string) {\n\t\tconst startMarkerIndex = existingContent.indexOf(this.start);\n\t\tconst endMarkerIndex = existingContent.lastIndexOf(this.end);\n\n\t\tif (startMarkerIndex === -1 || endMarkerIndex === -1) {\n\t\t\treturn [existingContent, '', false] as const;\n\t\t}\n\n\t\treturn [\n\t\t\texistingContent.slice(0, startMarkerIndex),\n\t\t\texistingContent.slice(endMarkerIndex + this.end.length),\n\t\t\ttrue,\n\t\t] as const;\n\t}\n\n\tprotected addBlockToContent(existingContent: string) {\n\t\tconst block = `${this.start}\\n${this.content}\\n${this.end}`;\n\t\tconst [startSlice, endSlice, hasMarkers] = this.getSlices(existingContent);\n\t\tconst padding = hasMarkers ? '' : this.buildPadding(existingContent);\n\t\treturn startSlice + padding + block + endSlice;\n\t}\n\n\tprotected buildPadding(existingContent: string) {\n\t\tif (existingContent === '') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n\\n')) {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (existingContent.endsWith('\\n')) {\n\t\t\treturn '\\n';\n\t\t}\n\n\t\treturn '\\n\\n';\n\t}\n}\n","import { File, type FileOptions } from './file.ts';\n\nexport class FileManager {\n\tfiles: File[] = [];\n\n\tconstructor(public fileOptions?: FileOptions) {}\n\n\tcreateAndAdd(filename: string, content: string, tag: string) {\n\t\tconst file = new File(filename, content, tag, this.fileOptions);\n\t\tthis.add(file);\n\t\treturn file;\n\t}\n\n\tadd(...file: File[]) {\n\t\tthis.files.push(...file);\n\t}\n\n\tget(filename: string) {\n\t\treturn this.files.find((file) => file.filename === filename);\n\t}\n\n\tgetAll() {\n\t\treturn this.files;\n\t}\n\n\tgetByTag(tag: string) {\n\t\treturn this.files.filter((file) => file.tag === tag);\n\t}\n\n\tremove(filename: string) {\n\t\tconst index = this.files.findIndex((file) => file.filename === filename);\n\t\tthis.files.splice(index, 1);\n\t}\n\n\tremoveAll() {\n\t\tthis.files = [];\n\t}\n\n\tremoveByTag(tag: string) {\n\t\tthis.files = this.files.filter((file) => file.tag !== tag);\n\t}\n\n\twriteAll() {\n\t\tconst toWrite = this.files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\twriteByTag(tag: string) {\n\t\tconst files = this.getByTag(tag);\n\t\tconst toWrite = files.filter((file) => !file.persisted);\n\t\treturn Promise.all(toWrite.map((file) => file.write()));\n\t}\n\n\tunlinkAll() {\n\t\treturn Promise.all(this.files.map((file) => file.unlink())).then(() => {\n\t\t\t// void\n\t\t});\n\t}\n\n\tgetPersistedFiles() {\n\t\treturn this.files.filter((file) => file.persisted);\n\t}\n}\n","import { camelCase, pascalCase } from 'change-case-all';\n\nexport function getModuleGetName(name: string) {\n\treturn `get${pascalCase(name)}Module`;\n}\n\nexport function getModuleCreateName(name: string) {\n\treturn `create${pascalCase(name)}Module`;\n}\n\nexport function getModuleVariableName(name: string) {\n\treturn camelCase(`${name}Module`);\n}\n","import { PluginType } from '@baeta/plugin';\nimport type { NormalizedGeneratorOptions } from './config.ts';\nimport type { Ctx } from './ctx.ts';\nimport type { Watcher, WatcherFile } from './watcher.ts';\n\nexport enum GeneratorPluginVersion {\n\tV1 = 'v1',\n}\n\nexport type GeneratorPluginV1Fn<Store = unknown> = (\n\tctx: Ctx<Store>,\n\tnext: () => Promise<void>,\n) => Promise<void>;\n\nexport type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;\n\nexport type GeneratorPluginV1WatchOptions = (\n\toptions: NormalizedGeneratorOptions,\n\twatcher: Watcher,\n\treload: GeneratorPluginV1ReloadFn,\n) => void;\n\nexport type GeneratorPluginV1Factory<Store = unknown> = {\n\tname: string;\n\tactionName: string;\n\tsetup?: GeneratorPluginV1Fn<Store>;\n\tgenerate?: GeneratorPluginV1Fn<Store>;\n\tend?: GeneratorPluginV1Fn<Store>;\n\twatch?: GeneratorPluginV1WatchOptions;\n};\n\nexport interface GeneratorPluginV1<Store = unknown> {\n\tname: string;\n\tactionName: string;\n\tversion: GeneratorPluginVersion.V1;\n\ttype: PluginType.Generator;\n\tsetup: GeneratorPluginV1Fn<Store>;\n\tgenerate: GeneratorPluginV1Fn<Store>;\n\tend: GeneratorPluginV1Fn<Store>;\n\twatch: GeneratorPluginV1WatchOptions;\n}\n\nconst defaultPluginFn: GeneratorPluginV1Fn<unknown> = async (ctx, next) => {\n\treturn next();\n};\n\nconst defaultWatchFn = () => ({ include: [], ignore: [] });\n\nexport function createPluginV1<Store = unknown>(\n\toptions: GeneratorPluginV1Factory<Store>,\n): GeneratorPluginV1<Store> {\n\treturn {\n\t\tname: options.name,\n\t\tactionName: options.actionName,\n\t\tversion: GeneratorPluginVersion.V1,\n\t\ttype: PluginType.Generator,\n\t\tend: options.end ?? defaultPluginFn,\n\t\tgenerate: options.generate ?? defaultPluginFn,\n\t\tsetup: options.setup ?? defaultPluginFn,\n\t\twatch: options.watch ?? defaultWatchFn,\n\t};\n}\n\nexport function isGeneratorPlugin(plugin: {\n\ttype: PluginType;\n}): plugin is GeneratorPluginV1<unknown> {\n\treturn plugin.type === PluginType.Generator;\n}\n\nexport function getGeneratorPlugins(plugins?: Array<{ type: PluginType }>) {\n\tif (!plugins) {\n\t\treturn [];\n\t}\n\treturn plugins.filter(isGeneratorPlugin);\n}\n","import path, { posixPath } from '@baeta/util-path';\nimport {\n\ttype AsyncSubscription,\n\ttype Event,\n\ttype EventType,\n\ttype Options,\n\tsubscribe,\n} from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport { type MatchPattern, WatcherIgnore } from './watcher-ignore.ts';\n\nexport { micromatch };\nexport const isMatch = micromatch.isMatch;\n\nexport type WatcherListener = (path: WatcherFile) => void;\n\nexport interface WatcherFile {\n\ttype: EventType;\n\tpath: string;\n\trelativePath: string;\n}\nexport class Watcher {\n\tprivate subscription: AsyncSubscription;\n\n\tprivate listeners: Record<EventType, WatcherListener[]> = {\n\t\tcreate: [],\n\t\tupdate: [],\n\t\tdelete: [],\n\t};\n\n\tprivate watcherIgnore: WatcherIgnore;\n\n\tconstructor(\n\t\tprivate readonly cwd: string,\n\t\tprivate readonly options?: Options,\n\t) {\n\t\tthis.watcherIgnore = new WatcherIgnore(cwd);\n\t\tthis.subscription = this.createSubscription();\n\t}\n\n\tonEvents = (err: Error | null, events: Event[]) => {\n\t\tif (err) {\n\t\t\tconsole.error(err);\n\t\t\treturn;\n\t\t}\n\n\t\tconst filteredEvents = events.filter((event) => {\n\t\t\treturn !this.watcherIgnore.isIgnored(posixPath(event.path));\n\t\t});\n\n\t\tfor (const event of filteredEvents) {\n\t\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\t\tlistener({\n\t\t\t\t\ttype: event.type,\n\t\t\t\t\tpath: posixPath(event.path),\n\t\t\t\t\trelativePath: posixPath(path.relative(this.cwd, event.path)),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\ton(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event].push(listener);\n\t}\n\n\toff(event: EventType, listener: WatcherListener) {\n\t\tthis.listeners[event] = this.listeners[event].filter((l) => l !== listener);\n\t}\n\n\tignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.ignore(pattern);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tthis.watcherIgnore.unignore(pattern);\n\t}\n\n\tcreateSubscription() {\n\t\tconst promise = subscribe(this.cwd, this.onEvents, this.options);\n\n\t\tconst unsubscribe = async () => {\n\t\t\tconst subscription = await promise;\n\t\t\tawait subscription.unsubscribe();\n\t\t};\n\n\t\treturn {\n\t\t\tunsubscribe,\n\t\t};\n\t}\n\n\tclose() {\n\t\treturn this.subscription.unsubscribe();\n\t}\n}\n","import path from '@baeta/util-path';\nimport micromatch from 'micromatch';\n\nexport type MatchFn = (testString: string) => boolean;\nexport type MatchPattern = string | RegExp | MatchFn;\n\nexport class WatcherIgnore {\n\tprivate files: string[] = [];\n\tprivate regexps: RegExp[] = [];\n\tprivate functions: MatchFn[] = [];\n\n\tprivate globs: MatchFn[] = [];\n\tprivate globsMap = new Map<string, MatchFn>();\n\n\tconstructor(private readonly cwd: string) {}\n\n\tignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions.push(pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tthis.files.push(this.resolveFile(pattern));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.set(pattern, micromatch.matcher(pattern));\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisMicromatch(pattern: string) {\n\t\tconst result = micromatch.scan(pattern);\n\t\treturn result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;\n\t}\n\n\tresolveFile(file: string) {\n\t\treturn path.isAbsolute(file) ? file : path.join(this.cwd, file);\n\t}\n\n\tunignore(pattern: MatchPattern) {\n\t\tif (pattern instanceof RegExp) {\n\t\t\tthis.regexps = this.regexps.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pattern === 'function') {\n\t\t\tthis.functions = this.functions.filter((p) => p !== pattern);\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.isMicromatch(pattern)) {\n\t\t\tconst file = this.resolveFile(pattern);\n\t\t\tthis.files = this.files.filter((p) => p !== file);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.globsMap.delete(pattern);\n\t\tthis.globs = Array.from(this.globsMap.values());\n\t}\n\n\tisIgnored(path: string) {\n\t\tif (this.files.includes(path)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.globs.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.regexps.some((r) => r.test(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (this.functions.some((f) => f(path))) {\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n}\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { EventType, Options, Event } from '@parcel/watcher';
|
|
2
|
-
import micromatch from 'micromatch';
|
|
3
|
-
export { default as micromatch } from 'micromatch';
|
|
4
|
-
import * as fs_promises from 'fs/promises';
|
|
5
|
-
import { PluginType } from '@baeta/plugin';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Options for generated files.
|
|
9
|
-
*/
|
|
10
|
-
interface FileOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Add generation notice at the beginning of the file.
|
|
13
|
-
* @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
|
-
*/
|
|
24
|
-
addHeader?: (name: string, content: string, tag: string) => string;
|
|
25
|
-
/**
|
|
26
|
-
* Edit the content of the file before writing it.
|
|
27
|
-
*/
|
|
28
|
-
transformContent?: (name: string, content: string, tag: string) => string | Promise<string>;
|
|
29
|
-
}
|
|
30
|
-
declare class File {
|
|
31
|
-
filename: string;
|
|
32
|
-
content: string;
|
|
33
|
-
tag: string;
|
|
34
|
-
private options?;
|
|
35
|
-
persisted: boolean;
|
|
36
|
-
constructor(filename: string, content: string, tag: string, options?: FileOptions | undefined);
|
|
37
|
-
write: () => Promise<void>;
|
|
38
|
-
unlink: () => Promise<void>;
|
|
39
|
-
protected buildContent(): Promise<string>;
|
|
40
|
-
protected buildHeader(): string;
|
|
41
|
-
protected createComment(comment: string): string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface Loader<TOptions = any> {
|
|
45
|
-
load(pointer: string, options?: TOptions): Promise<any[] | null | never>;
|
|
46
|
-
loadSync?(pointer: string, options?: TOptions): any[] | null | never;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Options for the graphql generator.
|
|
50
|
-
*/
|
|
51
|
-
interface GeneratorOptions {
|
|
52
|
-
/**
|
|
53
|
-
* Current working directory.
|
|
54
|
-
* @default process.cwd()
|
|
55
|
-
*/
|
|
56
|
-
cwd?: string;
|
|
57
|
-
/**
|
|
58
|
-
* Glob pattern(s) to load graphql schema files.
|
|
59
|
-
* @default ['src/∗∗/∗.graphql']
|
|
60
|
-
*/
|
|
61
|
-
schemas: string[];
|
|
62
|
-
/**
|
|
63
|
-
* Directory where modules are defined.
|
|
64
|
-
* @default 'src/modules'
|
|
65
|
-
*/
|
|
66
|
-
modulesDir?: string;
|
|
67
|
-
/**
|
|
68
|
-
* Name for the generated module definition file. This will contain type definitions and the graphql ast.
|
|
69
|
-
* @default 'typedef.ts'
|
|
70
|
-
*/
|
|
71
|
-
moduleDefinitionName?: string;
|
|
72
|
-
/**
|
|
73
|
-
* Path for the generated base types file.
|
|
74
|
-
* @default `${modulesDir}/../__generated__/types.ts`
|
|
75
|
-
*/
|
|
76
|
-
baseTypesPath?: string;
|
|
77
|
-
/**
|
|
78
|
-
* Path where the context type is exported.
|
|
79
|
-
* @example contextType: 'src/types/context#Context' // for named export
|
|
80
|
-
* @example contextType: 'src/types/context' // for default export
|
|
81
|
-
* @default undefined
|
|
82
|
-
*/
|
|
83
|
-
contextType?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Path where extensions (ex. auth-extension) are exported. Only default export is supported.
|
|
86
|
-
* @example extensions: 'src/extensions'
|
|
87
|
-
* @default undefined
|
|
88
|
-
*/
|
|
89
|
-
extensions?: string;
|
|
90
|
-
/**
|
|
91
|
-
* Custom scalar mappings.
|
|
92
|
-
* @example scalars: { DateTime: 'Date' }
|
|
93
|
-
* @default undefined
|
|
94
|
-
*/
|
|
95
|
-
scalars?: Record<string, string>;
|
|
96
|
-
/**
|
|
97
|
-
* Options for generated files.
|
|
98
|
-
*/
|
|
99
|
-
fileOptions?: FileOptions;
|
|
100
|
-
/**
|
|
101
|
-
* Additional schema loaders to be used for "schemas" option.
|
|
102
|
-
*/
|
|
103
|
-
loaders?: Loader[];
|
|
104
|
-
/**
|
|
105
|
-
* File extension for generated import statements.
|
|
106
|
-
*/
|
|
107
|
-
importExtension?: '.js' | '.ts';
|
|
108
|
-
}
|
|
109
|
-
interface NormalizedGeneratorOptions {
|
|
110
|
-
cwd: string;
|
|
111
|
-
schemas: string[];
|
|
112
|
-
modulesDir: string;
|
|
113
|
-
moduleDefinitionName: string;
|
|
114
|
-
baseTypesPath: string;
|
|
115
|
-
contextType?: string;
|
|
116
|
-
extensions?: string;
|
|
117
|
-
scalars?: Record<string, string>;
|
|
118
|
-
fileOptions?: FileOptions;
|
|
119
|
-
loaders?: Loader[];
|
|
120
|
-
importExtension?: '.js' | '.ts';
|
|
121
|
-
}
|
|
122
|
-
declare function loadOptions(options: GeneratorOptions): NormalizedGeneratorOptions;
|
|
123
|
-
|
|
124
|
-
declare class FileManager {
|
|
125
|
-
fileOptions?: FileOptions | undefined;
|
|
126
|
-
files: File[];
|
|
127
|
-
constructor(fileOptions?: FileOptions | undefined);
|
|
128
|
-
createAndAdd(filename: string, content: string, tag: string): File;
|
|
129
|
-
add(...file: File[]): void;
|
|
130
|
-
get(filename: string): File | undefined;
|
|
131
|
-
getAll(): File[];
|
|
132
|
-
getByTag(tag: string): File[];
|
|
133
|
-
remove(filename: string): void;
|
|
134
|
-
removeAll(): void;
|
|
135
|
-
removeByTag(tag: string): void;
|
|
136
|
-
writeAll(): Promise<void[]>;
|
|
137
|
-
writeByTag(tag: string): Promise<void[]>;
|
|
138
|
-
unlinkAll(): Promise<void>;
|
|
139
|
-
getPersistedFiles(): File[];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
type MatchFn = (testString: string) => boolean;
|
|
143
|
-
type MatchPattern = string | RegExp | MatchFn;
|
|
144
|
-
|
|
145
|
-
declare const isMatch: (string: string, pattern: string | readonly string[], options?: micromatch.Options) => boolean;
|
|
146
|
-
type WatcherListener = (path: WatcherFile) => void;
|
|
147
|
-
interface WatcherFile {
|
|
148
|
-
type: EventType;
|
|
149
|
-
path: string;
|
|
150
|
-
relativePath: string;
|
|
151
|
-
}
|
|
152
|
-
declare class Watcher {
|
|
153
|
-
private readonly cwd;
|
|
154
|
-
private readonly options?;
|
|
155
|
-
private subscription;
|
|
156
|
-
private listeners;
|
|
157
|
-
private watcherIgnore;
|
|
158
|
-
constructor(cwd: string, options?: Options | undefined);
|
|
159
|
-
onEvents: (err: Error | null, events: Event[]) => void;
|
|
160
|
-
on(event: EventType, listener: WatcherListener): void;
|
|
161
|
-
off(event: EventType, listener: WatcherListener): void;
|
|
162
|
-
ignore(pattern: MatchPattern): void;
|
|
163
|
-
unignore(pattern: MatchPattern): void;
|
|
164
|
-
createSubscription(): {
|
|
165
|
-
unsubscribe: () => Promise<void>;
|
|
166
|
-
};
|
|
167
|
-
close(): Promise<void>;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
type Ctx<T = unknown> = {
|
|
171
|
-
fileManager: FileManager;
|
|
172
|
-
didSetup: string[];
|
|
173
|
-
didGenerate: string[];
|
|
174
|
-
didEnd: string[];
|
|
175
|
-
pluginNames: string[];
|
|
176
|
-
generatorOptions: NormalizedGeneratorOptions;
|
|
177
|
-
watching: boolean;
|
|
178
|
-
changedFile?: WatcherFile;
|
|
179
|
-
} & T;
|
|
180
|
-
|
|
181
|
-
declare class FileBlock extends File {
|
|
182
|
-
filename: string;
|
|
183
|
-
content: string;
|
|
184
|
-
start: string;
|
|
185
|
-
end: string;
|
|
186
|
-
tag: string;
|
|
187
|
-
constructor(filename: string, content: string, start: string, end: string, tag: string, options?: FileOptions);
|
|
188
|
-
write: () => Promise<void>;
|
|
189
|
-
unlink: () => Promise<void>;
|
|
190
|
-
protected getExistingContent(): Promise<readonly [string, fs_promises.FileHandle] | readonly ["", null]>;
|
|
191
|
-
protected getSlices(existingContent: string): readonly [string, "", false] | readonly [string, string, true];
|
|
192
|
-
protected addBlockToContent(existingContent: string): string;
|
|
193
|
-
protected buildPadding(existingContent: string): "" | "\n" | "\n\n";
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
declare function getModuleGetName(name: string): string;
|
|
197
|
-
declare function getModuleCreateName(name: string): string;
|
|
198
|
-
declare function getModuleVariableName(name: string): string;
|
|
199
|
-
|
|
200
|
-
declare enum GeneratorPluginVersion {
|
|
201
|
-
V1 = "v1"
|
|
202
|
-
}
|
|
203
|
-
type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
|
|
204
|
-
type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;
|
|
205
|
-
type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions, watcher: Watcher, reload: GeneratorPluginV1ReloadFn) => void;
|
|
206
|
-
type GeneratorPluginV1Factory<Store = unknown> = {
|
|
207
|
-
name: string;
|
|
208
|
-
actionName: string;
|
|
209
|
-
setup?: GeneratorPluginV1Fn<Store>;
|
|
210
|
-
generate?: GeneratorPluginV1Fn<Store>;
|
|
211
|
-
end?: GeneratorPluginV1Fn<Store>;
|
|
212
|
-
watch?: GeneratorPluginV1WatchOptions;
|
|
213
|
-
};
|
|
214
|
-
interface GeneratorPluginV1<Store = unknown> {
|
|
215
|
-
name: string;
|
|
216
|
-
actionName: string;
|
|
217
|
-
version: GeneratorPluginVersion.V1;
|
|
218
|
-
type: PluginType.Generator;
|
|
219
|
-
setup: GeneratorPluginV1Fn<Store>;
|
|
220
|
-
generate: GeneratorPluginV1Fn<Store>;
|
|
221
|
-
end: GeneratorPluginV1Fn<Store>;
|
|
222
|
-
watch: GeneratorPluginV1WatchOptions;
|
|
223
|
-
}
|
|
224
|
-
declare function createPluginV1<Store = unknown>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
|
|
225
|
-
declare function isGeneratorPlugin(plugin: {
|
|
226
|
-
type: PluginType;
|
|
227
|
-
}): plugin is GeneratorPluginV1<unknown>;
|
|
228
|
-
declare function getGeneratorPlugins(plugins?: Array<{
|
|
229
|
-
type: PluginType;
|
|
230
|
-
}>): GeneratorPluginV1<unknown>[];
|
|
231
|
-
|
|
232
|
-
export { type Ctx, File, FileBlock, FileManager, type FileOptions, type GeneratorOptions, type GeneratorPluginV1, type GeneratorPluginV1Factory, type GeneratorPluginV1Fn, type GeneratorPluginV1ReloadFn, type GeneratorPluginV1WatchOptions, GeneratorPluginVersion, type Loader, type NormalizedGeneratorOptions, Watcher, type WatcherFile, type WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch, loadOptions };
|