hardhat-deploy 2.0.0-next.9 → 2.0.1

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 (126) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +194 -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 +276 -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/helpers.js +258 -0
  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/index.js +52 -0
  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 +4 -1
  39. package/dist/tasks/deploy.d.ts.map +1 -0
  40. package/dist/tasks/deploy.js +38 -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 +43 -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 +58 -26
  58. package/src/cli.ts +245 -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 +316 -0
  63. package/src/helpers.ts +324 -0
  64. package/src/hook-handlers/config.ts +80 -0
  65. package/src/hook-handlers/solidity.ts +33 -0
  66. package/src/index.ts +60 -0
  67. package/src/postinstall.ts +165 -0
  68. package/src/tasks/deploy.ts +53 -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 -242
  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 +0 -213
  101. package/dist/esm/helpers.js.map +0 -1
  102. package/dist/esm/hook-handlers/config.d.ts.map +0 -1
  103. package/dist/esm/hook-handlers/config.js +0 -16
  104. package/dist/esm/hook-handlers/config.js.map +0 -1
  105. package/dist/esm/hook-handlers/solidity.d.ts.map +0 -1
  106. package/dist/esm/hook-handlers/solidity.js +0 -17
  107. package/dist/esm/hook-handlers/solidity.js.map +0 -1
  108. package/dist/esm/index.d.ts +0 -5
  109. package/dist/esm/index.d.ts.map +0 -1
  110. package/dist/esm/index.js +0 -28
  111. package/dist/esm/index.js.map +0 -1
  112. package/dist/esm/tasks/deploy.d.ts.map +0 -1
  113. package/dist/esm/tasks/deploy.js +0 -24
  114. package/dist/esm/tasks/deploy.js.map +0 -1
  115. package/dist/esm/type-extensions.d.ts.map +0 -1
  116. package/dist/esm/type-extensions.js.map +0 -1
  117. package/dist/esm/types.d.ts +0 -15
  118. package/dist/esm/types.d.ts.map +0 -1
  119. package/dist/esm/types.js.map +0 -1
  120. /package/dist/{esm/config → config}/default.d.ts +0 -0
  121. /package/dist/{esm/config → config}/get-config.d.ts +0 -0
  122. /package/dist/{esm/config → config}/validation.d.ts +0 -0
  123. /package/dist/{esm/hook-handlers → hook-handlers}/config.d.ts +0 -0
  124. /package/dist/{esm/hook-handlers → hook-handlers}/solidity.d.ts +0 -0
  125. /package/dist/{esm/type-extensions.js → type-extensions.js} +0 -0
  126. /package/dist/{esm/types.js → types.js} +0 -0
