@rushstack/localization-utilities 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -74,6 +74,8 @@ export declare interface ITypingsGeneratorOptions {
74
74
  globsToIgnore?: string[];
75
75
  resxNewlineNormalization?: NewlineKind | undefined;
76
76
  ignoreMissingResxComments?: boolean | undefined;
77
+ ignoreString?: (resxFilePath: string, stringName: string) => boolean;
78
+ processComment?: (comment: string | undefined, resxFilePath: string, stringName: string) => string | undefined;
77
79
  }
78
80
 
79
81
  /**
@@ -11,6 +11,8 @@ export interface ITypingsGeneratorOptions {
11
11
  globsToIgnore?: string[];
12
12
  resxNewlineNormalization?: NewlineKind | undefined;
13
13
  ignoreMissingResxComments?: boolean | undefined;
14
+ ignoreString?: (resxFilePath: string, stringName: string) => boolean;
15
+ processComment?: (comment: string | undefined, resxFilePath: string, stringName: string) => string | undefined;
14
16
  }
15
17
  /**
16
18
  * This is a simple tool that generates .d.ts files for .loc.json, .resx.json, .resjson, and .resx files.
@@ -1 +1 @@
1
- {"version":3,"file":"LocFileTypingsGenerator.d.ts","sourceRoot":"","sources":["../src/LocFileTypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAsB,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAKtE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wBAAwB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IACnD,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACjD;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,4BAA4B;gBACpD,OAAO,EAAE,wBAAwB;CA2BrD"}
1
+ {"version":3,"file":"LocFileTypingsGenerator.d.ts","sourceRoot":"","sources":["../src/LocFileTypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAsB,MAAM,8BAA8B,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAKtE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wBAAwB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IACnD,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAChD,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IACrE,cAAc,CAAC,EAAE,CACf,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,KACf,MAAM,GAAG,SAAS,CAAC;CACzB;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,4BAA4B;gBACpD,OAAO,EAAE,wBAAwB;CAkCrD"}
@@ -12,7 +12,8 @@ const LocFileParser_1 = require("./LocFileParser");
12
12
  */
