Skip to content

Commit

Permalink
feat: add script for creating missing tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
kumiega committed Dec 9, 2023
2 parents 266a6a5 + 5434aad commit 8cccd67
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
"contributions": [
"maintenance"
]
},
{
"login": "MarcinParda",
"name": "Marcin Parda",
"avatar_url": "https://avatars.githubusercontent.com/u/32539248?v=4",
"profile": "https://marcinparda.vercel.app/",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ Zadania są dostępne na stronie [opanujfrontend.pl/advent](https://opanujfronte

Każdego dnia wykonaj w repozytorium polecenie `npm run create` a następnie skopiuj kod ze strony.

Użyj komendy `npm run create all`, jeśli chcesz wygenerować foldery z plikami startowymi
na każdy z dni wyzwania.

Użyj komendy `npm run create with-previous`, aby utworzyć brakujące zadania od aktualnej daty do
Użyj komendy `npm run create:missing`, aby utworzyć brakujące zadania od aktualnej daty do
dnia pierwszego wyzwania.

Możesz również wykonać polecenie `npm run create:month`, aby przygotować puste pliki do zadań na wszystkie 24 dni w kalendarzu.

Teraz możesz skupić się na wykonaniu zadania i weryfikacji testów poprzez polecenie `npm test`.

## 💜 Kontrybutorzy
Expand All @@ -28,7 +27,7 @@ Nasz projekt wspierają ([zobacz typ kontrybucji](https://allcontributors.org/do

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

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

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

Expand All @@ -39,8 +38,9 @@ Nasz projekt wspierają ([zobacz typ kontrybucji](https://allcontributors.org/do
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://opuchalski.pl"><img src="https://avatars.githubusercontent.com/u/45982530?v=4?s=100" width="100px;" alt="Oskar Puchalski"/><br /><sub><b>Oskar Puchalski</b></sub></a><br /><a href="https://github.com/przeprogramowani/advent-of-frontend/issues?q=author%3Amlodyoskar" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ssynowiec"><img src="https://avatars.githubusercontent.com/u/52856724?v=4?s=100" width="100px;" alt="Stanisław Synowiec"/><br /><sub><b>Stanisław Synowiec</b></sub></a><br /><a href="https://github.com/przeprogramowani/advent-of-frontend/commits?author=ssynowiec" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ssynowiec"><img src="https://avatars.githubusercontent.com/u/52856724?v=4?s=100" width="100px;" alt="Stanisław Synowiec"/><br /><sub><b>Stanisław Synowiec</b></sub></a><br /><a href="https://github.com/przeprogramowani/advent-of-frontend/commits?author=ssynowiec" title="Code">💻</a> <a href="https://github.com/przeprogramowani/advent-of-frontend/issues?q=author%3Assynowiec" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://adipol.dev"><img src="https://avatars.githubusercontent.com/u/27779154?v=4?s=100" width="100px;" alt="Adrian Polak"/><br /><sub><b>Adrian Polak</b></sub></a><br /><a href="#maintenance-AdiPol1359" title="Maintenance">🚧</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://marcinparda.vercel.app/"><img src="https://avatars.githubusercontent.com/u/32539248?v=4?s=100" width="100px;" alt="Marcin Parda"/><br /><sub><b>Marcin Parda</b></sub></a><br /><a href="https://github.com/przeprogramowani/advent-of-frontend/commits?author=MarcinParda" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "advent-of-frontend",
"version": "0.0.1",
"type": "module",
"description": "Szablon dla zadań z opanujfrontend.pl/advent",
"author": "Przeprogramowani",
"license": "ISC",
"scripts": {
"create": "node ./scripts/create-template.js",
"create-all": "node ./scripts/create-template.js all",
"create-previous": "node ./scripts/create-template.js with-previous",
"test": "jest ./tasks/$(date +'%Y-%m-%d')/index.test.ts",
"test:all": "jest"
},
"devDependencies": {
"@types/jest": "29.5.10",
"jest": "29.7.0",
"ts-jest": "29.1.1",
"tsx": "4.5.0",
"typescript": "5.3.2"
}
"name": "advent-of-frontend",
"version": "0.0.1",
"type": "module",
"description": "Szablon dla zadań z opanujfrontend.pl/advent",
"author": "Przeprogramowani",
"license": "ISC",
"scripts": {
"create": "node ./scripts/create-template.js",
"create:missing": "node ./scripts/create-template.js missing",
"create:month": "node ./scripts/create-month-templates.js",
"test": "jest ./tasks/$(date +'%Y-%m-%d')/index.test.ts",
"test:all": "jest"
},
"devDependencies": {
"@types/jest": "29.5.10",
"jest": "29.7.0",
"ts-jest": "29.1.1",
"tsx": "4.5.0",
"typescript": "5.3.2"
}
}
42 changes: 42 additions & 0 deletions scripts/create-month-templates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'fs';
import path from 'path';

const today = new Date();
const year = today.getFullYear();
const month = 12;
const daysInCalendar = 24;
const daysToGenerate = Array.from({ length: daysInCalendar }, (_, i) =>
String(i + 1).padStart(2, '0')
);

if (!fs.existsSync('tasks')) {
fs.mkdirSync('tasks');
}

let atLeastOneFolderCreated = false;

daysToGenerate.forEach((day) => {
const folderName = `${year}-${month}-${day}`;
const folderPath = path.join('tasks', folderName);

if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
const indexFilePath = path.join(folderPath, 'index.ts');
fs.writeFileSync(indexFilePath, '// Tutaj skopiuj kod zadania');

const testFilePath = path.join(folderPath, 'index.test.ts');
fs.writeFileSync(
testFilePath,
'// Tutaj skopiuj testy dla zadania. Uruchom je poleceniem `npm test`'
);
atLeastOneFolderCreated = true;

console.log(
`Przygotowano szablon na zadanie w folderze tasks/${folderName} 🎄`
);
}
});

if (!atLeastOneFolderCreated) {
console.log('Foldery na tegoroczne zadania już istnieją 🤔');
}
19 changes: 6 additions & 13 deletions scripts/create-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import { createTaskFolder, createTaskFoldersFromRange } from "./task-folder.js";
const arg = process.argv[2];

if (!fs.existsSync("tasks")) {
fs.mkdirSync("tasks");
fs.mkdirSync("tasks");
}

if (!arg) {
createTaskFolder(new Date());
createTaskFoldersFromRange(new Date(), new Date());
}

if (arg === "all") {
const startDate = new Date("2023-12-01");
const endDate = new Date("2023-12-24");
if (arg === "missing") {
const startDate = new Date("2023-12-01");
const endDate = new Date();

createTaskFoldersFromRange(startDate, endDate);
}

if (arg === "with-previous") {
const startDate = new Date("2023-12-01");
const endDate = new Date();

createTaskFoldersFromRange(startDate, endDate);
createTaskFoldersFromRange(startDate, endDate);
}

0 comments on commit 8cccd67

Please sign in to comment.