-
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: improve create template script
Refined the create-template script to introduce additional automation with two new arguments: "all" and "with-previous". The "all" parameter facilitates the creation of folders for all tasks from the event's start to its end, streamlining the process. The "with-previous" parameter option enables the generation of missing tasks from the current date to the event's start date.
- Loading branch information
Showing
2 changed files
with
68 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
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 (!arg) { | ||
createTaskFolder(new Date()); | ||
} | ||
|
||
if (!fs.existsSync(folderPath)) { | ||
fs.mkdirSync(folderPath); | ||
const indexFilePath = path.join(folderPath, 'index.ts'); | ||
fs.writeFileSync(indexFilePath, '// Tutaj skopiuj kod zadania'); | ||
if (arg === "all") { | ||
const startDate = new Date("2023-12-01"); | ||
const endDate = new Date("2023-12-24"); | ||
|
||
createTaskFoldersFromRange(startDate, endDate); | ||
} | ||
|
||
const testFilePath = path.join(folderPath, 'index.test.ts'); | ||
fs.writeFileSync(testFilePath, '// Tutaj skopiuj testy dla zadania. Uruchom je poleceniem `npm test`'); | ||
if (arg === "with-previous") { | ||
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); | ||
} |
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,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)); | ||
} | ||
} |