You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/utils/VersionPlugin.ts

42 lines
1.2 KiB

import FStream from 'fs';
/**
*
* @author phpdragon@qq.com
* @param options
* @constructor
*/
export class VersionPlugin
{
constructor(private dir_path: string, private version: string)
{
}
// apply方法是必须要有的因为当我们使用一个插件时new somePlugins({})webpack会去寻找插件的apply方法并执行
apply(compiler: { plugin: (arg0: string, arg1: { (params: any): void; (stats: any): void; }) => void; })
{
compiler.plugin("compile", (params: any) =>
{
FStream.stat(this.dir_path, (err, stats) =>
{
this.writeVersion(this.dir_path + "\\ver.json");
});
});
//编译器'对'所有任务已经完成'这个事件的监听
compiler.plugin("done", (stats: any) =>
{
console.log("应用编译完成!");
});
}
writeVersion = (versionFile: string) =>
{
console.log("\n当前版本号" + this.version);
//写入文件
FStream.writeFile(versionFile, this.version, (err: any) =>
{
if (err) throw err;
console.log("版本信息写入成功!");
});
};
}