Skip to content

Commit 4a9ef4d

Browse files
committed
feat: update regions.json paths and add copying logic in build process
1 parent a48ed73 commit 4a9ef4d

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

package.json

Lines changed: 4 additions & 3 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 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 regions.json || echo 'Warning: Failed to download regions.json, using existing file if available'"
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'"
3838
},
3939
"dependencies": {
4040
"@contentstack/core": "^1.3.1",
@@ -45,7 +45,8 @@
4545
"files": [
4646
"dist",
4747
"package.json",
48-
"README.md"
48+
"README.md",
49+
"src/assets/regions.json"
4950
],
5051
"devDependencies": {
5152
"@nrwl/jest": "^17.3.2",

src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Region, params } from './types';
2-
import regionsData from '../../regions.json';
2+
import regionsData from '../assets/regions.json';
33

44
export function getHostforRegion(cloudRegion: string = "aws_na", host?: string): string {
55
if (host) return host;

tsup.config.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { defineConfig } from 'tsup'
22
import { esbuildPluginFilePathExtensions } from 'esbuild-plugin-file-path-extensions'
33
import packageJson from './package.json' assert { type: "json" };
4+
import { copyFileSync, existsSync, mkdirSync } from 'fs';
5+
import { dirname, join } from 'path';
46

57
export default defineConfig([
68
modernConfig({
@@ -30,7 +32,21 @@ function modernConfig(opts) {
3032
replace: {
3133
'{{VERSION}}': `"${packageJson.version}"`,
3234
},
33-
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'js' })]
35+
esbuildPlugins: [esbuildPluginFilePathExtensions({ esmExtension: 'js' })],
36+
onSuccess: async () => {
37+
// Copy regions.json to dist/modern/assets/ (industry standard structure)
38+
const sourceFile = 'src/assets/regions.json';
39+
const targetFile = join('dist/modern/assets', 'regions.json');
40+
41+
if (existsSync(sourceFile)) {
42+
const targetDir = dirname(targetFile);
43+
if (!existsSync(targetDir)) {
44+
mkdirSync(targetDir, { recursive: true });
45+
}
46+
copyFileSync(sourceFile, targetFile);
47+
console.log('✓ Copied regions.json to dist/modern/assets');
48+
}
49+
}
3450
}
3551
}
3652

@@ -54,5 +70,19 @@ function legacyConfig(opts) {
5470
options.jsxImportSource = 'preact';
5571
options.jsx = 'automatic'
5672
},
73+
onSuccess: async () => {
74+
// Copy regions.json to dist/legacy/assets/ (industry standard structure)
75+
const sourceFile = 'src/assets/regions.json';
76+
const targetFile = join('dist/legacy/assets', 'regions.json');
77+
78+
if (existsSync(sourceFile)) {
79+
const targetDir = dirname(targetFile);
80+
if (!existsSync(targetDir)) {
81+
mkdirSync(targetDir, { recursive: true });
82+
}
83+
copyFileSync(sourceFile, targetFile);
84+
console.log('✓ Copied regions.json to dist/legacy/assets');
85+
}
86+
}
5787
}
5888
}

0 commit comments

Comments
 (0)