Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

chore: ignore challenges

bautistaaa1ba3fa1fe683
diff --git a/.eslintrc.js b/.eslintrc.js
index f3f2f856..9ad97cde 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -2,7 +2,14 @@
module.exports = {
root: true,
extends: [require.resolve('./tooling/config-eslint/node')],
- ignorePatterns: ['apps/**', 'packages/**', 'tooling/**', 'monaco-editor.d.ts', 'next-env.d.ts'],
+ ignorePatterns: [
+ 'apps/**',
+ 'packages/**',
+ 'tooling/**',
+ 'challenges/**',
+ 'monaco-editor.d.ts',
+ 'next-env.d.ts',
+ ],
parserOptions: {
project: `${__dirname}/tsconfig.json`,
},
diff --git a/.prettierignore b/.prettierignore
index 1b3054f9..173e8493 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -13,5 +13,6 @@ monaco-editor.d.ts
pnpm-lock.yaml
!apps/**
+!challenges/**
!packages/**
!tooling/**
diff --git a/packages/db/seed/data/tracks.ts b/packages/db/seed/data/tracks.ts
new file mode 100644
index 00000000..3d8a069a
--- /dev/null
+++ b/packages/db/seed/data/tracks.ts
@@ -0,0 +1,27 @@
+export const tracks = [
+ {
+ name: 'Crafting TypeScript Utility Types',
+ description:
+ "This collection guides you through hands-on exercises to recreate Typescript's built-in utility types.",
+ },
+ {
+ name: 'Typescript Wizardry',
+ description:
+ "Dive into the elite realm of TypeScript mastery with our 'Pro-Level TypeScript Challenges.' Designed for seasoned professionals, this collection offers a formidable gauntlet of intricate exercises, pushing the boundaries of your TypeScript expertise to the limit.",
+ },
+ {
+ name: 'Javascript Built in Methods',
+ description:
+ "This collection of challenges equips you to develop and enhance standard JavaScript methods, all while harnessing TypeScript's advanced type system to achieve a fully typesafe developer experience.",
+ },
+ {
+ name: 'Understanding Typescript Syntax',
+ description:
+ 'A collection of challenging exercises that dive into type annotations, generics, and more to level up your typescript abilities.',
+ },
+ {
+ name: 'Typescript Foundations',
+ description:
+ "'Typescript Foundations' is a curated set of challenges designed to build a strong foundation. From basic syntax to advanced concepts, this collection offers hands-on exercises to help you become a TypeScript Hero.",
+ },
+];
diff --git a/packages/db/seed/dev.ts b/packages/db/seed/dev.ts
new file mode 100644
index 00000000..f406d7a8
--- /dev/null
+++ b/packages/db/seed/dev.ts
@@ -0,0 +1,126 @@
+import { faker } from '@faker-js/faker';
+import { PrismaClient, type Challenge, type Prisma } from '@prisma/client';
+import uuidByString from 'uuid-by-string';
+import { loadChallengesFromTypeChallenge } from '../mocks/challenges.mock';
+import { createComment } from '../mocks/comment.mock';
+import { createUsers } from '../mocks/user.mock';
+import { tracks } from './data/tracks';
+
+const prisma = new PrismaClient();
+
+export const slugify = (str: string) => str.toLowerCase().replace(/\s/g, '-');
+export const trashId = uuidByString('trash');
+export const gId = uuidByString('g');
+
+try {
+ await prisma.user.createMany({
+ data: createUsers(15),
+ });
+
+ const challengesFromTypeChallenges = await loadChallengesFromTypeChallenge();
+ const users = await prisma.user
+ .findMany({
+ select: {
+ id: true,
+ },
+ })
+ .then((r) => r.map((u) => u.id));
+
+ await prisma.challenge.createMany({
+ data: challengesFromTypeChallenges.map((challenge) => ({
+ ...challenge,
+ userId: faker.helpers.arrayElement(users),
+ })),
+ });
+
+ for (const [index, track] of tracks.entries()) {
+ const challenges = await getRandomChallenges(index);
+
+ const createdTrack = await prisma.track.create({
+ data: {
+ name: track.name,
+ slug: slugify(track.name),
+ description: track.description,
+ visible: true,
+ },
+ });
+
+ await prisma.trackChallenge.createMany({
+ data: challenges.map((challenge, index) => ({
+ challengeId: challenge.id,
+ trackId: createdTrack.id,
+ orderId: index,
+ })),
+ });
+ }
+ const someChallenge = await prisma.challenge.findFirst({
+ where: {
+ status: 'ACTIVE',
+ },
+ });
+
+ await prisma.user.upsert({
+ where: { id: trashId },
+ update: {},
+ create: {
+ id: trashId,
+ email: '[email protected]',
+ name: 'chris',
+ sharedSolution: {
+ create: alotOfSharedSolutions(someChallenge?.id ?? 2),
+ },
+ },
+ });
+
+ let commentNum = 0;
+ const comments = Array.from({ length: 50 }, () => createComment(++commentNum));
+
+ const replies: Prisma.CommentCreateManyInput[] = [];
+
+ const { comment: createdComments } = await prisma.challenge.update({
+ where: { id: someChallenge?.id },
+ include: {
+ comment: true,
+ },
+ data: {
+ comment: {
+ create: comments,
+ },
+ },
+ });
+
+ for (const comment of createdComments) {
+ replies.push(createComment(++commentNum, comment.id), createComment(++commentNum, comment.id));
+ }
+
+ await prisma.challenge.update({
+ where: { id: someChallenge?.id },
+ data: {
+ comment: {
+ create: replies,
+ },
+ },
+ });
+
+ await prisma.$disconnect();
+} catch (e) {
+ console.error(e);
+ await prisma.$disconnect();
+ process.exit(1);
+}
+
+async function getRandomChallenges(iteration: number): Promise<Challenge[]> {
+ const challenges = await prisma.challenge.findMany({
+ take: 10,
+ skip: 10 * iteration,
+ });
+ return challenges;
+}
+
+function alotOfSharedSolutions(challengeId: number) {
+ return Array.from({ length: 50 }, () => ({
+ challengeId,
+ title: faker.lorem.words(7),
+ description: faker.lorem.words({ min: 5, max: 25 }),
+ }));
+}
diff --git a/packages/db/seed/prod.ts b/packages/db/seed/prod.ts
new file mode 100644
index 00000000..186447c9
--- /dev/null
+++ b/packages/db/seed/prod.ts
@@ -0,0 +1,40 @@
+import { PrismaClient } from '@prisma/client';
+import uuidByString from 'uuid-by-string';
+import { loadChallengesFromTypeChallenge } from '../mocks/challenges.mock';
+
+const prisma = new PrismaClient();
+
+export const slugify = (str: string) => str.toLowerCase().replace(/\s/g, '-');
+const TYPE_CHALLENGE_ID = uuidByString('type-challenges');
+
+try {
+ const typeChallengeUser = await prisma.user.upsert({
+ where: { id: TYPE_CHALLENGE_ID },
+ update: {},
+ create: {
+ id: TYPE_CHALLENGE_ID,
+ email: '[email protected]',
+ name: 'Type Challenges',
+ userLinks: {
+ create: {
+ url: 'https://tsch.js.org/',
+ },
+ },
+ },
+ });
+
+ const data = await loadChallengesFromTypeChallenge();
+
+ await prisma.challenge.createMany({
+ data: data.map((challenge) => ({
+ ...challenge,
+ userId: typeChallengeUser.id,
+ })),
+ });
+
+ await prisma.$disconnect();
+} catch (e) {
+ console.error(e);
+ await prisma.$disconnect();
+ process.exit(1);
+}