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


TypeScript fs-extra-promise.readFileAsync函数代码示例

本文整理汇总了TypeScript中fs-extra-promise.readFileAsync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript readFileAsync函数的具体用法?TypeScript readFileAsync怎么用?TypeScript readFileAsync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: generate

async function generate(rootDir: string) {

    const pbconfigPath = path.join(rootDir, 'pbconfig.json');
    if (!(await fs.existsAsync(pbconfigPath))) {
        if (await fs.existsAsync(path.join(rootDir, 'protobuf'))) {
            const pbconfigPath = path.join(rootDir, 'protobuf', 'pbconfig.json')
            if (!await (fs.existsAsync(pbconfigPath))) {
                await fs.writeFileAsync(pbconfigPath, pbconfigContent, 'utf-8');
            }
            await generate(path.join(rootDir, 'protobuf'));
        }
        else {
            throw '请首先执行 pb-egret add 命令'
        }
        return;
    }
    const pbconfig: ProtobufConfig = await fs.readJSONAsync(path.join(rootDir, 'pbconfig.json'));
    const tempfile = path.join(os.tmpdir(), 'pbegret', 'temp.js');
    await fs.mkdirpAsync(path.dirname(tempfile));
    const output = path.join(rootDir, pbconfig.outputFile);
    const dirname = path.dirname(output);
    await fs.mkdirpAsync(dirname);
    const protoRoot = path.join(rootDir, pbconfig.sourceRoot);
    const fileList = await fs.readdirAsync(protoRoot);
    const protoList = fileList.filter(item => path.extname(item) === '.proto')
    if (protoList.length == 0) {
        throw ' protofile 文件夹中不存在 .proto 文件'
    }
    await Promise.all(protoList.map(async (protofile) => {
        const content = await fs.readFileAsync(path.join(protoRoot, protofile), 'utf-8')
        if (content.indexOf('package') == -1) {
            throw `${protofile} 中必须包含 package 字段`
        }
    }))




    const args = ['-t', 'static', '-p', protoRoot, protoList.join(" "), '-o', tempfile]
    if (pbconfig.options['no-create']) {
        args.unshift('--no-create');
    }
    if (pbconfig.options['no-verify']) {
        args.unshift('--no-verify');
    }
    await shell('pbjs', args);
    let pbjsResult = await fs.readFileAsync(tempfile, 'utf-8');
    pbjsResult = 'var $protobuf = window.protobuf;\n$protobuf.roots.default=window;\n' + pbjsResult;
    await fs.writeFileAsync(output, pbjsResult, 'utf-8');
    const minjs = UglifyJS.minify(pbjsResult);
    await fs.writeFileAsync(output.replace('.js', '.min.js'), minjs.code, 'utf-8');
    await shell('pbts', ['--main', output, '-o', tempfile]);
    let pbtsResult = await fs.readFileAsync(tempfile, 'utf-8');
    pbtsResult = pbtsResult.replace(/\$protobuf/gi, "protobuf").replace(/export namespace/gi, 'declare namespace');
    pbtsResult = 'type Long = protobuf.Long;\n' + pbtsResult;
    await fs.writeFileAsync(output.replace(".js", ".d.ts"), pbtsResult, 'utf-8');
    await fs.removeAsync(tempfile);

}
开发者ID:bestdpf,项目名称:protobuf-egret,代码行数:59,代码来源:index.ts

示例2: updateREADME

async function updateREADME() {

  const README_PATH = jd('../../README.md')
  const README_BUFFER = await fsep.readFileAsync(README_PATH)
  const README_CONTENTS = README_BUFFER.toString()
  const SOURCE_TREE = await sourceFolderTree()

  const commentMarker = c => `[//]: # (${c})`
  const START_MARKER = commentMarker('START_FILE_STRUCTURE')
  const END_MARKER = commentMarker('END_FILE_STRUCTURE')

  const t = '```'
  const pre =
`${START_MARKER}

${t}plaintext
${SOURCE_TREE}${t}

${END_MARKER}`

  const newReadme = replaceBetween(START_MARKER, END_MARKER)(README_CONTENTS, pre)

  await fsep.writeFileAsync(README_PATH, newReadme)

  log('Wrote new README sucessfulyl')

}
开发者ID:Edward-Lombe,项目名称:elm-electron,代码行数:27,代码来源:update-README.ts

示例3: it

 it('should create an array of queries', () => {
     return fs.readFileAsync(standardDb, 'utf8')
         .then((originalData) => {
             let queries = util.splitToQueries(originalData)
             assert.deepEqual(homogenizeNewline(queries), standardAsQueries)
         })
 })
开发者ID:yinso,项目名称:easydbi,代码行数:7,代码来源:exec-file.ts

示例4: doxygen

export function doxygen(req: express.Request, res: express.Response){
	res.set('Content-Type', 'text/xml');
	// this should really go through the file_manager lock - TODO
	fs.readFileAsync(paths.Bela+'Documentation/xml/'+req.query.file+'.xml', 'utf-8')
		.then( xml => res.send(xml) )
		.catch( () => res.status(500).send('file '+req.query.file+'.xml not found') );
}
开发者ID:BelaPlatform,项目名称:Bela,代码行数:7,代码来源:RouteManager.ts

示例5: readTranslation

async function readTranslation(
  cwd: string,
  dir: string,
  locale: string,
  feature: string
): Promise<Translation> {
  const readPath = join(cwd, dir, feature, `${locale}.properties`);

  debug(`Read from ${readPath}.`);

  const translation: Translation = await readFileAsync(readPath, 'utf8')
    .then(parse)
    .catch(err => {
      if (err.code === 'ENOENT') {
        // translations can be "empty"
        return {};
      } else {
        throw err;
      }
    })
    .then(camelCaseKeys)
    .then(data => ({ data, locale }));

  return translation;
}
开发者ID:otbe,项目名称:ws,代码行数:25,代码来源:get-translations.ts

示例6:

 .then(() => {
     return fs.readFileAsync(fooTablePath, 'utf8')
         .then((data) => JSON.parse(data))
         .then((data) => assert.deepEqual([
             { c1: 2, c2: 2 },
             { c1: 3, c2: 4 }
         ], data))
 })
开发者ID:yinso,项目名称:easydbi,代码行数:8,代码来源:serialize-driver.ts

示例7: read_file_raw

export async function read_file_raw(file_path: string): Promise<Buffer>{
	await lock.acquire();
	let out: Buffer;
	try{
		out = await fs.readFileAsync(file_path);
	}
	finally{
		lock.release();
	}
	return out;
}
开发者ID:BelaPlatform,项目名称:Bela,代码行数:11,代码来源:FileManager.ts

示例8: read_file

export async function read_file(file_path: string): Promise<string> {
	await lock.acquire();
	let out: string;
	try{
		out = await fs.readFileAsync(file_path, 'utf8');
	}
	finally{
		lock.release();
	}
	return out;
}
开发者ID:BelaPlatform,项目名称:Bela,代码行数:11,代码来源:FileManager.ts


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