-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
54 lines (48 loc) · 1.46 KB
/
init.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
const fs = require('fs/promises');
const repo = process.env.GITHUB_REPOSITORY;
const slash_index = repo.indexOf('/');
const owner = repo.substring(0, slash_index);
const repo_name = repo.substring(slash_index+1);
/**
* replace ${{#name#}} in data with value
* @param {string} data
* @param {string} name
* @param {string} value
* @return {string}
*/
function fillReplace(data, name, value) {
return data.replace(new RegExp('\\$\\{\\{#' + name + '#\\}\\}', 'g'), value);
}
/**
* fill out the file
* @param {string} file
*/
async function apply(file) {
let data = (await fs.readFile(file)).toString();
data = fillReplace(data, 'REPO_NAME', repo_name);
data = fillReplace(data, 'REPO_OWNER', owner);
data = fillReplace(data, 'REPO_FULLNAME', repo);
fs.writeFile(file, data);
}
/**
* moves a .template file
* @param {string} file
*/
async function moveTemplate(file) {
await fs.unlink(file).catch(() => {});
await fs.rename(file + '.template', file);
}
async function init() {
await moveTemplate('README.md');
await moveTemplate('.github/ISSUE_TEMPLATE/bug_report.yml');
await moveTemplate('.github/ISSUE_TEMPLATE/feature_request.yml');
await apply('README.md');
await apply('package.json');
await apply('package-lock.json');
await apply('LICENSE');
await apply('.github/ISSUE_TEMPLATE/bug_report.yml');
await apply('.github/ISSUE_TEMPLATE/feature_request.yml');
await apply('nodes/README.md');
await apply('credentials/README.md');
}
init();