Skip to content

Commit

Permalink
fix: #568 react scaffold after migration to config.json (#693)
Browse files Browse the repository at this point in the history
Changes
- Add export default app.tsx
- Change index.tsx to remove import index.scss
  • Loading branch information
Pham Hai Duong authored Mar 23, 2020
1 parent cd59f3e commit 0fb24fb
Show file tree
Hide file tree
Showing 56 changed files with 100 additions and 80 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"react": "^16.12.0",
"react-datepicker": "^2.9.6",
"react-dom": "^16.12.0",
"react-ga": "^2.7.0",
"react-redux": "^7.1.3",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/aml-checklist/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"uploadApiUrl": "",
"cognitoClientId": "",
"googleAnalyticsKey": "",
"cognitoOAuthUrl": ""
"cognitoOAuthUrl": "",
"cognitoUserPoolId": ""
}
1 change: 1 addition & 0 deletions packages/aml-checklist/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ window.reapit = {
cognitoClientId: '',
googleAnalyticsKey: '',
cognitoOAuthUrl: '',
cognitoUserPoolId: '',
},
}

Expand Down
1 change: 1 addition & 0 deletions packages/aml-checklist/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Config = {
cognitoClientId: string
googleAnalyticsKey: string
cognitoOAuthUrl: string
cognitoUserPoolId: string
}

declare global {
Expand Down
5 changes: 3 additions & 2 deletions packages/cognito-auth/config.example.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"cognitoOAuthUrl": ""
}
"cognitoOAuthUrl": "",
"cognitoUserPoolId": ""
}
2 changes: 1 addition & 1 deletion packages/cognito-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reapit/cognito-auth",
"version": "2.0.19",
"version": "2.1.0",
"description": "Simple wrapper around AWS Cognito for basic authentication flow",
"keywords": [],
"homepage": "https://github.com/reapit/foundations#readme",
Expand Down
1 change: 1 addition & 0 deletions packages/cognito-auth/src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type Config = {
cognitoOAuthUrl: string
cognitoUserPoolId: string
}

declare global {
Expand Down
2 changes: 1 addition & 1 deletion packages/cognito-auth/src/utils/cognito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getLoginSession = (session: CognitoUserSession): Partial<LoginSessi

export const getNewUser = (userName: string, cognitoClientId: string) => {
const poolData = {
UserPoolId: process.env.COGNITO_USERPOOL_ID as string,
UserPoolId: window.reapit.config.cognitoUserPoolId,
ClientId: cognitoClientId,
}
const userPool = new CognitoUserPool(poolData)
Expand Down
3 changes: 2 additions & 1 deletion packages/geo-diary/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"cognitoClientId": "",
"googleAnalyticsKey": "",
"googleMapApiKey": "",
"cognitoOAuthUrl": ""
"cognitoOAuthUrl": "",
"cognitoUserPoolId": ""
}
1 change: 1 addition & 0 deletions packages/geo-diary/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ window.reapit = {
googleAnalyticsKey: '',
googleMapApiKey: '',
cognitoOAuthUrl: '',
cognitoUserPoolId: '',
},
}

Expand Down
2 changes: 1 addition & 1 deletion packages/geo-diary/src/sagas/__tests__/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('auth sagas', () => {
expect(gen.next().value).toEqual(call(store.purgeStore))
expect(gen.next().value).toEqual(call(removeSession, COOKIE_SESSION_KEY_GEO_DIARY))
expect(gen.next().value).toEqual(
call(redirectToLogout, window.reapit.config.cognitoClientId as string, `${window.location.origin}/login`),
call(redirectToLogout, window.reapit.config.cognitoClientId, `${window.location.origin}/login`),
)
expect(gen.next().done).toBe(true)
})
Expand Down
1 change: 1 addition & 0 deletions packages/geo-diary/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Config = {
googleAnalyticsKey: string
googleMapApiKey: string
cognitoOAuthUrl: string
cognitoUserPoolId: string
}

