本文整理汇总了TypeScript中fs-extra.readdir函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readdir函数的具体用法?TypeScript readdir怎么用?TypeScript readdir使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readdir函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: found
(async () => {
const dirsToCheck = [];
for (const subDir of await fs.readdir(PACKAGES_DIR)) {
for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
dirsToCheck.push(path.resolve(PACKAGES_DIR, subDir, packageDir));
}
}
let bad = false;
for (const dir of dirsToCheck) {
const pj = await fs.readJson(path.resolve(dir, 'package.json'));
if (pj.name === '@electron-forge/cli') continue;
if (!await fs.pathExists(path.resolve(dir, pj.main))) {
console.error(`${`[${pj.name}]`.cyan}:`, `Main entry not found (${pj.main})`.red);
bad = true;
}
if (!pj.typings || !await fs.pathExists(path.resolve(dir, pj.typings))) {
console.error(`${`[${pj.name}]`.cyan}:`, `Typings entry not found (${pj.typings})`.red);
bad = true;
}
}
if (bad) {
process.exit(1);
}
})().catch(console.error);
示例2: it
it('should create dry run hash JSON files', async () => {
expect(makeStub.callCount).to.equal(2);
const dryRunFolder = path.resolve(dir, 'out', 'publish-dry-run');
expect(await fs.pathExists(dryRunFolder)).to.equal(true);
const hashFolders = await fs.readdir(dryRunFolder);
expect(hashFolders).to.have.length(2, 'Should contain two hashes (two publishes)');
for (const hashFolderName of hashFolders) {
const hashFolder = path.resolve(dryRunFolder, hashFolderName);
const makes = await fs.readdir(hashFolder);
expect(makes).to.have.length(3, 'Should contain the results of three makes');
for (const makeJson of makes) {
const jsonPath = path.resolve(hashFolder, makeJson);
const contents = await fs.readFile(jsonPath, 'utf8');
expect(() => JSON.parse(contents), 'Should be valid JSON').to.not.throw();
const data = JSON.parse(contents);
expect(data).to.have.property('artifacts');
expect(data).to.have.property('platform');
expect(data).to.have.property('arch');
expect(data).to.have.property('packageJSON');
// Make the artifacts for later
for (const artifactPath of data.artifacts) {
await fs.mkdirp(path.dirname(path.resolve(dir, artifactPath)));
await fs.writeFile(path.resolve(dir, artifactPath), artifactPath);
}
}
}
});
示例3: function
export const refresh = async function () {
const paths = await ConfigService.getPaths();
const versions = [];
for (const path of paths) {
const versionPaths = [
npath.join(path, 'versions'),
npath.join(path, '.minecraft', 'versions'),
npath.join(path, 'minecraft', 'versions'),
]
let versionPath = '';
for (versionPath of versionPaths) {
if (await fs.pathExists(versionPath)) {
break;
}
}
if (!versionPath) {
continue;
}
const dirs = await fs.readdir(versionPath);
for (const dir of dirs) {
const detailPath = npath.join(versionPath, dir);
const stat = await fs.stat(detailPath);
if (!stat.isDirectory()) continue;
const files = await fs.readdir(detailPath);
if (!files.some((file) => !!file.match(/.json$/))) {
continue;
}
let jsonFile;
let json;
for (const file of files) {
if (!file.endsWith('.json')) continue;
const path = npath.join(detailPath, file);
let content = await fs.readFile(path, 'utf8');
try {
content = JSON.parse(content);
} catch (e) {}
if (content && content['minecraftArguments']) {
jsonFile = path;
json = content;
break;
}
}
versions.push({
name: dir,
versionPath: detailPath,
minecraftPath: npath.join(versionPath, '..'),
jsonFile,
json,
});
}
}
return versions;
}
示例4:
(async () => {
const dirsToLink = [];
for (const subDir of await fs.readdir(PACKAGES_DIR)) {
for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
dirsToLink.push(path.resolve(PACKAGES_DIR, subDir, packageDir));
}
}
for (const dir of dirsToLink) {
await fs.copy(path.resolve(BASE_DIR, 'tsconfig.json'), path.resolve(dir, 'tsconfig.json'));
await fs.copy(path.resolve(BASE_DIR, 'tslint.json'), path.resolve(dir, 'tslint.json'));
}
})();
示例5:
return Promise.resolve().then(() => {
let data = _.cloneDeep(tree);
if (data.numberOfUsers === 0)
return data;
else {
let promises: Promise<void>[] = [];
for (let steamDirectory in data.tree) {
for (let userId in data.tree[steamDirectory]) {
promises.push(
fs.readdir(path.join(steamDirectory, 'userdata', userId, 'config', 'grid')).then((files) => {
let extRegex = /png|tga|jpg|jpeg/i;
for (let i = 0; i < files.length; i++) {
let ext = path.extname(files[i]);
let appId = path.basename(files[i], ext);
if (data.tree[steamDirectory][userId][appId] === undefined) {
if (extRegex.test(ext))
data.tree[steamDirectory][userId][appId] = path.join(steamDirectory, 'userdata', userId, 'config', 'grid', files[i]);
}
}
}).catch((error) => {
if (error.code !== 'ENOENT')
throw error;
})
);
}
}
return Promise.all(promises).then(() => data);
}
});
示例6: resolve
readDirectory: (dir, callback) => {
fs.readdir(dir, (err, listing) => {
if (err) return callback(err);
const statPromises = listing
// Take away dot-files and directories, we won't list those
.filter(name => name.charAt(0) !== ".")
// Map them onto promises that will return the output info for each entry
.map(name => new Promise((resolve, reject) => {
getFileOutputInfo(dir + path.sep + name, (err, info) => {
if (err) return reject(err);
return resolve(info)
});
}));
Promise.all(statPromises).then(
resolution => callback(null, resolution),
rejection => callback(rejection)
);
});
},
示例7: downloadSeriesAsync
await mio.usingAsync(mio.Browser.createAsync(), async browser => {
let fileNames = await fs.readdir(shared.path.normal());
for (let fileName of fileNames) {
let fileExtension = path.extname(fileName);
if (fileExtension === shared.extension.json) {
let metaProviderPath = shared.path.normal(fileName);
let metaProvider = await fs.readJson(metaProviderPath) as shared.IMetaProvider;
for (let url in metaProvider) {
let timer = new mio.Timer();
let awaiter = mio.scrapeAsync(browser, url);
if (awaiter) {
console.log(`Awaiting ${url}`);
await mio.usingAsync(awaiter, async series => {
if (series.title !== metaProvider[url]) throw new Error(`Series at ${url} property changed: title`)
if (series.url !== url) throw new Error(`Series at ${url} property changed: url`);
console.log(`Fetching ${series.title}`);
await mio.commands.updateSeriesAsync(series);
await downloadSeriesAsync(series);
console.log(`Finished ${series.title} (${timer})`);
});
} else {
console.log(`Rejected ${url}`);
}
}
}
}
});
示例8: function
router.get("/listsearch", function (req: any, res: any) {
//var glob = require("glob")
fs.readdir(appRoot + "\\nodulus_modules\\", function (err: any, files: Array<string>) {
var arrRes: Array<any> = [];
for (var i = 0; i < files.length; i++) {
if (files[i].indexOf(".zip") > -1 && files[i].indexOf(req.query.name) > -1)
arrRes.push(files[i].replace(".zip", ""))
}
res.json(arrRes);
});
// // options is optional
// glob(appRoot + "\\nodulus_modules\\*" + req.query.name + "*/*.zip", function (er, files) {
// res.json(files);
// // files is an array of filenames.
// // If the `nonull` option is set, and nothing
// // was found, then files is ["**/*.js"]
// // er is an error object or null.
// })
});
示例9: readdir
export async function readdir(dir: string): Promise<string[]> {
try {
return await fs.readdir(dir);
} catch (e) {
return [];
}
}
示例10: read
public async read(): Promise<ObjectMap> {
let result: ObjectMap = {};
for (let file of await fs.readdir(this.path)) {
result[this.getId(file)] = await this.loadFile(join(this.path, file));
}
return result;
}