Skip to content

Commit

Permalink
chore: #629 migrate to config of json (#673)
Browse files Browse the repository at this point in the history
Changes
- Migrate for web-components
- Migrate for smb
- Migrate for cognito custom mail lambda
- Migrate for cognito auth
  • Loading branch information
Pham Hai Duong authored Mar 20, 2020
1 parent eb3f5c7 commit 4970058
Show file tree
Hide file tree
Showing 34 changed files with 67 additions and 103 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"lint:fix": "lerna run --parallel --stream lint:fix --",
"release:dev": "lerna run --parallel release:dev",
"release:prod": "lerna run --parallel release:prod",
"test": "lerna run --parallel test:ci -- --runInBand",
"test": "lerna run --parallel test:ci -- --runInBand --detectOpenHandles",
"test-e2e:ci": "lerna run --parallel test-e2e:ci"
},
"husky": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cognito-auth/src/utils/cognito.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('Session utils', () => {
describe('redirectToLogout', () => {
it('should redirect to the OAuth endpoint for logout', () => {
window.location.href = ''
process.env.COGNITO_OAUTH_URL = ''
window.reapit.config.cognitoOAuthUrl = ''
redirectToLogout('cognitoClientId', 'redirectUri', 'DEVELOPER')
expect(window.location.href).toEqual('/logout?client_id=cognitoClientId&logout_uri=redirectUri&state=DEVELOPER')
})
Expand Down
4 changes: 4 additions & 0 deletions packages/cognito-custom-mail-lambda/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"MARKET_PLACE_URL": "",
"COGNITO_USERPOOL_ID": ""
}
3 changes: 2 additions & 1 deletion packages/cognito-custom-mail-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"release:prod": "node ../../scripts/release/release-serverless.js cognito-custom-mail-lambda",
"test:update-badges": "yarn test:ci && jest-coverage-badges --input src/tests/coverage/coverage-summary.json --output src/tests/badges",
"lint": "concurrently \"tsc --noEmit\" \"eslint --cache --ext=ts,tsx,js src\"",
"lint:fix": "eslint --cache --ext=ts,tsx,js src --fix"
"lint:fix": "eslint --cache --ext=ts,tsx,js src --fix",
"fetch-config": "yarn config-manager fetchConfig cognito-custom-mail-lambda"
},
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions packages/cognito-custom-mail-lambda/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
service: cognito-mailer
custom: ${file(../../reapit-config.json)}
custom: ${file(./config.json)}
provider:
name: aws
runtime: nodejs10.x
Expand All @@ -9,8 +9,8 @@ provider:
name: cognito.mailer.${self:provider.stage}
blockPublicAccess: false
environment:
COGNITO_USERPOOL_ID: ${self:custom.${file(./yml-helpers.js):provider.stage.uppercase}.COGNITO_USERPOOL_ID}
MARKET_PLACE_URL: ${self:custom.${file(./yml-helpers.js):provider.stage.uppercase}.MARKET_PLACE_URL}
COGNITO_USERPOOL_ID: ${self:custom.COGNITO_USERPOOL_ID}
MARKET_PLACE_URL: ${self:custom.MARKET_PLACE_URL}
package:
include:
- dist/**
Expand All @@ -37,6 +37,6 @@ functions:
handler: dist/app.cognitoCustomMailerHandler
events:
- cognitoUserPool:
pool: ${self:custom.${file(./yml-helpers.js):provider.stage.uppercase}.COGNITO_USERPOOL_ID}
pool: ${self:custom.COGNITO_USERPOOL_ID}
trigger: CustomMessage
existing: true
19 changes: 0 additions & 19 deletions packages/cognito-custom-mail-lambda/yml-helpers.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/elements/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { EnvironmentPlugin } = require('webpack')
const path = require('path')
const envConfig = require('../../../reapit-config.json')
const configEnv = require('../config.json')
const { getVersionTag } = require('../../../scripts/release/utils')

module.exports = ({ config }) => {
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports = ({ config }) => {
)
config.resolve.extensions.push('.ts', '.tsx')
config.plugins.push(new EnvironmentPlugin({
...envConfig[process.env.REAPIT_ENV || 'LOCAL'],
...configEnv,
APP_VERSION: `${getVersionTag().version}`,
}))
return config
Expand Down
4 changes: 4 additions & 0 deletions packages/elements/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ELEMENTS_DOCUMENT_URL": "",
"GOOGLE_MAPS_API_KEY": ""
}
3 changes: 2 additions & 1 deletion packages/elements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"start:prod": "cross-env NODE_ENV=development tsdx watch",
"test:ci": "cross-env TZ=UTC jest --ci --colors --coverage --silent --forceExit",
"test:dev": "cross-env TZ=UTC jest --watch --verbose",
"test:update-badges": "yarn test:ci && jest-coverage-badges --input src/tests/coverage/coverage-summary.json --output src/tests/badges"
"test:update-badges": "yarn test:ci && jest-coverage-badges --input src/tests/coverage/coverage-summary.json --output src/tests/badges",
"fetch-config": "yarn config-manager fetchConfig elements"
},
"browserslist": [
"> 1%",
Expand Down
4 changes: 2 additions & 2 deletions packages/elements/src/components/Map/map.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { storiesOf } from '@storybook/react'
import { Map } from './index'

const MAP_API_KEY = process.env.MAP_API_KEY || ''
const GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY || ''

const onLoadedDirection = response => {
console.log(response)
Expand Down Expand Up @@ -33,7 +33,7 @@ const onLoaded = response => {
storiesOf('Map', module).add('Map', () => {
return (
<Map
apiKey={MAP_API_KEY}
apiKey={GOOGLE_MAPS_API_KEY}
libraries="places,drawing"
autoFitBounds={true}
coordinates={[
Expand Down
2 changes: 1 addition & 1 deletion packages/elements/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/elements/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/elements/src/tests/badges/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/graphql-server/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"PLATFORM_API_BASE_URL": "",
"MARKETPLACE_API_BASE_URL": "",
"COGNITO_USERPOOL_ID": ""
}
3 changes: 2 additions & 1 deletion packages/graphql-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"start:prod": "node ./dist/app.js",
"test:ci": "cross-env TZ=UTC jest --ci --colors --coverage --silent --forceExit",
"test:dev": "cross-env TZ=UTC jest --watch --verbose",
"fetch-ts-definitions": "node scripts/fetch-ts-definitions.js"
"fetch-ts-definitions": "node scripts/fetch-ts-definitions.js",
"fetch-config": "yarn config-manager fetchConfig graphql-server"
},
"dependencies": {
"@reapit/cognito-auth": "^2.0.19",
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql-server/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ service: graphql-server
plugins:
- serverless-webpack
custom:
env: ${file(../../reapit-config.json)}
env: ${file(./config.json)}
webpack:
webpackConfig: 'webpack.config.js'
includeModules: true
Expand All @@ -22,9 +22,9 @@ provider:
blockPublicAccess: false
environment:
NODE_ENV: 'production'
COGNITO_USERPOOL_ID: ${self:custom.env.${file(./yml-helpers.js):provider.stage.uppercase}.COGNITO_USERPOOL_ID}
MARKETPLACE_API_BASE_URL: ${self:custom.env.${file(./yml-helpers.js):provider.stage.uppercase}.MARKETPLACE_API_BASE_URL}
PLATFORM_API_BASE_URL: ${self:custom.env.${file(./yml-helpers.js):provider.stage.uppercase}.PLATFORM_API_BASE_URL}
COGNITO_USERPOOL_ID: ${self:custom.env.COGNITO_USERPOOL_ID}
MARKETPLACE_API_BASE_URL: ${self:custom.env.MARKETPLACE_API_BASE_URL}
PLATFORM_API_BASE_URL: ${self:custom.env.PLATFORM_API_BASE_URL}

package:
individually: true
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import resolvers from './resolvers'
const typeDefs = importSchema('./src/schema.graphql')

if (process.env.NODE_ENV === 'development') {
const envConfig = require(path.resolve(__dirname, '../../..', 'reapit-config.json'))
const envConfig = require(path.resolve(__dirname, '..', 'config.json'))
const configs = envConfig[process.env.REAPIT_ENV || 'LOCAL']
for (const k in configs) {
process.env[k] = configs[k]
Expand Down
19 changes: 0 additions & 19 deletions packages/graphql-server/yml-helpers.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/marketplace/src/tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const wp = require('@cypress/webpack-preprocessor')
const ResolveTSPathsToWebpackAlias = require('ts-paths-to-webpack-alias')
const tsConfigPath = path.resolve(__dirname, '../../tsconfig.json')

const reapitConfig = require('../../../../reapit-config.json')
const reapitConfig = require('../../config.json')

module.exports = (on, config) => {
// https://basarat.gitbooks.io/typescript/docs/testing/cypress.html
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = (on, config) => {
const reapitEnv = process.env.REAPIT_ENV || 'LOCAL'

if (typeof reapitConfig !== 'object') {
throw new Error("reapit-config.json's content is invalid. Its type should be an object")
throw new Error("config.json's content is invalid. Its type should be an object")
}

const reapitConfigMatchedEnv = reapitConfig[reapitEnv]
Expand Down
2 changes: 1 addition & 1 deletion packages/smb/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/smb/src/tests/badges/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/smb/src/tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const wp = require('@cypress/webpack-preprocessor')
const ResolveTSPathsToWebpackAlias = require('ts-paths-to-webpack-alias')
const tsConfigPath = path.resolve(__dirname, '../../tsconfig.json')

const reapitConfig = require('../../../../reapit-config.json')
const reapitConfig = require('../../../../config.json')

module.exports = (on, config) => {
// https://basarat.gitbooks.io/typescript/docs/testing/cypress.html
Expand Down
7 changes: 7 additions & 0 deletions packages/web-components/config.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"APP_ENV": "local",
"PLATFORM_API_BASE_URL": "",
"COGNITO_CLIENT_SECRET_SEARCH_WIDGET": "",
"COGNITO_CLIENT_ID_SEARCH_WIDGET": "",
"COGNITO_OAUTH_URL": ""
}
3 changes: 2 additions & 1 deletion packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"test:dev": "jest --watch --color",
"test:ci": "cross-env TZ=UTC jest --ci --colors --coverage --silent --forceExit",
"lint": "concurrently \"tsc --noEmit\" \"eslint --cache --ext=ts,tsx,js src\"",
"lint:fix": "eslint --cache --ext=ts,tsx,js src --fix"
"lint:fix": "eslint --cache --ext=ts,tsx,js src --fix",
"fetch-config": "yarn config-manager fetchConfig web-components"
}
}
Loading

0 comments on commit 4970058

Please sign in to comment.