declare global {
Expand Down
3 changes: 2 additions & 1 deletion packages/lifetime-legal/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"uploadApiUrl": "",
"cognitoClientId": "",
"googleAnalyticsKey": "",
"cognitoOAuthUrl": ""
"cognitoOAuthUrl": "",
"cognitoUserPoolId": ""
}
1 change: 1 addition & 0 deletions packages/lifetime-legal/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ window.reapit = {
cognitoClientId: '',
googleAnalyticsKey: '',
cognitoOAuthUrl: '',
cognitoUserPoolId: '',
},
}

Expand Down
1 change: 1 addition & 0 deletions packages/lifetime-legal/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Config = {
cognitoClientId: string
googleAnalyticsKey: string
cognitoOAuthUrl: string
cognitoUserPoolId: string
}

declare global {
Expand Down
3 changes: 2 additions & 1 deletion packages/marketplace/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"elementDocumentUrl": "",
"cognitoClientId": "",
"googleAnalyticsKey": "",
"cognitoOAuthUrl": ""
"cognitoOAuthUrl": "",
"cognitoUserPoolId": ""
}
1 change: 0 additions & 1 deletion packages/marketplace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"diff": "^4.0.1",
"lodash.orderby": "^4.6.0",
"react-chartjs-2": "^2.8.0",
"react-ga": "^2.7.0",
"react-slick": "^0.24.0",
"swagger-ui-react": "^3.24.3"
},
Expand Down
1 change: 1 addition & 0 deletions packages/marketplace/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.reapit = {
cognitoClientId: '',
googleAnalyticsKey: '',
cognitoOAuthUrl: '',
cognitoUserPoolId: '',
},
}