@@ -0,0 +1,118 @@
1
+ import { existsSync, readFileSync, readdirSync } from 'fs';
2
+ import { join } from 'path';
3
+ export const MIGRATION_URL = 'https://rocketh.dev/hardhat-deploy/migration-from-v1';
4
+ export const V1_INSTALL_CMD = 'npm install hardhat-deploy@1';
5
+ export function detectV1Patterns(projectRoot = process.cwd()) {
6
+ const reasons = [];
7
+ // Check hardhat.config for v1 patterns
8
+ const configPatterns = checkConfigPatterns(projectRoot);
9
+ reasons.push(...configPatterns);
10
+ // Check deploy scripts for v1 patterns
11
+ const deployPatterns = checkDeployScripts(projectRoot);
12
+ reasons.push(...deployPatterns);
13
+ return {
14
+ isV1Environment: reasons.length > 0,
15
+ reasons,
16
+ };
17
+ }
18
+ function checkConfigPatterns(projectRoot) {
19
+ const reasons = [];
20
+ const configFiles = ['hardhat.config.js', 'hardhat.config.ts'];
21
+ for (const configFile of configFiles) {
22
+ const configPath = join(projectRoot, configFile);
23
+ if (existsSync(configPath)) {
24
+ try {
25
+ const content = readFileSync(configPath, 'utf-8');
26
+ if (content.includes('namedAccounts')) {
27
+ reasons.push(`Found 'namedAccounts' in ${configFile} - this is a v1 pattern. In v2, use rocketh/config.ts`);
28
+ }
29
+ if (content.includes("require('hardhat-deploy')") || content.includes('require("hardhat-deploy")')) {
30
+ reasons.push(`Found require('hardhat-deploy') in ${configFile} - v2 uses ESM: import HardhatDeploy from 'hardhat-deploy'`);
31
+ }
32
+ if (content.includes('module.exports')) {
33
+ reasons.push(`Found 'module.exports' in ${configFile} - v2 uses ESM: export default defineConfig({...})`);
34
+ }
35
+ // Check for old solidity config (non-profile based)
36
+ if (content.match(/solidity:\s*['"][0-9]/) || content.match(/solidity:\s*\{\s*version:/)) {
37
+ reasons.push(`Found old-style solidity config in ${configFile} - v2 uses profiles: solidity: { profiles: { default: { version: '...' } } }`);
38
+ }
39
+ }
40
+ catch (e) {
41
+ // Failed to read config - continue
42
+ }
43
+ }
44
+ }
45
+ return reasons;
46
+ }
47
+ function checkDeployScripts(projectRoot) {
48
+ const reasons = [];
49
+ const deployDir = join(projectRoot, 'deploy');
50
+ if (!existsSync(deployDir)) {
51
+ return reasons;
52
+ }
53
+ try {
54
+ const files = readdirSync(deployDir);
55
+ for (const file of files) {
56
+ if (file.endsWith('.js') || file.endsWith('.ts')) {
57
+ const filePath = join(deployDir, file);
58
+ try {
59
+ const content = readFileSync(filePath, 'utf-8');
60
+ if (content.includes('module.exports') && content.includes('getNamedAccounts')) {
61
+ reasons.push(`Found v1-style deploy script: deploy/${file} - v2 uses: export default deployScript(async ({deploy, namedAccounts}) => {...})`);
62
+ break; // One example is enough
63
+ }
64
+ if (content.includes('deployments.deploy')) {
65
+ reasons.push(`Found 'deployments.deploy()' in deploy/${file} - v2 uses 'deploy()' directly with artifact parameter`);
66
+ break;
67
+ }
68
+ if (content.includes('from:') && !content.includes('account:')) {
69
+ reasons.push(`Found 'from:' parameter in deploy/${file} - v2 uses 'account:' instead`);
70
+ break;
71
+ }
72
+ }
73
+ catch (e) {
74
+ // Failed to read file - continue
75
+ }
76
+ }
77
+ }
78
+ }
79
+ catch (e) {
80
+ // Deploy folder scan failed - continue silently
81
+ }
82
+ return reasons;
83
+ }
84
+ export class V1PatternError extends Error {
85
+ constructor(reasons) {
86
+ const reasonsList = reasons.map((r) => ` • ${r}`).join('\n');
87
+ super(`
88
+ ╔══════════════════════════════════════════════════════════════════════════════╗
89
+ ║ HARDHAT-DEPLOY V2 - V1 PATTERNS DETECTED ║
90
+ ╚══════════════════════════════════════════════════════════════════════════════╝
91
+
92
+ Your project uses hardhat-deploy v1 patterns that are incompatible with v2:
93
+
94
+ ${reasonsList}
95
+
96
+ hardhat-deploy v2 has MAJOR breaking changes and requires hardhat 3.x with a
97
+ different configuration structure.
98
+
99
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
100
+
101
+ OPTION 1: Install v1 instead (recommended for existing v1 projects)
102
+
103
+ npm uninstall hardhat-deploy
104
+ ${V1_INSTALL_CMD}
105
+
106
+ OPTION 2: Migrate your project to v2
107
+
108
+ Migration guide: ${MIGRATION_URL}
109
+
110
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
111
+ `);
112
+ this.name = 'V1PatternError';
113
+ }
114
+ }
115
+ export function throwV1MigrationError(reasons) {
116
+ throw new V1PatternError(reasons);
117
+ }
118
+ //# sourceMappingURL=v1-detection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1-detection.js","sourceRoot":"","sources":["../src/v1-detection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG,sDAAsD,CAAC;AACpF,MAAM,CAAC,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAO7D,MAAM,UAAU,gBAAgB,CAAC,cAAsB,OAAO,CAAC,GAAG,EAAE;IAClE,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,uCAAuC;IACvC,MAAM,cAAc,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACxD,OAAO,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;IAEhC,uCAAuC;IACvC,MAAM,cAAc,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;IAEhC,OAAO;QACL,eAAe,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC;QACnC,OAAO;KACR,CAAC;AACJ,CAAC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ACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,gDAAgD;IAClD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAiB;QAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE9D,KAAK,CAAC;;;;;;;EAOR,WAAW;;;;;;;;;;IAUT,cAAc;;;;qBAIG,aAAa;;;CAGjC,CAAC,CAAC;QACC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAiB;IACrD,MAAM,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
@@ -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,53 +1,85 @@
1
1
  {
2
2
  "name": "hardhat-deploy",
3
- "version": "2.0.0-next.9",
4
- "description": "deployment plugin for hardhat",
3
+ "version": "2.0.1",
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.3",
58
+ "@changesets/cli": "^2.29.8",
59
+ "@rocketh/node": "^0.19.3",
60
+ "@types/node": "^25.2.3",
61
+ "as-soon": "^0.1.5",
62
+ "hardhat": "3.1.8",
63
+ "rimraf": "^6.1.3",
64
+ "rocketh": "^0.19.3",
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.3"
69
+ "@rocketh/node": "^0.19.3",
70
+ "hardhat": "^3.1.8",
71
+ "rocketh": "^0.19.3"
42
72
  },
43
73
  "dependencies": {
44
- "@nomicfoundation/hardhat-zod-utils": "3.0.0-next.0",
45
- "@types/debug": "^4.1.12",
46
- "debug": "^4.4.0",
47
- "zod": "^3.24.2"
74
+ "@nomicfoundation/hardhat-zod-utils": "^3.0.1",
75
+ "commander": "^14.0.3",
76
+ "named-logs": "^0.4.1",
77
+ "named-logs-console": "^0.5.1",
78
+ "zod": "^3.25.76"
48
79
  },
49
80
  "scripts": {
50
- "build": "tsc --project tsconfig.json",
51
- "dev": "as-soon -w src pnpm build"
81
+ "build": "tsc --project tsconfig.json && cp src/v1-entry.cjs dist/",
82
+ "dev": "as-soon -w src pnpm build",
83
+ "postinstall": "node ./dist/postinstall.js"
52
84
  }
53
85
  }
package/src/cli.ts ADDED
@@ -0,0 +1,245 @@
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(
128
+ (pattern) => 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.name('hardhat-deploy').description('CLI for hardhat-deploy').version(pkg.version);
192
+
193
+ program
194
+ .command('init')
195
+ .argument('[folder]', 'folder to initialize the project in')
196
+ .option('--install', 'auto-install dependencies with pnpm')
197
+ .description('Initialize a new hardhat-deploy project')
198
+ .action(async (folder?: string, options?: {install?: boolean}) => {
199
+ let targetFolder = folder;
200
+ let autoInstall = options?.install ?? false;
201
+
202
+ // If no folder specified, ask user
203
+ if (!targetFolder) {
204
+ targetFolder = await askFolder();
205
+ // If we prompted for folder, also prompt for auto-install
206
+ autoInstall = await askAutoInstall();
207
+ }
208
+
209
+ // Normalize path
210
+ targetFolder = targetFolder.trim();
211
+
212
+ // Check if folder is empty
213
+ if (!isFolderEmpty(targetFolder)) {
214
+ console.error(
215
+ `Error: Folder "${targetFolder}" is not empty. Please specify an empty folder or a new folder path.`,
216
+ );
217
+ process.exit(1);
218
+ }
219
+
220
+ // Generate project
221
+ generateProject(targetFolder);
222
+
223
+ // Auto-install if requested
224
+ if (autoInstall) {
225
+ try {
226
+ await runPnpmInstall(targetFolder);
227
+ } catch (error) {
228
+ console.error('Failed to install dependencies:', error);
229
+ console.log('\nYou can install dependencies manually:');
230
+ console.log(` cd ${targetFolder === './' ? '.' : targetFolder}`);
231
+ console.log(' pnpm install');
232
+ process.exit(1);
233
+ }
234
+ }
235
+
236
+ // Show next steps
237
+ console.log(`\nNext steps:`);
238
+ console.log(` cd ${targetFolder === './' ? '.' : targetFolder}`);
239
+ if (!autoInstall) {
240
+ console.log(` pnpm install`);
241
+ }
242
+ console.log(` pnpm hardhat test`);
243
+ });
244
+
245
+ 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
+ }