Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: template create automation #23

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ 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.

Teraz możesz skupić się na wykonaniu zadania i weryfikacji testów poprzez polecenie `npm test`.
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

Nasz projekt wspierają ([zobacz typ kontrybucji](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
39 changes: 20 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +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: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"
}
"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"
}
}
32 changes: 12 additions & 20 deletions scripts/create-template.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import fs from 'fs';
import path from 'path';
import fs from "fs";
import { createTaskFolder, createTaskFoldersFromRange } from "./task-folder.js";

const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const folderName = `${year}-${month}-${day}`;
const arg = process.argv[2];

const folderPath = path.join('tasks', folderName);

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

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

const testFilePath = path.join(folderPath, 'index.test.ts');
fs.writeFileSync(testFilePath, '// Tutaj skopiuj testy dla zadania. Uruchom je poleceniem `npm test`');
if (arg === "missing") {
const startDate = new Date("2023-12-01");
const endDate = new Date();

console.log(`Przygotowano szablon na zadanie w folderze tasks/${folderName} 🎄`)
} else {
console.log(`Folder na dzisiejsze zadania już istnieje (tasks/${folderName}) 🤔`);
createTaskFoldersFromRange(startDate, endDate);
}
50 changes: 50 additions & 0 deletions scripts/task-folder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import fs from "fs";
import path from "path";

export function getFolderName(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}`;

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}) 🤔`
);
}
}

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