forked from zalagruden/orange-lecture-notes-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-post.js
45 lines (39 loc) · 1.14 KB
/
new-post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const postType = process.argv.at(2)
const folderName = process.argv.at(3)
if (!postType || ['books', 'chapters'].indexOf(postType) === -1) {
throw 'Please specify a post type: "book" or "chapter"';
}
if (!folderName) {
console.log('Please provide a folder name as an argument.')
return;
}
const boilerplatePath = `./public/${postType}`;
const folderPath = `./public/${postType}/${folderName}`;
fs.mkdir(`${folderPath}/`, { recursive: true }, (err) => {
if (err) throw err;
/**
* Copy boilerplate.md
*/
fs.copyFile(
`${boilerplatePath}/boilerplate.md`,
`${folderPath}/index.md`,
(err) => {
if (err) throw err;
console.log('=-=-=-=-=-=-=-=-=')
console.log('')
console.log(`New ${postType} ${folderName} was created.`);
console.log('')
console.log('=-=-=-=-=-=-=-=-=')
console.log('')
}
);
/**
* Copy example image if exists
*/
fs.copyFile(
`${boilerplatePath}/example.png`,
`${folderPath}/example.png`,
() => { } // no error handling
);
});