-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: write the default environment files
Currently writing the default prod, dev and local files, as explained in the React starter kit. closes #16
- Loading branch information
1 parent
9af74ea
commit c0bf273
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// todo: remove when more items are exported | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const DEFAULT_STARTER = 'graasp/graasp-app-starter-react'; | ||
|
||
// environments | ||
export const LOCAL = 'local'; | ||
export const DEV = 'dev'; | ||
export const PROD = 'prod'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import { DEV, LOCAL, PROD } from './config'; | ||
|
||
const writeRemoteEnvFile = async ( | ||
env, | ||
rootPath, | ||
{ | ||
graaspDeveloperId = '', | ||
graaspAppId = '', | ||
awsAccessKeyId = '', | ||
awsSecretAccessKey = '', | ||
} = {}, | ||
) => { | ||
const host = env === PROD ? 'apps.graasp.eu' : 'apps.dev.graasp.eu'; | ||
const bucket = `graasp-apps-${env}`; | ||
const string = ` | ||
REACT_APP_GRAASP_DEVELOPER_ID=${graaspDeveloperId} | ||
REACT_APP_GRAASP_APP_ID=${graaspAppId} | ||
REACT_APP_GRAASP_DOMAIN=graasp.eu | ||
REACT_APP_HOST=${host} | ||
REACT_APP_VERSION=latest | ||
REACT_APP_BASE=//$REACT_APP_HOST/$REACT_APP_GRAASP_DEVELOPER_ID/$REACT_APP_GRAASP_APP_ID/$REACT_APP_VERSION/ | ||
NODE_ENV=production | ||
BUCKET=${bucket} | ||
AWS_DEFAULT_REGION=us-east-1 | ||
AWS_ACCESS_KEY_ID=${awsAccessKeyId} | ||
AWS_SECRET_ACCESS_KEY=${awsSecretAccessKey} | ||
`; | ||
try { | ||
await fs.writeFile(path.join(rootPath, `.env.${env}`), string, 'utf8'); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; | ||
|
||
const writeLocalEnvFile = async (env, rootPath) => { | ||
const string = ` | ||
REACT_APP_GRAASP_DEVELOPER_ID= | ||
REACT_APP_GRAASP_APP_ID= | ||
REACT_APP_GRAASP_DOMAIN=localhost | ||
REACT_APP_HOST= | ||
REACT_APP_VERSION= | ||
REACT_APP_BASE= | ||
`; | ||
try { | ||
await fs.writeFile(path.join(rootPath, '.env.local'), string, 'utf8'); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; | ||
|
||
|
||
const writeEnvFile = async (env, rootPath) => { | ||
switch (env) { | ||
case LOCAL: | ||
return writeLocalEnvFile(env, rootPath); | ||
case DEV: | ||
case PROD: | ||
return writeRemoteEnvFile(env, rootPath); | ||
default: | ||
return false; | ||
} | ||
}; | ||
|
||
|
||
const writeEnvFiles = async (rootPath) => { | ||
console.log('writing environment files...'); | ||
await Promise.all([LOCAL, DEV, PROD].map(env => writeEnvFile(env, rootPath))); | ||
console.log('wrote environment files'); | ||
}; | ||
|
||
export default writeEnvFiles; |