当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript recursive-readdir.default方法代码示例

本文整理汇总了TypeScript中recursive-readdir.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript recursive-readdir.default方法的具体用法?TypeScript recursive-readdir.default怎么用?TypeScript recursive-readdir.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在recursive-readdir的用法示例。


在下文中一共展示了recursive-readdir.default方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

;(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()
//.........这里部分代码省略.........
开发者ID:MsDacia,项目名称:msdacia,代码行数:101,代码来源:deploy.ts

示例2: 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;
    }
开发者ID:Arbitrage0,项目名称:augur-core,代码行数:30,代码来源:ContractCompiler.ts

示例3: Promise

  return new Promise((resolve, reject) => {
    readdir(dir, ignore, (err, files) => {
      if (err) {
        return reject(err);
      }

      resolve(files);
    });
  });
开发者ID:mrmlnc,项目名称:yellfy-pug-inheritance,代码行数:9,代码来源:inheritance.ts

示例4: Promise

 return new Promise((resolve, reject) => {
     recursive(baseDir, (err: any, files: any) => {
         if (err) {
             reject(err);
         } else {
             resolve(files);
         }
     });
 });
开发者ID:mickaelmarchal,项目名称:photo-sorter,代码行数:9,代码来源:fileUtils.ts

示例5: 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();
    });
  }, () => {
开发者ID:alphafork,项目名称:Game-Engine-superpowers-core,代码行数:53,代码来源:loadSystems.ts

示例6: 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;
    }
开发者ID:Arbitrage0,项目名称:augur-core,代码行数:49,代码来源:ContractCompiler.ts

示例7: Promise

 return new Promise((resolve, reject) => {
     recursiveReaddir(path, (err, data) => {
         if (err) reject(err);
         resolve(data);
     });
 });
开发者ID:pumlhorse,项目名称:pumlhorse,代码行数:6,代码来源:asyncFs.ts


注:本文中的recursive-readdir.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。