64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.updateReadmeFile = void 0;
|
|
const fs_1 = require("fs");
|
|
function updateReadmeFile(fileList) {
|
|
let readmeFile = getReadmeFileName();
|
|
if (readmeFile !== null) {
|
|
let [readmeStart, readmeEnd] = readReadmeFile(readmeFile);
|
|
let installLinks = fileList.map(readmeDataToString).join('\n');
|
|
let installLinksAll = `<!-- START INSTALL LINKS -->
|
|
## Installs
|
|
|
|
${installLinks}
|
|
<!-- END INSTALL LINKS -->`;
|
|
console.log(JSON.stringify(installLinksAll));
|
|
let content = readmeStart + installLinksAll + readmeEnd;
|
|
(0, fs_1.writeFileSync)(readmeFile, content);
|
|
}
|
|
}
|
|
exports.updateReadmeFile = updateReadmeFile;
|
|
function readmeDataToString(readmeData) {
|
|
let { meta, error } = readmeData;
|
|
let errStr = error !== null ? '~~' : '';
|
|
let errMsg = error !== null ? `\n - ${error}` : '';
|
|
return `- ${errStr}[${meta.name}](${meta.downloadURL})})${errStr}${errMsg}`;
|
|
}
|
|
function getReadmeFileName() {
|
|
let files = (0, fs_1.readdirSync)('.');
|
|
for (let 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 {
|
|
let content_replace = content.replace(regex, '');
|
|
contentPre = content_replace.slice(0, index);
|
|
contentPost = content_replace.slice(index);
|
|
}
|
|
if (!contentPre.endsWith('\n')) {
|
|
contentPre += '\n';
|
|
}
|
|
if (!contentPre.endsWith('\n\n')) {
|
|
contentPre += '\n';
|
|
}
|
|
if (!contentPost.startsWith('\n')) {
|
|
contentPost += '\n';
|
|
}
|
|
if (!contentPost.startsWith('\n\n')) {
|
|
contentPre += '\n';
|
|
}
|
|
console.log(JSON.stringify(index), JSON.stringify(content), JSON.stringify(contentPre), JSON.stringify(contentPost));
|
|
return [contentPre, contentPost];
|
|
}
|
|
//# sourceMappingURL=readmefile.js.map
|