-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script for creating missing tasks
- Loading branch information
Showing
5 changed files
with
83 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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ą 🤔'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters