@baeta/generator-sdk 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @baeta/generator-sdk
2
2
 
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+
9
+ - [#40](https://github.com/andreisergiu98/baeta/pull/40) [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - normalize config
10
+
11
+ ## 0.0.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - create cli sdk
16
+ release prisma plugin
17
+ update dependencies
18
+ refactor generator plugins
19
+ - Updated dependencies [[`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4)]:
20
+ - @baeta/plugin@0.0.17
21
+
3
22
  ## 0.0.3
4
23
 
5
24
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -67,11 +67,13 @@ var FileManager = (_class2 = class {constructor() { _class2.prototype.__init4.ca
67
67
  this.files = this.files.filter((file) => file.tag !== tag);
68
68
  }
69
69
  writeAll() {
70
- return Promise.all(this.files.map((file) => file.write()));
70
+ const toWrite = this.files.filter((file) => !file.persisted);
71
+ return Promise.all(toWrite.map((file) => file.write()));
71
72
  }
72
73
  writeByTag(tag) {
73
74
  const files = this.getByTag(tag);
74
- return Promise.all(files.map((file) => file.write()));
75
+ const toWrite = files.filter((file) => !file.persisted);
76
+ return Promise.all(toWrite.map((file) => file.write()));
75
77
  }
76
78
  unlinkAll() {
77
79
  return Promise.all(this.files.map((file) => file.unlink())).then(() => {
@@ -85,21 +87,21 @@ var GeneratorPluginVersion = /* @__PURE__ */ ((GeneratorPluginVersion2) => {
85
87
  GeneratorPluginVersion2[GeneratorPluginVersion2["V1"] = 0] = "V1";
86
88
  return GeneratorPluginVersion2;
87
89
  })(GeneratorPluginVersion || {});
88
- var defaultPluginFn = async (params) => {
89
- return params.next();
90
+ var defaultPluginFn = async (ctx, next) => {
91
+ return next();
90
92
  };
91
93
  var defaultWatchFn = () => ({ include: [], ignore: [] });
92
- function createPluginFactoryV1(options) {
93
- return (config) => ({
94
+ function createPluginV1(options) {
95
+ return {
94
96
  name: options.name,
95
- config,
97
+ actionName: options.actionName,
96
98
  version: 0 /* V1 */,
97
99
  type: _plugin.PluginType.Generator,
98
100
  end: _nullishCoalesce(options.end, () => ( defaultPluginFn)),
99
101
  generate: _nullishCoalesce(options.generate, () => ( defaultPluginFn)),
100
102
  setup: _nullishCoalesce(options.setup, () => ( defaultPluginFn)),
101
103
  watch: _nullishCoalesce(options.watch, () => ( defaultWatchFn))
102
- });
104
+ };
103
105
  }
104
106
  function isGeneratorPlugin(plugin) {
105
107
  return plugin.type === _plugin.PluginType.Generator;
@@ -117,4 +119,4 @@ function getGeneratorPlugins(plugins) {
117
119
 
118
120
 
119
121
 
120
- exports.File = File; exports.FileManager = FileManager; exports.GeneratorPluginVersion = GeneratorPluginVersion; exports.createPluginFactoryV1 = createPluginFactoryV1; exports.getGeneratorPlugins = getGeneratorPlugins; exports.isGeneratorPlugin = isGeneratorPlugin;
122
+ exports.File = File; exports.FileManager = FileManager; exports.GeneratorPluginVersion = GeneratorPluginVersion; exports.createPluginV1 = createPluginV1; exports.getGeneratorPlugins = getGeneratorPlugins; exports.isGeneratorPlugin = isGeneratorPlugin;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { PluginType } from '@baeta/plugin';
2
2
 
3
3
  interface GeneratorOptions {
4
+ cwd?: string;
4
5
  schemas: string[];
5
6
  modulesDir?: string;
6
7
  moduleDefinitionName?: string;
@@ -9,6 +10,16 @@ interface GeneratorOptions {
9
10
  extensions?: string;
10
11
  scalars?: Record<string, string>;
11
12
  }
13
+ interface NormalizedGeneratorOptions {
14
+ cwd: string;
15
+ schemas: string[];
16
+ modulesDir: string;
17
+ moduleDefinitionName: string;
18
+ baseTypesPath: string;
19
+ contextType?: string;
20
+ extensions?: string;
21
+ scalars?: Record<string, string>;
22
+ }
12
23
 
13
24
  declare class File {
14
25
  filename: string;
@@ -37,13 +48,15 @@ declare class FileManager {
37
48
  unlinkAll(): Promise<void>;
38
49
  }
39
50
 
40
- type Ctx<T = Record<string, unknown>> = {
51
+ type Ctx<T = unknown> = {
41
52
  fileManager: FileManager;
42
53
  didSetup: string[];
43
54
  didGenerate: string[];
44
55
  didEnd: string[];
45
56
  pluginNames: string[];
46
- generatorOptions: GeneratorOptions;
57
+ generatorOptions: NormalizedGeneratorOptions;
58
+ watching: boolean;
59
+ changedFile?: string;
47
60
  } & T;
48
61
 
49
62
  type MatchPattern = string | RegExp;
@@ -51,39 +64,35 @@ type Matcher = MatchPattern | MatchPattern[];
51
64
  declare enum GeneratorPluginVersion {
52
65
  V1 = 0
53
66
  }
54
- interface GeneratorPluginV1Params<Config, Store> {
55
- config: Config;
56
- ctx: Ctx<Store>;
57
- next: () => Promise<void>;
58
- }
59
- type GeneratorPluginV1Fn<Config, Store> = (params: GeneratorPluginV1Params<Config, Store>) => Promise<void>;
60
- type GeneratorPluginV1WatchOptions<Config> = (generatorOptions: GeneratorOptions, pluginConfig: Config) => {
67
+ type GeneratorPluginV1Fn<Store = unknown> = (ctx: Ctx<Store>, next: () => Promise<void>) => Promise<void>;
68
+ type GeneratorPluginV1WatchOptions = (options: NormalizedGeneratorOptions) => {
61
69
  include: string | string[];
62
70
  ignore: Matcher;
63
71
  };
64
- type GeneratorPluginV1Factory<Config, Store> = {
72
+ type GeneratorPluginV1Factory<Store = unknown> = {
65
73
  name: string;
66
- setup?: GeneratorPluginV1Fn<Config, Store>;
67
- generate?: GeneratorPluginV1Fn<Config, Store>;
68
- end?: GeneratorPluginV1Fn<Config, Store>;
69
- watch?: GeneratorPluginV1WatchOptions<Config>;
74
+ actionName: string;
75
+ setup?: GeneratorPluginV1Fn<Store>;
76
+ generate?: GeneratorPluginV1Fn<Store>;
77
+ end?: GeneratorPluginV1Fn<Store>;
78
+ watch?: GeneratorPluginV1WatchOptions;
70
79
  };
71
- interface GeneratorPluginV1<Config, Store> {
80
+ interface GeneratorPluginV1<Store = unknown> {
72
81
  name: string;
82
+ actionName: string;
73
83
  version: GeneratorPluginVersion.V1;
74
84
  type: PluginType.Generator;
75
- config: Config;
76
- setup: GeneratorPluginV1Fn<Config, Store>;
77
- generate: GeneratorPluginV1Fn<Config, Store>;
78
- end: GeneratorPluginV1Fn<Config, Store>;
79
- watch: GeneratorPluginV1WatchOptions<Config>;
85
+ setup: GeneratorPluginV1Fn<Store>;
86
+ generate: GeneratorPluginV1Fn<Store>;
87
+ end: GeneratorPluginV1Fn<Store>;
88
+ watch: GeneratorPluginV1WatchOptions;
80
89
  }
81
- declare function createPluginFactoryV1<Config, Store = {}>(options: GeneratorPluginV1Factory<Config, Store>): (config: Config) => GeneratorPluginV1<Config, Store>;
90
+ declare function createPluginV1<Store = {}>(options: GeneratorPluginV1Factory<Store>): GeneratorPluginV1<Store>;
82
91
  declare function isGeneratorPlugin(plugin: {
83
92
  type: PluginType;
84
- }): plugin is GeneratorPluginV1<unknown, unknown>;
93
+ }): plugin is GeneratorPluginV1<unknown>;
85
94
  declare function getGeneratorPlugins(plugins?: Array<{
86
95
  type: PluginType;
87
- }>): GeneratorPluginV1<unknown, unknown>[];
96
+ }>): GeneratorPluginV1<unknown>[];
88
97
 
89
- export { Ctx, File, FileManager, GeneratorOptions, GeneratorPluginV1, GeneratorPluginV1Factory, GeneratorPluginV1Fn, GeneratorPluginV1Params, GeneratorPluginV1WatchOptions, GeneratorPluginVersion, createPluginFactoryV1, getGeneratorPlugins, isGeneratorPlugin };
98
+ export { Ctx, File, FileManager, GeneratorOptions, GeneratorPluginV1, GeneratorPluginV1Factory, GeneratorPluginV1Fn, GeneratorPluginV1WatchOptions, GeneratorPluginVersion, NormalizedGeneratorOptions, createPluginV1, getGeneratorPlugins, isGeneratorPlugin };
package/dist/index.js CHANGED
@@ -67,11 +67,13 @@ var FileManager = class {
67
67
  this.files = this.files.filter((file) => file.tag !== tag);
68
68
  }
69
69
  writeAll() {
70
- return Promise.all(this.files.map((file) => file.write()));
70
+ const toWrite = this.files.filter((file) => !file.persisted);
71
+ return Promise.all(toWrite.map((file) => file.write()));
71
72
  }
72
73
  writeByTag(tag) {
73
74
  const files = this.getByTag(tag);
74
- return Promise.all(files.map((file) => file.write()));
75
+ const toWrite = files.filter((file) => !file.persisted);
76
+ return Promise.all(toWrite.map((file) => file.write()));
75
77
  }
76
78
  unlinkAll() {
77
79
  return Promise.all(this.files.map((file) => file.unlink())).then(() => {
@@ -85,21 +87,21 @@ var GeneratorPluginVersion = /* @__PURE__ */ ((GeneratorPluginVersion2) => {
85
87
  GeneratorPluginVersion2[GeneratorPluginVersion2["V1"] = 0] = "V1";
86
88
  return GeneratorPluginVersion2;
87
89
  })(GeneratorPluginVersion || {});
88
- var defaultPluginFn = async (params) => {
89
- return params.next();
90
+ var defaultPluginFn = async (ctx, next) => {
91
+ return next();
90
92
  };
91
93
  var defaultWatchFn = () => ({ include: [], ignore: [] });
92
- function createPluginFactoryV1(options) {
93
- return (config) => ({
94
+ function createPluginV1(options) {
95
+ return {
94
96
  name: options.name,
95
- config,
97
+ actionName: options.actionName,
96
98
  version: 0 /* V1 */,
97
99
  type: PluginType.Generator,
98
100
  end: options.end ?? defaultPluginFn,
99
101
  generate: options.generate ?? defaultPluginFn,
100
102
  setup: options.setup ?? defaultPluginFn,
101
103
  watch: options.watch ?? defaultWatchFn
102
- });
104
+ };
103
105
  }
104
106
  function isGeneratorPlugin(plugin) {
105
107
  return plugin.type === PluginType.Generator;
@@ -114,7 +116,7 @@ export {
114
116
  File,
115
117
  FileManager,
116
118
  GeneratorPluginVersion,
117
- createPluginFactoryV1,
119
+ createPluginV1,
118
120
  getGeneratorPlugins,
119
121
  isGeneratorPlugin
120
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeta/generator-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "homepage": "https://github.com/andreisergiu98/baeta#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/andreisergiu98/baeta/issues"
@@ -24,11 +24,12 @@
24
24
  "types": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "@baeta/plugin": "^0.0.16",
27
+ "@baeta/plugin": "^0.0.17",
28
28
  "chokidar": "^3.5.3"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@baeta/build-tools": "^0.0.0",
32
+ "@baeta/tsconfig": "^0.0.0",
32
33
  "@types/node": "^18.11.18",
33
34
  "typescript": "^4.9.4"
34
35
  },