本文整理汇总了TypeScript中mz/fs.writeFile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript writeFile函数的具体用法?TypeScript writeFile怎么用?TypeScript writeFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了writeFile函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: generate
/**
* Use code generation.
*/
async function generate(): Promise<void> {
await writeFile("./src/parser/tokenizer/types.ts", generateTokenTypes());
await run("./node_modules/.bin/prettier --write ./src/parser/tokenizer/types.ts");
await writeFile("./src/parser/tokenizer/readWordTree.ts", generateReadWordTree());
await run("./node_modules/.bin/prettier --write ./src/parser/tokenizer/readWordTree.ts");
console.log("Done with code generation.");
}
示例2:
.then((transpiled) => {
const sourceMap = JSON.parse(transpiled.sourceMapText);
sourceMap['file'] = path.basename(outputFile);
sourceMap['sources'] = [path.basename(inputFile)];
return Promise.all([
fs.writeFile(outputFile, transpiled.outputText),
fs.writeFile(`${outputFile}.map`, JSON.stringify(sourceMap))
]);
});
示例3: 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)
}
示例4: getTLSCertificate
export async function getTLSCertificate(
keyPath: string, certPath: string): Promise<KeyAndCert> {
let certObj = await _readKeyAndCert(keyPath, certPath);
if (!certObj) {
certObj = await createTLSCertificate();
if (keyPath && certPath) {
await Promise.all([
fs.writeFile(certPath, certObj.cert),
fs.writeFile(keyPath, certObj.key)
]);
}
}
return certObj;
}
示例5: 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);
}
示例6: 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);
}
示例7: writeThingSchemaToFilesAsync
public static async writeThingSchemaToFilesAsync(
thingSchema: ThingSchema, ramlFilePath: string): Promise<void> {
let ramlAndJson: { raml: string, json: {[fileName: string]: string}} =
await OcfSchemaWriter.writeThingSchema(thingSchema);
await fs.writeFile(ramlFilePath, ramlAndJson.raml, "utf8");
// TODO: Write each of the JSON files to the same directory as the raml file.
}
示例8: async
export const writeBaselineFile = async (filePath: string, contents: string[], commentMarker: string | undefined): Promise<void> => {
if (commentMarker !== undefined) {
contents = [commentMarker.trim(), ...contents, commentMarker.trim(), ""];
} else {
contents = [...contents, ""];
}
await mkdirpPromise(path.dirname(filePath));
await fs.writeFile(filePath, contents.join("\n"));
};
示例9: writeOutput
function writeOutput(ts: string, argOut: string): Promise<void> {
if (!argOut) {
try {
process.stdout.write(ts)
return Promise.resolve()
} catch (err) {
return Promise.reject(err)
}
}
return writeFile(argOut, ts)
}
示例10: async
export const testCSharpGenerator: IOutputGenerator = async ({ projectDirectory, projectName }): Promise<string[]> => {
const csprojPath = path.join(projectDirectory, projectName + ".csproj");
await fs.writeFile(csprojPath, template, {
flag: "w",
});
return spawnAndCaptureOutput("dotnet", {
args: ["run", "--project", csprojPath],
});
};