Skip to content

Commit a5da5c0

Browse files
Move package.json scripts into copyFile.js (typescript-cheatsheets#350)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 76b5082 commit a5da5c0

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

copyFile.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
const fs = require("fs");
2-
3-
const src = process.argv[2];
4-
const dest = process.argv[3];
5-
const hideHeader = process.argv[4];
2+
const filesTopCopy = [
3+
{
4+
src: "../CONTRIBUTORS.md",
5+
dest: "../docs/contributors.md",
6+
hideHeader: true,
7+
},
8+
{
9+
src: "../CONTRIBUTING.md",
10+
dest: "../docs/contributing.md",
11+
hideHeader: true,
12+
},
13+
];
614

715
const generatingPageOptions = `---
816
hide_title: true
917
---
1018
1119
`;
1220

13-
function writeNewFile() {
21+
function writeNewFile(src, dest) {
1422
const fileContent = fs.readFileSync(src).toString();
1523
const data = new Uint8Array(Buffer.from(generatingPageOptions + fileContent));
1624

@@ -23,7 +31,7 @@ function writeNewFile() {
2331
});
2432
}
2533

26-
function copyFile() {
34+
function copyFile(src, dest) {
2735
fs.copyFile(src, dest, (err) => {
2836
if (err) {
2937
console.log("Error Found:", err);
@@ -33,8 +41,10 @@ function copyFile() {
3341
});
3442
}
3543

36-
if (hideHeader) {
37-
writeNewFile();
38-
} else {
39-
copyFile();
40-
}
44+
filesTopCopy.forEach(({ src, dest, hideHeader }) => {
45+
if (hideHeader) {
46+
writeNewFile(src, dest);
47+
} else {
48+
copyFile(src, dest);
49+
}
50+
});

website/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"scripts": {
3-
"add-contributors-on-site": "node ../copyFile.js ../CONTRIBUTORS.md ../docs/contributors.md true",
4-
"add-contributing-on-site": "node ../copyFile.js ../CONTRIBUTING.md ../docs/contributing.md true",
5-
"add-pages-on-site": "yarn add-contributors-on-site && yarn add-contributing-on-site",
3+
"add-pages-on-site": "node ../copyFile.js",
64
"start": "yarn add-pages-on-site && docusaurus start",
75
"build": "yarn add-pages-on-site && docusaurus build",
86
"swizzle": "docusaurus swizzle",

0 commit comments

Comments
 (0)