-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathcreate-file.ts
37 lines (35 loc) · 1.15 KB
/
create-file.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { promises } from 'fs';
import { join } from 'path';
import { codeBlock } from '@sap-cloud-sdk/util';
const { writeFile } = promises;
/**
* @experimental This API is experimental and might change in newer versions. Use with caution.
* Write a file generated by the SAP Cloud SDK for JavaScript containing a copyright statement.
* @param directoryPath Path of the directory to write to.
* @param fileName Name of the file to write
* @param content Content to be written to the file. A copyright statement will be added to this.
* @param overwrite Whether or not existing files should be overwritten.
*/
export async function createFile(
directoryPath: string,
fileName: string,
content: string,
overwrite: boolean
): Promise<void> {
return writeFile(join(directoryPath, fileName), wrapContent(content), {
encoding: 'utf8',
flag: overwrite ? 'w' : 'wx'
});
}
function wrapContent(content: string): string {
return (
codeBlock`
/*
* Copyright (c) ${new Date().getFullYear()} SAP SE or an SAP affiliate company. All rights reserved.
*
* This is a generated file powered by the SAP Cloud SDK for JavaScript.
*/
${content}
` + '\n'
);
}