本文整理匯總了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();
}
});
示例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);
}
示例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}:`);
}
})
示例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;
}));
示例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)
}
示例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;
}
示例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;
};
示例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);
}
示例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);
}
示例10: review
export function* review (identifier) {
const pathToHtml = path.join(process.cwd(), 'rendered', identifier + '.html');
const html = yield fs.readFile(pathToHtml, 'utf8');
return html;
};