@rushstack/typings-generator 0.5.7 → 0.6.3
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.
- package/CHANGELOG.json +1976 -1910
- package/CHANGELOG.md +629 -607
- package/README.md +132 -132
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/typings-generator.d.ts +13 -6
- package/lib/StringValuesTypingsGenerator.d.ts.map +1 -1
- package/lib/StringValuesTypingsGenerator.js +2 -2
- package/lib/StringValuesTypingsGenerator.js.map +1 -1
- package/lib/TypingsGenerator.d.ts +13 -6
- package/lib/TypingsGenerator.d.ts.map +1 -1
- package/lib/TypingsGenerator.js +120 -56
- package/lib/TypingsGenerator.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
# @rushstack/typings-generator
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
`npm install @rushstack/typings-generator --save-dev`
|
|
6
|
-
|
|
7
|
-
## Overview
|
|
8
|
-
|
|
9
|
-
This is a utility for generating typings for non-TS files. It can operate in either a single-run mode or
|
|
10
|
-
a watch mode. It is designed to generate `.d.ts` files with a specified generation function for all files matching
|
|
11
|
-
specified file extensions, with an option to ignore individual files.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```TypeScript
|
|
16
|
-
import { TypingsGenerator } from '@rushstack/typings-generator';
|
|
17
|
-
|
|
18
|
-
const typingsGenerator: TypingsGenerator = new TypingsGenerator({
|
|
19
|
-
srcFolder: '/repo/package/src',
|
|
20
|
-
generatedTsFolder: '/repo/package/temp/generated-typings',
|
|
21
|
-
fileExtensions: ['file-extension'],
|
|
22
|
-
parseAndGenerateTypings: (fileContents: string, filePath: string) => {
|
|
23
|
-
const parsedFile = parseFile(fileContents);
|
|
24
|
-
const typings: string = generateTypings(parsedFile);
|
|
25
|
-
return typings;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// To run once before a compilation:
|
|
30
|
-
await typingsGenerator.generateTypings();
|
|
31
|
-
|
|
32
|
-
// To start a watcher:
|
|
33
|
-
await typingsGenerator.runWatcher();
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Options
|
|
37
|
-
|
|
38
|
-
### `srcFolder = '...'`
|
|
39
|
-
|
|
40
|
-
This property is used as the source root folder for discovery of files for which typings should be generated.
|
|
41
|
-
|
|
42
|
-
### `generatedTsFolder = '...'`
|
|
43
|
-
|
|
44
|
-
This property specifies the folder in which `.d.ts` files should be dropped. It is recommended
|
|
45
|
-
that this be a folder parallel to the source folder, specified in addition to the source folder in the
|
|
46
|
-
[`rootDirs` `tsconfig.json` option](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
|
|
47
|
-
**The folder specified by this option is emptied when the utility is invoked.**
|
|
48
|
-
|
|
49
|
-
### `fileExtensions = [...]`
|
|
50
|
-
|
|
51
|
-
This property enumerates the file extensions that should be handled.
|
|
52
|
-
|
|
53
|
-
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => string | Promise<string>`
|
|
54
|
-
|
|
55
|
-
This property is used to specify the function that should be called on every file for which typings
|
|
56
|
-
are being generated. In watch mode, this is called on every file creation and file update. It should
|
|
57
|
-
return TypeScript declarations for the file it is called with.
|
|
58
|
-
|
|
59
|
-
### `terminal`
|
|
60
|
-
|
|
61
|
-
Optionally provide a [Terminal](https://github.com/microsoft/rushstack/blob/master/libraries/node-core-library/src/Terminal/Terminal.ts)
|
|
62
|
-
object for logging. If one isn't provided, logs will go to the console.
|
|
63
|
-
|
|
64
|
-
### `globsToIgnore`
|
|
65
|
-
|
|
66
|
-
Optionally, provide an array of globs matching files that should be ignored. These globs are evaluated
|
|
67
|
-
under [`srcFolder`](#srcFolder--)
|
|
68
|
-
|
|
69
|
-
## `StringValuesTypingsGenerator`
|
|
70
|
-
|
|
71
|
-
There is an extension of this utility specifically for file types where typings should be a simple
|
|
72
|
-
set of exported string values. This is useful for file types like CSS and RESX. This class takes
|
|
73
|
-
the same options as the standard `TypingsGenerator`, with one additional option ([`exportAsDefault`](#exportAsDefault--)) and a different return value for `parseAndGenerateTypings`.
|
|
74
|
-
|
|
75
|
-
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => { typings: ({ exportName: string, comment?: string })[] } | Promise<{ typings: ({ exportName: string, comment?: string })[] }>`
|
|
76
|
-
|
|
77
|
-
This function should behave the same as the `parseAndGenerateTypings` function for the standard
|
|
78
|
-
`TypingsGenerator`, except that it should return an object with a `typings` property, set to
|
|
79
|
-
an array of objects with an `exportName` property and an optional `comment` property.
|
|
80
|
-
See the example below.
|
|
81
|
-
|
|
82
|
-
#### Example return value:
|
|
83
|
-
|
|
84
|
-
```TypeScript
|
|
85
|
-
{
|
|
86
|
-
typings: [
|
|
87
|
-
{
|
|
88
|
-
exportName: 'myExport'
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
exportName: 'myOtherExport',
|
|
92
|
-
comment: 'This is the other export'
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
#### Example generated declaration file:
|
|
99
|
-
|
|
100
|
-
```TypeScript
|
|
101
|
-
// This file was generated by a tool. Modifying it will produce unexpected behavior
|
|
102
|
-
|
|
103
|
-
export declare const myExport: string;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* This is the other export
|
|
107
|
-
*/
|
|
108
|
-
export declare const myOtherExport: string;
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### `exportAsDefault = true | false`
|
|
113
|
-
|
|
114
|
-
If this option is set to `true`, the typings will be exported wrapped in a `default` property. This
|
|
115
|
-
allows the file to be imported by using the `import myFile from './myFile.my-extension';` syntax instead of
|
|
116
|
-
the `import { myExport } from './myFile.my-extension';` or the `import * as myFile from './myFile.my-extension';`
|
|
117
|
-
syntax. This style of export is not recommended as it can prevent tree-shaking optimization.
|
|
118
|
-
|
|
119
|
-
### `exportAsDefaultInterfaceName = true | false`
|
|
120
|
-
|
|
121
|
-
When `exportAsDefault` is true, this optional setting determines the interface name
|
|
122
|
-
for the default wrapped export. For example, in the Sass Typings plugin, the interface name
|
|
123
|
-
is set to `IExportStyles`. If not specified, the interface name will be `IExport`.
|
|
124
|
-
(This setting is ignored when `exportAsDefault` is false).
|
|
125
|
-
|
|
126
|
-
## Links
|
|
127
|
-
|
|
128
|
-
- [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/master/libraries/typings-generator/CHANGELOG.md) - Find
|
|
129
|
-
out what's new in the latest version
|
|
130
|
-
- [API Reference](https://rushstack.io/pages/api/typings-generator/)
|
|
131
|
-
|
|
132
|
-
`@rushstack/typings-generator` is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
|
1
|
+
# @rushstack/typings-generator
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
`npm install @rushstack/typings-generator --save-dev`
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This is a utility for generating typings for non-TS files. It can operate in either a single-run mode or
|
|
10
|
+
a watch mode. It is designed to generate `.d.ts` files with a specified generation function for all files matching
|
|
11
|
+
specified file extensions, with an option to ignore individual files.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```TypeScript
|
|
16
|
+
import { TypingsGenerator } from '@rushstack/typings-generator';
|
|
17
|
+
|
|
18
|
+
const typingsGenerator: TypingsGenerator = new TypingsGenerator({
|
|
19
|
+
srcFolder: '/repo/package/src',
|
|
20
|
+
generatedTsFolder: '/repo/package/temp/generated-typings',
|
|
21
|
+
fileExtensions: ['file-extension'],
|
|
22
|
+
parseAndGenerateTypings: (fileContents: string, filePath: string) => {
|
|
23
|
+
const parsedFile = parseFile(fileContents);
|
|
24
|
+
const typings: string = generateTypings(parsedFile);
|
|
25
|
+
return typings;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// To run once before a compilation:
|
|
30
|
+
await typingsGenerator.generateTypings();
|
|
31
|
+
|
|
32
|
+
// To start a watcher:
|
|
33
|
+
await typingsGenerator.runWatcher();
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Options
|
|
37
|
+
|
|
38
|
+
### `srcFolder = '...'`
|
|
39
|
+
|
|
40
|
+
This property is used as the source root folder for discovery of files for which typings should be generated.
|
|
41
|
+
|
|
42
|
+
### `generatedTsFolder = '...'`
|
|
43
|
+
|
|
44
|
+
This property specifies the folder in which `.d.ts` files should be dropped. It is recommended
|
|
45
|
+
that this be a folder parallel to the source folder, specified in addition to the source folder in the
|
|
46
|
+
[`rootDirs` `tsconfig.json` option](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
|
|
47
|
+
**The folder specified by this option is emptied when the utility is invoked.**
|
|
48
|
+
|
|
49
|
+
### `fileExtensions = [...]`
|
|
50
|
+
|
|
51
|
+
This property enumerates the file extensions that should be handled.
|
|
52
|
+
|
|
53
|
+
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => string | Promise<string>`
|
|
54
|
+
|
|
55
|
+
This property is used to specify the function that should be called on every file for which typings
|
|
56
|
+
are being generated. In watch mode, this is called on every file creation and file update. It should
|
|
57
|
+
return TypeScript declarations for the file it is called with.
|
|
58
|
+
|
|
59
|
+
### `terminal`
|
|
60
|
+
|
|
61
|
+
Optionally provide a [Terminal](https://github.com/microsoft/rushstack/blob/master/libraries/node-core-library/src/Terminal/Terminal.ts)
|
|
62
|
+
object for logging. If one isn't provided, logs will go to the console.
|
|
63
|
+
|
|
64
|
+
### `globsToIgnore`
|
|
65
|
+
|
|
66
|
+
Optionally, provide an array of globs matching files that should be ignored. These globs are evaluated
|
|
67
|
+
under [`srcFolder`](#srcFolder--)
|
|
68
|
+
|
|
69
|
+
## `StringValuesTypingsGenerator`
|
|
70
|
+
|
|
71
|
+
There is an extension of this utility specifically for file types where typings should be a simple
|
|
72
|
+
set of exported string values. This is useful for file types like CSS and RESX. This class takes
|
|
73
|
+
the same options as the standard `TypingsGenerator`, with one additional option ([`exportAsDefault`](#exportAsDefault--)) and a different return value for `parseAndGenerateTypings`.
|
|
74
|
+
|
|
75
|
+
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => { typings: ({ exportName: string, comment?: string })[] } | Promise<{ typings: ({ exportName: string, comment?: string })[] }>`
|
|
76
|
+
|
|
77
|
+
This function should behave the same as the `parseAndGenerateTypings` function for the standard
|
|
78
|
+
`TypingsGenerator`, except that it should return an object with a `typings` property, set to
|
|
79
|
+
an array of objects with an `exportName` property and an optional `comment` property.
|
|
80
|
+
See the example below.
|
|
81
|
+
|
|
82
|
+
#### Example return value:
|
|
83
|
+
|
|
84
|
+
```TypeScript
|
|
85
|
+
{
|
|
86
|
+
typings: [
|
|
87
|
+
{
|
|
88
|
+
exportName: 'myExport'
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
exportName: 'myOtherExport',
|
|
92
|
+
comment: 'This is the other export'
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Example generated declaration file:
|
|
99
|
+
|
|
100
|
+
```TypeScript
|
|
101
|
+
// This file was generated by a tool. Modifying it will produce unexpected behavior
|
|
102
|
+
|
|
103
|
+
export declare const myExport: string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* This is the other export
|
|
107
|
+
*/
|
|
108
|
+
export declare const myOtherExport: string;
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### `exportAsDefault = true | false`
|
|
113
|
+
|
|
114
|
+
If this option is set to `true`, the typings will be exported wrapped in a `default` property. This
|
|
115
|
+
allows the file to be imported by using the `import myFile from './myFile.my-extension';` syntax instead of
|
|
116
|
+
the `import { myExport } from './myFile.my-extension';` or the `import * as myFile from './myFile.my-extension';`
|
|
117
|
+
syntax. This style of export is not recommended as it can prevent tree-shaking optimization.
|
|
118
|
+
|
|
119
|
+
### `exportAsDefaultInterfaceName = true | false`
|
|
120
|
+
|
|
121
|
+
When `exportAsDefault` is true, this optional setting determines the interface name
|
|
122
|
+
for the default wrapped export. For example, in the Sass Typings plugin, the interface name
|
|
123
|
+
is set to `IExportStyles`. If not specified, the interface name will be `IExport`.
|
|
124
|
+
(This setting is ignored when `exportAsDefault` is false).
|
|
125
|
+
|
|
126
|
+
## Links
|
|
127
|
+
|
|
128
|
+
- [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/master/libraries/typings-generator/CHANGELOG.md) - Find
|
|
129
|
+
out what's new in the latest version
|
|
130
|
+
- [API Reference](https://rushstack.io/pages/api/typings-generator/)
|
|
131
|
+
|
|
132
|
+
`@rushstack/typings-generator` is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -37,7 +37,8 @@ export declare interface ITypingsGeneratorOptions<TTypingsResult = string | unde
|
|
|
37
37
|
srcFolder: string;
|
|
38
38
|
generatedTsFolder: string;
|
|
39
39
|
fileExtensions: string[];
|
|
40
|
-
parseAndGenerateTypings: (fileContents: string, filePath: string) => TTypingsResult | Promise<TTypingsResult>;
|
|
40
|
+
parseAndGenerateTypings: (fileContents: string, filePath: string, relativePath: string) => TTypingsResult | Promise<TTypingsResult>;
|
|
41
|
+
getAdditionalOutputFiles?: (relativePath: string) => string[];
|
|
41
42
|
terminal?: ITerminal;
|
|
42
43
|
globsToIgnore?: string[];
|
|
43
44
|
/**
|
|
@@ -64,22 +65,28 @@ export declare class StringValuesTypingsGenerator extends TypingsGenerator {
|
|
|
64
65
|
* @public
|
|
65
66
|
*/
|
|
66
67
|
export declare class TypingsGenerator {
|
|
67
|
-
private
|
|
68
|
-
private
|
|
68
|
+
private readonly _dependenciesOfFile;
|
|
69
|
+
private readonly _consumersOfFile;
|
|
70
|
+
private readonly _relativePaths;
|
|
69
71
|
protected _options: ITypingsGeneratorOptions;
|
|
72
|
+
private readonly _fileGlob;
|
|
70
73
|
constructor(options: ITypingsGeneratorOptions);
|
|
71
74
|
generateTypingsAsync(): Promise<void>;
|
|
72
75
|
runWatcherAsync(): Promise<void>;
|
|
73
76
|
/**
|
|
74
|
-
* Register file dependencies that may effect the typings of a
|
|
77
|
+
* Register file dependencies that may effect the typings of a consumer file.
|
|
75
78
|
* Note: This feature is only useful in watch mode.
|
|
76
79
|
* The registerDependency method must be called in the body of parseAndGenerateTypings every
|
|
77
80
|
* time because the registry for a file is cleared at the beginning of processing.
|
|
78
81
|
*/
|
|
79
|
-
registerDependency(
|
|
82
|
+
registerDependency(consumer: string, rawDependency: string): void;
|
|
83
|
+
getOutputFilePaths(relativePath: string): string[];
|
|
84
|
+
private _reprocessFiles;
|
|
80
85
|
private _parseFileAndGenerateTypingsAsync;
|
|
86
|
+
/**
|
|
87
|
+
* Removes the consumer from all extant dependencies
|
|
88
|
+
*/
|
|
81
89
|
private _clearDependencies;
|
|
82
|
-
private _getDependencyTargets;
|
|
83
90
|
private _getTypingsFilePath;
|
|
84
91
|
private _normalizeFileExtensions;
|
|
85
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringValuesTypingsGenerator.d.ts","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,oCACf,SAAQ,wBAAwB,CAAC,mBAAmB,GAAG,SAAS,CAAC;IACjE;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACvC;AAID;;;;;GAKG;AACH,qBAAa,4BAA6B,SAAQ,gBAAgB;gBAC7C,OAAO,EAAE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"StringValuesTypingsGenerator.d.ts","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,oCACf,SAAQ,wBAAwB,CAAC,mBAAmB,GAAG,SAAS,CAAC;IACjE;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;CACvC;AAID;;;;;GAKG;AACH,qBAAa,4BAA6B,SAAQ,gBAAgB;gBAC7C,OAAO,EAAE,oCAAoC;CAwDjE"}
|
|
@@ -14,8 +14,8 @@ const EXPORT_AS_DEFAULT_INTERFACE_NAME = 'IExport';
|
|
|
14
14
|
*/
|
|
15
15
|
class StringValuesTypingsGenerator extends TypingsGenerator_1.TypingsGenerator {
|
|
16
16
|
constructor(options) {
|
|
17
|
-
super(Object.assign(Object.assign({}, options), { parseAndGenerateTypings: async (fileContents, filePath) => {
|
|
18
|
-
const stringValueTypings = await options.parseAndGenerateTypings(fileContents, filePath);
|
|
17
|
+
super(Object.assign(Object.assign({}, options), { parseAndGenerateTypings: async (fileContents, filePath, relativePath) => {
|
|
18
|
+
const stringValueTypings = await options.parseAndGenerateTypings(fileContents, filePath, relativePath);
|
|
19
19
|
if (stringValueTypings === undefined) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringValuesTypingsGenerator.js","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AAEzB,yDAAgF;AAkChF,MAAM,gCAAgC,GAAW,SAAS,CAAC;AAE3D;;;;;GAKG;AACH,MAAa,4BAA6B,SAAQ,mCAAgB;IAChE,YAAmB,OAA6C;QAC9D,KAAK,iCACA,OAAO,KACV,uBAAuB,EAAE,KAAK,EAAE,YAAoB,EAAE,QAAgB,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"StringValuesTypingsGenerator.js","sourceRoot":"","sources":["../src/StringValuesTypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AAEzB,yDAAgF;AAkChF,MAAM,gCAAgC,GAAW,SAAS,CAAC;AAE3D;;;;;GAKG;AACH,MAAa,4BAA6B,SAAQ,mCAAgB;IAChE,YAAmB,OAA6C;QAC9D,KAAK,iCACA,OAAO,KACV,uBAAuB,EAAE,KAAK,EAAE,YAAoB,EAAE,QAAgB,EAAE,YAAoB,EAAE,EAAE;gBAC9F,MAAM,kBAAkB,GAAoC,MAAM,OAAO,CAAC,uBAAuB,CAC/F,YAAY,EACZ,QAAQ,EACR,YAAY,CACb,CAAC;gBAEF,IAAI,kBAAkB,KAAK,SAAS,EAAE;oBACpC,OAAO;iBACR;gBAED,MAAM,WAAW,GAAa,EAAE,CAAC;gBACjC,MAAM,aAAa,GAAW,OAAO,CAAC,4BAA4B;oBAChE,CAAC,CAAC,OAAO,CAAC,4BAA4B;oBACtC,CAAC,CAAC,gCAAgC,CAAC;gBACrC,IAAI,MAAM,GAAW,EAAE,CAAC;gBACxB,IAAI,OAAO,CAAC,eAAe,EAAE;oBAC3B,WAAW,CAAC,IAAI,CAAC,oBAAoB,aAAa,IAAI,CAAC,CAAC;oBACxD,MAAM,GAAG,IAAI,CAAC;iBACf;gBAED,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,CAAC,OAAO,EAAE;oBAC1D,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC;oBAElD,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;wBACpC,WAAW,CAAC,IAAI,CACd,GAAG,MAAM,KAAK,EACd,GAAG,MAAM,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EACjD,GAAG,MAAM,KAAK,CACf,CAAC;qBACH;oBAED,IAAI,OAAO,CAAC,eAAe,EAAE;wBAC3B,WAAW,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,UAAU,YAAY,EAAE,EAAE,CAAC,CAAC;qBAC3D;yBAAM;wBACL,WAAW,CAAC,IAAI,CAAC,wBAAwB,UAAU,WAAW,EAAE,EAAE,CAAC,CAAC;qBACrE;iBACF;gBAED,IAAI,OAAO,CAAC,eAAe,EAAE;oBAC3B,WAAW,CAAC,IAAI,CACd,GAAG,EACH,EAAE,EACF,0BAA0B,aAAa,GAAG,EAC1C,EAAE,EACF,yBAAyB,CAC1B,CAAC;iBACH;gBAED,OAAO,WAAW,CAAC,IAAI,CAAC,QAAG,CAAC,CAAC;YAC/B,CAAC,IACD,CAAC;IACL,CAAC;CACF;AAzDD,oEAyDC","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 { EOL } from 'os';\n\nimport { ITypingsGeneratorOptions, TypingsGenerator } from './TypingsGenerator';\n\n/**\n * @public\n */\nexport interface IStringValueTyping {\n exportName: string;\n comment?: string;\n}\n\n/**\n * @public\n */\nexport interface IStringValueTypings {\n typings: IStringValueTyping[];\n}\n\n/**\n * @public\n */\nexport interface IStringValuesTypingsGeneratorOptions\n extends ITypingsGeneratorOptions<IStringValueTypings | undefined> {\n /**\n * Setting this option wraps the typings export in a default property.\n */\n exportAsDefault?: boolean;\n\n /**\n * When `exportAsDefault` is true, this optional setting determines the interface name\n * for the default wrapped export. Ignored when `exportAsDefault` is false.\n */\n exportAsDefaultInterfaceName?: string;\n}\n\nconst EXPORT_AS_DEFAULT_INTERFACE_NAME: string = 'IExport';\n\n/**\n * This is a simple tool that generates .d.ts files for non-TS files that can be represented as\n * a simple set of named string exports.\n *\n * @public\n */\nexport class StringValuesTypingsGenerator extends TypingsGenerator {\n public constructor(options: IStringValuesTypingsGeneratorOptions) {\n super({\n ...options,\n parseAndGenerateTypings: async (fileContents: string, filePath: string, relativePath: string) => {\n const stringValueTypings: IStringValueTypings | undefined = await options.parseAndGenerateTypings(\n fileContents,\n filePath,\n relativePath\n );\n\n if (stringValueTypings === undefined) {\n return;\n }\n\n const outputLines: string[] = [];\n const interfaceName: string = options.exportAsDefaultInterfaceName\n ? options.exportAsDefaultInterfaceName\n : EXPORT_AS_DEFAULT_INTERFACE_NAME;\n let indent: string = '';\n if (options.exportAsDefault) {\n outputLines.push(`export interface ${interfaceName} {`);\n indent = ' ';\n }\n\n for (const stringValueTyping of stringValueTypings.typings) {\n const { exportName, comment } = stringValueTyping;\n\n if (comment && comment.trim() !== '') {\n outputLines.push(\n `${indent}/**`,\n `${indent} * ${comment.replace(/\\*\\//g, '*\\\\/')}`,\n `${indent} */`\n );\n }\n\n if (options.exportAsDefault) {\n outputLines.push(`${indent}'${exportName}': string;`, '');\n } else {\n outputLines.push(`export declare const ${exportName}: string;`, '');\n }\n }\n\n if (options.exportAsDefault) {\n outputLines.push(\n '}',\n '',\n `declare const strings: ${interfaceName};`,\n '',\n 'export default strings;'\n );\n }\n\n return outputLines.join(EOL);\n }\n });\n }\n}\n"]}
|
|
@@ -6,7 +6,8 @@ export interface ITypingsGeneratorOptions<TTypingsResult = string | undefined> {
|
|
|
6
6
|
srcFolder: string;
|
|
7
7
|
generatedTsFolder: string;
|
|
8
8
|
fileExtensions: string[];
|
|
9
|
-
parseAndGenerateTypings: (fileContents: string, filePath: string) => TTypingsResult | Promise<TTypingsResult>;
|
|
9
|
+
parseAndGenerateTypings: (fileContents: string, filePath: string, relativePath: string) => TTypingsResult | Promise<TTypingsResult>;
|
|
10
|
+
getAdditionalOutputFiles?: (relativePath: string) => string[];
|
|
10
11
|
terminal?: ITerminal;
|
|
11
12
|
globsToIgnore?: string[];
|
|
12
13
|
/**
|
|
@@ -22,22 +23,28 @@ export interface ITypingsGeneratorOptions<TTypingsResult = string | undefined> {
|
|
|
22
23
|
* @public
|
|
23
24
|
*/
|
|
24
25
|
export declare class TypingsGenerator {
|
|
25
|
-
private
|
|
26
|
-
private
|
|
26
|
+
private readonly _dependenciesOfFile;
|
|
27
|
+
private readonly _consumersOfFile;
|
|
28
|
+
private readonly _relativePaths;
|
|
27
29
|
protected _options: ITypingsGeneratorOptions;
|
|
30
|
+
private readonly _fileGlob;
|
|
28
31
|
constructor(options: ITypingsGeneratorOptions);
|
|
29
32
|
generateTypingsAsync(): Promise<void>;
|
|
30
33
|
runWatcherAsync(): Promise<void>;
|
|
31
34
|
/**
|
|
32
|
-
* Register file dependencies that may effect the typings of a
|
|
35
|
+
* Register file dependencies that may effect the typings of a consumer file.
|
|
33
36
|
* Note: This feature is only useful in watch mode.
|
|
34
37
|
* The registerDependency method must be called in the body of parseAndGenerateTypings every
|
|
35
38
|
* time because the registry for a file is cleared at the beginning of processing.
|
|
36
39
|
*/
|
|
37
|
-
registerDependency(
|
|
40
|
+
registerDependency(consumer: string, rawDependency: string): void;
|
|
41
|
+
getOutputFilePaths(relativePath: string): string[];
|
|
42
|
+
private _reprocessFiles;
|
|
38
43
|
private _parseFileAndGenerateTypingsAsync;
|
|
44
|
+
/**
|
|
45
|
+
* Removes the consumer from all extant dependencies
|
|
46
|
+
*/
|
|
39
47
|
private _clearDependencies;
|
|
40
|
-
private _getDependencyTargets;
|
|
41
48
|
private _getTypingsFilePath;
|
|
42
49
|
private _normalizeFileExtensions;
|
|
43
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypingsGenerator.d.ts","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,SAAS,EAOV,MAAM,8BAA8B,CAAC;AAMtC;;GAEG;AACH,MAAM,WAAW,wBAAwB,CAAC,cAAc,GAAG,MAAM,GAAG,SAAS;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,uBAAuB,EAAE,CACvB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"TypingsGenerator.d.ts","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,SAAS,EAOV,MAAM,8BAA8B,CAAC;AAMtC;;GAEG;AACH,MAAM,WAAW,wBAAwB,CAAC,cAAc,GAAG,MAAM,GAAG,SAAS;IAC3E,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,uBAAuB,EAAE,CACvB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,KACjB,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC9C,wBAAwB,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAC9D,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAE3B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA2B;IAG/D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAG5D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsB;IAErD,SAAS,CAAC,QAAQ,EAAE,wBAAwB,CAAC;IAE7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEhB,OAAO,EAAE,wBAAwB;IA8CvC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBrC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAoE7C;;;;;OAKG;IACI,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAmBjE,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,EAAE;YAM3C,eAAe;YAkCf,iCAAiC;IAoC/C;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,wBAAwB;CAYjC"}
|