Skip to content

Commit

Permalink
refactor(lib): Refactors Topic, Project and Challenge to use yml arra…
Browse files Browse the repository at this point in the history
…y format from meta object instead of csv
  • Loading branch information
mfdebian committed Nov 8, 2023
1 parent ffe7d98 commit 9cd9762
Show file tree
Hide file tree
Showing 21 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
tracks: web-dev
tracks:
- web-dev
env: cjs
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
tracks: web-dev
tracks:
- web-dev
env: cjs
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
track: web-dev
tracks: web-dev
tracks:
- web-dev
learningObjectives:
- html/semantics
- css/selectors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
track: web-dev
tracks: web-dev
tracks:
- web-dev
learningObjectives:
- html/semantics
- css
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: web-dev
tracks: web-dev
tracks:
- web-dev
learningObjectives:
- html/semantics
- css/selectors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: web-dev
tracks: web-dev
tracks:
- web-dev
---

# Tarjeta de crédito válida
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
track: web-dev
tracks: web-dev
tracks:
- web-dev
learningObjectives:
- html/foo
- css/selectors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: web-dev
tracks: web-dev
tracks:
- web-dev
---

# Tarjeta de crédito válida
Expand Down
3 changes: 2 additions & 1 deletion lib/__tests__/__fixtures__/challenge-cjs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: web-dev
tracks: web-dev
tracks:
- web-dev
env: cjs
---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
track: data
tracks: data
tracks:
- data
env: form
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
track: ux
tracks: ux
tracks:
- ux
env: form
3 changes: 2 additions & 1 deletion lib/__tests__/__fixtures__/challenge-form/challenge.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
track: data
tracks: data
tracks:
- data
env: form
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: ux
tracks: ux
tracks:
- ux
---

# Prototipado
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: ux
tracks: ux
tracks:
- ux
---

# Prototipado
Expand Down
3 changes: 2 additions & 1 deletion lib/__tests__/__fixtures__/topic-with-bad-part/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: ux
tracks: ux
tracks:
- ux
---

# Prototipado
Expand Down
3 changes: 2 additions & 1 deletion lib/__tests__/__fixtures__/topic-with-bad-part/README.pt.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: ux
tracks: ux
tracks:
- ux
---

# Prototipado
Expand Down
3 changes: 2 additions & 1 deletion lib/__tests__/__fixtures__/topic-with-translations/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: ux
tracks: ux
tracks:
- ux
---

# Prototipado
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
track: ux
tracks: ux
tracks:
- ux
---

# Prototipado
Expand Down
4 changes: 2 additions & 2 deletions lib/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const parseChallenge = async (dir, opts, pkg) => {
// TODO: Validate files (boilerplate, tests and solution)
const files = flattenTree(await dirToTree(dir));

const tracks = meta.tracks?.split(/[ ,]+/);
const { track, tracks } = meta;

if (!tracks) {
throw new Error('No tracks found. Expected at least one.');
Expand All @@ -234,7 +234,7 @@ export const parseChallenge = async (dir, opts, pkg) => {
version: opts?.version,
parserVersion: pkg?.version,
createdAt: new Date(),
track: meta.track,
track,
tracks,
env: meta.env,
intl: langs.reduce(
Expand Down
4 changes: 1 addition & 3 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ export const parseProject = async (dir, opts, pkg) => {
}),
);

const { track, cover, thumb } = meta;

const tracks = meta.tracks?.split(/[ ,]+/);
const { track, tracks, cover, thumb } = meta;

if (!['web-dev', 'ux', 'data'].includes(track)) {
throw new Error(`Invalid track "${track}". Expected "web-dev", "ux" or "data".`);
Expand Down
4 changes: 1 addition & 3 deletions lib/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ export const parseTopic = async (dir, opts, pkg) => {
}),
);

const { track, cover, thumb } = meta;

const tracks = meta.tracks?.split(/[ ,]+/);
const { track, tracks, cover, thumb } = meta;

if (!['web-dev', 'ux', 'data'].includes(track)) {
throw new Error(`Invalid track "${track}". Expected "web-dev", "ux" or "data".`);
Expand Down

0 comments on commit 9cd9762

Please sign in to comment.