13
13
  class LocFileTypingsGenerator extends typings_generator_1.StringValuesTypingsGenerator {
14
14
  constructor(options) {
15
- super(Object.assign(Object.assign({}, options), { fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'], parseAndGenerateTypings: (fileContents, filePath) => {
15
+ const { ignoreString, processComment } = options;
16
+ super(Object.assign(Object.assign({}, options), { fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'], parseAndGenerateTypings: (fileContents, filePath, resxFilePath) => {
16
17
  const locFileData = (0, LocFileParser_1.parseLocFile)({
17
18
  filePath: filePath,
18
19
  content: fileContents,
@@ -23,10 +24,16 @@ class LocFileTypingsGenerator extends typings_generator_1.StringValuesTypingsGen
23
24
  const typings = [];
24
25
  // eslint-disable-next-line guard-for-in
25
26
  for (const stringName in locFileData) {
26
- typings.push({
27
- exportName: stringName,
28
- comment: locFileData[stringName].comment
29
- });
27
+ if (!(ignoreString === null || ignoreString === void 0 ? void 0 : ignoreString(resxFilePath, stringName))) {
28
+ let comment = locFileData[stringName].comment;
29
+ if (processComment) {
30
+ comment = processComment(comment, resxFilePath, stringName);
31
+ }
32
+ typings.push({
33
+ exportName: stringName,
34
+ comment
35
+ });
36
+ }
30
37
  }
31
38
  return { typings };
32
39
  } }));
@@ -1 +1 @@
1
- {"version":3,"file":"LocFileTypingsGenerator.js","sourceRoot":"","sources":["../src/LocFileTypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAAgG;AAIhG,mDAA+C;AAe/C;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,gDAA4B;IACvE,YAAmB,OAAiC;QAClD,KAAK,iCACA,OAAO,KACV,cAAc,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,CAAC,EAChE,uBAAuB,EAAE,CAAC,YAAoB,EAAE,QAAgB,EAAE,EAAE;gBAClE,MAAM,WAAW,GAAsB,IAAA,4BAAY,EAAC;oBAClD,QAAQ,EAAE,QAAQ;oBAClB,OAAO,EAAE,YAAY;oBACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAS;oBACjC,wBAAwB,EAAE,OAAO,CAAC,wBAAwB;oBAC1D,yBAAyB,EAAE,OAAO,CAAC,yBAAyB;iBAC7D,CAAC,CAAC;gBAEH,MAAM,OAAO,GAAyB,EAAE,CAAC;gBAEzC,wCAAwC;gBACxC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;oBACpC,OAAO,CAAC,IAAI,CAAC;wBACX,UAAU,EAAE,UAAU;wBACtB,OAAO,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC,OAAO;qBACzC,CAAC,CAAC;iBACJ;gBAED,OAAO,EAAE,OAAO,EAAE,CAAC;YACrB,CAAC,IACD,CAAC;IACL,CAAC;CACF;AA5BD,0DA4BC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { StringValuesTypingsGenerator, IStringValueTyping } from '@rushstack/typings-generator';\nimport { ITerminal, NewlineKind } from '@rushstack/node-core-library';\n\nimport { ILocalizationFile } from './interfaces';\nimport { parseLocFile } from './LocFileParser';\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorOptions {\n srcFolder: string;\n generatedTsFolder: string;\n terminal?: ITerminal;\n exportAsDefault?: boolean;\n globsToIgnore?: string[];\n resxNewlineNormalization?: NewlineKind | undefined;\n ignoreMissingResxComments?: boolean | undefined;\n}\n\n/**\n * This is a simple tool that generates .d.ts files for .loc.json, .resx.json, .resjson, and .resx files.\n *\n * @public\n */\nexport class LocFileTypingsGenerator extends StringValuesTypingsGenerator {\n public constructor(options: ITypingsGeneratorOptions) {\n super({\n ...options,\n fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'],\n parseAndGenerateTypings: (fileContents: string, filePath: string) => {\n const locFileData: ILocalizationFile = parseLocFile({\n filePath: filePath,\n content: fileContents,\n terminal: this._options.terminal!,\n resxNewlineNormalization: options.resxNewlineNormalization,\n ignoreMissingResxComments: options.ignoreMissingResxComments\n });\n\n const typings: IStringValueTyping[] = [];\n\n // eslint-disable-next-line guard-for-in\n for (const stringName in locFileData) {\n typings.push({\n exportName: stringName,\n comment: locFileData[stringName].comment\n });\n }\n\n return { typings };\n }\n });\n }\n}\n"]}
1
+ {"version":3,"file":"LocFileTypingsGenerator.js","sourceRoot":"","sources":["../src/LocFileTypingsGen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ft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { StringValuesTypingsGenerator, IStringValueTyping } from '@rushstack/typings-generator';\nimport { ITerminal, NewlineKind } from '@rushstack/node-core-library';\n\nimport { ILocalizationFile } from './interfaces';\nimport { parseLocFile } from './LocFileParser';\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorOptions {\n srcFolder: string;\n generatedTsFolder: string;\n terminal?: ITerminal;\n exportAsDefault?: boolean;\n globsToIgnore?: string[];\n resxNewlineNormalization?: NewlineKind | undefined;\n ignoreMissingResxComments?: boolean | undefined;\n ignoreString?: (resxFilePath: string, stringName: string) => boolean;\n processComment?: (\n comment: string | undefined,\n resxFilePath: string,\n stringName: string\n ) => string | undefined;\n}\n\n/**\n * This is a simple tool that generates .d.ts files for .loc.json, .resx.json, .resjson, and .resx files.\n *\n * @public\n */\nexport class LocFileTypingsGenerator extends StringValuesTypingsGenerator {\n public constructor(options: ITypingsGeneratorOptions) {\n const { ignoreString, processComment } = options;\n super({\n ...options,\n fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'],\n parseAndGenerateTypings: (fileContents: string, filePath: string, resxFilePath: string) => {\n const locFileData: ILocalizationFile = parseLocFile({\n filePath: filePath,\n content: fileContents,\n terminal: this._options.terminal!,\n resxNewlineNormalization: options.resxNewlineNormalization,\n ignoreMissingResxComments: options.ignoreMissingResxComments\n });\n\n const typings: IStringValueTyping[] = [];\n\n // eslint-disable-next-line guard-for-in\n for (const stringName in locFileData) {\n if (!ignoreString?.(resxFilePath, stringName)) {\n let comment: string | undefined = locFileData[stringName].comment;\n if (processComment) {\n comment = processComment(comment, resxFilePath, stringName);\n }\n typings.push({\n exportName: stringName,\n comment\n });\n }\n }\n\n return { typings };\n }\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/localization-utilities",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "This plugin contains some useful functions for localization.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "dist/localization-utilities.d.ts",