hardhat-deploy 2.0.0-next.7 → 2.0.0-next.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +197 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config/default.d.ts.map +1 -0
  8. package/dist/config/default.js +5 -0
  9. package/dist/config/default.js.map +1 -0
  10. package/dist/config/get-config.d.ts.map +1 -0
  11. package/dist/config/get-config.js +9 -0
  12. package/dist/config/get-config.js.map +1 -0
  13. package/dist/config/validation.d.ts.map +1 -0
  14. package/dist/config/validation.js +17 -0
  15. package/dist/config/validation.js.map +1 -0
  16. package/dist/generate-types.d.ts +5 -0
  17. package/dist/generate-types.d.ts.map +1 -0
  18. package/dist/generate-types.js +241 -0
  19. package/dist/generate-types.js.map +1 -0
  20. package/dist/helpers.d.ts +34 -0
  21. package/dist/helpers.d.ts.map +1 -0
  22. package/dist/{esm/helpers.js → helpers.js} +106 -73
  23. package/dist/helpers.js.map +1 -0
  24. package/dist/hook-handlers/config.d.ts.map +1 -0
  25. package/dist/hook-handlers/config.js +68 -0
  26. package/dist/hook-handlers/config.js.map +1 -0
  27. package/dist/hook-handlers/solidity.d.ts.map +1 -0
  28. package/dist/hook-handlers/solidity.js +21 -0
  29. package/dist/hook-handlers/solidity.js.map +1 -0
  30. package/dist/index.d.ts +8 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/{esm/index.js → index.js} +20 -3
  33. package/dist/index.js.map +1 -0
  34. package/dist/postinstall.d.ts +3 -0
  35. package/dist/postinstall.d.ts.map +1 -0
  36. package/dist/postinstall.js +148 -0
  37. package/dist/postinstall.js.map +1 -0
  38. package/dist/{esm/tasks → tasks}/deploy.d.ts +1 -0
  39. package/dist/tasks/deploy.d.ts.map +1 -0
  40. package/dist/tasks/deploy.js +32 -0
  41. package/dist/tasks/deploy.js.map +1 -0
  42. package/dist/{esm/type-extensions.d.ts → type-extensions.d.ts} +2 -2
  43. package/dist/type-extensions.d.ts.map +1 -0
  44. package/dist/type-extensions.js.map +1 -0
  45. package/dist/types.d.ts +13 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js.map +1 -0
  48. package/dist/utils/files.d.ts +10 -0
  49. package/dist/utils/files.d.ts.map +1 -0
  50. package/dist/utils/files.js +44 -0
  51. package/dist/utils/files.js.map +1 -0
  52. package/dist/v1-detection.d.ts +12 -0
  53. package/dist/v1-detection.d.ts.map +1 -0
  54. package/dist/v1-detection.js +118 -0
  55. package/dist/v1-detection.js.map +1 -0
  56. package/dist/v1-entry.cjs +92 -0
  57. package/package.json +57 -27
  58. package/src/cli.ts +246 -0
  59. package/src/config/default.ts +6 -0
  60. package/src/config/get-config.ts +12 -0
  61. package/src/config/validation.ts +25 -0
  62. package/src/generate-types.ts +278 -0
  63. package/src/helpers.ts +311 -0
  64. package/src/hook-handlers/config.ts +80 -0
  65. package/src/hook-handlers/solidity.ts +33 -0
  66. package/src/index.ts +53 -0
  67. package/src/postinstall.ts +166 -0
  68. package/src/tasks/deploy.ts +43 -0
  69. package/src/type-extensions.ts +12 -0
  70. package/src/types.ts +9 -0
  71. package/src/utils/files.ts +59 -0
  72. package/src/v1-entry.cjs +92 -0
  73. package/templates/basic/README.md +44 -0
  74. package/templates/basic/contracts/Counter.sol +19 -0
  75. package/templates/basic/contracts/Counter.t.sol +29 -0
  76. package/templates/basic/deploy/01_deploy_counter.ts +13 -0
  77. package/templates/basic/hardhat.config.ts +50 -0
  78. package/templates/basic/package.json +31 -0
  79. package/templates/basic/pnpm-lock.yaml +1643 -0
  80. package/templates/basic/rocketh/config.ts +65 -0
  81. package/templates/basic/rocketh/deploy.ts +20 -0
  82. package/templates/basic/rocketh/environment.ts +22 -0
  83. package/templates/basic/test/Counter.ts +61 -0
  84. package/templates/basic/tsconfig.json +13 -0
  85. package/dist/esm/config/default.d.ts.map +0 -1
  86. package/dist/esm/config/default.js +0 -8
  87. package/dist/esm/config/default.js.map +0 -1
  88. package/dist/esm/config/get-config.d.ts.map +0 -1
  89. package/dist/esm/config/get-config.js +0 -8
  90. package/dist/esm/config/get-config.js.map +0 -1
  91. package/dist/esm/config/validation.d.ts.map +0 -1
  92. package/dist/esm/config/validation.js +0 -16
  93. package/dist/esm/config/validation.js.map +0 -1
  94. package/dist/esm/generate-types.d.ts +0 -6
  95. package/dist/esm/generate-types.d.ts.map +0 -1
  96. package/dist/esm/generate-types.js +0 -198
  97. package/dist/esm/generate-types.js.map +0 -1
  98. package/dist/esm/helpers.d.ts +0 -18
  99. package/dist/esm/helpers.d.ts.map +0 -1
  100. package/dist/esm/helpers.js.map +0 -1
  101. package/dist/esm/hook-handlers/config.d.ts.map +0 -1
  102. package/dist/esm/hook-handlers/config.js +0 -16
  103. package/dist/esm/hook-handlers/config.js.map +0 -1
  104. package/dist/esm/hook-handlers/solidity.d.ts.map +0 -1
  105. package/dist/esm/hook-handlers/solidity.js +0 -15
  106. package/dist/esm/hook-handlers/solidity.js.map +0 -1
  107. package/dist/esm/index.d.ts +0 -5
  108. package/dist/esm/index.d.ts.map +0 -1
  109. package/dist/esm/index.js.map +0 -1
  110. package/dist/esm/tasks/deploy.d.ts.map +0 -1
  111. package/dist/esm/tasks/deploy.js +0 -21
  112. package/dist/esm/tasks/deploy.js.map +0 -1
  113. package/dist/esm/type-extensions.d.ts.map +0 -1
  114. package/dist/esm/type-extensions.js.map +0 -1
  115. package/dist/esm/types.d.ts +0 -15
  116. package/dist/esm/types.d.ts.map +0 -1
  117. package/dist/esm/types.js.map +0 -1
  118. /package/dist/{esm/config → config}/default.d.ts +0 -0
  119. /package/dist/{esm/config → config}/get-config.d.ts +0 -0
  120. /package/dist/{esm/config → config}/validation.d.ts +0 -0
  121. /package/dist/{esm/hook-handlers → hook-handlers}/config.d.ts +0 -0
  122. /package/dist/{esm/hook-handlers → hook-handlers}/solidity.d.ts +0 -0
  123. /package/dist/{esm/type-extensions.js → type-extensions.js} +0 -0
  124. /package/dist/{esm/types.js → types.js} +0 -0
