Skip to content

Commit 071b808

Browse files
authored
Merge pull request #256 from contentstack/development
Development
2 parents 2189a38 + daae12d commit 071b808

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
3434
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json",
3535
"husky-check": "npm run build && husky && chmod +x .husky/pre-commit",
36-
"postinstall": "curl -s --max-time 30 --fail https://artifacts.contentstack.com/regions.json -o src/assets/regions.json || echo 'Warning: Failed to download regions.json, using existing file if available'",
37-
"postupdate": "curl -s --max-time 30 --fail https://artifacts.contentstack.com/regions.json -o src/assets/regions.json || echo 'Warning: Failed to download regions.json, using existing file if available'"
36+
"postinstall": "node scripts/download-regions.cjs",
37+
"postupdate": "node scripts/download-regions.cjs"
3838
},
3939
"dependencies": {
4040
"@contentstack/core": "^1.3.1",
@@ -44,6 +44,7 @@
4444
},
4545
"files": [
4646
"dist",
47+
"scripts/download-regions.cjs",
4748
"package.json",
4849
"README.md",
4950
"src/assets/regions.json"

scripts/download-regions.cjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const https = require('https');
4+
const path = require('path');
5+
6+
const targetFiles = [
7+
'src/assets/regions.json',
8+
'dist/modern/assets/regions.json',
9+
'dist/legacy/assets/regions.json'
10+
];
11+
12+
function downloadRegions(targetFile) {
13+
const targetDir = path.dirname(targetFile);
14+
15+
// Ensure directory exists
16+
if (!fs.existsSync(targetDir)) {
17+
fs.mkdirSync(targetDir, { recursive: true });
18+
}
19+
20+
const url = 'https://artifacts.contentstack.com/regions.json';
21+
22+
https.get(url, { timeout: 30000 }, (response) => {
23+
if (response.statusCode === 200) {
24+
const fileStream = fs.createWriteStream(targetFile);
25+
response.pipe(fileStream);
26+
27+
fileStream.on('close', () => {
28+
console.log(`✓ Updated ${targetFile}`);
29+
});
30+
31+
fileStream.on('error', (err) => {
32+
console.log(`Warning: Failed to write ${targetFile}, using bundled version`);
33+
});
34+
} else {
35+
console.log(`Warning: HTTP ${response.statusCode}, using bundled regions.json`);
36+
}
37+
}).on('error', (err) => {
38+
console.log(`Warning: Failed to download regions.json (${err.message}), using bundled version`);
39+
}).setTimeout(30000, function() {
40+
this.destroy();
41+
console.log('Warning: Download timeout, using bundled regions.json');
42+
});
43+
}
44+
45+
// Download to all target locations
46+
targetFiles.forEach(downloadRegions);
47+

scripts/download-regions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)