Skip to content

Commit b86ad1a

Browse files
authored
feat(stac-browser): configurable config file in stac browser deployment (#84)
1 parent b704c6e commit b86ad1a

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

lib/stac-browser/index.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class StacBrowser extends Construct {
1616
constructor(scope: Construct, id: string, props: StacBrowserProps) {
1717
super(scope, id);
1818

19-
const buildPath = this.buildApp(props.stacCatalogUrl, props.githubRepoTag, props.cloneDirectory || DEFAULT_CLONE_DIRECTORY);
19+
const buildPath = this.buildApp(props, props.cloneDirectory || DEFAULT_CLONE_DIRECTORY);
2020

2121
// import a bucket from props.bucketArn if defined, otherwise create a new bucket
2222
if (props.bucketArn) {
@@ -58,16 +58,16 @@ export class StacBrowser extends Construct {
5858

5959
}
6060

61-
private buildApp(stacCatalogUrl: string, githubRepoTag: string, cloneDirectory: string): string {
61+
private buildApp(props: StacBrowserProps, cloneDirectory: string): string {
6262

6363
// Define where to clone and build
6464
const githubRepoUrl = 'https://github.com/radiantearth/stac-browser.git';
6565

6666

6767
// Maybe the repo already exists in cloneDirectory. Try checking out the desired version and if it fails, delete and reclone.
6868
try {
69-
console.log(`Checking if a valid cloned repo exists with version ${githubRepoTag}...`)
70-
execSync(`git checkout tags/${githubRepoTag}`, { cwd: cloneDirectory });
69+
console.log(`Checking if a valid cloned repo exists with version ${props.githubRepoTag}...`)
70+
execSync(`git checkout tags/${props.githubRepoTag}`, { cwd: cloneDirectory });
7171
}
7272
catch (error) {
7373

@@ -83,18 +83,28 @@ export class StacBrowser extends Construct {
8383
execSync(`git clone ${githubRepoUrl} ${cloneDirectory}`);
8484

8585
// Check out the desired version
86-
console.log(`Checking out version ${githubRepoTag}...`)
87-
execSync(`git checkout tags/${githubRepoTag}`, { cwd: cloneDirectory });
86+
console.log(`Checking out version ${props.githubRepoTag}...`)
87+
execSync(`git checkout tags/${props.githubRepoTag}`, { cwd: cloneDirectory });
8888

8989
}
9090

9191
// Install the dependencies and build the application
9292
console.log(`Installing dependencies`)
9393
execSync('npm install', { cwd: cloneDirectory });
9494

95+
// If a config file is provided, copy it to the stac-browser directory at "config.js", replaces the default config.js.
96+
if (props.configFilePath) {
97+
// check that the file exists at this location. if not, raise an error and print current working directory.
98+
if (!fs.existsSync(props.configFilePath)) {
99+
throw new Error(`Config file ${props.configFilePath} does not exist. Current working directory is ${process.cwd()}`);
100+
}
101+
console.log(`Copying config file ${props.configFilePath} to ${cloneDirectory}/config.js`)
102+
fs.copyFileSync(props.configFilePath, `${cloneDirectory}/config.js`);
103+
}
104+
95105
// Build the app with catalogUrl
96-
console.log(`Building app with catalogUrl=${stacCatalogUrl} into ${cloneDirectory}`)
97-
execSync(`npm run build -- --catalogUrl=${stacCatalogUrl}`, { cwd: cloneDirectory });
106+
console.log(`Building app with catalogUrl=${props.stacCatalogUrl} into ${cloneDirectory}`)
107+
execSync(`npm run build -- --catalogUrl=${props.stacCatalogUrl}`, { cwd: cloneDirectory });
98108

99109
return './stac-browser/dist'
100110

@@ -115,10 +125,16 @@ export interface StacBrowserProps {
115125
readonly bucketArn?: string;
116126

117127
/**
118-
* STAC catalog URL
128+
* STAC catalog URL. Overrides the catalog URL in the stac-browser configuration.
119129
*/
120130
readonly stacCatalogUrl: string;
121131

132+
/**
133+
* Path to config file for the STAC browser. If not provided, default configuration in the STAC browser
134+
* repository is used.
135+
*/
136+
readonly configFilePath?: string;
137+
122138
/**
123139
* Tag of the radiant earth stac-browser repo to use to build the app.
124140
*/

0 commit comments

Comments
 (0)