@@ -0,0 +1,92 @@
1
+ // This file serves as a CommonJS entry point for hardhat v2
2
+ // It detects v1 users and shows them a migration message
3
+
4
+ const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/documentation/how-to/migration-from-v1.html';
5
+ const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
6
+
7
+ function getHardhatVersion() {
8
+ try {
9
+ const {execSync} = require('child_process');
10
+ // Run hardhat --version to get the version
11
+ const output = execSync('hardhat --version', {encoding: 'utf-8', stdio: 'pipe'});
12
+ return output.trim();
13
+ } catch (e) {
14
+ console.error(e);
15
+ return 'unknown';
16
+ }
17
+ }
18
+
19
+ function detectV1Patterns() {
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+ const reasons = [];
23
+
24
+ // Check hardhat.config for v1 patterns
25
+ const configFiles = ['hardhat.config.js', 'hardhat.config.cjs', 'hardhat.config.ts'];
26
+
27
+ for (const configFile of configFiles) {
28
+ const configPath = path.join(process.cwd(), configFile);
29
+ if (fs.existsSync(configPath)) {
30
+ try {
31
+ const content = fs.readFileSync(configPath, 'utf-8');
32
+
33
+ if (content.includes('namedAccounts')) {
34
+ reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern`);
35
+ }
36
+
37
+ if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
38
+ reasons.push(
39
+ `Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`,
40
+ );
41
+ }
42
+
43
+ if (content.includes('module.exports')) {
44
+ reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
45
+ }
46
+ } catch (e) {
47
+ // Failed to read config - continue
48
+ }
49
+ }
50
+ }
51
+
52
+ return reasons;
53
+ }
54
+
55
+ function throwV1Error() {
56
+ const hardhatVersion = getHardhatVersion();
57
+ const reasons = detectV1Patterns();
58
+
59
+ let reasonsList = '';
60
+ if (reasons.length > 0) {
61
+ reasonsList = '\nYour project uses hardhat-deploy v1 patterns:\n\n' + reasons.map((r) => ` • ${r}`).join('\n');
62
+ }
63
+
64
+ throw new Error(`
65
+ ╔══════════════════════════════════════════════════════════════════════════════╗
66
+ ║ HARDHAT-DEPLOY V2 - INCOMPATIBLE WITH HARDHAT V2 ║
67
+ ╚══════════════════════════════════════════════════════════════════════════════╝
68
+
69
+ hardhat-deploy v2 requires hardhat 3.x, but you are using hardhat ${hardhatVersion}.${reasonsList}
70
+
71
+ hardhat-deploy v2 has MAJOR breaking changes and uses ESM modules.
72
+
73
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
74
+
75
+ OPTION 1: Install hardhat-deploy v1 (recommended for hardhat v2 projects)
76
+
77
+ npm uninstall hardhat-deploy
78
+ ${V1_INSTALL_CMD}
79
+
80
+ OPTION 2: Upgrade to hardhat 3.x and hardhat-deploy v2
81
+
82
+ Migration guide: ${MIGRATION_URL}
83
+
84
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
85
+ `);
86
+ }
87
+
88
+ // Throw error immediately when loaded by hardhat v2
89
+ throwV1Error();
90
+
91
+ // Export a dummy function to satisfy hardhat's plugin loading
92
+ module.exports = function () {};
package/package.json CHANGED
@@ -1,54 +1,84 @@
1
1
  {
2
2
  "name": "hardhat-deploy",
3
- "version": "2.0.0-next.7",
4
- "description": "deployment plugin for hardhat",
3
+ "version": "2.0.0-next.71",
4
+ "description": "Hardhat plugin for replicable smart contract deployments and easy testing across multiple EVM chains, with support for proxies, diamonds, named accounts, and deployment fixtures",
5
+ "keywords": [
6
+ "hardhat",
7
+ "ethereum",
8
+ "solidity",
9
+ "deployment",
10
+ "test",
11
+ "cli"
12
+ ],
13
+ "author": "Ronan Sandford",
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/wighawag/hardhat-deploy#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/wighawag/hardhat-deploy.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/wighawag/hardhat-deploy/issues"
22
+ },
5
23
  "publishConfig": {
6
24
  "access": "public"
7
25
  },
8
26
  "type": "module",
9
- "main": "dist/esm/index.js",
10
- "module": "./dist/esm/index.js",
11
- "types": "./dist/esm/index.d.ts",
27
+ "main": "dist/index.js",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
12
30
  "exports": {
13
31
  ".": {
14
32
  "import": {
15
- "types": "./dist/esm/index.d.ts",
16
- "default": "./dist/esm/index.js"
17
- }
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "require": "./dist/v1-entry.cjs"
18
37
  },
19
38
  "./helpers": {
20
39
  "import": {
21
- "types": "./dist/esm/helpers.d.ts",
22
- "default": "./dist/esm/helpers.js"
40
+ "types": "./dist/helpers.d.ts",
41
+ "default": "./dist/helpers.js"
23
42
  }
24
43
  }
25
44
  },
26
45
  "files": [
27
- "dist"
46
+ "dist",
47
+ "src",
48
+ "bin",
49
+ "templates"
28
50
  ],
51
+ "bin": {
52
+ "hardhat-deploy": "./dist/cli.js"
53
+ },
54
+ "engines": {
55
+ "node": ">=22.0.0"
56
+ },
29
57
  "devDependencies": {
30
- "@changesets/cli": "^2.28.1",
31
- "@types/node": "^22.13.10",
32
- "as-soon": "^0.0.11",
33
- "hardhat": "^3.0.0-next.1",
34
- "rimraf": "^6.0.1",
35
- "rocketh": "1.0.0-next.2",
58
+ "@changesets/cli": "^2.29.8",
59
+ "@rocketh/node": "0.17.21",
60
+ "@types/node": "^25.0.10",
61
+ "as-soon": "^0.1.5",
62
+ "hardhat": "3.1.5",
63
+ "rimraf": "^6.1.2",
64
+ "rocketh": "0.17.18",
36
65
  "set-defaults": "^0.0.5",
37
- "typescript": "^5.5.2"
66
+ "typescript": "^5.9.3"
38
67
  },
39
68
  "peerDependencies": {
40
- "hardhat": "^3.0.0-next.1",
41
- "rocketh": "1.0.0-next.2"
69
+ "@rocketh/node": "^0.17.21",
70
+ "hardhat": "^3.1.5"
42
71
  },
43
72
  "dependencies": {
44
- "@nomicfoundation/hardhat-errors": "3.0.0-next.0",
45
- "@nomicfoundation/hardhat-zod-utils": "3.0.0-next.0",
46
- "@types/debug": "^4.1.12",
47
- "debug": "^4.4.0",
48
- "zod": "^3.24.2"
73
+ "@nomicfoundation/hardhat-zod-utils": "3.0.1",
74
+ "commander": "^14.0.2",
75
+ "named-logs": "^0.4.1",
76
+ "named-logs-console": "^0.5.1",
77
+ "zod": "^4.3.6"
49
78
  },
50
79
  "scripts": {
51
- "build": "tsc --project tsconfig.json",
52
- "dev": "as-soon -w src pnpm build"
80
+ "build": "tsc --project tsconfig.json && cp src/v1-entry.cjs dist/",
81
+ "dev": "as-soon -w src pnpm build",
82
+ "postinstall": "node ./dist/postinstall.js"
53
83
  }
54
84
  }
package/src/cli.ts ADDED
@@ -0,0 +1,246 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { readFileSync, readdirSync, mkdirSync, copyFileSync, existsSync, writeFileSync, statSync } from 'fs';
5
+ import { join, dirname, basename } from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ import * as readline from 'readline';
8
+ import pkg from '../package.json' with { type: 'json' };
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+
13
+ const program = new Command();
14
+
15
+ // Get the current version of hardhat-deploy
16
+ const getHardhatDeployVersion = (): string => {
17
+ return pkg.version;
18
+ };
19
+
20
+ const askFolder = async (): Promise<string> => {
21
+ const rl = readline.createInterface({
22
+ input: process.stdin,
23
+ output: process.stdout,
24
+ });
25
+
26
+ return new Promise((resolve) => {
27
+ rl.question('Enter folder path (default: ./): ', (answer) => {
28
+ rl.close();
29
+ resolve(answer.trim() || './');
30
+ });
31
+ });
32
+ };
33
+
34
+ const askAutoInstall = async (): Promise<boolean> => {
35
+ const rl = readline.createInterface({
36
+ input: process.stdin,
37
+ output: process.stdout,
38
+ });
39
+
40
+ return new Promise((resolve) => {
41
+ rl.question('Auto-install dependencies with pnpm? (Y/n): ', (answer) => {
42
+ rl.close();
43
+ const trimmed = answer.trim().toLowerCase();
44
+ resolve(trimmed === '' || trimmed === 'y' || trimmed === 'yes');
45
+ });
46
+ });
47
+ };
48
+
49
+ const isFolderEmpty = (folderPath: string): boolean => {
50
+ if (!existsSync(folderPath)) {
51
+ return true;
52
+ }
53
+
54
+ try {
55
+ const files = readdirSync(folderPath);
56
+ return files.length === 0;
57
+ } catch (error) {
58
+ // If we can't read the directory, treat it as not empty
59
+ return false;
60
+ }
61
+ };
62
+
63
+ const copyFile = (
64
+ source: string,
65
+ target: string,
66
+ replacements: Record<string, string> = {},
67
+ gitignorePatterns: string[] = []
68
+ ): void => {
69
+ const fileName = basename(source);
70
+
71
+ // Check if file should be skipped based on gitignore patterns
72
+ for (const pattern of gitignorePatterns) {
73
+ if (fileName === pattern || fileName.endsWith(pattern.replace('*', ''))) {
74
+ return; // Skip this file
75
+ }
76
+ }
77
+
78
+ let content = readFileSync(source, 'utf-8');
79
+
80
+ // Apply replacements
81
+ for (const [search, replace] of Object.entries(replacements)) {
82
+ content = content.replaceAll(search, replace);
83
+ }
84
+
85
+ mkdirSync(dirname(target), { recursive: true });
86
+
87
+ // For binary files, just copy as-is
88
+ if (source.endsWith('.lock') || source.endsWith('.so') || source.endsWith('.wasm')) {
89
+ copyFileSync(source, target);
90
+ } else {
91
+ writeFileSync(target, content, 'utf-8');
92
+ }
93
+ };
94
+
95
+ const parseGitignore = (gitignorePath: string): string[] => {
96
+ if (!existsSync(gitignorePath)) {
97
+ return [];
98
+ }
99
+
100
+ const content = readFileSync(gitignorePath, 'utf-8');
101
+ return content
102
+ .split('\n')
103
+ .map((line: string) => line.trim())
104
+ .filter((line: string) => line && !line.startsWith('#'));
105
+ };
106
+
107
+ const copyFolder = (
108
+ source: string,
109
+ target: string,
110
+ replacements: Record<string, string> = {},
111
+ gitignorePatterns: string[] = []
112
+ ): void => {
113
+ if (!existsSync(target)) {
114
+ mkdirSync(target, { recursive: true });
115
+ }
116
+
117
+ const files = readdirSync(source);
118
+
119
+ files.forEach((file) => {
120
+ const sourcePath = join(source, file);
121
+ const targetPath = join(target, file);
122
+
123
+ const stat = statSync(sourcePath);
124
+
125
+ if (stat.isDirectory()) {
126
+ // Check if directory should be skipped based on gitignore patterns
127
+ const shouldSkip = gitignorePatterns.some(pattern =>
128
+ file === pattern.replace('/', '') || pattern.startsWith('/') && file === pattern.slice(1)
129
+ );
130
+
131
+ if (!shouldSkip) {
132
+ copyFolder(sourcePath, targetPath, replacements, gitignorePatterns);
133
+ }
134
+ } else {
135
+ copyFile(sourcePath, targetPath, replacements, gitignorePatterns);
136
+ }
137
+ });
138
+ };
139
+
140
+ const generateProject = (targetFolder: string, projectName?: string): void => {
141
+ // find template in published package
142
+ const templatePath = join(__dirname, '../templates/basic');
143
+ const gitignorePath = join(templatePath, '.gitignore');
144
+
145
+ // Parse gitignore patterns
146
+ const gitignorePatterns = parseGitignore(gitignorePath);
147
+
148
+ // Determine project name from folder or use placeholder
149
+ const folderName = projectName || basename(targetFolder === './' ? process.cwd() : targetFolder);
150
+
151
+ // Get the current version of hardhat-deploy
152
+ const hardhatDeployVersion = getHardhatDeployVersion();
153
+
154
+ const replacements: Record<string, string> = {
155
+ 'template-hardhat-node-test-runner': `${folderName}`,
156
+ 'workspace:*': hardhatDeployVersion,
157
+ };
158
+
159
+ console.log(`Generating project in: ${targetFolder}`);
160
+ copyFolder(templatePath, targetFolder, replacements, gitignorePatterns);
161
+ console.log('✓ Project initialized successfully!');
162
+ };
163
+
164
+ const runPnpmInstall = async (folderPath: string): Promise<void> => {
165
+ console.log(`Installing dependencies...`);
166
+ const { spawn } = await import('child_process');
167
+
168
+ return new Promise((resolve, reject) => {
169
+ // Use --ignore-workspace to ensure dependencies are installed locally
170
+ // This prevents pnpm from treating the target folder as part of a parent workspace
171
+ const pnpm = spawn('pnpm', ['install', '--ignore-workspace', `--no-frozen-lockfile`], {
172
+ cwd: folderPath,
173
+ stdio: 'inherit',
174
+ });
175
+
176
+ pnpm.on('close', (code) => {
177
+ if (code === 0) {
178
+ console.log('✓ Dependencies installed successfully!');
179
+ resolve();
180
+ } else {
181
+ reject(new Error(`pnpm install failed with exit code ${code}`));
182
+ }
183
+ });
184
+
185
+ pnpm.on('error', (error) => {
186
+ reject(error);
187
+ });
188
+ });
189
+ };
190
+
191
+ program
192
+ .name('hardhat-deploy')
193
+ .description('CLI for hardhat-deploy')
194
+ .version(pkg.version);
195
+
196
+ program
197
+ .command('init')
198
+ .argument('[folder]', 'folder to initialize the project in')
199
+ .option('--install', 'auto-install dependencies with pnpm')
200
+ .description('Initialize a new hardhat-deploy project')
201
+ .action(async (folder?: string, options?: { install?: boolean }) => {
202
+ let targetFolder = folder;
203
+ let autoInstall = options?.install ?? false;
204
+
205
+ // If no folder specified, ask user
206
+ if (!targetFolder) {
207
+ targetFolder = await askFolder();
208
+ // If we prompted for folder, also prompt for auto-install
209
+ autoInstall = await askAutoInstall();
210
+ }
211
+
212
+ // Normalize path
213
+ targetFolder = targetFolder.trim();
214
+
215
+ // Check if folder is empty
216
+ if (!isFolderEmpty(targetFolder)) {
217
+ console.error(`Error: Folder "${targetFolder}" is not empty. Please specify an empty folder or a new folder path.`);
218
+ process.exit(1);
219
+ }
220
+
221
+ // Generate project
222
+ generateProject(targetFolder);
223
+
224
+ // Auto-install if requested
225
+ if (autoInstall) {
226
+ try {
227
+ await runPnpmInstall(targetFolder);
228
+ } catch (error) {
229
+ console.error('Failed to install dependencies:', error);
230
+ console.log('\nYou can install dependencies manually:');
231
+ console.log(` cd ${targetFolder === './' ? '.' : targetFolder}`);
232
+ console.log(' pnpm install');
233
+ process.exit(1);
234
+ }
235
+ }
236
+
237
+ // Show next steps
238
+ console.log(`\nNext steps:`);
239
+ console.log(` cd ${targetFolder === './' ? '.' : targetFolder}`);
240
+ if (!autoInstall) {
241
+ console.log(` pnpm install`);
242
+ }
243
+ console.log(` pnpm hardhat test`);
244
+ });
245
+
246
+ program.parse();
@@ -0,0 +1,6 @@
1
+ import type {ArtifactGenerationConfig} from '../types.js';
2
+
3
+ export const DEFAULT_CONFIG: ArtifactGenerationConfig = {
4
+ // externalArtifacts: [],
5
+ destinations: [{mode: 'javascript', folder: './generated'}],
6
+ };
@@ -0,0 +1,12 @@
1
+ import type {ArtifactGenerationConfig, ArtifactGenerationUserConfig} from '../types.js';
2
+
3
+ import {DEFAULT_CONFIG} from './default.js';
4
+
5
+ export function getConfig(userConfig: ArtifactGenerationUserConfig | undefined): ArtifactGenerationConfig {
6
+ return {
7
+ destinations:
8
+ userConfig?.destinations?.map((v) => ({mode: v.mode || 'javascript', folder: v.folder || './generated'})) ||
9
+ DEFAULT_CONFIG.destinations,
10
+ // externalArtifacts: userConfig?.externalArtifacts || DEFAULT_CONFIG.externalArtifacts,
11
+ };
12
+ }
@@ -0,0 +1,25 @@
1
+ import type {HardhatUserConfigValidationError} from '@nomicfoundation/hardhat-zod-utils';
2
+ import type {HardhatUserConfig} from 'hardhat/config';
3
+
4
+ import {validateUserConfigZodType} from '@nomicfoundation/hardhat-zod-utils';
5
+ import {z} from 'zod';
6
+
7
+ const artifactGenerationUserConfigSchema = z
8
+ .object({
9
+ // externalArtifacts: z.array(z.string()).optional(),
10
+ destinations: z
11
+ .array(
12
+ z.object({
13
+ mode: z.union([z.literal('javascript'), z.literal('typescript')]).optional(),
14
+ folder: z.string().optional(),
15
+ })
16
+ )
17
+ .optional(),
18
+ })
19
+ .optional();
20
+
21
+ export async function validateTypechainUserConfig(
22
+ userConfig: HardhatUserConfig
23
+ ): Promise<HardhatUserConfigValidationError[]> {
24
+ return validateUserConfigZodType(userConfig.generateTypedArtifacts, artifactGenerationUserConfigSchema);
25
+ }