90 lines
2.9 KiB
JavaScript
90 lines
2.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.updateReadmeFile = updateReadmeFile;
|
|
const fs_1 = require("fs");
|
|
function updateReadmeFile(fileList) {
|
|
const readmeFile = getReadmeFileName();
|
|
if (readmeFile !== null) {
|
|
const [readmeStart, readmeEnd] = readReadmeFile(readmeFile);
|
|
const installLinks = fileList.map(readmeDataToString).join('\n');
|
|
const installLinksAll = `<!-- START INSTALL LINKS -->
|
|
## Installs
|
|
|
|
${installLinks}
|
|
<!-- END INSTALL LINKS -->`;
|
|
const content = readmeStart + installLinksAll + readmeEnd;
|
|
(0, fs_1.writeFileSync)(readmeFile, content);
|
|
}
|
|
}
|
|
function readmeDataErrorString(error) {
|
|
if (error === null)
|
|
return '';
|
|
error = error
|
|
.split('\n')
|
|
.map(line => ` ${line}`)
|
|
.join('\n');
|
|
return `\n\n${error}`;
|
|
}
|
|
function arrayify(val) {
|
|
const newval = Array.isArray(val) ? val : [val];
|
|
return newval.map(v => v.trim()).filter(v => v);
|
|
}
|
|
function readmeDataMatches(meta) {
|
|
const matches = arrayify(meta.match).map(v => '`' + v + '`');
|
|
const matchesStr = `
|
|
- ${matches.join(',')}`;
|
|
if (matches.length === 0) {
|
|
return '';
|
|
}
|
|
const excludes = arrayify(meta.excludematch).map(v => '`' + v + '`');
|
|
const excludesStr = `
|
|
- excluding: ${excludes.join(',')}`;
|
|
if (excludes.length === 0) {
|
|
return matchesStr;
|
|
}
|
|
return matchesStr + excludesStr;
|
|
}
|
|
function readmeDataToString(results) {
|
|
const { meta, error } = results;
|
|
const errStr = error !== null ? '~~' : '';
|
|
const errMsg = readmeDataErrorString(error);
|
|
const matchesStr = readmeDataMatches(meta);
|
|
return `
|
|
- ${errStr}[${meta.name}](${meta.downloadURL})${errStr}${errMsg}
|
|
- **${meta.namespace}** v${meta.version}${matchesStr}
|
|
- ${meta.description}
|
|
`.trim();
|
|
}
|
|
function getReadmeFileName() {
|
|
const files = (0, fs_1.readdirSync)('.');
|
|
for (const name of files) {
|
|
if (/^readme\.md$/i.test(name)) {
|
|
return name;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
function readReadmeFile(readmeFile) {
|
|
const content = (0, fs_1.readFileSync)(readmeFile).toString();
|
|
const regex = /<!-- START INSTALL LINKS -->(?:.|\n)*?<!-- END INSTALL LINKS -->/;
|
|
const index = regex.exec(content)?.index;
|
|
let contentPre = '', contentPost = '';
|
|
if (index === undefined) {
|
|
contentPre = content;
|
|
}
|
|
else {
|
|
const content_replace = content.replace(regex, '');
|
|
contentPre = content_replace.slice(0, index);
|
|
contentPost = content_replace.slice(index);
|
|
}
|
|
if (contentPre.trimEnd().length === 0)
|
|
contentPre = '';
|
|
else
|
|
contentPre = contentPre.trimEnd() + '\n\n';
|
|
if (contentPost.trimStart().length === 0)
|
|
contentPost = '\n';
|
|
else
|
|
contentPost = '\n\n' + contentPost.trimStart();
|
|
return [contentPre, contentPost];
|
|
}
|
|
//# sourceMappingURL=readmefile.js.map
|