Added a auto generated comment to the generated files

master
WolverinDEV 2020-08-09 13:33:19 +02:00
parent e3f4d67a0f
commit c3b1a70f56
4 changed files with 21 additions and 4 deletions

7
demo/app/test.d.ts vendored
View File

@ -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" { 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"; 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";

View File

@ -18,7 +18,6 @@ export = {
module: true, module: true,
enumName: "TestIcons", enumName: "TestIcons",
classUnionName: "TestIconClasses", classUnionName: "TestIconClasses",
cssClassPrefix: "client-",
}, },
cssOptions: [ cssOptions: [
{ {

View File

@ -150,9 +150,19 @@ function generateEnumMembers(options: SpriteDtsOptions, sprite: GeneratedSprite,
return result; 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 = []; 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 = ""; let union = "";
for(const file of sprite.entries) for(const file of sprite.entries)
@ -194,12 +204,13 @@ export async function generateSpriteDts(options: SpriteDtsOptions, moduleName: s
if(options.module) { if(options.module) {
let result = ""; let result = "";
result += headerLines.join("\n");
result += `declare module "${modulePrefix}${moduleName}" {\n`; result += `declare module "${modulePrefix}${moduleName}" {\n`;
result += lines.map(e => " " + e).join("\n"); result += lines.map(e => " " + e).join("\n");
result += `\n}`; result += `\n}`;
return result; return result;
} else { } else {
return lines.join("\n"); return headerLines.join("\n") + lines.join("\n");
} }
} }

View File

@ -92,7 +92,7 @@ class SvgSpriteModule extends Module {
this.spriteJs = await generateSpriteJs(this.config.dtsOptions, this.sprite, this.spriteAssetUrl, this.config.cssClassPrefix); 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); await fs.writeFile(path.join(this.pluginConfig.dtsOutputFolder, this.configName + ".d.ts"), dtsContent);
})().then(() => { })().then(() => {
callback(); callback();