"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});const fs_extra_1=__importDefault(require("fs-extra")),tapable_1=require("tapable");class Generator{constructor({template:t,tempDir:e,projectPath:s,ui:i,plugins:a,lang:r,execute:o,environment:p}){this.state={},this.absoluteProjectDir="",this.tempDir="",this._plugins=[],this.hooks={start:new tapable_1.AsyncSeriesHook(["generator"]),prompt:new tapable_1.AsyncSeriesHook(["generator","ui"]),render:new tapable_1.AsyncSeriesHook(["generator"]),output:new tapable_1.AsyncSeriesHook(["generator"]),afterOutput:new tapable_1.AsyncSeriesHook(["generator"])},this.template=t,this.tempDir=e,this.absoluteProjectDir=s,this.ui=i,this.lang=r,this.execute=o,this.environment=p,this.addPlugins(a)}_applyPlugins(){this._plugins.forEach(t=>t.apply(this))}async _output(){await fs_extra_1.default.copy(this.tempDir,this.absoluteProjectDir),await fs_extra_1.default.remove(this.tempDir)}async run(){this._applyPlugins(),await this.hooks.start.promise(this),await this.hooks.prompt.promise(this,this.ui),await this.hooks.render.promise(this),await this.hooks.output.promise(this),await this._output(),await this.hooks.afterOutput.promise(this)}setState(t){this.state=Object.assign(Object.assign({},this.state),t)}getState(){return this.state}addPlugins(t){this._plugins.push(...t)}}exports.default=Generator;