Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function getDocsForNodeVersion (major, version) {
const docDir = path.join(__dirname, `../content/${major}/en-US/doc`)
const tempDir = path.join(__dirname, `../temp/${major}`)
// TODO exit early if docs for this version have already been downloaded
// download repo bundle and extract to a temporary directory
const tarballUrl = `https://github.com/nodejs/node/archive/${version}.tar.gz`
console.log('downloading', tarballUrl)
await download(tarballUrl, tempDir, {extract: true})
// move docs from temp dir to this repo
const tempDocDir = path.join(tempDir, `node-${version.replace('v', '')}`, 'doc')
// removes files other than markdown
walk(tempDocDir, {directories: false})
.filter(file => path.extname(file.relativePath.toLowerCase()) !== '.md')
.forEach(file => fs.unlinkSync(path.join(tempDocDir, file.relativePath)))
await fs.copy(tempDocDir, docDir)
fs.remove(tempDir)
}
module.exports = function loadPages (jexConfig) {
const { pagesDirectory, pagesIncludePatterns: globs, pagesExcludePatterns: ignore } = jexConfig
const pages = walk(pagesDirectory, { globs, ignore, directories: false })
.map(entry => new Page(entry, jexConfig))
// add named keys to the array for fast object-like URL reference
for (const page of pages) {
page.permalinks.forEach(permalink => {
pages[permalink] = page
})
}
return pages
}
StubGenerator.prototype.build = function() {
var start = Date.now();
var inputPath = this.inputPaths[0];
var previous = this._previousTree;
// get patchset
var input = walkSync.entries(inputPath, [ '**/*.js' ]);
debug('input: %d', input.length);
var next = this._previousTree = FSTree.fromEntries(input);
var patchset = previous.calculatePatch(next);
debug('patchset: %d', patchset.length);
var applyPatch = Date.now();
// process patchset
patchset.forEach(function(patch) {
var operation = patch[0];
var path = patch[1];
var fullPath = inputPath + '/' + path;
build() {
let output = this.outputPath;
let input = this.inputPaths[0];
let { id, css } = this.transport;
// Test if anything has changed since last time. If not, skip trying to update tree.
let newFsTree = FSTree.fromEntries(walkSync.entries(input));
let diff = this.previous.calculatePatch(newFsTree);
// Auto-discover common preprocessor extensions.
if (!this._out) {
let prev = path.parse(path.join(input, this.out));
let origExt = prev.ext;
prev.base = ""; // Needed for path.format to register ext change
for (let ending of COMMON_FILE_ENDINGS) {
prev.ext = ending;
if (fs.existsSync(path.format(prev))) { break; }
prev.ext = origExt;
}
let out = path.parse(this.out);
out.base = ""; // Needed for path.format to register ext change
out.ext = prev.ext;
this._out = path.format(out);
private appendedPatchset() {
let input = walkSync.entries(this.appendedDir);
let passthroughEntries = input
.map(e => {
let first = e.relativePath.split('/')[0];
let remapped = this.passthrough.get(first);
if (remapped) {
let o = Object.create(e);
o.relativePath = e.relativePath.replace(new RegExp('^' + first), remapped);
o.isPassthrough = true;
o.originalRelativePath = e.relativePath;
return o;
}
}).filter(Boolean);
let previous = this.previousAppendedTree;
let next = (this.previousAppendedTree = FSTree.fromEntries(input));
return { patchset: previous.calculatePatch(next), passthroughEntries };
function updateNameByTitle (): void {
let files = walkSync.entries(savePath, { globs: ['**/*.md'], ignore: ['README.md'] })
files.forEach(function (file) {
let fileName = file.relativePath
let fileData = fs.readFileSync(savePath + fileName, 'utf8')
let firstLine = fileData.split('\n')[0]
let title = firstLine.replace(/#\s\d+\.\s/g, '')
let indexRegex = /#\s(\d+)\.\s/.exec(firstLine)
let oldIndex
if (!indexRegex) {
oldIndex = Utils.getIndexByString(fileName)
if (!oldIndex) {
return
}
} else {
oldIndex = indexRegex[1]
}
const getFolderEntries = module.exports.getFolderEntries = (path) => {
return walkSync.entries(path)
}
getDirectoryEntries(directory) {
return walkSync.entries(directory);
}
private appendedPatchset() {
let input = walkSync.entries(this.appendedDir);
let passthroughEntries = input
.map(e => {
let match = findByPrefix(e.relativePath, this.passthrough);
if (match) {
let o = Object.create(e);
o.relativePath = e.relativePath.replace(new RegExp('^' + match.prefix), match.mapsTo);
o.isPassthrough = true;
o.originalRelativePath = e.relativePath;
return o;
}
}).filter(e => e && e.relativePath !== './') as AugmentedWalkSyncEntry[];
let previous = this.previousAppendedTree;
let next = (this.previousAppendedTree = FSTree.fromEntries(input));
return { patchset: previous.calculatePatch(next), passthroughEntries };
}