@rushstack/typings-generator
Advanced tools
Comparing version 0.1.52 to 0.2.0
@@ -5,2 +5,25 @@ { | ||
{ | ||
"version": "0.2.0", | ||
"tag": "@rushstack/typings-generator_v0.2.0", | ||
"date": "Sun, 13 Sep 2020 01:53:20 GMT", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"comment": "Change TypingsGenerator to support async methods. Typings generation now returns a promise." | ||
} | ||
], | ||
"dependency": [ | ||
{ | ||
"comment": "Updating dependency \"@microsoft/rush-stack-compiler-3.5\" to `0.8.14`" | ||
}, | ||
{ | ||
"comment": "Updating dependency \"@microsoft/node-library-build\" to `6.4.45`" | ||
}, | ||
{ | ||
"comment": "Updating dependency \"@rushstack/heft\" to `0.12.0`" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.1.52", | ||
@@ -7,0 +30,0 @@ "tag": "@rushstack/typings-generator_v0.1.52", |
# Change Log - @rushstack/typings-generator | ||
This log was last generated on Fri, 11 Sep 2020 02:13:35 GMT and should not be manually modified. | ||
This log was last generated on Sun, 13 Sep 2020 01:53:20 GMT and should not be manually modified. | ||
## 0.2.0 | ||
Sun, 13 Sep 2020 01:53:20 GMT | ||
### Minor changes | ||
- Change TypingsGenerator to support async methods. Typings generation now returns a promise. | ||
## 0.1.52 | ||
@@ -6,0 +13,0 @@ Fri, 11 Sep 2020 02:13:35 GMT |
@@ -32,3 +32,3 @@ import { Terminal } from '@rushstack/node-core-library'; | ||
fileExtensions: string[]; | ||
parseAndGenerateTypings: (fileContents: string, filePath: string) => TTypingsResult; | ||
parseAndGenerateTypings: (fileContents: string, filePath: string) => TTypingsResult | Promise<TTypingsResult>; | ||
terminal?: Terminal; | ||
@@ -56,5 +56,5 @@ filesToIgnore?: string[]; | ||
constructor(options: ITypingsGeneratorOptions); | ||
generateTypings(): void; | ||
runWatcher(): void; | ||
private _parseFileAndGenerateTypings; | ||
generateTypingsAsync(): Promise<void>; | ||
runWatcherAsync(): Promise<void>; | ||
private _parseFileAndGenerateTypingsAsync; | ||
private _getTypingsFilePath; | ||
@@ -61,0 +61,0 @@ private _normalizeFileExtensions; |
@@ -16,4 +16,4 @@ "use strict"; | ||
constructor(options) { | ||
super(Object.assign({}, options, { parseAndGenerateTypings: (fileContents, filePath) => { | ||
const stringValueTypings = options.parseAndGenerateTypings(fileContents, filePath); | ||
super(Object.assign({}, options, { parseAndGenerateTypings: async (fileContents, filePath) => { | ||
const stringValueTypings = await options.parseAndGenerateTypings(fileContents, filePath); | ||
const outputLines = []; | ||
@@ -20,0 +20,0 @@ let indent = ''; |
@@ -9,3 +9,3 @@ import { Terminal } from '@rushstack/node-core-library'; | ||
fileExtensions: string[]; | ||
parseAndGenerateTypings: (fileContents: string, filePath: string) => TTypingsResult; | ||
parseAndGenerateTypings: (fileContents: string, filePath: string) => TTypingsResult | Promise<TTypingsResult>; | ||
terminal?: Terminal; | ||
@@ -22,5 +22,5 @@ filesToIgnore?: string[]; | ||
constructor(options: ITypingsGeneratorOptions); | ||
generateTypings(): void; | ||
runWatcher(): void; | ||
private _parseFileAndGenerateTypings; | ||
generateTypingsAsync(): Promise<void>; | ||
runWatcherAsync(): Promise<void>; | ||
private _parseFileAndGenerateTypingsAsync; | ||
private _getTypingsFilePath; | ||
@@ -27,0 +27,0 @@ private _normalizeFileExtensions; |
@@ -41,4 +41,4 @@ "use strict"; | ||
} | ||
generateTypings() { | ||
node_core_library_1.FileSystem.ensureEmptyFolder(this._options.generatedTsFolder); | ||
async generateTypingsAsync() { | ||
await node_core_library_1.FileSystem.ensureEmptyFolderAsync(this._options.generatedTsFolder); | ||
const filesToIgnore = new Set(this._options.filesToIgnore.map((fileToIgnore) => { | ||
@@ -58,21 +58,24 @@ return path.resolve(this._options.srcFolder, fileToIgnore); | ||
} | ||
this._parseFileAndGenerateTypings(filePath); | ||
await this._parseFileAndGenerateTypingsAsync(filePath); | ||
} | ||
} | ||
runWatcher() { | ||
node_core_library_1.FileSystem.ensureEmptyFolder(this._options.generatedTsFolder); | ||
async runWatcherAsync() { | ||
await node_core_library_1.FileSystem.ensureEmptyFolderAsync(this._options.generatedTsFolder); | ||
const globBase = path.resolve(this._options.srcFolder, '**'); | ||
const watcher = chokidar.watch(this._options.fileExtensions.map((fileExtension) => path.join(globBase, `*${fileExtension}`))); | ||
const boundGenerateTypingsFunction = this._parseFileAndGenerateTypings.bind(this); | ||
watcher.on('add', boundGenerateTypingsFunction); | ||
watcher.on('change', boundGenerateTypingsFunction); | ||
watcher.on('unlink', (filePath) => { | ||
const generatedTsFilePath = this._getTypingsFilePath(filePath); | ||
node_core_library_1.FileSystem.deleteFile(generatedTsFilePath); | ||
await new Promise((resolve, reject) => { | ||
const watcher = chokidar.watch(this._options.fileExtensions.map((fileExtension) => path.join(globBase, `*${fileExtension}`))); | ||
const boundGenerateTypingsFunction = this._parseFileAndGenerateTypingsAsync.bind(this); | ||
watcher.on('add', boundGenerateTypingsFunction); | ||
watcher.on('change', boundGenerateTypingsFunction); | ||
watcher.on('unlink', async (filePath) => { | ||
const generatedTsFilePath = this._getTypingsFilePath(filePath); | ||
await node_core_library_1.FileSystem.deleteFileAsync(generatedTsFilePath); | ||
}); | ||
watcher.on('error', reject); | ||
}); | ||
} | ||
_parseFileAndGenerateTypings(locFilePath) { | ||
async _parseFileAndGenerateTypingsAsync(locFilePath) { | ||
try { | ||
const fileContents = node_core_library_1.FileSystem.readFile(locFilePath); | ||
const typingsData = this._options.parseAndGenerateTypings(fileContents, locFilePath); | ||
const fileContents = await node_core_library_1.FileSystem.readFileAsync(locFilePath); | ||
const typingsData = await this._options.parseAndGenerateTypings(fileContents, locFilePath); | ||
const generatedTsFilePath = this._getTypingsFilePath(locFilePath); | ||
@@ -84,3 +87,3 @@ const prefixedTypingsData = [ | ||
].join(os_1.EOL); | ||
node_core_library_1.FileSystem.writeFile(generatedTsFilePath, prefixedTypingsData, { | ||
await node_core_library_1.FileSystem.writeFileAsync(generatedTsFilePath, prefixedTypingsData, { | ||
ensureFolderExists: true, | ||
@@ -87,0 +90,0 @@ convertLineEndings: "os" /* OsDefault */ |
{ | ||
"name": "@rushstack/typings-generator", | ||
"version": "0.1.52", | ||
"description": "This library provides functionality for automatically generator typings for non-TS files.", | ||
"version": "0.2.0", | ||
"description": "This library provides functionality for automatically generating typings for non-TS files.", | ||
"keywords": [ | ||
@@ -27,8 +27,8 @@ "dts", | ||
"devDependencies": { | ||
"@microsoft/rush-stack-compiler-3.5": "0.8.13", | ||
"@microsoft/node-library-build": "6.4.44", | ||
"@microsoft/rush-stack-compiler-3.5": "0.8.14", | ||
"@microsoft/node-library-build": "6.4.45", | ||
"@rushstack/eslint-config": "1.3.0", | ||
"@rushstack/heft": "0.11.1", | ||
"@rushstack/heft": "0.12.0", | ||
"@types/glob": "7.1.1" | ||
} | ||
} |
@@ -30,6 +30,6 @@ # Typings Generator | ||
// To run once before a compilation: | ||
typingsGenerator.generateTypings(); | ||
await typingsGenerator.generateTypings(); | ||
// To start a watcher: | ||
typingsGenerator.runWatcher(); | ||
await typingsGenerator.runWatcher(); | ||
``` | ||
@@ -54,3 +54,3 @@ | ||
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => string` | ||
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => string | Promise<string>` | ||
@@ -77,3 +77,3 @@ This property is used to specify the function that should be called on every file for which typings | ||
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => { typings: ({ exportName: string, comment?: string })[] }` | ||
### `parseAndGenerateTypings = (fileContents: string, filePath: string) => { typings: ({ exportName: string, comment?: string })[] } | Promise<{ typings: ({ exportName: string, comment?: string })[] }>` | ||
@@ -80,0 +80,0 @@ This function should behave the same as the `parseAndGenerateTypings` function for the standard |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
67715
1218