@baeta/plugin-prisma 0.0.0-107-20241005143517-53e56e9

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 ADDED
@@ -0,0 +1,139 @@
1
+ # @baeta/plugin-prisma
2
+
3
+ ## 0.0.0-107-20241005143517-53e56e9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#152](https://github.com/andreisergiu98/baeta/pull/152) [`d538c79`](https://github.com/andreisergiu98/baeta/commit/d538c7905e6ba96d9f294e2d528f9252e83acbe7) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update formatter
8
+
9
+ - [#145](https://github.com/andreisergiu98/baeta/pull/145) [`08428d4`](https://github.com/andreisergiu98/baeta/commit/08428d4f03b79cab9c116ff7b3a3cf9a0b2620f2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
10
+
11
+ - Updated dependencies [[`d538c79`](https://github.com/andreisergiu98/baeta/commit/d538c7905e6ba96d9f294e2d528f9252e83acbe7), [`08428d4`](https://github.com/andreisergiu98/baeta/commit/08428d4f03b79cab9c116ff7b3a3cf9a0b2620f2)]:
12
+ - @baeta/generator-sdk@0.0.0-107-20241005143517-53e56e9
13
+ - @baeta/plugin-exec@0.0.0-107-20241005143517-53e56e9
14
+ - @baeta/util-path@0.0.0-107-20241005143517-53e56e9
15
+
16
+ ## 0.0.24
17
+
18
+ ### Patch Changes
19
+
20
+ - [#139](https://github.com/andreisergiu98/baeta/pull/139) [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
21
+
22
+ - [#139](https://github.com/andreisergiu98/baeta/pull/139) [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update typescript
23
+
24
+ - Updated dependencies [[`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4), [`00dbc8f`](https://github.com/andreisergiu98/baeta/commit/00dbc8f35839aaa6524a6c0125ff38a766e45be4)]:
25
+ - @baeta/generator-sdk@0.0.14
26
+ - @baeta/plugin-exec@0.0.12
27
+ - @baeta/util-path@0.0.6
28
+
29
+ ## 0.0.23
30
+
31
+ ### Patch Changes
32
+
33
+ - [#128](https://github.com/andreisergiu98/baeta/pull/128) [`534917a`](https://github.com/andreisergiu98/baeta/commit/534917a18e7ed5d788a90a0335a5370d6af8f4a4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
34
+
35
+ - Updated dependencies [[`534917a`](https://github.com/andreisergiu98/baeta/commit/534917a18e7ed5d788a90a0335a5370d6af8f4a4)]:
36
+ - @baeta/generator-sdk@0.0.13
37
+ - @baeta/plugin-exec@0.0.11
38
+ - @baeta/util-path@0.0.5
39
+
40
+ ## 0.0.22
41
+
42
+ ### Patch Changes
43
+
44
+ - [#121](https://github.com/andreisergiu98/baeta/pull/121) [`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - Update Node to v20
45
+
46
+ - Updated dependencies [[`ceae50d`](https://github.com/andreisergiu98/baeta/commit/ceae50d88e4e59b22c603637620f4fc6b28b2454), [`d94ee47`](https://github.com/andreisergiu98/baeta/commit/d94ee47bc485c541ff011290c4ac6ef0c145c83f)]:
47
+ - @baeta/generator-sdk@0.0.12
48
+ - @baeta/plugin-exec@0.0.10
49
+ - @baeta/util-path@0.0.4
50
+
51
+ ## 0.0.21
52
+
53
+ ### Patch Changes
54
+
55
+ - [#119](https://github.com/andreisergiu98/baeta/pull/119) [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
56
+
57
+ - Updated dependencies [[`18db339`](https://github.com/andreisergiu98/baeta/commit/18db339719aa309c619372d2161c5fdbc08fa316), [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a)]:
58
+ - @baeta/generator-sdk@0.0.11
59
+ - @baeta/plugin-exec@0.0.9
60
+ - @baeta/util-path@0.0.3
61
+
62
+ ## 0.0.20
63
+
64
+ ### Patch Changes
65
+
66
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
67
+
68
+ - [#102](https://github.com/andreisergiu98/baeta/pull/102) [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies and builder
69
+
70
+ - [#106](https://github.com/andreisergiu98/baeta/pull/106) [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - add compatibility with windows
71
+
72
+ - Updated dependencies [[`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`c9e37fd`](https://github.com/andreisergiu98/baeta/commit/c9e37fd1d64588fd8eb63facd7eda08c0009470c), [`01788ab`](https://github.com/andreisergiu98/baeta/commit/01788ab04ff6956b2b50186af5bec8ed7ebbe76e)]:
73
+ - @baeta/generator-sdk@0.0.10
74
+ - @baeta/plugin-exec@0.0.8
75
+ - @baeta/util-path@0.0.2
76
+
77
+ ## 0.0.19
78
+
79
+ ### Patch Changes
80
+
81
+ - [#69](https://github.com/andreisergiu98/baeta/pull/69) [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
82
+
83
+ - [#91](https://github.com/andreisergiu98/baeta/pull/91) [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
84
+
85
+ - Updated dependencies [[`3ff5e54`](https://github.com/andreisergiu98/baeta/commit/3ff5e54f31cf42ba2264b12309338d6e78710722), [`3cdd9b3`](https://github.com/andreisergiu98/baeta/commit/3cdd9b30369d21179769a4b8d5f76e326ae6db37), [`e0944f6`](https://github.com/andreisergiu98/baeta/commit/e0944f6320e6cf2f0a3d2c9f51edd282bdce0546)]:
86
+ - @baeta/generator-sdk@0.0.9
87
+ - @baeta/plugin-exec@0.0.7
88
+
89
+ ## 0.0.18
90
+
91
+ ### Patch Changes
92
+
93
+ - [#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
94
+
95
+ - Updated dependencies [[`9a4a021`](https://github.com/andreisergiu98/baeta/commit/9a4a0214351b70295ce4f7eecaa8c49ab0e1325b)]:
96
+ - @baeta/generator-sdk@0.0.8
97
+ - @baeta/plugin-exec@0.0.6
98
+
99
+ ## 0.0.17
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies [[`6a2dd11`](https://github.com/andreisergiu98/baeta/commit/6a2dd110d6ffd2bff25d9c4501faebb052e0cd40)]:
104
+ - @baeta/plugin-exec@0.0.5
105
+ - @baeta/generator-sdk@0.0.7
106
+
107
+ ## 0.0.16
108
+
109
+ ### Patch Changes
110
+
111
+ - [#47](https://github.com/andreisergiu98/baeta/pull/47) [`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
112
+
113
+ - [#43](https://github.com/andreisergiu98/baeta/pull/43) [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - bump dependencies
114
+
115
+ - Updated dependencies [[`eb7096d`](https://github.com/andreisergiu98/baeta/commit/eb7096d42a53b17bae0a8365eccb795e7ded02e9), [`670501b`](https://github.com/andreisergiu98/baeta/commit/670501b2b1cfb1126be3421293b8ccd597c6ffc2)]:
116
+ - @baeta/generator-sdk@0.0.6
117
+ - @baeta/plugin-exec@0.0.4
118
+
119
+ ## 0.0.15
120
+
121
+ ### Patch Changes
122
+
123
+ - [#40](https://github.com/andreisergiu98/baeta/pull/40) [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - normalize config
124
+
125
+ - Updated dependencies [[`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056), [`9f937f4`](https://github.com/andreisergiu98/baeta/commit/9f937f47d3464a082680047414ee13a76cf6c056)]:
126
+ - @baeta/generator-sdk@0.0.5
127
+ - @baeta/plugin-exec@0.0.3
128
+
129
+ ## 0.0.14
130
+
131
+ ### Patch Changes
132
+
133
+ - [`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - create cli sdk
134
+ release prisma plugin
135
+ update dependencies
136
+ refactor generator plugins
137
+ - Updated dependencies [[`d1190c1`](https://github.com/andreisergiu98/baeta/commit/d1190c10e3c259c73ddeeb73a4bd312b22bf2ea4)]:
138
+ - @baeta/generator-sdk@0.0.4
139
+ - @baeta/plugin-exec@0.0.2
package/dist/index.cjs ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }// lib/client-generator.ts
2
+ var _promises = require('fs/promises');
3
+ var _pluginexec = require('@baeta/plugin-exec');
4
+ var _utilpath = require('@baeta/util-path');
5
+ async function compareSchemas(cwd, current, generated) {
6
+ const [currentSchema, generatedSchema] = await Promise.all([
7
+ _promises.readFile.call(void 0, _utilpath.resolve.call(void 0, cwd, current), "utf-8"),
8
+ _promises.readFile.call(void 0, _utilpath.resolve.call(void 0, cwd, generated), "utf-8").catch(() => null)
9
+ ]);
10
+ return currentSchema === generatedSchema;
11
+ }
12
+ function createPrismaClientPlugin(options) {
13
+ const { prismaSchema, generateCommand, generatedSchemaPath } = options;
14
+ const skip = async (ctx) => {
15
+ const schema = _utilpath.resolve.call(void 0, ctx.generatorOptions.cwd, prismaSchema);
16
+ if (ctx.watching && _optionalChain([ctx, 'access', _ => _.changedFile, 'optionalAccess', _2 => _2.path]) !== schema) {
17
+ return true;
18
+ }
19
+ if (!ctx.watching && generatedSchemaPath) {
20
+ return compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);
21
+ }
22
+ return false;
23
+ };
24
+ return _pluginexec.createExecPlugin.call(void 0, {
25
+ name: "prisma-client",
26
+ actionName: "Prisma client",
27
+ exec: _nullishCoalesce(generateCommand, () => ( "prisma generate")),
28
+ watch: (generatorOptions, watcher, reload) => {
29
+ const prismaPath = _utilpath.resolve.call(void 0, generatorOptions.cwd, prismaSchema);
30
+ const handleChange = (file) => {
31
+ if (file.path === prismaPath) {
32
+ reload(file);
33
+ }
34
+ };
35
+ watcher.on("update", handleChange);
36
+ watcher.on("delete", handleChange);
37
+ },
38
+ skip
39
+ });
40
+ }
41
+
42
+ // index.ts
43
+ var plugin_prisma_default = prismaPlugin;
44
+ function prismaPlugin(options) {
45
+ if (options.generateClient === false) {
46
+ return [];
47
+ }
48
+ return [createPrismaClientPlugin(options)];
49
+ }
50
+
51
+
52
+
53
+ exports.default = plugin_prisma_default; exports.prismaPlugin = prismaPlugin;
54
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/baeta/baeta/packages/plugin-prisma/dist/index.cjs","../lib/client-generator.ts","../index.ts"],"names":[],"mappings":"AAAA;ACAA,uCAAyB;AAEzB,gDAAiC;AACjC,4CAAwB;AAGxB,MAAA,SAAe,cAAA,CAAe,GAAA,EAAa,OAAA,EAAiB,SAAA,EAAmB;AAC9E,EAAA,MAAM,CAAC,aAAA,EAAe,eAAe,EAAA,EAAI,MAAM,OAAA,CAAQ,GAAA,CAAI;AAAA,IAC1D,gCAAA,+BAAS,GAAQ,EAAK,OAAO,CAAA,EAAG,OAAO,CAAA;AAAA,IACvC,gCAAA,+BAAS,GAAQ,EAAK,SAAS,CAAA,EAAG,OAAO,CAAA,CAAE,KAAA,CAAM,CAAA,EAAA,GAAM,IAAI;AAAA,EAC5D,CAAC,CAAA;AACD,EAAA,OAAO,cAAA,IAAkB,eAAA;AAC1B;AAEO,SAAS,wBAAA,CAAyB,OAAA,EAA8B;AACtE,EAAA,MAAM,EAAE,YAAA,EAAc,eAAA,EAAiB,oBAAoB,EAAA,EAAI,OAAA;AAE/D,EAAA,MAAM,KAAA,EAAO,MAAA,CAAO,GAAA,EAAA,GAAa;AAChC,IAAA,MAAM,OAAA,EAAS,+BAAA,GAAQ,CAAI,gBAAA,CAAiB,GAAA,EAAK,YAAY,CAAA;AAE7D,IAAA,GAAA,CAAI,GAAA,CAAI,SAAA,mBAAY,GAAA,mBAAI,WAAA,6BAAa,OAAA,IAAS,MAAA,EAAQ;AACrD,MAAA,OAAO,IAAA;AAAA,IACR;AAEA,IAAA,GAAA,CAAI,CAAC,GAAA,CAAI,SAAA,GAAY,mBAAA,EAAqB;AACzC,MAAA,OAAO,cAAA,CAAe,GAAA,CAAI,gBAAA,CAAiB,GAAA,EAAK,YAAA,EAAc,mBAAmB,CAAA;AAAA,IAClF;AAEA,IAAA,OAAO,KAAA;AAAA,EACR,CAAA;AAEA,EAAA,OAAO,0CAAA;AAAiB,IACvB,IAAA,EAAM,eAAA;AAAA,IACN,UAAA,EAAY,eAAA;AAAA,IACZ,IAAA,mBAAM,eAAA,UAAmB,mBAAA;AAAA,IACzB,KAAA,EAAO,CAAC,gBAAA,EAAkB,OAAA,EAAS,MAAA,EAAA,GAAW;AAC7C,MAAA,MAAM,WAAA,EAAa,+BAAA,gBAAQ,CAAiB,GAAA,EAAK,YAAY,CAAA;AAE7D,MAAA,MAAM,aAAA,EAAe,CAAC,IAAA,EAAA,GAAsB;AAC3C,QAAA,GAAA,CAAI,IAAA,CAAK,KAAA,IAAS,UAAA,EAAY;AAC7B,UAAA,MAAA,CAAO,IAAI,CAAA;AAAA,QACZ;AAAA,MACD,CAAA;AAEA,MAAA,OAAA,CAAQ,EAAA,CAAG,QAAA,EAAU,YAAY,CAAA;AACjC,MAAA,OAAA,CAAQ,EAAA,CAAG,QAAA,EAAU,YAAY,CAAA;AAAA,IAClC,CAAA;AAAA,IACA;AAAA,EACD,CAAC,CAAA;AACF;ADTA;AACA;AErCA,IAAO,sBAAA,EAAQ,YAAA;AAER,SAAS,YAAA,CAAa,OAAA,EAA8B;AAC1D,EAAA,GAAA,CAAI,OAAA,CAAQ,eAAA,IAAmB,KAAA,EAAO;AACrC,IAAA,OAAO,CAAC,CAAA;AAAA,EACT;AACA,EAAA,OAAO,CAAC,wBAAA,CAAyB,OAAO,CAAC,CAAA;AAC1C;AFsCA;AACE;AACA;AACF,6EAAC","file":"/home/runner/work/baeta/baeta/packages/plugin-prisma/dist/index.cjs","sourcesContent":[null,"import { readFile } from 'node:fs/promises';\nimport { Ctx, WatcherFile } from '@baeta/generator-sdk';\nimport { createExecPlugin } from '@baeta/plugin-exec';\nimport { resolve } from '@baeta/util-path';\nimport { PrismaPluginOptions } from './options';\n\nasync function compareSchemas(cwd: string, current: string, generated: string) {\n\tconst [currentSchema, generatedSchema] = await Promise.all([\n\t\treadFile(resolve(cwd, current), 'utf-8'),\n\t\treadFile(resolve(cwd, generated), 'utf-8').catch(() => null),\n\t]);\n\treturn currentSchema === generatedSchema;\n}\n\nexport function createPrismaClientPlugin(options: PrismaPluginOptions) {\n\tconst { prismaSchema, generateCommand, generatedSchemaPath } = options;\n\n\tconst skip = async (ctx: Ctx) => {\n\t\tconst schema = resolve(ctx.generatorOptions.cwd, prismaSchema);\n\n\t\tif (ctx.watching && ctx.changedFile?.path !== schema) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!ctx.watching && generatedSchemaPath) {\n\t\t\treturn compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);\n\t\t}\n\n\t\treturn false;\n\t};\n\n\treturn createExecPlugin({\n\t\tname: 'prisma-client',\n\t\tactionName: 'Prisma client',\n\t\texec: generateCommand ?? 'prisma generate',\n\t\twatch: (generatorOptions, watcher, reload) => {\n\t\t\tconst prismaPath = resolve(generatorOptions.cwd, prismaSchema);\n\n\t\t\tconst handleChange = (file: WatcherFile) => {\n\t\t\t\tif (file.path === prismaPath) {\n\t\t\t\t\treload(file);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\twatcher.on('update', handleChange);\n\t\t\twatcher.on('delete', handleChange);\n\t\t},\n\t\tskip,\n\t});\n}\n","import { createPrismaClientPlugin } from './lib/client-generator';\nimport { PrismaPluginOptions } from './lib/options';\n\nexport type { PrismaPluginOptions };\nexport default prismaPlugin;\n\nexport function prismaPlugin(options: PrismaPluginOptions) {\n\tif (options.generateClient === false) {\n\t\treturn [];\n\t}\n\treturn [createPrismaClientPlugin(options)];\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import * as _baeta_generator_sdk from '@baeta/generator-sdk';
2
+
3
+ interface PrismaPluginOptions {
4
+ prismaSchema: string;
5
+ generateClient?: boolean;
6
+ generateCommand?: string;
7
+ generatedSchemaPath?: string;
8
+ }
9
+
10
+ declare function prismaPlugin(options: PrismaPluginOptions): _baeta_generator_sdk.GeneratorPluginV1<{}>[];
11
+
12
+ export { type PrismaPluginOptions, prismaPlugin as default, prismaPlugin };
@@ -0,0 +1,12 @@
1
+ import * as _baeta_generator_sdk from '@baeta/generator-sdk';
2
+
3
+ interface PrismaPluginOptions {
4
+ prismaSchema: string;
5
+ generateClient?: boolean;
6
+ generateCommand?: string;
7
+ generatedSchemaPath?: string;
8
+ }
9
+
10
+ declare function prismaPlugin(options: PrismaPluginOptions): _baeta_generator_sdk.GeneratorPluginV1<{}>[];
11
+
12
+ export { type PrismaPluginOptions, prismaPlugin as default, prismaPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ // lib/client-generator.ts
2
+ import { readFile } from "node:fs/promises";
3
+ import { createExecPlugin } from "@baeta/plugin-exec";
4
+ import { resolve } from "@baeta/util-path";
5
+ async function compareSchemas(cwd, current, generated) {
6
+ const [currentSchema, generatedSchema] = await Promise.all([
7
+ readFile(resolve(cwd, current), "utf-8"),
8
+ readFile(resolve(cwd, generated), "utf-8").catch(() => null)
9
+ ]);
10
+ return currentSchema === generatedSchema;
11
+ }
12
+ function createPrismaClientPlugin(options) {
13
+ const { prismaSchema, generateCommand, generatedSchemaPath } = options;
14
+ const skip = async (ctx) => {
15
+ const schema = resolve(ctx.generatorOptions.cwd, prismaSchema);
16
+ if (ctx.watching && ctx.changedFile?.path !== schema) {
17
+ return true;
18
+ }
19
+ if (!ctx.watching && generatedSchemaPath) {
20
+ return compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);
21
+ }
22
+ return false;
23
+ };
24
+ return createExecPlugin({
25
+ name: "prisma-client",
26
+ actionName: "Prisma client",
27
+ exec: generateCommand ?? "prisma generate",
28
+ watch: (generatorOptions, watcher, reload) => {
29
+ const prismaPath = resolve(generatorOptions.cwd, prismaSchema);
30
+ const handleChange = (file) => {
31
+ if (file.path === prismaPath) {
32
+ reload(file);
33
+ }
34
+ };
35
+ watcher.on("update", handleChange);
36
+ watcher.on("delete", handleChange);
37
+ },
38
+ skip
39
+ });
40
+ }
41
+
42
+ // index.ts
43
+ var plugin_prisma_default = prismaPlugin;
44
+ function prismaPlugin(options) {
45
+ if (options.generateClient === false) {
46
+ return [];
47
+ }
48
+ return [createPrismaClientPlugin(options)];
49
+ }
50
+ export {
51
+ plugin_prisma_default as default,
52
+ prismaPlugin
53
+ };
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../lib/client-generator.ts","../index.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { Ctx, WatcherFile } from '@baeta/generator-sdk';\nimport { createExecPlugin } from '@baeta/plugin-exec';\nimport { resolve } from '@baeta/util-path';\nimport { PrismaPluginOptions } from './options';\n\nasync function compareSchemas(cwd: string, current: string, generated: string) {\n\tconst [currentSchema, generatedSchema] = await Promise.all([\n\t\treadFile(resolve(cwd, current), 'utf-8'),\n\t\treadFile(resolve(cwd, generated), 'utf-8').catch(() => null),\n\t]);\n\treturn currentSchema === generatedSchema;\n}\n\nexport function createPrismaClientPlugin(options: PrismaPluginOptions) {\n\tconst { prismaSchema, generateCommand, generatedSchemaPath } = options;\n\n\tconst skip = async (ctx: Ctx) => {\n\t\tconst schema = resolve(ctx.generatorOptions.cwd, prismaSchema);\n\n\t\tif (ctx.watching && ctx.changedFile?.path !== schema) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!ctx.watching && generatedSchemaPath) {\n\t\t\treturn compareSchemas(ctx.generatorOptions.cwd, prismaSchema, generatedSchemaPath);\n\t\t}\n\n\t\treturn false;\n\t};\n\n\treturn createExecPlugin({\n\t\tname: 'prisma-client',\n\t\tactionName: 'Prisma client',\n\t\texec: generateCommand ?? 'prisma generate',\n\t\twatch: (generatorOptions, watcher, reload) => {\n\t\t\tconst prismaPath = resolve(generatorOptions.cwd, prismaSchema);\n\n\t\t\tconst handleChange = (file: WatcherFile) => {\n\t\t\t\tif (file.path === prismaPath) {\n\t\t\t\t\treload(file);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\twatcher.on('update', handleChange);\n\t\t\twatcher.on('delete', handleChange);\n\t\t},\n\t\tskip,\n\t});\n}\n","import { createPrismaClientPlugin } from './lib/client-generator';\nimport { PrismaPluginOptions } from './lib/options';\n\nexport type { PrismaPluginOptions };\nexport default prismaPlugin;\n\nexport function prismaPlugin(options: PrismaPluginOptions) {\n\tif (options.generateClient === false) {\n\t\treturn [];\n\t}\n\treturn [createPrismaClientPlugin(options)];\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,wBAAwB;AACjC,SAAS,eAAe;AAGxB,eAAe,eAAe,KAAa,SAAiB,WAAmB;AAC9E,QAAM,CAAC,eAAe,eAAe,IAAI,MAAM,QAAQ,IAAI;AAAA,IAC1D,SAAS,QAAQ,KAAK,OAAO,GAAG,OAAO;AAAA,IACvC,SAAS,QAAQ,KAAK,SAAS,GAAG,OAAO,EAAE,MAAM,MAAM,IAAI;AAAA,EAC5D,CAAC;AACD,SAAO,kBAAkB;AAC1B;AAEO,SAAS,yBAAyB,SAA8B;AACtE,QAAM,EAAE,cAAc,iBAAiB,oBAAoB,IAAI;AAE/D,QAAM,OAAO,OAAO,QAAa;AAChC,UAAM,SAAS,QAAQ,IAAI,iBAAiB,KAAK,YAAY;AAE7D,QAAI,IAAI,YAAY,IAAI,aAAa,SAAS,QAAQ;AACrD,aAAO;AAAA,IACR;AAEA,QAAI,CAAC,IAAI,YAAY,qBAAqB;AACzC,aAAO,eAAe,IAAI,iBAAiB,KAAK,cAAc,mBAAmB;AAAA,IAClF;AAEA,WAAO;AAAA,EACR;AAEA,SAAO,iBAAiB;AAAA,IACvB,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,MAAM,mBAAmB;AAAA,IACzB,OAAO,CAAC,kBAAkB,SAAS,WAAW;AAC7C,YAAM,aAAa,QAAQ,iBAAiB,KAAK,YAAY;AAE7D,YAAM,eAAe,CAAC,SAAsB;AAC3C,YAAI,KAAK,SAAS,YAAY;AAC7B,iBAAO,IAAI;AAAA,QACZ;AAAA,MACD;AAEA,cAAQ,GAAG,UAAU,YAAY;AACjC,cAAQ,GAAG,UAAU,YAAY;AAAA,IAClC;AAAA,IACA;AAAA,EACD,CAAC;AACF;;;AC7CA,IAAO,wBAAQ;AAER,SAAS,aAAa,SAA8B;AAC1D,MAAI,QAAQ,mBAAmB,OAAO;AACrC,WAAO,CAAC;AAAA,EACT;AACA,SAAO,CAAC,yBAAyB,OAAO,CAAC;AAC1C;","names":[]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@baeta/plugin-prisma",
3
+ "version": "0.0.0-107-20241005143517-53e56e9",
4
+ "keywords": [
5
+ "baeta",
6
+ "graphql",
7
+ "schema",
8
+ "types",
9
+ "typescript",
10
+ "framework",
11
+ "builder"
12
+ ],
13
+ "homepage": "https://github.com/andreisergiu98/baeta#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/andreisergiu98/baeta/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/andreisergiu98/baeta.git",
20
+ "directory": "packages/plugin-prisma"
21
+ },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Andrei Pampu",
25
+ "url": "https://github.com/andreisergiu98"
26
+ },
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs",
32
+ "types": "./dist/index.d.ts"
33
+ }
34
+ },
35
+ "types": "dist/index.d.ts",
36
+ "files": [
37
+ "dist",
38
+ "package.json"
39
+ ],
40
+ "scripts": {
41
+ "build": "tsup",
42
+ "prepack": "prep",
43
+ "postpack": "prep --clean",
44
+ "types": "tsc --noEmit"
45
+ },
46
+ "dependencies": {
47
+ "@baeta/generator-sdk": "^0.0.0-107-20241005143517-53e56e9",
48
+ "@baeta/plugin-exec": "^0.0.0-107-20241005143517-53e56e9",
49
+ "@baeta/util-path": "^0.0.0-107-20241005143517-53e56e9",
50
+ "execa": "^9.4.0"
51
+ },
52
+ "devDependencies": {
53
+ "@baeta/builder": "^0.0.0",
54
+ "@baeta/tsconfig": "^0.0.0",
55
+ "@types/node": "^20.16.10",
56
+ "typescript": "^5.6.2"
57
+ },
58
+ "engines": {
59
+ "node": ">=20.0.0"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ }
64
+ }