本文整理匯總了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],
});
};