Skip to content

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

adds author to challenge metadata (#1004)

Dimitri Mitropoulos628f275cd886
diff --git a/challenges/blank/metadata.json b/challenges/blank/metadata.json
index 0a467610..cf5eb6ea 100644
--- a/challenges/blank/metadata.json
+++ b/challenges/blank/metadata.json
@@ -3,5 +3,6 @@
"label": "Lower Snake Case",
"description": "Try to keep it to one shortish sentence.",
"difficulty": "beginner",
- "prerequisites": []
+ "prerequisites": [],
+ "author": "your-github-user-id"
}
diff --git a/challenges/default-generic-arguments/metadata.json b/challenges/default-generic-arguments/metadata.json
index 193be736..d34ac88c 100644
--- a/challenges/default-generic-arguments/metadata.json
+++ b/challenges/default-generic-arguments/metadata.json
@@ -8,5 +8,6 @@
"type-unions",
"generic-type-constraints",
"indexed-types"
- ]
+ ],
+ "author": "dimitropoulos"
}
diff --git a/challenges/generic-function-arguments/metadata.json b/challenges/generic-function-arguments/metadata.json
index a78897a2..4bd7c399 100644
--- a/challenges/generic-function-arguments/metadata.json
+++ b/challenges/generic-function-arguments/metadata.json
@@ -3,5 +3,6 @@
"label": "Generic Function Arguments",
"description": "Give generic function types to your functions",
"difficulty": "beginner",
- "prerequisites": ["generic-type-arguments", "literal-types"]
+ "prerequisites": ["generic-type-arguments", "literal-types"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/generic-type-arguments/metadata.json b/challenges/generic-type-arguments/metadata.json
index a105e1e1..e036088b 100644
--- a/challenges/generic-type-arguments/metadata.json
+++ b/challenges/generic-type-arguments/metadata.json
@@ -3,5 +3,6 @@
"label": "Generic Type Arguments",
"description": "Generic types are like function arguments.",
"difficulty": "beginner",
- "prerequisites": ["primitive-data-types", "type-aliases"]
+ "prerequisites": ["primitive-data-types", "type-aliases"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/generic-type-constraints/metadata.json b/challenges/generic-type-constraints/metadata.json
index e962dad8..83269970 100644
--- a/challenges/generic-type-constraints/metadata.json
+++ b/challenges/generic-type-constraints/metadata.json
@@ -3,5 +3,6 @@
"label": "Generic Type Constraints",
"description": "Generic type constraints allow us to restrict the possible types a generic type will accept.",
"difficulty": "beginner",
- "prerequisites": []
+ "prerequisites": [],
+ "author": "dimitropoulos"
}
diff --git a/challenges/index-signatures/metadata.json b/challenges/index-signatures/metadata.json
index 047b9dfe..6f7d9f95 100644
--- a/challenges/index-signatures/metadata.json
+++ b/challenges/index-signatures/metadata.json
@@ -3,5 +3,6 @@
"label": "Index Signatures",
"description": "Index signatures allow us to handle types where the properties are a non-specific literal value.",
"difficulty": "beginner",
- "prerequisites": ["type-aliases", "primitive-data-types"]
+ "prerequisites": ["type-aliases", "primitive-data-types"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/indexed-types/metadata.json b/challenges/indexed-types/metadata.json
index a75f4358..eb7411fd 100644
--- a/challenges/indexed-types/metadata.json
+++ b/challenges/indexed-types/metadata.json
@@ -3,5 +3,6 @@
"label": "Indexed Types",
"description": "Some types can be indexed to lookup a particular value.",
"difficulty": "beginner",
- "prerequisites": ["primitive-data-types", "type-unions", "keyof", "literal-types"]
+ "prerequisites": ["primitive-data-types", "type-unions", "keyof", "literal-types"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/keyof/metadata.json b/challenges/keyof/metadata.json
index bcf1dd61..7c93e83f 100644
--- a/challenges/keyof/metadata.json
+++ b/challenges/keyof/metadata.json
@@ -3,5 +3,6 @@
"label": "The `keyof` operator",
"description": "`keyof` allows us to extract a union of another type's keys.",
"difficulty": "beginner",
- "prerequisites": ["type-aliases", "literal-types", "type-unions"]
+ "prerequisites": ["type-aliases", "literal-types", "type-unions"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/literal-types/metadata.json b/challenges/literal-types/metadata.json
index 17d25e7a..afffabf3 100644
--- a/challenges/literal-types/metadata.json
+++ b/challenges/literal-types/metadata.json
@@ -3,5 +3,6 @@
"label": "Literal Types",
"description": "TypeScript can be more specific than `string` or `number`. It can remember literal values.",
"difficulty": "beginner",
- "prerequisites": ["primitive-data-types", "type-unions"]
+ "prerequisites": ["primitive-data-types", "type-unions"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/mapped-object-types/metadata.json b/challenges/mapped-object-types/metadata.json
index 99022101..f41e0185 100644
--- a/challenges/mapped-object-types/metadata.json
+++ b/challenges/mapped-object-types/metadata.json
@@ -3,5 +3,6 @@
"label": "Mapped Object Types",
"description": "Mapping objects is a foundational skill that allows you to write type translation logic.",
"difficulty": "beginner",
- "prerequisites": ["index-signatures", "keyof", "generic-type-arguments", "indexed-types"]
+ "prerequisites": ["index-signatures", "keyof", "generic-type-arguments", "indexed-types"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/metadata.schema.json b/challenges/metadata.schema.json
index fe7f1092..ff2bc5f8 100644
--- a/challenges/metadata.schema.json
+++ b/challenges/metadata.schema.json
@@ -28,7 +28,11 @@
"items": {
"type": "string"
}
+ },
+ "author": {
+ "description": "The author of this challenge",
+ "type": "string"
}
},
- "required": ["id", "label", "description", "difficulty", "prerequisites"]
+ "required": ["id", "label", "description", "difficulty", "prerequisites", "author"]
}
diff --git a/challenges/pick/metadata.json b/challenges/pick/metadata.json
index 2aac4d1f..5fbe534d 100644
--- a/challenges/pick/metadata.json
+++ b/challenges/pick/metadata.json
@@ -3,5 +3,6 @@
"label": "The `Pick` builtin",
"description": "TypeScript ships with a `Pick` type. Learn how to make it yourself!",
"difficulty": "easy",
- "prerequisites": ["literal-types", "keyof", "mapped-object-types", "generic-type-constraints"]
+ "prerequisites": ["literal-types", "keyof", "mapped-object-types", "generic-type-constraints"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/primitive-data-types/metadata.json b/challenges/primitive-data-types/metadata.json
index a955d8c2..bd96e18c 100644
--- a/challenges/primitive-data-types/metadata.json
+++ b/challenges/primitive-data-types/metadata.json
@@ -3,5 +3,6 @@
"label": "Primitive Data Types",
"description": "Your TypeScript journey starts with these building blocks.",
"difficulty": "beginner",
- "prerequisites": []
+ "prerequisites": [],
+ "author": "dimitropoulos"
}
diff --git a/challenges/type-aliases/metadata.json b/challenges/type-aliases/metadata.json
index bb348c47..16d5f568 100644
--- a/challenges/type-aliases/metadata.json
+++ b/challenges/type-aliases/metadata.json
@@ -3,5 +3,6 @@
"label": "Type Aliases",
"description": "You can create multiple names for the same type.",
"difficulty": "beginner",
- "prerequisites": ["primitive-data-types"]
+ "prerequisites": ["primitive-data-types"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/type-unions/metadata.json b/challenges/type-unions/metadata.json
index 4868f31f..da13c528 100644
--- a/challenges/type-unions/metadata.json
+++ b/challenges/type-unions/metadata.json
@@ -3,5 +3,6 @@
"label": "Type Unions",
"description": "Type unions are a powerful tool that allow you to create a type that's many values all at once.",
"difficulty": "beginner",
- "prerequisites": ["type-aliases", "literal-types"]
+ "prerequisites": ["type-aliases", "literal-types"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/typeof/metadata.json b/challenges/typeof/metadata.json
index a23e81e6..08f38ab4 100644
--- a/challenges/typeof/metadata.json
+++ b/challenges/typeof/metadata.json
@@ -3,5 +3,6 @@
"label": "The `typeof` Operator",
"description": "When you need to create a type from existing JavaScript values, `typeof` is the tool for the job.",
"difficulty": "beginner",
- "prerequisites": ["literal-types", "type-unions", "type-aliases"]
+ "prerequisites": ["literal-types", "type-unions", "type-aliases"],
+ "author": "dimitropoulos"
}
diff --git a/challenges/validate.ts b/challenges/validate.ts
index 32ba746d..1653d557 100644
--- a/challenges/validate.ts
+++ b/challenges/validate.ts
@@ -13,14 +13,16 @@ this script does a few checks:
1. make sure the prerequisites don't contain the current
*/
-const getChallengeIds = (dir: string) => {
+const dir = __dirname;
+
+const getChallengeIds = () => {
return readdirSync(dir)
.filter((entry) => entry !== 'blank')
.filter((entry) => statSync(join(dir, entry)).isDirectory())
.filter((entry) => statSync(join(dir, entry, 'metadata.json')).isFile());
};
-const getMetadata = (dir: string, id: string) => {
+const getMetadata = (id: string) => {
const metadataFilePath = join(dir, id, 'metadata.json');
const metadataFile = readFileSync(metadataFilePath).toString();
const metadata = JSON.parse(metadataFile) as {
@@ -33,7 +35,7 @@ const getMetadata = (dir: string, id: string) => {
};
};
-const validateMetadataSchema = (dir: string, ids: string[]) => {
+const validateMetadataSchema = (ids: string[]) => {
const ajv = new Ajv();
const schema = JSON.parse(readFileSync(join(dir, 'metadata.schema.json')).toString());
@@ -41,7 +43,7 @@ const validateMetadataSchema = (dir: string, ids: string[]) => {
const validate = ajv.compile(schema);
ids.forEach((id) => {
- const { metadata, metadataFilePath } = getMetadata(dir, id);
+ const { metadata, metadataFilePath } = getMetadata(id);
if (!validate(metadata)) {
console.error(
@@ -53,8 +55,8 @@ const validateMetadataSchema = (dir: string, ids: string[]) => {
});
};
-const ensureChallengeIdMatchesDirectory = (dir: string) => (id: string) => {
- const { metadataFilePath, metadata } = getMetadata(dir, id);
+const ensureChallengeIdMatchesDirectory = (id: string) => {
+ const { metadataFilePath, metadata } = getMetadata(id);
if (id !== metadata.id) {
console.error(
@@ -63,8 +65,8 @@ const ensureChallengeIdMatchesDirectory = (dir: string) => (id: string) => {
}
};
-const validatePrerequisiteIds = (dir: string) => (id: string, _: number, ids: string[]) => {
- const { metadataFilePath, metadata } = getMetadata(dir, id);
+const validatePrerequisiteIds = (id: string, _: number, ids: string[]) => {
+ const { metadataFilePath, metadata } = getMetadata(id);
metadata.prerequisites.forEach((prerequisite) => {
if (!ids.includes(prerequisite)) {
@@ -82,11 +84,11 @@ const validatePrerequisiteIds = (dir: string) => (id: string, _: number, ids: st
};
const validateMetadataFiles = () => {
- const challengeIds = getChallengeIds(__dirname);
+ const challengeIds = getChallengeIds();
- validateMetadataSchema(__dirname, challengeIds);
- challengeIds.forEach(ensureChallengeIdMatchesDirectory(__dirname));
- challengeIds.forEach(validatePrerequisiteIds(__dirname));
+ validateMetadataSchema(challengeIds);
+ challengeIds.forEach(ensureChallengeIdMatchesDirectory);
+ challengeIds.forEach(validatePrerequisiteIds);
};
validateMetadataFiles();
diff --git a/cspell.json b/cspell.json
index 97c53363..fef3803f 100644
--- a/cspell.json
+++ b/cspell.json
@@ -6,37 +6,38 @@
"Asgardian",
"Caprese",
"Chewbacca",
+ "codebases",
"Darabont",
"Demme",
+ "dimitropoulos",
+ "doomscrolling",
"Ferarri",
+ "footgun",
"Jolie",
+ "keyof",
"Lambo",
"Lasseter",
+ "leetcode",
"Mariah",
"Morissette",
"Morty",
+ "multicursor",
"Odinson",
+ "omniverse",
"Pikachu",
+ "prolly",
"Radiohead",
"Ramis",
+ "rebeccapurple",
"Romanoff",
"Shawshank",
"Skywalker",
- "TLDR",
"Tiernan",
+ "TLDR",
+ "twoslash",
+ "typeof",
"Weisz",
"Wookiee",
- "XKCD",
- "codebases",
- "doomscrolling",
- "footgun",
- "keyof",
- "leetcode",
- "multicursor",
- "omniverse",
- "prolly",
- "rebeccapurple",
- "twoslash",
- "typeof"
+ "XKCD"
]
}
diff --git a/package.json b/package.json
index 86677cea..41a73a73 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"format:fix": "prettier . \"!./apps/**\" \"!./packages/**\" \"!./tooling/**\" \"!challenges/**/tests.ts\" --write --cache --cache-location=\"node_modules/.cache/prettiercache\" --log-level=warn",
"lint": "eslint . --cache --cache-location \"node_modules/.cache/.eslintcache\" --max-warnings 0",
"lint:markdown": "markdownlint-cli2 \"challenges/**/*.md\" \"#**/node_modules\" && cspell challenges/** --no-progress",
+ "lint:markdown:validate": "tsx challenges/validate.ts",
"lint:fix": "eslint . --fix --cache --cache-location \"node_modules/.cache/.eslintcache\" --max-warnings 0",
"refresh": "turbo db:reset db:seed --concurrency=1",
"test:e2e": "turbo test:e2e",