Skip to content

Commit

Permalink
docs: update README.md with new scripts
Browse files Browse the repository at this point in the history
styles: fix whitespaces
  • Loading branch information
kumiega committed Dec 6, 2023
1 parent f1afa75 commit 266a6a5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 65 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ 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
dnia pierwszego wyzwania.

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

## 💜 Kontrybutorzy

Nasz projekt wspierają ([zobacz typ kontrybucji](https://allcontributors.org/docs/en/emoji-key)):

<!-- 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-BADGE:END -->

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
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-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"
}
}
16 changes: 8 additions & 8 deletions scripts/create-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ 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());
createTaskFolder(new Date());
}

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

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

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

createTaskFoldersFromRange(startDate, endDate);
createTaskFoldersFromRange(startDate, endDate);
}
74 changes: 37 additions & 37 deletions scripts/task-folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@ import fs from "fs";
import path from "path";

export function getFolderName(date) {
if (!date) {
date = new Date();
}
if (!date) {
date = new Date();
}

const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const folderName = `${year}-${month}-${day}`;
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const folderName = `${year}-${month}-${day}`;

return folderName;
return folderName;
}

export function createTaskFolder(date = new Date()) {
const folderName = getFolderName(date);
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`"
);

console.log(
`Przygotowano szablon na zadanie w folderze tasks/${folderName} 🎄`
);
} else {
console.log(
`Folder na dzisiejsze zadania już istnieje (tasks/${folderName}) 🤔`
);
}
const folderName = getFolderName(date);
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`"
);

console.log(
`Przygotowano szablon na zadanie w folderze tasks/${folderName} 🎄`
);
} else {
console.log(
`Folder na dzisiejsze zadania już istnieje (tasks/${folderName}) 🤔`
);
}
}

export function createTaskFoldersFromRange(startDate, endDate) {
for (
let date = startDate;
date <= endDate;
date.setDate(date.getDate() + 1)
) {
createTaskFolder(new Date(date));
}
for (
let date = startDate;
date <= endDate;
date.setDate(date.getDate() + 1)
) {
createTaskFolder(new Date(date));
}
}

0 comments on commit 266a6a5

Please sign in to comment.