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


TypeScript fs.readFile函数代码示例

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


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

示例1: test

      test('generates new TLS cert/key if unspecified', async() => {
        const createCertSpy = sinon.spy(pem, 'createCertificate');

        // reset paths to key/cert files so that default paths are used
        _serverOptions.keyPath = undefined;
        _serverOptions.certPath = undefined;

        const certFilePath = 'cert.pem';
        const keyFilePath = 'key.pem';
        _deleteFiles([certFilePath, keyFilePath]);

        try {
          const server = await _startStubServer(_serverOptions);
          assert.isOk(server);
          await sinon.assert.calledOnce(createCertSpy);
          await Promise.all([
            fs.readFile(certFilePath)
                .then(buf => _assertValidCert(buf.toString())),
            fs.readFile(keyFilePath)
                .then(buf => _assertValidKey(buf.toString()))
          ]);
          await _deleteFiles([certFilePath, keyFilePath]);
          await new Promise((resolve) => server.close(resolve));
        } finally {
          createCertSpy.restore();
        }
      });
开发者ID:tony19-contrib,项目名称:polyserve,代码行数:27,代码来源:start_server_test.ts

示例2: run

async function run() {
    const msedgeDocument = new DOMParser().parseFromString(await mz.readFile("supplements/browser.webidl.xml", "utf8"), "text/xml");
    const standardDocument = new DOMParser().parseFromString(await mz.readFile("built/browser.webidl.xml", "utf8"), "text/xml");
    const ignore = JSON.parse(await mz.readFile("msedge-ignore.json", "utf8")) as MSEdgeIgnore;;

    compareArray(extractInterfaceNames(msedgeDocument), extractInterfaceNames(standardDocument), ignore.interfaces);
}
开发者ID:SaschaNaz,项目名称:webxml,代码行数:7,代码来源:compare.ts

示例3: it

 it("should same", async () => {
     const output = (await mz.readFile("built/browser.webidl.xml", "utf8")).split('\n');
     const baseline = (await mz.readFile("baseline/browser.webidl.xml", "utf8")).split('\n');
     
     chai.assert.strictEqual(output.length, baseline.length, `Output length is different from baseline`);
     for (let i = 0; i < baseline.length; i++) {
         chai.assert.strictEqual(output[i], baseline[i], `Diff found on line ${i}:`);
     }
 })
开发者ID:SaschaNaz,项目名称:webxml,代码行数:9,代码来源:test.ts

示例4: if

    const results = await Promise.all(exportList.map(async (description): Promise<FetchResult> => {
        if (description.idl === "local") {
            const result: FetchResult = {
                description,
                content: await mz.readFile(`localcopies/${description.title}.widl`, "utf8")
            }
            console.log(`Got a local copy for ${description.title}`);
            return result;
        }
        else if (description.idl === "none") {
            return {
                description,
                content: ""
            }
        }

        const response = await fetch(description.url);
        if (!response.ok) {
            throw new Error(`Fetching failed: HTTP ${response.status} ${response.statusText}`);
        }
        const result: FetchResult = {
            description,
            content: await response.text()
        }
        console.log(`Fetching finished from ${description.url}`);
        return result;
    }));
开发者ID:SaschaNaz,项目名称:webxml,代码行数:27,代码来源:webxml.ts

示例5: graphQLTypes

export async function graphQLTypes(): Promise<void> {
    const schemaStr = await readFile(GRAPHQL_SCHEMA_PATH, 'utf8')
    const schema = buildSchema(schemaStr)
    const result = (await graphql(schema, introspectionQuery)) as { data: IntrospectionQuery }

    const formatOptions = (await resolveConfig(__dirname, { config: __dirname + '/../prettier.config.js' }))!
    const typings =
        'export type ID = string\n\n' +
        generateNamespace(
            '',
            result,
            {
                typeMap: {
                    ...DEFAULT_TYPE_MAP,
                    ID: 'ID',
                },
            },
            {
                generateNamespace: (name: string, interfaces: string) => interfaces,
                interfaceBuilder: (name: string, body: string) =>
                    'export ' + DEFAULT_OPTIONS.interfaceBuilder(name, body),
                enumTypeBuilder: (name: string, values: string) =>
                    'export ' + DEFAULT_OPTIONS.enumTypeBuilder(name, values),
                typeBuilder: (name: string, body: string) => 'export ' + DEFAULT_OPTIONS.typeBuilder(name, body),
                wrapList: (type: string) => `${type}[]`,
                postProcessor: (code: string) => format(code, { ...formatOptions, parser: 'typescript' }),
            }
        )
    await writeFile(__dirname + '/src/graphql/schema.ts', typings)
}
开发者ID:JoYiRis,项目名称:sourcegraph,代码行数:30,代码来源:gulpfile.ts