Expand Down
4 changes: 2 additions & 2 deletions packages/marketplace/src/sagas/__tests__/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('settings', () => {
password: '123',
newPassword: '456',
userName: '[email protected]',
cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '',
cognitoClientId: window.reapit.config.cognitoClientId || '',
}),
)
expect(clone.next('SUCCESS').value).toEqual(call(removeSession))
Expand All @@ -141,7 +141,7 @@ describe('settings', () => {
password: '123',
newPassword: '456',
userName: '[email protected]',
cognitoClientId: process.env.COGNITO_CLIENT_ID_MARKETPLACE || '',
cognitoClientId: window.reapit.config.cognitoClientId || '',
}),
)
expect(clone.next('FAIL').value).toEqual(
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-branches.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/marketplace/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/marketplace/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/marketplace/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.
1 change: 1 addition & 0 deletions packages/marketplace/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Config = {
cognitoClientId: string
googleAnalyticsKey: string
cognitoOAuthUrl: string
cognitoUserPoolId: string
}

declare global {
Expand Down
16 changes: 8 additions & 8 deletions packages/react-app-scaffolder/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ module.exports = class extends Generator {
name,
})

this.fs.copyTpl(this.templatePath('_config.json'), this.destinationPath('./config.json'), {
clientId,
})

this.fs.copyTpl(this.templatePath('_config.example.json'), this.destinationPath('./config.example.json'), {
clientId,
})

this.fs.copyTpl(this.templatePath('./base'), this.destinationPath('./'), {
name,
nameInConstantCase: constantCase(name),
Expand Down Expand Up @@ -230,12 +238,6 @@ module.exports = class extends Generator {
message: 'Pick project type',
choices: ['Redux', 'No Redux'],
},
// {
// type: 'confirm',
// name: 'azure',
// message: 'Would you like an Azure Pipeline?',
// default: false,
// },
{
type: 'confirm',
name: 'githubPush',
Expand All @@ -244,8 +246,6 @@ module.exports = class extends Generator {
},
])

this.answers.azure = false

const { stateManagementStyle, stylesSolution } = this.answers
if (stateManagementStyle === 'Redux') {
this.projectTypePath = 'redux'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"appEnv": "development",
"appEnv": "local",
"sentryDns": "",
"cognitoClientId": "",
"googleAnalyticsKey": ""
"cognitoClientId": "<%= clientId %>",
"googleAnalyticsKey": "",
"cognitoOAuthUrl": "https://dev.connect.reapit.cloud",
"cognitoUserPoolId": ""
}
8 changes: 8 additions & 0 deletions packages/react-app-scaffolder/app/templates/_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"appEnv": "local",
"sentryDns": "",
"cognitoClientId": "<%= clientId %>",
"googleAnalyticsKey": "",
"cognitoOAuthUrl": "https://dev.connect.reapit.cloud",
"cognitoUserPoolId": ""
}
1 change: 1 addition & 0 deletions packages/react-app-scaffolder/app/templates/_gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# misc
.DS_Store
reapit-config.json
config.json

# log files
npm-debug.log*
Expand Down
5 changes: 4 additions & 1 deletion packages/react-app-scaffolder/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2"
"react-router-dom": "^5.1.2",
"@sentry/browser": "^5.11.1",
"react-ga": "^2.7.0",

<% if (redux) { %>
,"react-redux": "^7.1.3",
Expand Down Expand Up @@ -76,6 +78,7 @@
"@types/react-router-dom": "^5.1.2",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"@sentry/webpack-plugin": "^1.10.0",
"cross-env": "^7.0.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const session = {
idToken: '123',
idTokenExpiry: 1583492838,
refreshToken: '123',
cognitoClientId: 'ue1e0vujti1p9f133ckfkbkdh',
cognitoClientId: '123',
loginType: 'CLIENT',
userName: '[email protected]',
mode: 'WEB',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const session = {
idToken: '123',
idTokenExpiry: 1583492838,
refreshToken: '123',
cognitoClientId: 'ue1e0vujti1p9f133ckfkbkdh',
cognitoClientId: '123',
loginType: 'CLIENT',
userName: '[email protected]',
mode: 'WEB',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export type Config = {
cognitoClientId: string
googleAnalyticsKey: string
graphqlUri: string
cognitoOAuthUrl: string
cognitoUserPoolId: string
}

declare global {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const PATHS = {
src: `${process.cwd()}/src`,
entryWeb: `${process.cwd()}/src/core/index.tsx`,
config: `${process.cwd()}/../../reapit-config.json`,
template: `${process.cwd()}/public/index.html`,
tsConfig: `${process.cwd()}/tsconfig.json`,
logo: `${process.cwd()}/public/logo.png`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const ResolveTSPathsToWebpackAlias = require('ts-paths-to-webpack-alias')
const HashedModuleIdsPlugin = require('webpack').HashedModuleIdsPlugin
const { EnvironmentPlugin } = require('webpack')
const { PATHS } = require('./constants')
const path = require('path')
const readReapitConfig = require('./read-reapit-config')

module.exports = {
context: process.cwd(),
Expand All @@ -19,6 +19,7 @@ module.exports = {
new ResolveTSPathsToWebpackAlias({
tsconfig: PATHS.tsConfig,
}),
new CopyPlugin([{ from: 'config.json', to: PATHS.output }]),
new ForkTsCheckerWebpackPlugin({
async: false,
useTypescriptIncrementalApi: true,
Expand Down Expand Up @@ -62,7 +63,6 @@ module.exports = {
},
}),
new HashedModuleIdsPlugin(),
new EnvironmentPlugin(readReapitConfig()),
],
module: {
rules: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-web
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const { EnvironmentPlugin } = require('webpack')
const ResolveTSPathsToWebpackAlias = require('ts-paths-to-webpack-alias')
const readReapitConfig = require('./read-reapit-config')
const { PATHS } = require('./constants')

module.exports = {
context: process.cwd(),
Expand All @@ -26,7 +23,6 @@ module.exports = {
title: 'TypeScript',
excludeWarnings: false,
}),
new EnvironmentPlugin(readReapitConfig()),
new HtmlWebpackPlugin({
inject: true,
template: 'public/index.html',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const glob = require('glob')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const ResolveTSPathsToWebpackAlias = require('ts-paths-to-webpack-alias')
const HashedModuleIdsPlugin = require('webpack').HashedModuleIdsPlugin
Expand Down Expand Up @@ -29,6 +30,7 @@ module.exports = {
new ResolveTSPathsToWebpackAlias({
tsconfig: path.resolve(__dirname, '../..', 'tsconfig.json')
}),
new CopyPlugin([{ from: 'config.json', to: PATHS.output }]),
new ForkTsCheckerWebpackPlugin({
async: false,
useTypescriptIncrementalApi: true,
Expand Down
Loading

0 comments on commit 0fb24fb

Please sign in to comment.