Skip to content

Commit

Permalink
🌱 chore(seeds): add images to markdown seeds, use markdown for organi…
Browse files Browse the repository at this point in the history
…zation descriptions (#568)

chore: add images to fake markdown
  • Loading branch information
larwaa authored Mar 22, 2024
1 parent 8b22b25 commit f4ea2a7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 45 deletions.
41 changes: 1 addition & 40 deletions src/repositories/events/seed.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { faker } from "@faker-js/faker";
import type { Prisma, PrismaClient } from "@prisma/client";
import { startCase, toLower } from "lodash-es";
import { DateTime } from "luxon";
import { env } from "~/config.js";
import { fakeMarkdown, toTitleCase } from "../seed.js";

faker.seed(42);

const toTitleCase = (str: string) => {
return startCase(toLower(str));
};

const fakeName = () => {
return toTitleCase(
`${faker.word.adjective()} ${faker.word.verb()} ${faker.word.adverb()}`,
Expand Down Expand Up @@ -372,38 +368,3 @@ export const load = async (db: PrismaClient) => {

return events;
};

function fakeMarkdown() {
const fakeHeader = () =>
`${"#".repeat(faker.number.int({ min: 1, max: 6 }))} ${toTitleCase(
faker.lorem.words(3),
)}`;
const fakeParagraph = () => faker.lorem.paragraph().split("\n").join("\n\n");
const fakeList = () => {
const listItems = faker.lorem.paragraphs(3).split("\n");
return listItems.map((item) => `* ${item}`).join("\n");
};
const fakeCode = () => {
const code = faker.lorem.paragraphs(3).split("\n");
return code.map((line) => ` ${line}`).join("\n");
};
const fakeQuote = () => {
const quote = faker.lorem.paragraphs(3).split("\n");
return quote.map((line) => `> ${line}`).join("\n");
};
const fakeLink = () => `[${faker.lorem.words(3)}](${faker.internet.url()})`;
return `
${fakeHeader()}
${fakeParagraph()}
${fakeList()}
${fakeHeader()}
${fakeCode()}
${fakeQuote()}
${fakeLink()}
`;
}
15 changes: 10 additions & 5 deletions src/repositories/organizations/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import {
type Prisma,
type PrismaClient,
} from "@prisma/client";
import { fakeMarkdown } from "../seed.js";

faker.seed(42);

const organizationCreateInput: Prisma.OrganizationCreateInput[] = [
{
id: faker.string.uuid(),
name: faker.company.name(),
description: faker.lorem.paragraph(),
description: fakeMarkdown(),
},
{
id: faker.string.uuid(),
name: faker.company.name(),
description: faker.lorem.paragraph(),
description: fakeMarkdown(),
},
{
id: faker.string.uuid(),
name: faker.company.name(),
description: faker.lorem.paragraph(),
description: fakeMarkdown(),
},
{
id: faker.string.uuid(),
name: faker.company.name(),
description: faker.lorem.paragraph(),
description: fakeMarkdown(),
},
];

Expand All @@ -37,7 +38,7 @@ export const load = async (db: PrismaClient) => {
where: {
id: organization.id,
},
update: {},
update: organization,
create: organization,
});
}
Expand All @@ -49,10 +50,12 @@ export const load = async (db: PrismaClient) => {
},
update: {
featurePermissions: [FeaturePermission.CABIN_ADMIN],
description: fakeMarkdown(),
},
create: {
name: "Hyttestyret",
featurePermissions: [FeaturePermission.CABIN_ADMIN],
description: fakeMarkdown(),
},
});

Expand All @@ -62,10 +65,12 @@ export const load = async (db: PrismaClient) => {
},
update: {
featurePermissions: [FeaturePermission.CABIN_ADMIN],
description: fakeMarkdown(),
},
create: {
name: "Rubberdøk",
featurePermissions: [FeaturePermission.CABIN_ADMIN],
description: fakeMarkdown(),
},
});

Expand Down
56 changes: 56 additions & 0 deletions src/repositories/seed.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { faker } from "@faker-js/faker";
import { PrismaClient } from "@prisma/client";
import { startCase, toLower } from "lodash-es";
import * as Cabins from "./cabins/seed.js";
import * as Documents from "./documents/seed.js";
import * as Events from "./events/seed.js";
Expand Down Expand Up @@ -44,3 +46,57 @@ try {
console.log("Finished");
await db.$disconnect();
}

function fakeMarkdown() {
const images = [
"https://source.unsplash.com/3tYZjGSBwbk",
"https://source.unsplash.com/t7YycgAoVSw",
"https://source.unsplash.com/lSIxP2H5Dmc",
"https://source.unsplash.com/2Eewt6DoSRI",
"https://source.unsplash.com/WqZoyvzViBA",
];
const fakeHeader = () =>
`${"#".repeat(faker.number.int({ min: 1, max: 6 }))} ${toTitleCase(
faker.lorem.words(3),
)}`;
const fakeParagraph = () => faker.lorem.paragraph().split("\n").join("\n\n");
const fakeList = () => {
const listItems = faker.lorem.paragraphs(3).split("\n");
return listItems.map((item) => `* ${item}`).join("\n");
};
const fakeCode = () => {
const code = faker.lorem.paragraphs(3).split("\n");
return code.map((line) => ` ${line}`).join("\n");
};
const fakeQuote = () => {
const quote = faker.lorem.paragraphs(3).split("\n");
return quote.map((line) => `> ${line}`).join("\n");
};
const fakeLink = () => `[${faker.lorem.words(3)}](${faker.internet.url()})`;
const fakeImage = () =>
`![${faker.lorem.words(3)}](${
images[faker.number.int({ min: 0, max: images.length - 1 })]
})`;
return `
${fakeHeader()}
${fakeParagraph()}
${fakeImage()}
${fakeList()}
${fakeHeader()}
${fakeCode()}
${fakeQuote()}
${fakeLink()}
- `;
}

function toTitleCase(str: string) {
return startCase(toLower(str));
}

export { fakeMarkdown, toTitleCase };

0 comments on commit f4ea2a7

Please sign in to comment.