Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const read = async (directory: string) => {
const stream = readdirp(directory, { type: 'all' });
let i = 0;
for await (const chunk of stream) {
// Check memory usage with this line. It should be 10MB or so.
// Comment it out if you simply want to list files.
await new Promise(resolve => setTimeout(resolve, 500));
console.log(`${++i}: ${chunk.path}`);
}
console.log('Stream done', i);
const entries = await readdirp.promise(directory);
console.log('Promise done', entries.map(e => e.path));
};
const cacheWidgetManifests = function(done) {
widgetManifestCache = {};
readdirp(
// Cache all of the widget config files under packages
path.join(uiDirectory, 'packages'),
{
// Only recurse in folders that contain widgets
directoryFilter: _widgetDirectoryFilter,
// We're only interested in the manifest files
fileFilter: 'manifest.json'
}
)
.on('data', entry => {
// Extract the widget id from the path
const widgetId = entry.path
.split(path.sep)
.splice(1, 1)
.join();
const dstPackInode = lnkModSrcDst.dstPackInode;
const dstPackMTimeEpoch = lnkModSrcDst.dstPackMTimeEpoch;
if (updatePackRefs) {
let packRefs = rtenv.updatedPackRefs[devNameVer] || [];
if (!packRefs.length) {
packRefs.push(buildPackRef(srcRoot, srcPackInode, srcPackMTimeEpoch));
}
packRefs = packRefs.filter(packRef => packRef[0] !== dstRoot);
if (packRefs.length < config.refSize) {
packRefs.push(buildPackRef(dstRoot, dstPackInode, dstPackMTimeEpoch));
}
rtenv.updatedPackRefs[devNameVer] = packRefs;
}
const fstream = readdirp({
root: lnkModSrcDst.src,
entryType: 'files',
lstat: true, // want actual files not symlinked
fileFilter: ['!.*'],
directoryFilter: ['!.*', '!node_modules']
});
fstream.once('end', () => {
rtenv.completedPackages += 1;
logUpdate();
});
rtenv.cancelled$.subscribe(() => fstream.destroy()); // stop reading
return Observable.fromEvent(fstream, 'data')
.takeWhile(() => !rtenv.cancelled)
.takeUntil(Observable.fromEvent(fstream, 'close'))
.takeUntil(Observable.fromEvent(fstream, 'end'))
return new Promise((resolve) => {
const fm = []
readdirp(p, { fileFilter: '*.mdx' })
.on('data', (entry) => {
let lineNum = 0
const content = []
fm.push(
new Promise((resolve2, reject2) => {
lineReader.eachLine(
entry.fullPath,
(line) => {
// if it has any content other than `---`, the file doesn't have front matter, so we close
if (lineNum === 0 && !line.match(/^---$/)) return false
// if it's not the first line and we have a bottom delimiter, exit
if (lineNum !== 0 && line.match(/^---$/)) return false
// now we read lines until we match the bottom delimiters
content.push(line)
// increment line number
lineNum++
startDir => {
const readdirpOptions = {
root: startDir,
entryType: 'files',
lstat: true, // want actual files not symlinked
fileFilter: ['package.json'],
directoryFilter: filterDirsNodeModPacks
};
if (config.treeDepth) { readdirpOptions.depth = config.treeDepth; }
const fstream = readdirp(readdirpOptions);
rtenv.cancelled$.subscribe(() => fstream.destroy()); // stop reading
return Observable.fromEvent(fstream, 'data')
.takeWhile(() => !rtenv.cancelled)
.takeUntil(Observable.fromEvent(fstream, 'close'))
.takeUntil(Observable.fromEvent(fstream, 'end'));
},
config.concurrentOps
let blockCommentPrivate = /\/\*\*([^](?!\*\/))*@module([^](?!\*\/))*@private[^]*?\*\//g;
if (blockCommentPrivate.test(content)) {
return { shouldDelete: true };
}
let newContent = content;
newContent = newContent.replace(/\/\/[\/\s]*@private[^]*?\/\/[\/\s]*?@endprivate/gm, "");
if (newContent !== content) {
return { shouldReplace: true, newContent: newContent };
}
return { shouldReplace: false, shouldDelete: false };
}
readdirp(inputFolder, {
fileFilter: ["*.d.ts"],
directoryFilter: function (di) { return !di.path.includes("node_modules"); }
}).on("data", (entry: EntryInfo) => {
const { fullPath } = entry;
const content = fs.readFileSync(fullPath, "utf8");
const { shouldDelete, shouldReplace, newContent } = filterTypeScriptFiles(content);
if (shouldDelete) {
console.log("[Delete]", fullPath);
fs.unlinkSync(fullPath);
} else if (shouldReplace) {
console.log("[Cleared]", fullPath);
try {
fs.writeFileSync(fullPath, newContent, "utf8");
} catch (error) {
console.log("ERROR writing file: " + fullPath, error);
return new Promise((resolve, reject) => {
const paths = []
readdirp({ root: this.baseDir, fileFilter: 'socket.yml' })
.on('data', (entry) => {
paths.push(entry.fullPath)
})
.on('end', () => {
resolve(paths)
})
.on('error', (err) => {
reject(err)
})
})
}