@towns-protocol/generated 0.0.378 → 0.0.380
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.
- package/package.json +3 -3
- package/scripts/prepare.js +45 -38
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@towns-protocol/generated",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.380",
|
|
4
4
|
"packageManager": "yarn@3.8.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"ethers": "^5.8.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@towns-protocol/contracts": "^0.0.
|
|
16
|
+
"@towns-protocol/contracts": "^0.0.380"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"config/**/*",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "7560ed0123757c125b45e033f373c481e437bb06"
|
|
36
36
|
}
|
package/scripts/prepare.js
CHANGED
|
@@ -2,17 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* CONTRACT ARTIFACT MANAGEMENT
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Strategy: npm download when possible, local generation when needed.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* - Hash mismatch + NO Foundry: use npm artifacts with warning (Vercel case)
|
|
13
|
-
* 2. Artifacts exist + contracts changed → regenerate locally (Foundry required, local only)
|
|
14
|
-
* 3. SKIP_CONTRACT_GEN=true → skip checks, use existing artifacts
|
|
15
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* 1. No artifacts → try npm download → validate hash → fallback to local gen
|
|
9
|
+
* 2. Artifacts exist → compare hash → regenerate if contracts changed
|
|
10
|
+
* 3. SKIP_CONTRACT_GEN=true → use existing or npm download, never fail
|
|
11
|
+
*
|
|
16
12
|
* Uses package.json version + git tree hash for validation.
|
|
17
13
|
*/
|
|
18
14
|
|
|
@@ -27,6 +23,7 @@ const packageRoot = resolve(__dirname, '..');
|
|
|
27
23
|
const contractsDir = resolve(packageRoot, '../contracts');
|
|
28
24
|
const devDir = resolve(packageRoot, 'dev');
|
|
29
25
|
const hashFile = resolve(devDir, '.contracts-hash');
|
|
26
|
+
const foundryPath = `${process.env.HOME}/.foundry/bin`;
|
|
30
27
|
|
|
31
28
|
// Get current package version
|
|
32
29
|
function getCurrentVersion() {
|
|
@@ -120,56 +117,66 @@ function isFoundryInstalled() {
|
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
119
|
|
|
120
|
+
// Install Foundry if not present
|
|
121
|
+
function installFoundry() {
|
|
122
|
+
console.log('Installing Foundry...');
|
|
123
|
+
try {
|
|
124
|
+
// Install foundryup
|
|
125
|
+
execSync('curl -L https://foundry.paradigm.xyz | bash', { stdio: 'inherit' });
|
|
126
|
+
|
|
127
|
+
// foundryup is installed to ~/.foundry/bin, call it directly with full path
|
|
128
|
+
// Install latest foundry
|
|
129
|
+
execSync(`${foundryPath}/foundryup`, { stdio: 'inherit' });
|
|
130
|
+
|
|
131
|
+
console.log('Foundry installation completed');
|
|
132
|
+
return true;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.log('Foundry installation failed:', error.message);
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
123
139
|
// Generate contract artifacts
|
|
124
140
|
function generateArtifacts() {
|
|
125
|
-
// Check for contracts directory
|
|
141
|
+
// Check for contracts directory FIRST (before trying to install Foundry)
|
|
126
142
|
if (!existsSync(contractsDir)) {
|
|
127
|
-
|
|
143
|
+
console.log('Contracts directory not found, cannot generate locally');
|
|
144
|
+
throw new Error('Cannot generate artifacts: contracts package not available and npm download failed');
|
|
128
145
|
}
|
|
129
|
-
|
|
130
|
-
// Require Foundry to be installed
|
|
146
|
+
|
|
131
147
|
if (!isFoundryInstalled()) {
|
|
132
|
-
|
|
148
|
+
console.log('Foundry not found, attempting installation...');
|
|
149
|
+
if (!installFoundry()) {
|
|
150
|
+
throw new Error('Failed to install Foundry - cannot generate contract artifacts');
|
|
151
|
+
}
|
|
133
152
|
}
|
|
134
|
-
|
|
153
|
+
|
|
135
154
|
const buildScript = resolve(contractsDir, 'scripts/build-contract-types.sh');
|
|
136
155
|
|
|
137
156
|
if (!existsSync(buildScript)) {
|
|
138
157
|
throw new Error(`Build script not found at ${buildScript}`);
|
|
139
158
|
}
|
|
140
159
|
|
|
160
|
+
// Prepare environment with Foundry in PATH so forge can be found
|
|
161
|
+
const envWithFoundry = {
|
|
162
|
+
...process.env,
|
|
163
|
+
PATH: `${foundryPath}:${process.env.PATH}`
|
|
164
|
+
};
|
|
165
|
+
|
|
141
166
|
execSync(`bash ${buildScript}`, {
|
|
142
167
|
cwd: contractsDir,
|
|
143
|
-
stdio: 'inherit'
|
|
168
|
+
stdio: 'inherit',
|
|
169
|
+
env: envWithFoundry
|
|
144
170
|
});
|
|
145
171
|
}
|
|
146
172
|
|
|
147
173
|
// Main logic
|
|
148
174
|
async function main() {
|
|
149
175
|
const skipRequested = process.env.SKIP_CONTRACT_GEN === 'true';
|
|
150
|
-
|
|
176
|
+
|
|
151
177
|
if (!generatedFilesExist()) {
|
|
152
178
|
console.log('No artifacts found, trying npm download first...');
|
|
153
|
-
|
|
154
|
-
// Check if hash validation is needed
|
|
155
|
-
const currentHash = getContractsHash();
|
|
156
|
-
if (currentHash && existsSync(hashFile)) {
|
|
157
|
-
const downloadedHash = readFileSync(hashFile, 'utf8').trim();
|
|
158
|
-
if (currentHash !== downloadedHash) {
|
|
159
|
-
// Hash mismatch: regenerate if Foundry available, otherwise use downloaded
|
|
160
|
-
if (isFoundryInstalled()) {
|
|
161
|
-
console.log('Hash mismatch detected, regenerating locally with Foundry...');
|
|
162
|
-
generateArtifacts();
|
|
163
|
-
} else {
|
|
164
|
-
console.log('WARNING: Hash mismatch but Foundry not available, using downloaded artifacts');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
console.log('NPM download failed, attempting local generation...');
|
|
170
|
-
generateArtifacts();
|
|
171
|
-
}
|
|
172
|
-
return;
|
|
179
|
+
await downloadArtifactsFromNpm();
|
|
173
180
|
}
|
|
174
181
|
|
|
175
182
|
if (skipRequested) {
|