From c3b1a70f56d09b0995377132fc94e50830526c53 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 9 Aug 2020 13:33:19 +0200 Subject: [PATCH] Added a auto generated comment to the generated files --- demo/app/test.d.ts | 7 +++++++ demo/webpack.config.ts | 1 - plugin/generator.ts | 15 +++++++++++++-- plugin/plugin.ts | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/demo/app/test.d.ts b/demo/app/test.d.ts index 04e6cf0..aef64d9 100644 --- a/demo/app/test.d.ts +++ b/demo/app/test.d.ts @@ -1,3 +1,10 @@ +/* + * DO NOT MODIFY THIS FILE! + * + * This file has been auto generated by the svg-sprite generator. + * Sprite source directory: D:\git\web\webpack-svg-sprite\demo\sprites + * Sprite count: 20 + */ declare module "svg-sprites/test" { export type TestIconClasses = "client-about" | "client-activate_microphone" | "client-add" | "client-add_foe" | "client-add_folder" | "client-add_friend" | "client-addon-collection" | "client-addon" | "client-apply" | "client-arrow_down" | "client-arrow_left" | "client-arrow_right" | "client-arrow_up" | "client-away" | "client-ban_client" | "client-ban_list" | "client-bookmark_add" | "client-bookmark_add_folder" | "client-bookmark_duplicate" | "client-w2g"; diff --git a/demo/webpack.config.ts b/demo/webpack.config.ts index 4b71fb8..bcb0587 100644 --- a/demo/webpack.config.ts +++ b/demo/webpack.config.ts @@ -18,7 +18,6 @@ export = { module: true, enumName: "TestIcons", classUnionName: "TestIconClasses", - cssClassPrefix: "client-", }, cssOptions: [ { diff --git a/plugin/generator.ts b/plugin/generator.ts index 3dbc23b..e6cac17 100644 --- a/plugin/generator.ts +++ b/plugin/generator.ts @@ -150,9 +150,19 @@ function generateEnumMembers(options: SpriteDtsOptions, sprite: GeneratedSprite, return result; } -export async function generateSpriteDts(options: SpriteDtsOptions, moduleName: string, sprite: GeneratedSprite, cssClassPrefix: string, modulePrefix: string) { +export async function generateSpriteDts(options: SpriteDtsOptions, moduleName: string, sprite: GeneratedSprite, cssClassPrefix: string, modulePrefix: string, sourceDirectory: string) { + const headerLines = []; const lines = []; + headerLines.push(`/*`); + headerLines.push(` * DO NOT MODIFY THIS FILE!`); + headerLines.push(` *`); + headerLines.push(` * This file has been auto generated by the svg-sprite generator.`); + headerLines.push(` * Sprite source directory: ${sourceDirectory}`); + headerLines.push(` * Sprite count: ${sprite.entries.length}`); + headerLines.push(` */`); + headerLines.push(``); + { let union = ""; for(const file of sprite.entries) @@ -194,12 +204,13 @@ export async function generateSpriteDts(options: SpriteDtsOptions, moduleName: s if(options.module) { let result = ""; + result += headerLines.join("\n"); result += `declare module "${modulePrefix}${moduleName}" {\n`; result += lines.map(e => " " + e).join("\n"); result += `\n}`; return result; } else { - return lines.join("\n"); + return headerLines.join("\n") + lines.join("\n"); } } diff --git a/plugin/plugin.ts b/plugin/plugin.ts index cf523ea..5a167c5 100644 --- a/plugin/plugin.ts +++ b/plugin/plugin.ts @@ -92,7 +92,7 @@ class SvgSpriteModule extends Module { this.spriteJs = await generateSpriteJs(this.config.dtsOptions, this.sprite, this.spriteAssetUrl, this.config.cssClassPrefix); - const dtsContent = await generateSpriteDts(this.config.dtsOptions, this.configName, this.sprite, this.config.cssClassPrefix, this.pluginConfig.modulePrefix); + const dtsContent = await generateSpriteDts(this.config.dtsOptions, this.configName, this.sprite, this.config.cssClassPrefix, this.pluginConfig.modulePrefix, this.config.folder); await fs.writeFile(path.join(this.pluginConfig.dtsOutputFolder, this.configName + ".d.ts"), dtsContent); })().then(() => { callback();