Skip to content

Commit b41eca0

Browse files
committed
Add bun new script for quicker template creation for both en and ru posts.
1 parent 6728190 commit b41eca0

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"clear": "npm run clean -- package-lock.json node_modules",
88
"clean": "rimraf -rf src/.vuepress/.cache src/.vuepress/.temp src/.vuepress/dist",
9+
"new": "bun ./src/new.ts",
910
"dev": "vuepress dev src",
1011
"build": "vuepress build src",
1112
"build-github-pages": "npm run build"

src/new.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// perse path argument
2+
import { path, fs } from "@vuepress/utils";
3+
4+
if (process.argv.length <= 2) {
5+
console.log('Script requires argument for path post to be created');
6+
const date = new Date();
7+
const year = date.getFullYear();
8+
const month = String(date.getMonth() + 1).padStart(2, '0');
9+
const day = String(date.getDate()).padStart(2, '0');
10+
console.log(`
11+
Usage: bun new ${year}/${year}-${month}-${day}-Hello-World
12+
or: bun new ${year} ${year}-${month}-${day}-Hello-World
13+
`);
14+
process.exit(1);
15+
}
16+
17+
const [_exec, _script, ...rest] = process.argv;
18+
const input = rest.join(' ');
19+
20+
const blogDir = path.join(__dirname, 'blog', ...rest);
21+
fs.mkdirpSync(blogDir);
22+
23+
const blobPost = path.join(blogDir, 'README.md');
24+
fs.writeSync(fs.openSync(blobPost, 'w'), `# TODO ${input}
25+
${input}
26+
27+
[[toc]]
28+
`);
29+
console.log(`file ${blobPost} created`);
30+
31+
const ruBlogDir = path.join(__dirname, 'ru', 'blog', ...rest);
32+
fs.mkdirpSync(ruBlogDir);
33+
34+
const ruBlobPost = path.join(ruBlogDir, 'README.md');
35+
fs.writeSync(fs.openSync(ruBlobPost, 'w'), `---
36+
lang: ru-RU
37+
---
38+
39+
# В разработке ${input}
40+
${input}
41+
42+
[[toc]]
43+
`);
44+
console.log(`file ${ruBlobPost} created`);

0 commit comments

Comments
 (0)