|
| 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