forked from lydell/eslint-plugin-simple-import-sort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
40 lines (33 loc) · 945 Bytes
/
build.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
"use strict";
const fs = require("fs");
const path = require("path");
const DIR = __dirname;
const SRC = "src";
const BUILD = path.join(DIR, "build");
const READ_MORE =
"**[➡️ Full readme](https://github.com/lydell/eslint-plugin-simple-import-sort/)**";
const FILES_TO_COPY = [
{ src: "LICENSE" },
{ src: "package-real.json", dest: "package.json" },
{
src: "README.md",
transform: (content) => content.replace(/<!--[^]*$/, READ_MORE),
},
...fs
.readdirSync(SRC)
.map((file) => ({ src: path.join(SRC, file), dest: file })),
];
if (fs.existsSync(BUILD)) {
fs.rmdirSync(BUILD, { recursive: true });
}
fs.mkdirSync(BUILD);
for (const { src, dest = src, transform } of FILES_TO_COPY) {
if (transform) {
fs.writeFileSync(
path.join(BUILD, dest),
transform(fs.readFileSync(path.join(DIR, src), "utf8"))
);
} else {
fs.copyFileSync(path.join(DIR, src), path.join(BUILD, dest));
}
}