| 12 | }; |
| 13 | |
| 14 | export class ScriptLogger { |
| 15 | // filenames |
| 16 | readonly folderName: string; |
| 17 | readonly fileName: string; |
| 18 | readonly latestFileName: string; |
| 19 | |
| 20 | // output parameters |
| 21 | deployer: string = ''; |
| 22 | config: Record<string, any> = {}; // eslint-disable-line @typescript-eslint/no-explicit-any |
| 23 | contracts: Record<string, string> = {}; |
| 24 | actions: Record<string, string> = {}; |
| 25 | |
| 26 | constructor(readonly deployName: string, readonly network: string, readonly folder: string = './deploy-history') { |
| 27 | const now = new Date().toISOString(); |
| 28 | this.folderName = folder; |
| 29 | this.fileName = `${this.folderName}/${deployName}-${network}-${now}.json`; |
| 30 | this.latestFileName = `${this.folderName}/${deployName}-${network}-latest.json`; |
| 31 | } |
| 32 | |
| 33 | async confirmContinue(): Promise<void> { |
| 34 | console.log(`Deploying to: ${this.network}`); |
| 35 | console.log(`Deployer address: ${this.deployer}`); |
| 36 | console.log('Deployment configuration'); |
| 37 | console.log('------------------------'); |
| 38 | |
| 39 | for (const param in this.config) { |
| 40 | let value = this.config[param]; |
| 41 | |
| 42 | if (typeof value === 'object') { |
| 43 | value = JSON.stringify(value); |
| 44 | } |
| 45 | |
| 46 | console.log(` ${param}: ${value}`); |
| 47 | } |
| 48 | |
| 49 | const response = await waitForInput('\nDo you want to continue with deployment? y/N\n'); |
| 50 | if (response !== 'y') { |
| 51 | throw new Error('User chose to cancel deployment'); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | recordContract(name: string, address: string): void { |
| 56 | console.log(`Deployed ${name} to ${address}`); |
| 57 | this.contracts[name] = address; |
| 58 | } |
| 59 | |
| 60 | recordAction(name: string, content: string): void { |
| 61 | console.log(`${name}: ${content}`); |
| 62 | this.actions[name] = content; |
| 63 | } |
| 64 | |
| 65 | save(): void { |
| 66 | // conditionally create the deploy history folder |
| 67 | fs.mkdir(this.folderName, (err) => { |
| 68 | if (err && err.code !== 'EEXIST') throw err; |
| 69 | }); |
| 70 | |
| 71 | const allOutput = { |
nothing calls this directly
no outgoing calls
no test coverage detected