@baeta/generator-sdk 0.0.0-57-20230619210342-5073d33
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 +71 -0
- package/dist/index.cjs +282 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +282 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @baeta/generator-sdk
|
|
2
|
+
|
|
3
|
+
## 0.0.0-57-20230619210342-5073d33
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#69](https://github.com/andreisergiu98/baeta/pull/69) [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37)]:
|
|
10
|
+
- @baeta/plugin@0.0.0-57-20230619210342-5073d33
|
|
11
|
+
|
|
12
|
+
## 0.0.8
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#66](https://github.com/andreisergiu98/baeta/pull/66) [`9a4a021`](https://github.com/andreisergiu98/baeta/commit/9a4a0214351b70295ce4f7eecaa8c49ab0e1325b) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - replace chokidar with @parcel/watcher
|
|
17
|
+
|
|
18
|
+
## 0.0.7
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [[`6a2dd11`](https://github.com/andreisergiu98/baeta/commit/6a2dd110d6ffd2bff25d9c4501faebb052e0cd40)]:
|
|
23
|
+
- @baeta/plugin@0.0.19
|
|
24
|
+
|
|
25
|
+
## 0.0.6
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- [#47](https://github.com/andreisergiu98/baeta/pull/47) [`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
|
|
30
|
+
|
|
31
|
+
- [#43](https://github.com/andreisergiu98/baeta/pull/43) [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump dependencies
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [[`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9), [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2)]:
|
|
34
|
+
- @baeta/plugin@0.0.18
|
|
35
|
+
|
|
36
|
+
## 0.0.5
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- [#40](https://github.com/andreisergiu98/baeta/pull/40) [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - avoid rewriting persisted files
|
|
41
|
+
|
|
42
|
+
- [#40](https://github.com/andreisergiu98/baeta/pull/40) [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - normalize config
|
|
43
|
+
|
|
44
|
+
## 0.0.4
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- [`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - create cli sdk
|
|
49
|
+
release prisma plugin
|
|
50
|
+
update dependencies
|
|
51
|
+
refactor generator plugins
|
|
52
|
+
- Updated dependencies [[`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4)]:
|
|
53
|
+
- @baeta/plugin@0.0.17
|
|
54
|
+
|
|
55
|
+
## 0.0.3
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- [`02936ae`](https://github.com/andreisergiu98/baeta/commit/02936aeb606c75a2a79b6ce4524851c6c62afb82) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump packages
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [[`02936ae`](https://github.com/andreisergiu98/baeta/commit/02936aeb606c75a2a79b6ce4524851c6c62afb82)]:
|
|
62
|
+
- @baeta/plugin@0.0.16
|
|
63
|
+
|
|
64
|
+
## 0.0.2
|
|
65
|
+
|
|
66
|
+
### Patch Changes
|
|
67
|
+
|
|
68
|
+
- [#25](https://github.com/andreisergiu98/baeta/pull/25) [`c2c5875`](https://github.com/andreisergiu98/baeta/commit/c2c5875f8356e166f34a20b3e4384f9bce093e61) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - refactor cli and plugins
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [[`c2c5875`](https://github.com/andreisergiu98/baeta/commit/c2c5875f8356e166f34a20b3e4384f9bce093e61)]:
|
|
71
|
+
- @baeta/plugin@0.0.15
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
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(); } } var _class; var _class2; var _class3; var _class4;// lib/file.ts
|
|
2
|
+
var _promises = require('fs/promises'); var _promises2 = _interopRequireDefault(_promises);
|
|
3
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
4
|
+
var File = (_class = class {
|
|
5
|
+
constructor(filename, content, tag) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
6
|
+
this.filename = filename;
|
|
7
|
+
this.content = content;
|
|
8
|
+
this.tag = tag;
|
|
9
|
+
}
|
|
10
|
+
__init() {this.persisted = false}
|
|
11
|
+
__init2() {this.write = async () => {
|
|
12
|
+
if (this.persisted) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.persisted = true;
|
|
16
|
+
const dir = _path.dirname.call(void 0, this.filename);
|
|
17
|
+
await _promises2.default.mkdir(dir, { recursive: true });
|
|
18
|
+
return _promises2.default.writeFile(this.filename, this.buildContent(), "utf-8");
|
|
19
|
+
}}
|
|
20
|
+
__init3() {this.unlink = async () => {
|
|
21
|
+
this.persisted = false;
|
|
22
|
+
return _promises2.default.unlink(this.filename);
|
|
23
|
+
}}
|
|
24
|
+
buildContent() {
|
|
25
|
+
return this.buildHeader() + this.content;
|
|
26
|
+
}
|
|
27
|
+
buildHeader() {
|
|
28
|
+
const ext = _path.extname.call(void 0, this.filename);
|
|
29
|
+
const header = [
|
|
30
|
+
this.createComment("This file was generated by baeta. Do not edit it directly.", ext) + "\n",
|
|
31
|
+
this.createComment("eslint-disable", ext),
|
|
32
|
+
this.createComment("prettier-ignore", ext)
|
|
33
|
+
].join("\n");
|
|
34
|
+
return header + "\n\n";
|
|
35
|
+
}
|
|
36
|
+
createComment(comment, extension) {
|
|
37
|
+
if ([".gql", ".graphql"].includes(extension)) {
|
|
38
|
+
return `# ${comment}`;
|
|
39
|
+
}
|
|
40
|
+
return `/* ${comment} */`;
|
|
41
|
+
}
|
|
42
|
+
}, _class);
|
|
43
|
+
|
|
44
|
+
// lib/file-manager.ts
|
|
45
|
+
var FileManager = (_class2 = class {constructor() { _class2.prototype.__init4.call(this); }
|
|
46
|
+
__init4() {this.files = []}
|
|
47
|
+
add(...file) {
|
|
48
|
+
this.files.push(...file);
|
|
49
|
+
}
|
|
50
|
+
get(filename) {
|
|
51
|
+
return this.files.find((file) => file.filename === filename);
|
|
52
|
+
}
|
|
53
|
+
getAll() {
|
|
54
|
+
return this.files;
|
|
55
|
+
}
|
|
56
|
+
getByTag(tag) {
|
|
57
|
+
return this.files.filter((file) => file.tag === tag);
|
|
58
|
+
}
|
|
59
|
+
remove(filename) {
|
|
60
|
+
const index = this.files.findIndex((file) => file.filename === filename);
|
|
61
|
+
this.files.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
removeAll() {
|
|
64
|
+
this.files = [];
|
|
65
|
+
}
|
|
66
|
+
removeByTag(tag) {
|
|
67
|
+
this.files = this.files.filter((file) => file.tag !== tag);
|
|
68
|
+
}
|
|
69
|
+
writeAll() {
|
|
70
|
+
const toWrite = this.files.filter((file) => !file.persisted);
|
|
71
|
+
return Promise.all(toWrite.map((file) => file.write()));
|
|
72
|
+
}
|
|
73
|
+
writeByTag(tag) {
|
|
74
|
+
const files = this.getByTag(tag);
|
|
75
|
+
const toWrite = files.filter((file) => !file.persisted);
|
|
76
|
+
return Promise.all(toWrite.map((file) => file.write()));
|
|
77
|
+
}
|
|
78
|
+
unlinkAll() {
|
|
79
|
+
return Promise.all(this.files.map((file) => file.unlink())).then(() => {
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getPersistedFiles() {
|
|
83
|
+
return this.files.filter((file) => file.persisted);
|
|
84
|
+
}
|
|
85
|
+
getPersistedFileNames() {
|
|
86
|
+
return this.getPersistedFiles().map((file) => file.filename);
|
|
87
|
+
}
|
|
88
|
+
}, _class2);
|
|
89
|
+
|
|
90
|
+
// lib/module.ts
|
|
91
|
+
var _changecaseall = require('change-case-all');
|
|
92
|
+
function getModuleGetName(name) {
|
|
93
|
+
return `get${_changecaseall.pascalCase.call(void 0, name)}Module`;
|
|
94
|
+
}
|
|
95
|
+
function getModuleCreateName(name) {
|
|
96
|
+
return `create${_changecaseall.pascalCase.call(void 0, name)}Module`;
|
|
97
|
+
}
|
|
98
|
+
function getModuleVariableName(name) {
|
|
99
|
+
return _changecaseall.camelCase.call(void 0, `${name}Module`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// lib/plugin.ts
|
|
103
|
+
var _plugin = require('@baeta/plugin');
|
|
104
|
+
var GeneratorPluginVersion = /* @__PURE__ */ ((GeneratorPluginVersion2) => {
|
|
105
|
+
GeneratorPluginVersion2["V1"] = "v1";
|
|
106
|
+
return GeneratorPluginVersion2;
|
|
107
|
+
})(GeneratorPluginVersion || {});
|
|
108
|
+
var defaultPluginFn = async (ctx, next) => {
|
|
109
|
+
return next();
|
|
110
|
+
};
|
|
111
|
+
var defaultWatchFn = () => ({ include: [], ignore: [] });
|
|
112
|
+
function createPluginV1(options) {
|
|
113
|
+
return {
|
|
114
|
+
name: options.name,
|
|
115
|
+
actionName: options.actionName,
|
|
116
|
+
version: "v1" /* V1 */,
|
|
117
|
+
type: _plugin.PluginType.Generator,
|
|
118
|
+
end: _nullishCoalesce(options.end, () => ( defaultPluginFn)),
|
|
119
|
+
generate: _nullishCoalesce(options.generate, () => ( defaultPluginFn)),
|
|
120
|
+
setup: _nullishCoalesce(options.setup, () => ( defaultPluginFn)),
|
|
121
|
+
watch: _nullishCoalesce(options.watch, () => ( defaultWatchFn))
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function isGeneratorPlugin(plugin) {
|
|
125
|
+
return plugin.type === _plugin.PluginType.Generator;
|
|
126
|
+
}
|
|
127
|
+
function getGeneratorPlugins(plugins) {
|
|
128
|
+
if (!plugins) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
return plugins.filter(isGeneratorPlugin);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// lib/watcher.ts
|
|
135
|
+
var _watcher = require('@parcel/watcher');
|
|
136
|
+
var _micromatch = require('micromatch'); var _micromatch2 = _interopRequireDefault(_micromatch);
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// lib/watcher-ignore.ts
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
var WatcherIgnore = (_class3 = class {
|
|
143
|
+
constructor(cwd) {;_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);
|
|
144
|
+
this.cwd = cwd;
|
|
145
|
+
}
|
|
146
|
+
__init5() {this.files = []}
|
|
147
|
+
__init6() {this.regexps = []}
|
|
148
|
+
__init7() {this.functions = []}
|
|
149
|
+
__init8() {this.globs = []}
|
|
150
|
+
__init9() {this.globsMap = /* @__PURE__ */ new Map()}
|
|
151
|
+
ignore(pattern) {
|
|
152
|
+
if (pattern instanceof RegExp) {
|
|
153
|
+
this.regexps.push(pattern);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (typeof pattern === "function") {
|
|
157
|
+
this.functions.push(pattern);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!this.isMicromatch(pattern)) {
|
|
161
|
+
this.files.push(this.resolveFile(pattern));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.globsMap.set(pattern, _micromatch2.default.matcher(pattern));
|
|
165
|
+
this.globs = Array.from(this.globsMap.values());
|
|
166
|
+
}
|
|
167
|
+
isMicromatch(pattern) {
|
|
168
|
+
const result = _micromatch2.default.scan(pattern);
|
|
169
|
+
return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;
|
|
170
|
+
}
|
|
171
|
+
resolveFile(file) {
|
|
172
|
+
return _path2.default.isAbsolute(file) ? file : _path2.default.join(this.cwd, file);
|
|
173
|
+
}
|
|
174
|
+
unignore(pattern) {
|
|
175
|
+
if (pattern instanceof RegExp) {
|
|
176
|
+
this.regexps = this.regexps.filter((p) => p !== pattern);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (typeof pattern === "function") {
|
|
180
|
+
this.functions = this.functions.filter((p) => p !== pattern);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!this.isMicromatch(pattern)) {
|
|
184
|
+
const file = this.resolveFile(pattern);
|
|
185
|
+
this.files = this.files.filter((p) => p !== file);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.globsMap.delete(pattern);
|
|
189
|
+
this.globs = Array.from(this.globsMap.values());
|
|
190
|
+
}
|
|
191
|
+
isIgnored(path3) {
|
|
192
|
+
if (this.files.includes(path3)) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
if (this.globs.some((f) => f(path3))) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
if (this.regexps.some((r) => r.test(path3))) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (this.functions.some((f) => f(path3))) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}, _class3);
|
|
207
|
+
|
|
208
|
+
// lib/watcher.ts
|
|
209
|
+
var isMatch = _micromatch2.default.isMatch;
|
|
210
|
+
var Watcher = (_class4 = class {
|
|
211
|
+
constructor(cwd, options) {;_class4.prototype.__init10.call(this);_class4.prototype.__init11.call(this);
|
|
212
|
+
this.cwd = cwd;
|
|
213
|
+
this.options = options;
|
|
214
|
+
this.watcherIgnore = new WatcherIgnore(cwd);
|
|
215
|
+
this.subscription = this.createSubscription();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
__init10() {this.listeners = {
|
|
219
|
+
create: [],
|
|
220
|
+
update: [],
|
|
221
|
+
delete: []
|
|
222
|
+
}}
|
|
223
|
+
|
|
224
|
+
__init11() {this.onEvents = (err, events) => {
|
|
225
|
+
if (err) {
|
|
226
|
+
console.error(err);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const filteredEvents = events.filter((event) => {
|
|
230
|
+
return !this.watcherIgnore.isIgnored(event.path);
|
|
231
|
+
});
|
|
232
|
+
for (const event of filteredEvents) {
|
|
233
|
+
for (const listener of this.listeners[event.type]) {
|
|
234
|
+
listener({
|
|
235
|
+
type: event.type,
|
|
236
|
+
path: event.path,
|
|
237
|
+
relativePath: _path2.default.relative(this.cwd, event.path)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}}
|
|
242
|
+
on(event, listener) {
|
|
243
|
+
this.listeners[event].push(listener);
|
|
244
|
+
}
|
|
245
|
+
off(event, listener) {
|
|
246
|
+
this.listeners[event] = this.listeners[event].filter((l) => l !== listener);
|
|
247
|
+
}
|
|
248
|
+
ignore(pattern) {
|
|
249
|
+
this.watcherIgnore.ignore(pattern);
|
|
250
|
+
}
|
|
251
|
+
unignore(pattern) {
|
|
252
|
+
this.watcherIgnore.unignore(pattern);
|
|
253
|
+
}
|
|
254
|
+
createSubscription() {
|
|
255
|
+
const promise = _watcher.subscribe.call(void 0, this.cwd, this.onEvents, this.options);
|
|
256
|
+
const unsubscribe = async () => {
|
|
257
|
+
const subscription = await promise;
|
|
258
|
+
await subscription.unsubscribe();
|
|
259
|
+
};
|
|
260
|
+
return {
|
|
261
|
+
unsubscribe
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
close() {
|
|
265
|
+
return this.subscription.unsubscribe();
|
|
266
|
+
}
|
|
267
|
+
}, _class4);
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
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;
|
|
282
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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","micromatch","path"],"mappings":";AAAA,OAAO,QAAQ;AACf,SAAS,SAAS,eAAe;AAE1B,IAAM,OAAN,MAAW;AAAA,EAGhB,YAAmB,UAAyB,SAAwB,KAAa;AAA9D;AAAyB;AAAwB;AAAA,EAAc;AAAA,EAFlF,YAAY;AAAA,EAIZ,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;AACvC,WAAO,GAAG,UAAU,KAAK,UAAU,KAAK,aAAa,GAAG,OAAO;AAAA,EACjE;AAAA,EAEA,SAAS,YAAY;AACnB,SAAK,YAAY;AACjB,WAAO,GAAG,OAAO,KAAK,QAAQ;AAAA,EAChC;AAAA,EAEQ,eAAe;AACrB,WAAO,KAAK,YAAY,IAAI,KAAK;AAAA,EACnC;AAAA,EAEU,cAAc;AACtB,UAAM,MAAM,QAAQ,KAAK,QAAQ;AAEjC,UAAM,SAAS;AAAA,MACb,KAAK,cAAc,8DAA8D,GAAG,IAAI;AAAA,MACxF,KAAK,cAAc,kBAAkB,GAAG;AAAA,MACxC,KAAK,cAAc,mBAAmB,GAAG;AAAA,IAC3C,EAAE,KAAK,IAAI;AACX,WAAO,SAAS;AAAA,EAClB;AAAA,EAEU,cAAc,SAAiB,WAAmB;AAC1D,QAAI,CAAC,QAAQ,UAAU,EAAE,SAAS,SAAS,GAAG;AAC5C,aAAO,KAAK;AAAA,IACd;AAEA,WAAO,MAAM;AAAA,EACf;AACF;;;AC5CO,IAAM,cAAN,MAAkB;AAAA,EACvB,QAAgB,CAAC;AAAA,EAEjB,OAAO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AAK,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 fs from 'fs/promises';\nimport { dirname, extname } from 'path';\n\nexport class File {\n persisted = false;\n\n constructor(public filename: string, public content: string, public tag: string) {}\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 return fs.writeFile(this.filename, this.buildContent(), 'utf-8');\n };\n\n unlink = async () => {\n this.persisted = false;\n return fs.unlink(this.filename);\n };\n\n private buildContent() {\n return this.buildHeader() + this.content;\n }\n\n protected buildHeader() {\n const ext = extname(this.filename);\n\n const header = [\n this.createComment('This file was generated by baeta. Do not edit it directly.', ext) + '\\n',\n this.createComment('eslint-disable', ext),\n this.createComment('prettier-ignore', ext),\n ].join('\\n');\n return header + '\\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 } from './file';\n\nexport class FileManager {\n files: File[] = [];\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 { AsyncSubscription, Event, EventType, Options, subscribe } from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport path from 'path';\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(private readonly cwd: string, private readonly options?: Options) {\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(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: event.path,\n relativePath: 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 micromatch from 'micromatch';\nimport path from 'path';\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.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { EventType, Options, Event } from '@parcel/watcher';
|
|
2
|
+
import micromatch from 'micromatch';
|
|
3
|
+
export { default as micromatch } from 'micromatch';
|
|
4
|
+
import { PluginType } from '@baeta/plugin';
|
|
5
|
+
|
|
6
|
+
interface GeneratorOptions {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
schemas: string[];
|
|
9
|
+
modulesDir?: string;
|
|
10
|
+
moduleDefinitionName?: string;
|
|
11
|
+
baseTypesPath?: string;
|
|
12
|
+
contextType?: string;
|
|
13
|
+
extensions?: string;
|
|
14
|
+
scalars?: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
interface NormalizedGeneratorOptions {
|
|
17
|
+
cwd: string;
|
|
18
|
+
schemas: string[];
|
|
19
|
+
modulesDir: string;
|
|
20
|
+
moduleDefinitionName: string;
|
|
21
|
+
baseTypesPath: string;
|
|
22
|
+
contextType?: string;
|
|
23
|
+
extensions?: string;
|
|
24
|
+
scalars?: Record<string, string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare class File {
|
|
28
|
+
filename: string;
|
|
29
|
+
content: string;
|
|
30
|
+
tag: string;
|
|
31
|
+
persisted: boolean;
|
|
32
|
+
constructor(filename: string, content: string, tag: string);
|
|
33
|
+
write: () => Promise<void>;
|
|
34
|
+
unlink: () => Promise<void>;
|
|
35
|
+
private buildContent;
|
|
36
|
+
protected buildHeader(): string;
|
|
37
|
+
protected createComment(comment: string, extension: string): string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare class FileManager {
|
|
41
|
+
files: File[];
|
|
42
|
+
add(...file: File[]): void;
|
|
43
|
+
get(filename: string): File | undefined;
|
|
44
|
+
getAll(): File[];
|
|
45
|
+
getByTag(tag: string): File[];
|
|
46
|
+
remove(filename: string): void;
|
|
47
|
+
removeAll(): void;
|
|
48
|
+
removeByTag(tag: string): void;
|
|
49
|
+
writeAll(): Promise<void[]>;
|
|
50
|
+
writeByTag(tag: string): Promise<void[]>;
|
|
51
|
+
unlinkAll(): Promise<void>;
|
|
52
|
+
getPersistedFiles(): File[];
|
|
53
|
+
getPersistedFileNames(): string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type MatchFn = (testString: string) => boolean;
|
|
57
|
+
type MatchPattern = string | RegExp | MatchFn;
|
|
58
|
+
|
|
59
|
+
declare const isMatch: (string: string, pattern: string | readonly string[], options?: micromatch.Options | undefined) => boolean;
|
|
60
|
+
type WatcherListener = (path: WatcherFile) => void;
|
|
61
|
+
interface WatcherFile {
|
|
62
|
+
type: EventType;
|
|
63
|
+
path: string;
|
|
64
|
+
relativePath: string;
|
|
65
|
+
}
|
|
66
|
+
declare class Watcher {
|
|
67
|
+
private readonly cwd;
|
|
68
|
+
private readonly options?;
|
|
69
|
+
private subscription;
|
|
70
|
+
private listeners;
|
|
71
|
+
private watcherIgnore;
|
|
72
|
+
constructor(cwd: string, options?: Options | undefined);
|
|
73
|
+
onEvents: (err: Error | null, events: Event[]) => void;
|
|
74
|
+
on(event: EventType, listener: WatcherListener): void;
|
|
75
|
+
off(event: EventType, listener: WatcherListener): void;
|
|
76
|
+
ignore(pattern: MatchPattern): void;
|
|
77
|
+
unignore(pattern: MatchPattern): void;
|
|
78
|
+
createSubscription(): {
|
|
79
|
+
unsubscribe: () => Promise<void>;
|
|
80
|
+
};
|
|
81
|
+
close(): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type Ctx<T = unknown> = {
|
|
85
|
+
fileManager: FileManager;
|
|
86
|
+
didSetup: string[];
|
|
87
|
+
didGenerate: string[];
|
|
88
|
+
didEnd: string[];
|
|
89
|
+
pluginNames: string[];
|
|
90
|
+
generatorOptions: NormalizedGeneratorOptions;
|
|
91
|
+
watching: boolean;
|
|
92
|
+
changedFile?: WatcherFile;
|
|
93
|
+
} & T;
|
|
94
|
+
|
|
95
|
+
declare function getModuleGetName(name: string): string;
|
|
96
|
+
declare function getModuleCreateName(name: string): string;
|
|
97
|
+
declare function getModuleVariableName(name: string): string;
|
|
98
|
+
|
|
99
|
+
declare enum GeneratorPluginVersion {
|
|
100
|
+
V1 = "v1"
|
|
101
|
+
}
|
|
102
|
+
type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
|
|
103
|
+
type GeneratorPluginV1ReloadFn = (file: WatcherFile) => void;
|
|
104
|
+
type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions, watcher: Watcher, reload: GeneratorPluginV1ReloadFn) => void;
|
|
105
|
+
type GeneratorPluginV1Factory<Store = unknown> = {
|
|
106
|
+
name: string;
|
|
107
|
+
actionName: string;
|
|
108
|
+
setup?: GeneratorPluginV1Fn<Store>;
|
|
109
|
+
generate?: GeneratorPluginV1Fn<Store>;
|
|
110
|
+
end?: GeneratorPluginV1Fn<Store>;
|
|
111
|
+
watch?: GeneratorPluginV1WatchOptions;
|
|
112
|
+
};
|
|
113
|
+
interface GeneratorPluginV1<Store = unknown> {
|
|
114
|
+
name: string;
|
|
115
|
+
actionName: string;
|
|
116
|
+
version: GeneratorPluginVersion.V1;
|
|
117
|
+
type: PluginType.Generator;
|
|
118
|
+
setup: GeneratorPluginV1Fn<Store>;
|
|
119
|
+
generate: GeneratorPluginV1Fn<Store>;
|
|
120
|
+
end: GeneratorPluginV1Fn<Store>;
|
|
121
|
+
watch: GeneratorPluginV1WatchOptions;
|
|
122
|
+
}
|
|
123
|
+
declare function createPluginV1<Store = {}>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
|
|
124
|
+
declare function isGeneratorPlugin(plugin: {
|
|
125
|
+
type: PluginType;
|
|
126
|
+
}): plugin is GeneratorPluginV1<unknown>;
|
|
127
|
+
declare function getGeneratorPlugins(plugins?: Array<{
|
|
128
|
+
type: PluginType;
|
|
129
|
+
}>): GeneratorPluginV1<unknown>[];
|
|
130
|
+
|
|
131
|
+
export { Ctx, File, FileManager, GeneratorOptions, GeneratorPluginV1, GeneratorPluginV1Factory, GeneratorPluginV1Fn, GeneratorPluginV1ReloadFn, GeneratorPluginV1WatchOptions, GeneratorPluginVersion, NormalizedGeneratorOptions, Watcher, WatcherFile, WatcherListener, createPluginV1, getGeneratorPlugins, getModuleCreateName, getModuleGetName, getModuleVariableName, isGeneratorPlugin, isMatch };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// lib/file.ts
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import { dirname, extname } from "path";
|
|
4
|
+
var File = class {
|
|
5
|
+
constructor(filename, content, tag) {
|
|
6
|
+
this.filename = filename;
|
|
7
|
+
this.content = content;
|
|
8
|
+
this.tag = tag;
|
|
9
|
+
}
|
|
10
|
+
persisted = false;
|
|
11
|
+
write = async () => {
|
|
12
|
+
if (this.persisted) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.persisted = true;
|
|
16
|
+
const dir = dirname(this.filename);
|
|
17
|
+
await fs.mkdir(dir, { recursive: true });
|
|
18
|
+
return fs.writeFile(this.filename, this.buildContent(), "utf-8");
|
|
19
|
+
};
|
|
20
|
+
unlink = async () => {
|
|
21
|
+
this.persisted = false;
|
|
22
|
+
return fs.unlink(this.filename);
|
|
23
|
+
};
|
|
24
|
+
buildContent() {
|
|
25
|
+
return this.buildHeader() + this.content;
|
|
26
|
+
}
|
|
27
|
+
buildHeader() {
|
|
28
|
+
const ext = extname(this.filename);
|
|
29
|
+
const header = [
|
|
30
|
+
this.createComment("This file was generated by baeta. Do not edit it directly.", ext) + "\n",
|
|
31
|
+
this.createComment("eslint-disable", ext),
|
|
32
|
+
this.createComment("prettier-ignore", ext)
|
|
33
|
+
].join("\n");
|
|
34
|
+
return header + "\n\n";
|
|
35
|
+
}
|
|
36
|
+
createComment(comment, extension) {
|
|
37
|
+
if ([".gql", ".graphql"].includes(extension)) {
|
|
38
|
+
return `# ${comment}`;
|
|
39
|
+
}
|
|
40
|
+
return `/* ${comment} */`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// lib/file-manager.ts
|
|
45
|
+
var FileManager = class {
|
|
46
|
+
files = [];
|
|
47
|
+
add(...file) {
|
|
48
|
+
this.files.push(...file);
|
|
49
|
+
}
|
|
50
|
+
get(filename) {
|
|
51
|
+
return this.files.find((file) => file.filename === filename);
|
|
52
|
+
}
|
|
53
|
+
getAll() {
|
|
54
|
+
return this.files;
|
|
55
|
+
}
|
|
56
|
+
getByTag(tag) {
|
|
57
|
+
return this.files.filter((file) => file.tag === tag);
|
|
58
|
+
}
|
|
59
|
+
remove(filename) {
|
|
60
|
+
const index = this.files.findIndex((file) => file.filename === filename);
|
|
61
|
+
this.files.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
removeAll() {
|
|
64
|
+
this.files = [];
|
|
65
|
+
}
|
|
66
|
+
removeByTag(tag) {
|
|
67
|
+
this.files = this.files.filter((file) => file.tag !== tag);
|
|
68
|
+
}
|
|
69
|
+
writeAll() {
|
|
70
|
+
const toWrite = this.files.filter((file) => !file.persisted);
|
|
71
|
+
return Promise.all(toWrite.map((file) => file.write()));
|
|
72
|
+
}
|
|
73
|
+
writeByTag(tag) {
|
|
74
|
+
const files = this.getByTag(tag);
|
|
75
|
+
const toWrite = files.filter((file) => !file.persisted);
|
|
76
|
+
return Promise.all(toWrite.map((file) => file.write()));
|
|
77
|
+
}
|
|
78
|
+
unlinkAll() {
|
|
79
|
+
return Promise.all(this.files.map((file) => file.unlink())).then(() => {
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getPersistedFiles() {
|
|
83
|
+
return this.files.filter((file) => file.persisted);
|
|
84
|
+
}
|
|
85
|
+
getPersistedFileNames() {
|
|
86
|
+
return this.getPersistedFiles().map((file) => file.filename);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// lib/module.ts
|
|
91
|
+
import { camelCase, pascalCase } from "change-case-all";
|
|
92
|
+
function getModuleGetName(name) {
|
|
93
|
+
return `get${pascalCase(name)}Module`;
|
|
94
|
+
}
|
|
95
|
+
function getModuleCreateName(name) {
|
|
96
|
+
return `create${pascalCase(name)}Module`;
|
|
97
|
+
}
|
|
98
|
+
function getModuleVariableName(name) {
|
|
99
|
+
return camelCase(`${name}Module`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// lib/plugin.ts
|
|
103
|
+
import { PluginType } from "@baeta/plugin";
|
|
104
|
+
var GeneratorPluginVersion = /* @__PURE__ */ ((GeneratorPluginVersion2) => {
|
|
105
|
+
GeneratorPluginVersion2["V1"] = "v1";
|
|
106
|
+
return GeneratorPluginVersion2;
|
|
107
|
+
})(GeneratorPluginVersion || {});
|
|
108
|
+
var defaultPluginFn = async (ctx, next) => {
|
|
109
|
+
return next();
|
|
110
|
+
};
|
|
111
|
+
var defaultWatchFn = () => ({ include: [], ignore: [] });
|
|
112
|
+
function createPluginV1(options) {
|
|
113
|
+
return {
|
|
114
|
+
name: options.name,
|
|
115
|
+
actionName: options.actionName,
|
|
116
|
+
version: "v1" /* V1 */,
|
|
117
|
+
type: PluginType.Generator,
|
|
118
|
+
end: options.end ?? defaultPluginFn,
|
|
119
|
+
generate: options.generate ?? defaultPluginFn,
|
|
120
|
+
setup: options.setup ?? defaultPluginFn,
|
|
121
|
+
watch: options.watch ?? defaultWatchFn
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function isGeneratorPlugin(plugin) {
|
|
125
|
+
return plugin.type === PluginType.Generator;
|
|
126
|
+
}
|
|
127
|
+
function getGeneratorPlugins(plugins) {
|
|
128
|
+
if (!plugins) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
return plugins.filter(isGeneratorPlugin);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// lib/watcher.ts
|
|
135
|
+
import { subscribe } from "@parcel/watcher";
|
|
136
|
+
import micromatch2 from "micromatch";
|
|
137
|
+
import path2 from "path";
|
|
138
|
+
|
|
139
|
+
// lib/watcher-ignore.ts
|
|
140
|
+
import micromatch from "micromatch";
|
|
141
|
+
import path from "path";
|
|
142
|
+
var WatcherIgnore = class {
|
|
143
|
+
constructor(cwd) {
|
|
144
|
+
this.cwd = cwd;
|
|
145
|
+
}
|
|
146
|
+
files = [];
|
|
147
|
+
regexps = [];
|
|
148
|
+
functions = [];
|
|
149
|
+
globs = [];
|
|
150
|
+
globsMap = /* @__PURE__ */ new Map();
|
|
151
|
+
ignore(pattern) {
|
|
152
|
+
if (pattern instanceof RegExp) {
|
|
153
|
+
this.regexps.push(pattern);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (typeof pattern === "function") {
|
|
157
|
+
this.functions.push(pattern);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!this.isMicromatch(pattern)) {
|
|
161
|
+
this.files.push(this.resolveFile(pattern));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.globsMap.set(pattern, micromatch.matcher(pattern));
|
|
165
|
+
this.globs = Array.from(this.globsMap.values());
|
|
166
|
+
}
|
|
167
|
+
isMicromatch(pattern) {
|
|
168
|
+
const result = micromatch.scan(pattern);
|
|
169
|
+
return result.isBrace || result.isGlobstar || result.isExtglob || result.isGlob;
|
|
170
|
+
}
|
|
171
|
+
resolveFile(file) {
|
|
172
|
+
return path.isAbsolute(file) ? file : path.join(this.cwd, file);
|
|
173
|
+
}
|
|
174
|
+
unignore(pattern) {
|
|
175
|
+
if (pattern instanceof RegExp) {
|
|
176
|
+
this.regexps = this.regexps.filter((p) => p !== pattern);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (typeof pattern === "function") {
|
|
180
|
+
this.functions = this.functions.filter((p) => p !== pattern);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!this.isMicromatch(pattern)) {
|
|
184
|
+
const file = this.resolveFile(pattern);
|
|
185
|
+
this.files = this.files.filter((p) => p !== file);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.globsMap.delete(pattern);
|
|
189
|
+
this.globs = Array.from(this.globsMap.values());
|
|
190
|
+
}
|
|
191
|
+
isIgnored(path3) {
|
|
192
|
+
if (this.files.includes(path3)) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
if (this.globs.some((f) => f(path3))) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
if (this.regexps.some((r) => r.test(path3))) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (this.functions.some((f) => f(path3))) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// lib/watcher.ts
|
|
209
|
+
var isMatch = micromatch2.isMatch;
|
|
210
|
+
var Watcher = class {
|
|
211
|
+
constructor(cwd, options) {
|
|
212
|
+
this.cwd = cwd;
|
|
213
|
+
this.options = options;
|
|
214
|
+
this.watcherIgnore = new WatcherIgnore(cwd);
|
|
215
|
+
this.subscription = this.createSubscription();
|
|
216
|
+
}
|
|
217
|
+
subscription;
|
|
218
|
+
listeners = {
|
|
219
|
+
create: [],
|
|
220
|
+
update: [],
|
|
221
|
+
delete: []
|
|
222
|
+
};
|
|
223
|
+
watcherIgnore;
|
|
224
|
+
onEvents = (err, events) => {
|
|
225
|
+
if (err) {
|
|
226
|
+
console.error(err);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const filteredEvents = events.filter((event) => {
|
|
230
|
+
return !this.watcherIgnore.isIgnored(event.path);
|
|
231
|
+
});
|
|
232
|
+
for (const event of filteredEvents) {
|
|
233
|
+
for (const listener of this.listeners[event.type]) {
|
|
234
|
+
listener({
|
|
235
|
+
type: event.type,
|
|
236
|
+
path: event.path,
|
|
237
|
+
relativePath: path2.relative(this.cwd, event.path)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
on(event, listener) {
|
|
243
|
+
this.listeners[event].push(listener);
|
|
244
|
+
}
|
|
245
|
+
off(event, listener) {
|
|
246
|
+
this.listeners[event] = this.listeners[event].filter((l) => l !== listener);
|
|
247
|
+
}
|
|
248
|
+
ignore(pattern) {
|
|
249
|
+
this.watcherIgnore.ignore(pattern);
|
|
250
|
+
}
|
|
251
|
+
unignore(pattern) {
|
|
252
|
+
this.watcherIgnore.unignore(pattern);
|
|
253
|
+
}
|
|
254
|
+
createSubscription() {
|
|
255
|
+
const promise = subscribe(this.cwd, this.onEvents, this.options);
|
|
256
|
+
const unsubscribe = async () => {
|
|
257
|
+
const subscription = await promise;
|
|
258
|
+
await subscription.unsubscribe();
|
|
259
|
+
};
|
|
260
|
+
return {
|
|
261
|
+
unsubscribe
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
close() {
|
|
265
|
+
return this.subscription.unsubscribe();
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
export {
|
|
269
|
+
File,
|
|
270
|
+
FileManager,
|
|
271
|
+
GeneratorPluginVersion,
|
|
272
|
+
Watcher,
|
|
273
|
+
createPluginV1,
|
|
274
|
+
getGeneratorPlugins,
|
|
275
|
+
getModuleCreateName,
|
|
276
|
+
getModuleGetName,
|
|
277
|
+
getModuleVariableName,
|
|
278
|
+
isGeneratorPlugin,
|
|
279
|
+
isMatch,
|
|
280
|
+
micromatch2 as micromatch
|
|
281
|
+
};
|
|
282
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 fs from 'fs/promises';\nimport { dirname, extname } from 'path';\n\nexport class File {\n persisted = false;\n\n constructor(public filename: string, public content: string, public tag: string) {}\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 return fs.writeFile(this.filename, this.buildContent(), 'utf-8');\n };\n\n unlink = async () => {\n this.persisted = false;\n return fs.unlink(this.filename);\n };\n\n private buildContent() {\n return this.buildHeader() + this.content;\n }\n\n protected buildHeader() {\n const ext = extname(this.filename);\n\n const header = [\n this.createComment('This file was generated by baeta. Do not edit it directly.', ext) + '\\n',\n this.createComment('eslint-disable', ext),\n this.createComment('prettier-ignore', ext),\n ].join('\\n');\n return header + '\\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 } from './file';\n\nexport class FileManager {\n files: File[] = [];\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 { AsyncSubscription, Event, EventType, Options, subscribe } from '@parcel/watcher';\nimport micromatch from 'micromatch';\nimport path from 'path';\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(private readonly cwd: string, private readonly options?: Options) {\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(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: event.path,\n relativePath: 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 micromatch from 'micromatch';\nimport path from 'path';\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,OAAO,QAAQ;AACf,SAAS,SAAS,eAAe;AAE1B,IAAM,OAAN,MAAW;AAAA,EAGhB,YAAmB,UAAyB,SAAwB,KAAa;AAA9D;AAAyB;AAAwB;AAAA,EAAc;AAAA,EAFlF,YAAY;AAAA,EAIZ,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;AACvC,WAAO,GAAG,UAAU,KAAK,UAAU,KAAK,aAAa,GAAG,OAAO;AAAA,EACjE;AAAA,EAEA,SAAS,YAAY;AACnB,SAAK,YAAY;AACjB,WAAO,GAAG,OAAO,KAAK,QAAQ;AAAA,EAChC;AAAA,EAEQ,eAAe;AACrB,WAAO,KAAK,YAAY,IAAI,KAAK;AAAA,EACnC;AAAA,EAEU,cAAc;AACtB,UAAM,MAAM,QAAQ,KAAK,QAAQ;AAEjC,UAAM,SAAS;AAAA,MACb,KAAK,cAAc,8DAA8D,GAAG,IAAI;AAAA,MACxF,KAAK,cAAc,kBAAkB,GAAG;AAAA,MACxC,KAAK,cAAc,mBAAmB,GAAG;AAAA,IAC3C,EAAE,KAAK,IAAI;AACX,WAAO,SAAS;AAAA,EAClB;AAAA,EAEU,cAAc,SAAiB,WAAmB;AAC1D,QAAI,CAAC,QAAQ,UAAU,EAAE,SAAS,SAAS,GAAG;AAC5C,aAAO,KAAK;AAAA,IACd;AAEA,WAAO,MAAM;AAAA,EACf;AACF;;;AC5CO,IAAM,cAAN,MAAkB;AAAA,EACvB,QAAgB,CAAC;AAAA,EAEjB,OAAO,MA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,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","micromatch","path","path","micromatch","path"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@baeta/generator-sdk",
|
|
3
|
+
"version": "0.0.0-57-20230619210342-5073d33",
|
|
4
|
+
"homepage": "https://github.com/andreisergiu98/baeta#readme",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/andreisergiu98/baeta/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/andreisergiu98/baeta.git",
|
|
11
|
+
"directory": "packages/generator-sdk"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Andrei Pampu <pampu.andrei@pm.me>",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"types": "./dist/index.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"prepack": "prep",
|
|
32
|
+
"postpack": "prep --clean",
|
|
33
|
+
"types": "tsc --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@baeta/plugin": "^0.0.0-57-20230619210342-5073d33",
|
|
37
|
+
"@parcel/watcher": "^2.1.0",
|
|
38
|
+
"change-case-all": "1.0.15",
|
|
39
|
+
"micromatch": "^4.0.5"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@baeta/builder": "^0.0.0",
|
|
43
|
+
"@baeta/tsconfig": "^0.0.0",
|
|
44
|
+
"@types/micromatch": "^4.0.2",
|
|
45
|
+
"@types/node": "^18.16.18",
|
|
46
|
+
"typescript": "^5.1.3"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|