forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocFileTypingsGenerator.ts
More file actions
62 lines (53 loc) · 1.8 KB
/
LocFileTypingsGenerator.ts
File metadata and controls
62 lines (53 loc) · 1.8 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import {
StringValuesTypingsGenerator,
IStringValueTyping
} from '@rushstack/typings-generator';
import { Terminal } from '@rushstack/node-core-library';
import { ILocalizationFile } from './interfaces';
import { ILoggerOptions } from './utilities/Logging';
import { LocFileParser } from './utilities/LocFileParser';
/**
* @public
*/
export interface ITypingsGeneratorOptions {
srcFolder: string;
generatedTsFolder: string;
terminal?: Terminal;
exportAsDefault?: boolean;
filesToIgnore?: string[];
}
/**
* This is a simple tool that generates .d.ts files for .loc.json and .resx files.
*
* @public
*/
export class LocFileTypingsGenerator extends StringValuesTypingsGenerator {
private _loggingOptions: ILoggerOptions;
public constructor(options: ITypingsGeneratorOptions) {
super({
...options,
fileExtensions: ['resx', 'loc.json'],
parseAndGenerateTypings: (fileContents: string, filePath: string) => {
const locFileData: ILocalizationFile = LocFileParser.parseLocFile({
filePath: filePath,
content: fileContents,
loggerOptions: this._loggingOptions
});
const typings: IStringValueTyping[] = [];
for (const stringName in locFileData) { // eslint-disable-line guard-for-in
typings.push({
exportName: stringName,
comment: locFileData[stringName].comment
});
}
return { typings };
}
});
this._loggingOptions = {
writeError: this._options.terminal!.writeErrorLine.bind(this._options.terminal),
writeWarning: this._options.terminal!.writeWarningLine.bind(this._options.terminal)
};
}
}