There doesn’t seem to be a good way to manage different packs in the same pack directory.
My usecase is that I need to be able to develop my pack and test changes in coda, while also supporting a “stable” release.
I’ve worked around this by hardcoding a config object and then indexing its values depending on another hardcoded env
const:
// index.ts
import { codaPack, buildPack } from "./pack";
const configs = {
dev: {
baseAuthUrl: "https://dev.auth.us-east-1.amazoncognito.com",
baseApiUrl: `https://dev-api.execute-api.us-east-1.amazonaws.com/DEV/`,
},
test: {
baseAuthUrl: "https://test.auth.us-east-1.amazoncognito.com",
baseApiUrl: `https://test.execute-api.us-east-1.amazonaws.com/TEST/`,
},
prod: {
baseAuthUrl: "https://prod.auth.com",
baseApiUrl: `https://prod.execute-api.us-east-1.amazonaws.com/PROD/`,
},
};
const env = "dev";
// const env = "test";
// const env = "prod";
const config = configs[env];
export const pack = codaPack;
buildPack(pack, config.baseApiUrl, config.baseAuthUrl);
This obviously isn’t ideal, but it helps me get around the issue.
I also had to create two packs, one for my test/dev work, and one for prod.
I did this by running npx coda create
twice, and then taking the generated .coda-pack.json
file and naming it .coda-pack.dev.json
and .coda-pack.prod.json
. Then in my build script, I cp
the desired working config to the .coda-pack.json
:
// package.json
{
...
"scripts": {
"deploy": "cp config/.coda-pack.dev.json .coda-pack.json && npx coda upload index.js",
"deploy:prod": "cp config/.coda-pack.prod.json .coda-pack.json && npx coda upload index.js",
...
},
...
}
This is a very clunky workaround and could be easily fixed by allowing developers to pass an --env {my_env}
into the npx coda upload
command that could then be queried from the process
node variable.
The command should also be updated to allow passing in the .coda-pack.json
file path so that I can configure the deployment to use the proper dev or prod pack id:
// package.json
{
...
"scripts": {
"deploy": "npx coda upload index.js --env dev --pack config/.coda-pack.dev.json",
"deploy:prod": "npx coda upload index.js --env prod --pack config/.coda-pack.prod.json",
...
},
...
}
Or, another option would be to allow an ambiguous amount of variables to reside in the .coda-pack.json
file where I can define my URLs for each environment and associated pack id.
// .coda-pack.dev.json
{
"packId": 1,
"env": {
"authUrl": "https://auth.url",
"apiUrl": "https://api.url"
}
}
These values would then be exposed in the process.env
object.
Cheers.
~ CG