Skip to content

Commit 3a1a991

Browse files
committed
feat: convert pwsh script to js
1 parent 30e1d59 commit 3a1a991

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dev": "vitepress dev . --host",
55
"build": "vitepress build .",
66
"preview": "vitepress preview .",
7-
"new": "pwsh ./scripts/new-post.ps1",
7+
"new": "node ./scripts/new.js",
88
"summary": "node --env-file-if-exists=.env ./scripts/summary.js"
99
},
1010
"devDependencies": {
@@ -14,6 +14,8 @@
1414
"@types/webfontloader": "^1.6.38",
1515
"@vueuse/core": "^10.11.1",
1616
"clsx": "^2.1.1",
17+
"commander": "^13.1.0",
18+
"dayjs": "^1.11.13",
1719
"lucide-vue-next": "^0.378.0",
1820
"markdown-it-container": "^4.0.0",
1921
"markdown-it-footnote": "^4.0.0",

pnpm-lock.yaml

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/new-post.ps1

-17
This file was deleted.

scripts/new.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { writeFile, mkdir } from 'fs/promises'
2+
import path from 'path'
3+
import { program } from 'commander'
4+
import dayjs from 'dayjs'
5+
6+
program.arguments('<id> [name]').parse()
7+
const [id, name = id] = program.args
8+
9+
const time = dayjs().format('YYYY-MM-DDTHH:mm:ssZ')
10+
const content = `---
11+
title: ${name}
12+
create: ${time}
13+
---
14+
15+
`
16+
await mkdir(path.join(import.meta.dirname, '..', 'posts', id))
17+
const filePath = path.join(import.meta.dirname, '..', 'posts', id, 'index.md')
18+
writeFile(filePath, content, { encoding: 'utf-8' })

0 commit comments

Comments
 (0)