-
Notifications
You must be signed in to change notification settings - Fork 127
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
Changes from 3 commits
81f2b01
f1afa75
266a6a5
8cccd67
0002a8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
"license": "ISC", | ||
"scripts": { | ||
"create": "node ./scripts/create-template.js", | ||
"create-all": "node ./scripts/create-template.js all", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use semicolons like with |
||
"create-previous": "node ./scripts/create-template.js with-previous", | ||
"test": "jest ./tasks/$(date +'%Y-%m-%d')/index.test.ts", | ||
"test:all": "jest" | ||
}, | ||
|
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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a follow-up, would be nice to reuse |
||
} | ||
|
||
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); | ||
} |
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)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best to reference explicit names of npm scripts just to be consistent.
npm run create:month
as suggested by @MarcinPardanpm run create:?
- I can't find any single-word name for "up until today"