-
Notifications
You must be signed in to change notification settings - Fork 71
/
build.js
40 lines (34 loc) · 1.02 KB
/
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 PACKAGE = require("./package-real.json");
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,
transform: (content) => content.replace(/%VERSION%/g, PACKAGE.version),
})),
];
fs.rmSync(BUILD, { recursive: true, force: 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));
}
}