Skip to content

Commit 2c905dd

Browse files
committed
Merge branch 'main' into alpha
2 parents 1895c98 + f86ff4d commit 2c905dd

File tree

6 files changed

+99
-5
lines changed

6 files changed

+99
-5
lines changed

.all-contributorsrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@
171171
"contributions": [
172172
"doc"
173173
]
174+
},
175+
{
176+
"login": "shiralwz",
177+
"name": "Lucia",
178+
"avatar_url": "https://avatars.githubusercontent.com/u/6162142?v=4",
179+
"profile": "https://github.com/shiralwz",
180+
"contributions": [
181+
"bug"
182+
]
183+
},
184+
{
185+
"login": "halostatue",
186+
"name": "Austin Ziegler",
187+
"avatar_url": "https://avatars.githubusercontent.com/u/11361?v=4",
188+
"profile": "https://github.com/halostatue",
189+
"contributions": [
190+
"code"
191+
]
174192
}
175193
],
176194
"contributorsPerLine": 7,

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
44

5-
[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors-)
5+
[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors-)
66

77
<!-- ALL-CONTRIBUTORS-BADGE:END -->
88

@@ -191,6 +191,17 @@ generator erd {
191191
}
192192
```
193193

194+
### Disable emoji output
195+
196+
The emoji output for primary keys (`🗝️`) and nullable fields (``) can be disabled, restoring the older values of `PK` and `nullable`, respectively.
197+
198+
```prisma
199+
generator erd {
200+
provider = "prisma-erd-generator"
201+
disableEmoji = true
202+
}
203+
```
204+
194205
### Puppeteer configuration
195206

196207
If you want to change the configuration of Puppeteer, create a [Puppeteer config file (JSON)](https://pptr.dev/guides/configuration#configuration-files) and pass the file path to the generator.
@@ -269,6 +280,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
269280
<td align="center" valign="top" width="14.28%"><a href="https://www.chintristan.io/"><img src="https://avatars.githubusercontent.com/u/23557893?v=4?s=100" width="100px;" alt="Tristan Chin"/><br /><sub><b>Tristan Chin</b></sub></a><br /><a href="https://github.com/keonik/prisma-erd-generator/commits?author=maxijonson" title="Code">💻</a></td>
270281
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bcanfield"><img src="https://avatars.githubusercontent.com/u/12603953?v=4?s=100" width="100px;" alt="Brandin Canfield"/><br /><sub><b>Brandin Canfield</b></sub></a><br /><a href="https://github.com/keonik/prisma-erd-generator/commits?author=bcanfield" title="Code">💻</a></td>
271282
<td align="center" valign="top" width="14.28%"><a href="https://scrapbox.io/mrsekut-p/"><img src="https://avatars.githubusercontent.com/u/24796587?v=4?s=100" width="100px;" alt="kota marusue"/><br /><sub><b>kota marusue</b></sub></a><br /><a href="https://github.com/keonik/prisma-erd-generator/commits?author=mrsekut" title="Documentation">📖</a></td>
283+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/shiralwz"><img src="https://avatars.githubusercontent.com/u/6162142?v=4?s=100" width="100px;" alt="Lucia"/><br /><sub><b>Lucia</b></sub></a><br /><a href="https://github.com/keonik/prisma-erd-generator/issues?q=author%3Ashiralwz" title="Bug reports">🐛</a></td>
284+
<td align="center" valign="top" width="14.28%"><a href="http://www.halostatue.ca/"><img src="https://avatars.githubusercontent.com/u/11361?v=4?s=100" width="100px;" alt="Austin Ziegler"/><br /><sub><b>Austin Ziegler</b></sub></a><br /><a href="https://github.com/keonik/prisma-erd-generator/commits?author=halostatue" title="Code">💻</a></td>
272285
</tr>
273286
</tbody>
274287
</table>

__tests__/disableEmoji.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as child_process from 'child_process';
2+
3+
test('disableEmoji.prisma', async () => {
4+
const fileName = 'disableEmoji.svg';
5+
const folderName = '__tests__';
6+
child_process.execSync(`rm -f ${folderName}/${fileName}`);
7+
child_process.execSync(
8+
`prisma generate --schema ./prisma/disableEmoji.prisma`
9+
);
10+
const listFile = child_process.execSync(`ls -la ${folderName}/${fileName}`);
11+
// did it generate a file
12+
expect(listFile.toString()).toContain(fileName);
13+
14+
const svgAsString = child_process
15+
.execSync(`cat ${folderName}/${fileName}`)
16+
.toString();
17+
18+
// did it generate a file with the correct content
19+
expect(svgAsString).toContain(`<svg`);
20+
expect(svgAsString).not.toContain(`❓`);
21+
expect(svgAsString).not.toContain(`🗝️`);
22+
expect(svgAsString).toContain(`nullable`);
23+
expect(svgAsString).toContain(`PK`);
24+
expect(svgAsString).toContain(`inviteeEmail`);
25+
expect(svgAsString).toContain(`cancelCode`);
26+
expect(svgAsString).toContain(`name`);
27+
});

prisma/disableEmoji.prisma

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
datasource db {
5+
provider = "postgresql"
6+
url = env("DATABASE_URL")
7+
}
8+
9+
generator erd {
10+
provider = "node ./dist/index.js"
11+
output = "../__tests__/disableEmoji.svg"
12+
theme = "forest"
13+
disableEmoji = true
14+
}
15+
16+
model Booking {
17+
id Int @id @default(autoincrement())
18+
inviteeEmail String?
19+
startDateUTC DateTime
20+
cancelCode String?
21+
events Event[]
22+
}
23+
24+
model Event {
25+
id Int @id @default(autoincrement())
26+
name String?
27+
startDate DateTime
28+
bookings Booking[]
29+
}

src/generate.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface DMLRendererOptions {
2828
tableOnly?: boolean;
2929
ignoreEnums?: boolean;
3030
includeRelationFromFields?: boolean;
31+
disableEmoji?: boolean;
3132
}
3233

3334
// Copy paste of the DMLModel
@@ -140,6 +141,7 @@ function renderDml(dml: DML, options?: DMLRendererOptions) {
140141
tableOnly = false,
141142
ignoreEnums = false,
142143
includeRelationFromFields = false,
144+
disableEmoji = false,
143145
} = options ?? {};
144146

145147
const diagram = 'erDiagram';
@@ -166,6 +168,8 @@ function renderDml(dml: DML, options?: DMLRendererOptions) {
166168
)
167169
.join('\n\n');
168170

171+
const pkSigil = disableEmoji ? '"PK"' : '"🗝️"';
172+
const nullableSigil = disableEmoji ? '"nullable"' : '"❓"';
169173
const classes = modellikes
170174
.map(
171175
(model) =>
@@ -183,9 +187,9 @@ ${
183187
)} ${
184188
field.isId ||
185189
model.primaryKey?.fields?.includes(field.name)
186-
? '"🗝️"'
190+
? pkSigil
187191
: ''
188-
}${field.isRequired ? '' : '"❓"'}`;
192+
}${field.isRequired ? '' : nullableSigil}`;
189193
})
190194
.join('\n')
191195
}
@@ -367,6 +371,7 @@ export const mapPrismaToDb = (dmlModels: DMLModel[], dataModel: string) => {
367371

368372
export default async (options: GeneratorOptions) => {
369373
try {
374+
console.log('generator options', options);
370375
const output = options.generator.output?.value || './prisma/ERD.svg';
371376
const config: ERDGeneratorConfig = options.generator.config;
372377

@@ -375,10 +380,11 @@ export default async (options: GeneratorOptions) => {
375380
path.join(config.mmdcPath || 'node_modules/.bin', 'mmdc')
376381
);
377382
const tableOnly = config.tableOnly === 'true';
383+
const disableEmoji = config.disableEmoji === 'true';
378384
const ignoreEnums = config.ignoreEnums === 'true';
379385
const includeRelationFromFields =
380386
config.includeRelationFromFields === 'true';
381-
const disabled = Boolean(process.env.DISABLE_ERD);
387+
const disabled = process.env.DISABLE_ERD === 'true';
382388
const debug =
383389
config.erdDebug === 'true' || Boolean(process.env.ERD_DEBUG);
384390

@@ -432,6 +438,7 @@ export default async (options: GeneratorOptions) => {
432438
tableOnly,
433439
ignoreEnums,
434440
includeRelationFromFields,
441+
disableEmoji,
435442
});
436443
if (debug && mermaid) {
437444
const mermaidFile = path.resolve('prisma/debug/3-mermaid.mmd');

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { generatorHandler } from '@prisma/generator-helper';
33
import generate from './generate';
44

5-
const disabled = Boolean(process.env.DISABLE_ERD);
5+
const disabled = process.env.DISABLE_ERD === 'true';
66

77
generatorHandler({
88
onManifest: () => ({

0 commit comments

Comments
 (0)