示例6: getPackageInfoAsync

    /**
     * Gets information about an OpenT2T package from the source
     * (potentially without downloading the whole package).
     *
     * @param {string} name  Name of the package
     * @returns {(Promise<PackageInfo | null)} Information about the requested
     * package, or null if the requested package is not found at the source
     */
    public async getPackageInfoAsync(name: string): Promise<PackageInfo | null> {
        let packageJsonPath: string = path.join(this.cacheDirectory, name, "package.json");

        let packageJsonContents: string;
        try {
            packageJsonContents = await fs.readFile(packageJsonPath, "utf8");
        } catch (error) {
            console.warn("Failed to read package.json for package '" + name + "': " + error.message);
            return null;
        }

        let packageJson: any;
        try {
            packageJson = JSON.parse(packageJsonContents);
        } catch (error) {
            console.warn("Failed to parse package.json for package '" + name + "': " + error.message);
            return null;
        }

        if (!packageJson.opent2t) {
            // Not an OpenT2T translator package. Just return null with no warning.
            return null;
        }

        let packageInfo: PackageInfo | null;
        try {
            packageInfo = PackageInfo.parse(packageJson);
        } catch (error) {
            console.warn("Failed to parse package.json package '" + name + "': " + error.message);
            return null;
        }

        return packageInfo;
    }
开发者ID:arjun-msft,项目名称:opent2t,代码行数:42,代码来源:InstalledPackageSource.ts

示例7: async

export const readCommandFile = async (filePath: string, useWrappingComments?: boolean): Promise<string[]> => {
    const extension = filePath.substring(filePath.lastIndexOf("."));
    let lines = (await fs.readFile(filePath))
        .toString()
        .replace(/\r/g, "")
        .split("\n");

    if (lines[lines.length - 1] !== "") {
        throw new Error(`The last line of the a '${filePath}' case should be blank.`);
    }

    if (useWrappingComments) {
        const comment = getCommentMarker(extension);

        if (lines[0] !== comment) {
            throw new Error(`The first line in '${filePath}' should be a '${comment}' comment, not '${lines[0]}'.`);
        }

        if (lines[lines.length - 2] !== comment) {
            throw new Error(`The last line in '${filePath}' should be a '${comment}' comment, not '${lines[0]}'.`);
        }

        lines = lines.slice(1, lines.length - 2);
    } else {
        lines = lines.slice(0, lines.length - 1);
    }

    return lines;
};
开发者ID:HighSchoolHacking,项目名称:GLS,代码行数:29,代码来源:Files.ts

示例8: buildFile

async function buildFile(srcPath: string, outPath: string, options: CLIOptions): Promise<void> {
  if (!options.quiet) {
    console.log(`${srcPath} -> ${outPath}`);
  }
  const code = (await readFile(srcPath)).toString();
  const transformedCode = transform(code, {...options.sucraseOptions, filePath: srcPath}).code;
  await writeFile(outPath, transformedCode);
}
开发者ID:alangpierce,项目名称:sucrase,代码行数:8,代码来源:cli.ts

示例9: processFile

 async function processFile(path: string): Promise<void> {
   let extension = path.endsWith('.coffee.md') ? '.coffee.md' : extname(path);
   let outputPath = join(dirname(path), basename(path, extension)) + '.js';
   console.log(`${path} → ${outputPath}`);
   let data = await readFile(path, 'utf8');
   let resultCode = runWithCode(path, data, options);
   await writeFile(outputPath, resultCode);
 }
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:8,代码来源:cli.ts

示例10: review

export function* review (identifier) {
    
    const pathToHtml = path.join(process.cwd(), 'rendered', identifier + '.html');
    
    const html = yield fs.readFile(pathToHtml, 'utf8');

    return html;
};
开发者ID:bennage,项目名称:pundit,代码行数:8,代码来源:review.ts


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