fs.readFileSync(gitignorePath, "utf8") .split(/\r?\n/) .map((sourceLine) => { sourceLine = sourceLine.trim() if (sourceLine !== "") { return sourceLine.startsWith("/") ? sourceLine.slice(1) : "**/" + sourceLine } return sourceLine }) .filter(Boolean)
function cleanJS() { for (const filename of jsPaths) { const content = fs.readFileSync(filename, "utf8") process.once("exit", () => fs.outputFileSync(filename, content)) fs.outputFileSync(filename, minifyJS(content)) } }
function readmeContent() { if (!fs.existsSync(readmePath)) throw new Error(`Cannot find ${readmePath}`); return fs.readFileSync(readmePath, 'utf8'); }
function updateGradleConfig() { let content = fs.readFileSync(`${rnDir}/android/app/build.gradle`, 'utf8'); content = increaseGradleVersionCode(content); content = increaseGradleVersionName(content); fs.writeFileSync(`${rnDir}/android/app/build.gradle`, content); return content; }
writeSideBar(renderer: RendererEvent, docusarusRoot: string) { const childDirectory = renderer.outputDirectory.split(docusarusRoot + 'docs/')[1]; const docsRoot = childDirectory ? childDirectory + '/' : ''; const websitePath = docusarusRoot + 'website'; const packageName = renderer.project.packageInfo.name; const navObject = this.getNavObject(renderer, docsRoot); const sidebarPath = websitePath + '/sidebars.json'; let contents: any; if (!fs.existsSync(sidebarPath)) { contents = '{}'; if (!fs.existsSync(websitePath)) { fs.mkdirSync(websitePath); } } else { contents = fs.readFileSync(sidebarPath); } const jsonContent = JSON.parse(contents.toString()); const update = { ...jsonContent, [packageName]: navObject, }; try { fs.writeFileSync(sidebarPath, JSON.stringify(update, null, 2)); this.application.logger.write(`[typedoc-plugin-markdown] sidebars.json updated at ${sidebarPath}`); } catch (e) { this.application.logger.write(`[typedoc-plugin-markdown] failed to update sidebars.json at ${sidebarPath}`); } }
function makeHomePageMd() { let md = fs.readFileSync(`${rootDir}/README.md`, 'utf8'); md = md.replace(tocRegex_, ''); // HACK: GitHub needs the \| or the inline code won't be displayed correctly inside the table, // while MarkdownIt doesn't and will in fact display the \. So we remove it here. md = md.replace(/\\\| bash/g, '| bash'); return md; }
async function parseNoteFile(filePath) { const n = basename(filePath); const number = n.split('_')[0]; const body = fs.readFileSync(filePath, 'utf8'); const title = `${number}. ${body.split('\n')[0].substr(2)}`; const resources = {}; const imagePaths = markdownUtils.extractImageUrls(body); for (let i = 0; i < imagePaths.length; i++) { const imagePath = imagePaths[i]; const fullImagePath = `${welcomeDir}/${imagePath}`; const base64 = fileToBase64(fullImagePath); resources[imagePath] = { id: itemIdFromPath(fullImagePath), body: base64, }; } return { id: itemIdFromPath(filePath), title: title, body: body, tags: noteTags(filePath), resources: resources, }; }
includesPath = path.join(this.includes!, includesPath.trim()); if (fs.existsSync(includesPath) && fs.statSync(includesPath).isFile()) { const contents = fs.readFileSync(includesPath, 'utf-8'); if (includesPath.substr(-4).toLocaleLowerCase() === '.hbs') { const template = Handlebars.compile(contents);
function fileToBase64(filePath) { const content = fs.readFileSync(filePath); return Buffer.from(content).toString('base64'); }
function cleanPackageJSON() { const content = fs.readFileSync(pkgPath, "utf8") process.once("exit", () => fs.outputFileSync(pkgPath, content)) const pkgJSON = JSON.parse(content) for (const field of fieldsToRemove) { Reflect.deleteProperty(pkgJSON, field) } pkgJSON.scripts = defaultScripts fs.outputFileSync(pkgPath, fleece.patch(content, pkgJSON)) }
function parsePoFile(filePath) { const content = fs.readFileSync(filePath); return gettextParser.po.parse(content); }
function tocMd() { if (tocMd_) return tocMd_; const md = fs.readFileSync(`${rootDir}/README.md`, 'utf8'); const toc = md.match(tocRegex_); tocMd_ = toc[1]; return tocMd_; }
function renderFileToHtml(sourcePath, targetPath, templateParams) { const md = fs.readFileSync(sourcePath, 'utf8'); return renderMdToHtml(md, targetPath, templateParams); }
function cleanReadme() { const content = fs.readFileSync(readmePath, "utf8") process.once("exit", () => fs.outputFileSync(readmePath, content)) fs.outputFileSync(readmePath, content.replace(tableRegExp, minifyHTML)) }
function cleanJS() { for (const filename of jsPaths) { const content = fs.readFileSync(filename, "utf8") process.once("exit", () => fs.outputFileSync(filename, content)) fs.outputFileSync(filename, minifyJS(content)) } }