Skip to content

Commit

Permalink
Merge branch 'main' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
keonik committed Aug 8, 2023
2 parents 1895c98 + f86ff4d commit 2c905dd
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@
"contributions": [
"doc"
]
},
{
"login": "shiralwz",
"name": "Lucia",
"avatar_url": "https://avatars.githubusercontent.com/u/6162142?v=4",
"profile": "https://github.com/shiralwz",
"contributions": [
"bug"
]
},
{
"login": "halostatue",
"name": "Austin Ziegler",
"avatar_url": "https://avatars.githubusercontent.com/u/11361?v=4",
"profile": "https://github.com/halostatue",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

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

Expand Down Expand Up @@ -191,6 +191,17 @@ generator erd {
}
```

### Disable emoji output

The emoji output for primary keys (`🗝️`) and nullable fields (``) can be disabled, restoring the older values of `PK` and `nullable`, respectively.

```prisma
generator erd {
provider = "prisma-erd-generator"
disableEmoji = true
}
```

### Puppeteer configuration

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.
Expand Down Expand Up @@ -269,6 +280,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<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>
<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>
<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>
<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>
<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>
</tr>
</tbody>
</table>
Expand Down
27 changes: 27 additions & 0 deletions __tests__/disableEmoji.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as child_process from 'child_process';

test('disableEmoji.prisma', async () => {
const fileName = 'disableEmoji.svg';
const folderName = '__tests__';
child_process.execSync(`rm -f ${folderName}/${fileName}`);
child_process.execSync(
`prisma generate --schema ./prisma/disableEmoji.prisma`
);
const listFile = child_process.execSync(`ls -la ${folderName}/${fileName}`);
// did it generate a file
expect(listFile.toString()).toContain(fileName);

const svgAsString = child_process
.execSync(`cat ${folderName}/${fileName}`)
.toString();

// did it generate a file with the correct content
expect(svgAsString).toContain(`<svg`);
expect(svgAsString).not.toContain(`❓`);
expect(svgAsString).not.toContain(`🗝️`);
expect(svgAsString).toContain(`nullable`);
expect(svgAsString).toContain(`PK`);
expect(svgAsString).toContain(`inviteeEmail`);
expect(svgAsString).toContain(`cancelCode`);
expect(svgAsString).toContain(`name`);
});
29 changes: 29 additions & 0 deletions prisma/disableEmoji.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

generator erd {
provider = "node ./dist/index.js"
output = "../__tests__/disableEmoji.svg"
theme = "forest"
disableEmoji = true
}

model Booking {
id Int @id @default(autoincrement())
inviteeEmail String?
startDateUTC DateTime
cancelCode String?
events Event[]
}

model Event {
id Int @id @default(autoincrement())
name String?
startDate DateTime
bookings Booking[]
}
13 changes: 10 additions & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface DMLRendererOptions {
tableOnly?: boolean;
ignoreEnums?: boolean;
includeRelationFromFields?: boolean;
disableEmoji?: boolean;
}

// Copy paste of the DMLModel
Expand Down Expand Up @@ -140,6 +141,7 @@ function renderDml(dml: DML, options?: DMLRendererOptions) {
tableOnly = false,
ignoreEnums = false,
includeRelationFromFields = false,
disableEmoji = false,
} = options ?? {};

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

const pkSigil = disableEmoji ? '"PK"' : '"🗝️"';
const nullableSigil = disableEmoji ? '"nullable"' : '"❓"';
const classes = modellikes
.map(
(model) =>
Expand All @@ -183,9 +187,9 @@ ${
)} ${
field.isId ||
model.primaryKey?.fields?.includes(field.name)
? '"🗝️"'
? pkSigil
: ''
}${field.isRequired ? '' : '"❓"'}`;
}${field.isRequired ? '' : nullableSigil}`;
})
.join('\n')
}
Expand Down Expand Up @@ -367,6 +371,7 @@ export const mapPrismaToDb = (dmlModels: DMLModel[], dataModel: string) => {

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

Expand All @@ -375,10 +380,11 @@ export default async (options: GeneratorOptions) => {
path.join(config.mmdcPath || 'node_modules/.bin', 'mmdc')
);
const tableOnly = config.tableOnly === 'true';
const disableEmoji = config.disableEmoji === 'true';
const ignoreEnums = config.ignoreEnums === 'true';
const includeRelationFromFields =
config.includeRelationFromFields === 'true';
const disabled = Boolean(process.env.DISABLE_ERD);
const disabled = process.env.DISABLE_ERD === 'true';
const debug =
config.erdDebug === 'true' || Boolean(process.env.ERD_DEBUG);

Expand Down Expand Up @@ -432,6 +438,7 @@ export default async (options: GeneratorOptions) => {
tableOnly,
ignoreEnums,
includeRelationFromFields,
disableEmoji,
});
if (debug && mermaid) {
const mermaidFile = path.resolve('prisma/debug/3-mermaid.mmd');
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { generatorHandler } from '@prisma/generator-helper';
import generate from './generate';

const disabled = Boolean(process.env.DISABLE_ERD);
const disabled = process.env.DISABLE_ERD === 'true';

generatorHandler({
onManifest: () => ({
Expand Down

0 comments on commit 2c905dd

Please sign in to comment.