Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"build:esm": "node tools/cleanup esm && tsc -p config/tsconfig.esm.json",
"build:types": "node tools/cleanup types && tsc -p config/tsconfig.types.json",
"husky-check": "npm run build && husky && chmod +x .husky/pre-commit",
"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'",
"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'"
"postinstall": "node scripts/download-regions.cjs",
"postupdate": "node scripts/download-regions.cjs"
},
"dependencies": {
"@contentstack/core": "^1.3.1",
Expand All @@ -44,6 +44,7 @@
},
"files": [
"dist",
"scripts/download-regions.cjs",
"package.json",
"README.md",
"src/assets/regions.json"
Expand Down
47 changes: 47 additions & 0 deletions scripts/download-regions.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env node
const fs = require('fs');
const https = require('https');
const path = require('path');

const targetFiles = [
'src/assets/regions.json',
'dist/modern/assets/regions.json',
'dist/legacy/assets/regions.json'
];

function downloadRegions(targetFile) {
const targetDir = path.dirname(targetFile);

// Ensure directory exists
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}

const url = 'https://artifacts.contentstack.com/regions.json';

https.get(url, { timeout: 30000 }, (response) => {
if (response.statusCode === 200) {
const fileStream = fs.createWriteStream(targetFile);
response.pipe(fileStream);

fileStream.on('close', () => {
console.log(`✓ Updated ${targetFile}`);
});

fileStream.on('error', (err) => {
console.log(`Warning: Failed to write ${targetFile}, using bundled version`);
});
} else {
console.log(`Warning: HTTP ${response.statusCode}, using bundled regions.json`);
}
}).on('error', (err) => {
console.log(`Warning: Failed to download regions.json (${err.message}), using bundled version`);
}).setTimeout(30000, function() {
this.destroy();
console.log('Warning: Download timeout, using bundled regions.json');
});
}

// Download to all target locations
targetFiles.forEach(downloadRegions);

1 change: 1 addition & 0 deletions scripts/download-regions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@