本文整理汇总了TypeScript中recursive-readdir类的典型用法代码示例。如果您正苦于以下问题:TypeScript recursive-readdir类的具体用法?TypeScript recursive-readdir怎么用?TypeScript recursive-readdir使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了recursive-readdir类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generateCompilerInput
public async generateCompilerInput(): Promise<CompilerInput> {
const ignoreFile = function(file: string, stats: fs.Stats): boolean {
return file.indexOf("legacy_reputation") > -1 || (stats.isFile() && path.extname(file) !== ".sol");
}
const filePaths = await recursiveReadDir(this.configuration.contractSourceRoot, [ignoreFile]);
const filesPromises = filePaths.map(async filePath => (await readFile(filePath)).toString('utf8'));
const files = await Promise.all(filesPromises);
let inputJson: CompilerInput = {
language: "Solidity",
settings: {
optimizer: {
enabled: true,
runs: 500
},
outputSelection: {
"*": {
"*": [ "abi", "evm.bytecode.object" ]
}
}
},
sources: {}
};
for (var file in files) {
const filePath = filePaths[file].replace(this.configuration.contractSourceRoot, "").replace(/\\/g, "/");
inputJson.sources[filePath] = { content : files[file] };
}
return inputJson;
}
示例2: Promise
return new Promise((resolve, reject) => {
readdir(dir, ignore, (err, files) => {
if (err) {
return reject(err);
}
resolve(files);
});
});
示例3: Promise
return new Promise((resolve, reject) => {
recursive(baseDir, (err: any, files: any) => {
if (err) {
reject(err);
} else {
resolve(files);
}
});
});
示例4: catch
async.eachSeries(fs.readdirSync(SupCore.systemsPath), (systemFolderName, cb) => {
if (systemFolderName.indexOf(".") !== -1) { cb(); return; }
const systemPath = path.join(SupCore.systemsPath, systemFolderName);
if (!fs.statSync(systemPath).isDirectory()) { cb(); return; }
const systemId = JSON.parse(fs.readFileSync(path.join(SupCore.systemsPath, systemFolderName, "package.json"), { encoding: "utf8" })).superpowers.systemId;
SupCore.system = SupCore.systems[systemId] = new SupCore.System(systemId, systemFolderName);
// Expose public stuff
try { fs.mkdirSync(`${systemPath}/public`); } catch (err) { /* Ignore */ }
mainApp.use(`/systems/${systemId}`, express.static(`${systemPath}/public`));
buildApp.use(`/systems/${systemId}`, express.static(`${systemPath}/public`));
// Write templates list
let templatesList: string[] = [];
const templatesFolder = `${systemPath}/public/templates`;
if (fs.existsSync(templatesFolder)) templatesList = fs.readdirSync(templatesFolder);
fs.writeFileSync(`${systemPath}/public/templates.json`, JSON.stringify(templatesList, null, 2));
// Load plugins
const pluginsInfo = loadPlugins(systemId, `${systemPath}/plugins`, mainApp, buildApp);
const packagePath = `${systemPath}/package.json`;
if (fs.existsSync(packagePath)) {
const packageJSON = JSON.parse(fs.readFileSync(packagePath, { encoding: "utf8" }));
if (packageJSON.superpowers != null && packageJSON.superpowers.publishedPluginBundles != null)
pluginsInfo.publishedBundles = pluginsInfo.publishedBundles.concat(packageJSON.superpowers.publishedPluginBundles);
}
fs.writeFileSync(`${systemPath}/public/plugins.json`, JSON.stringify(pluginsInfo, null, 2));
// Build files
const buildFiles: string[] = buildFilesBySystem[systemId] = [ "/SupCore.js" ];
for (const plugin of pluginsInfo.list) {
for (const bundleName of pluginsInfo.publishedBundles) {
buildFiles.push(`/systems/${systemId}/plugins/${plugin}/bundles/${bundleName}.js`);
}
}
readdirRecursive(`${systemPath}/public`, (err, entries) => {
for (const entry of entries) {
const relativePath = path.relative(`${systemPath}/public`, entry);
if (relativePath === "manifest.json") continue;
if (relativePath.slice(0, "templates".length) === "templates") continue;
if (relativePath.slice(0, "locales".length) === "templates") continue;
buildFiles.push(`/systems/${systemId}/${relativePath}`);
}
cb();
});
}, () => {
示例5: compileContracts
public async compileContracts(): Promise<CompilerOutput> {
// Check if all contracts are cached (and thus do not need to be compiled)
try {
const stats = await fs.stat(this.configuration.contractOutputPath);
const lastCompiledTimestamp = stats.mtime;
const ignoreCachedFile = function(file: string, stats: fs.Stats): boolean {
return (stats.isFile() && path.extname(file) !== ".sol") || (stats.isFile() && path.extname(file) === ".sol" && stats.mtime < lastCompiledTimestamp);
}
const uncachedFiles = await recursiveReadDir(this.configuration.contractSourceRoot, [ignoreCachedFile]);
if (uncachedFiles.length === 0) {
return JSON.parse(await fs.readFile(this.configuration.contractOutputPath, "utf8"));
}
} catch {
// Unable to read compiled contracts output file (likely because it has not been generated)
}
console.log('Compiling contracts, this may take a minute...');
// Compile all contracts in the specified input directory
const compilerInputJson = await this.generateCompilerInput();
const compilerOutputJson = compileStandardWrapper(JSON.stringify(compilerInputJson));
const compilerOutput: CompilerOutput = JSON.parse(compilerOutputJson);
if (compilerOutput.errors) {
let errors = "";
for (let error of compilerOutput.errors) {
// FIXME: https://github.com/ethereum/solidity/issues/3273
if (error.message.includes("instruction is only available after the Metropolis hard fork")) continue;
errors += error.formattedMessage + "\n";
}
if (errors.length > 0) {
throw new Error("The following errors/warnings were returned by solc:\n\n" + errors);
}
}
// Create output directory (if it doesn't exist)
await asyncMkdirp(path.dirname(this.configuration.contractOutputPath));
// Output contract data to single file
const filteredCompilerOutput = this.filterCompilerOutput(compilerOutput);
await fs.writeFile(this.configuration.contractOutputPath, JSON.stringify(filteredCompilerOutput, null, '\t'));
// Output abi data to a single file
const abiOutput = this.generateAbiOutput(filteredCompilerOutput);
await fs.writeFile(this.configuration.abiOutputPath, JSON.stringify(abiOutput, null, '\t'));
return filteredCompilerOutput;
}
示例6: Listr
;(async function (){
const answers = await inquirer.prompt<{ password: string, username: string }>([
{
default: 'msdacia',
message: 'User Name:',
name: 'username',
type: 'input'
},
{
message: 'Password:',
name: 'password',
type: 'password'
}
])
const { username, password } = answers
const sftp = new SftpClient()
const createQueue = async.queue<CreatePayload, Error>(({ observer, remotePath, title }, callback) => {
createQueue.drain = () => observer.complete()
observer.next(title)
sftp.mkdir(remotePath, true).then(() => callback()).catch(callback)
})
const uploadQueue = async.priorityQueue<UploadPayload, Error>(({ localPath, observer, remotePath, title }, callback) => {
uploadQueue.drain = () => observer.complete()
const remainingCount = uploadQueue.length()
const inProgressTitles = uploadQueue.workersList()
.map(worker => worker.data.title)
.sort()
.map(title => title.length <= 27 ? title : `${title.substr(0, 12)}...${title.slice(-12)}`)
const message = inProgressTitles.join(', ') + (remainingCount ? ` + ${remainingCount} more` : '')
observer.next(message)
sftp.put(localPath, remotePath, true).then(() => callback()).catch(callback)
}, 4)
const deleteQueue = async.queue<DeletePayload, Error>(({ observer, remotePath, title }, callback) => {
deleteQueue.drain = () => observer.complete()
observer.next(title)
sftp.delete(remotePath).then(() => callback()).catch(callback)
})
try {
await sftp.connect({ host: HOST, username, password })
const [localFiles, remoteFiles] = await Promise.all([
(await readdir('dist')).map(file => path.relative('dist', file)).map(file => path.posix.format(path.parse(file))),
(await readdirRemote(sftp, DEPLOY_DIR)).map(file => path.posix.relative(DEPLOY_DIR, file)),
])
const remoteFilesToDelete = getRemoteFilesToDelete(remoteFiles, localFiles)
const remoteDirectoriesToCreate = getRequiredDirectories(localFiles)
const createObserver = new Observable<string>(observer => {
for (const directory of remoteDirectoriesToCreate) {
const remotePath = path.posix.join(DEPLOY_DIR, directory)
createQueue.push({ observer, remotePath, title: directory })
}
})
const uploadObserver = new Observable<string>(observer => {
for (const file of localFiles) {
const localPath = path.resolve(path.join('dist', file))
const remotePath = path.posix.join(DEPLOY_DIR, file)
const payload: UploadPayload = {
localPath,
observer,
remotePath,
title: file,
}
uploadQueue.push(payload, getUploadPriority(file))
}
})
const deleteObserver = new Observable<string>(observer => {
for (const file of remoteFilesToDelete) {
const remotePath = path.posix.join(DEPLOY_DIR, file)
deleteQueue.push({ observer, remotePath, title: file })
}
})
await new Listr([
{
title: `Creating ${remoteDirectoriesToCreate.length} Directories`,
task: () => createObserver as any,
skip: () => remoteDirectoriesToCreate.length === 0 ? 'No directories to create' : '',
},
{
title: `Uploading ${localFiles.length} File(s)`,
task: () => uploadObserver as any,
skip: () => localFiles.length === 0 ? 'No files to upload' : '',
},
{
title: `Deleting ${remoteFilesToDelete.length} File(s)`,
task: () => deleteObserver as any,
skip: () => remoteFilesToDelete.length === 0 ? 'No files to delete' : '',
},
]).run()
//.........这里部分代码省略.........
示例7: Promise
return new Promise((resolve, reject) => {
recursiveReaddir(path, (err, data) => {
if (err) reject(err);
resolve(data);
});
});