feat(config): add smartconfig metadata and update TypeScript build configuration docs
This commit is contained in:
@@ -17,7 +17,8 @@ export interface ITsPublishJson {
|
||||
*/
|
||||
export class TsPublishConfig {
|
||||
private folderPath: string;
|
||||
private cachedConfig: ITsPublishJson | null | undefined = undefined;
|
||||
private cachedConfig: ITsPublishJson | null = null;
|
||||
private cacheLoaded = false;
|
||||
|
||||
constructor(folderPath: string) {
|
||||
this.folderPath = folderPath;
|
||||
@@ -35,7 +36,7 @@ export class TsPublishConfig {
|
||||
* Returns null if file doesn't exist or is invalid
|
||||
*/
|
||||
public async load(): Promise<ITsPublishJson | null> {
|
||||
if (this.cachedConfig !== undefined) {
|
||||
if (this.cacheLoaded) {
|
||||
return this.cachedConfig;
|
||||
}
|
||||
|
||||
@@ -43,9 +44,11 @@ export class TsPublishConfig {
|
||||
const configPath = path.join(this.folderPath, 'tspublish.json');
|
||||
const content = await fs.promises.readFile(configPath, 'utf8');
|
||||
this.cachedConfig = JSON.parse(content);
|
||||
this.cacheLoaded = true;
|
||||
return this.cachedConfig;
|
||||
} catch {
|
||||
this.cachedConfig = null;
|
||||
this.cacheLoaded = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +58,7 @@ export class TsPublishConfig {
|
||||
* Returns null if file doesn't exist or is invalid
|
||||
*/
|
||||
public loadSync(): ITsPublishJson | null {
|
||||
if (this.cachedConfig !== undefined) {
|
||||
if (this.cacheLoaded) {
|
||||
return this.cachedConfig;
|
||||
}
|
||||
|
||||
@@ -63,9 +66,11 @@ export class TsPublishConfig {
|
||||
const configPath = path.join(this.folderPath, 'tspublish.json');
|
||||
const content = fs.readFileSync(configPath, 'utf8');
|
||||
this.cachedConfig = JSON.parse(content);
|
||||
this.cacheLoaded = true;
|
||||
return this.cachedConfig;
|
||||
} catch {
|
||||
this.cachedConfig = null;
|
||||
this.cacheLoaded = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -111,6 +116,7 @@ export class TsPublishConfig {
|
||||
* Clear the cached config (useful for reloading)
|
||||
*/
|
||||
public clearCache(): void {
|
||||
this.cachedConfig = undefined;
|
||||
this.cachedConfig = null;
|
||||
this.cacheLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user