-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathutils.ts
77 lines (72 loc) · 1.82 KB
/
utils.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {
Directory,
ImportDeclarationStructure,
IndentationText,
ModuleResolutionKind,
ProjectOptions,
QuoteKind,
ScriptTarget,
SourceFile,
SourceFileStructure,
StructureKind
} from 'ts-morph';
import { ModuleKind } from 'typescript';
import { unique } from '@sap-cloud-sdk/util';
export function projectOptions(): ProjectOptions {
return {
addFilesFromTsConfig: false,
manipulationSettings: {
indentationText: IndentationText.TwoSpaces,
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: true,
quoteKind: QuoteKind.Single
},
compilerOptions: {
target: ScriptTarget.ES5,
module: ModuleKind.CommonJS,
declaration: true,
declarationMap: true,
sourceMap: true,
diagnostics: true,
moduleResolution: ModuleResolutionKind.NodeJs,
esModuleInterop: true,
inlineSources: false,
noImplicitAny: true
}
};
}
export function sourceFile(
directory: Directory,
relativePath: string,
content: SourceFileStructure,
overwrite: boolean
): SourceFile {
const file = directory.createSourceFile(
`${relativePath}.ts`,
addFileComment(content),
{
overwrite
}
);
file.formatText({ insertSpaceAfterCommaDelimiter: true });
return file;
}
function addFileComment(content: SourceFileStructure): SourceFileStructure {
content.leadingTrivia = [
'/*',
' * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.',
' *',
' * This is a generated file powered by the SAP Cloud SDK for JavaScript.',
' */',
''
].join('\n');
return content;
}
export function coreImportDeclaration(
namedImports: string[]
): ImportDeclarationStructure {
return {
kind: StructureKind.ImportDeclaration,
moduleSpecifier: '@sap-cloud-sdk/core',
namedImports: unique(namedImports)
};
}