-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
71 lines (64 loc) · 2.34 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// MIT © 2017 azu
"use strict";
import cpx from "cpx";
import url from "node:url";
import path from "node:path";
import fs from "fs";
import addTextToMarkdown from "add-text-to-markdown";
import { References as Refs } from "./index.js";
const __filename__ = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename__);
const repoDir = path.join(__dirname, "repo");
const sourceDir = path.join(__dirname, "source");
/**
*
* @param {Object} repoObject リポジトリ情報
* @param {string} pattern glob pattern
*/
function copy(repoObject, pattern) {
const repo = repoObject.name;
const baseDir = path.join(repoDir, repo);
return new Promise((resolve, reject) => {
cpx.copy(`${baseDir}/${pattern}`, `${sourceDir}/${repo}`, {
clean: true,
preserve: true
}, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
function copyTask() {
return Promise.all([
copy(Refs["js-primer"], "source/basic/**/*.md"),
copy(Refs["JavaScript-Plugin-Architecture"], "ja/**/*.md"),
copy(Refs["Introduction-to-Addon-Development-in-Blender-Web"], "src/2.7/markdown/**/*.md"),
copy(Refs["The-Little-Book-on-CoffeeScript"], "coffeescript/chapters/ja_JP/**/*.md"),
copy(Refs["progit"], "ja/**/*.{md,markdown}"),
copy(Refs["what-is-maven"], "{deploy,implement-plugin,module,primer}/**/*.md"),
copy(Refs["Hatena-Textbook"], "/**/*.md"),
copy(Refs["build-web-application-with-golang"], "ja/**/{0,1}*.md"),
copy(Refs["Go-SCP-jaJP"], "src/**/*.md"),
]);
}
function updateReference() {
const README = fs.readFileSync(path.join(__dirname, "README.md"), "utf-8");
const refs = Object.keys(Refs).map(key => {
const repoInfo = Refs[key];
return `- [${repoInfo.name}](${repoInfo.url})
- License: ${repoInfo.license}`
}).join("\n");
const addContent = `このコーパスは次の文書を含んでいます。
それぞれの文書のライセンスに基づき再配布されています。
${refs}`;
const newContent = addTextToMarkdown(README, addContent, "References");
fs.writeFileSync(path.join(__dirname, "README.md"), newContent, "utf-8");
}
// main
(async function () {
await copyTask();
updateReference();
})();