Skip to content

Commit

Permalink
Merge branch 'develop' into supernova/1071_cropped_checkout_2
Browse files Browse the repository at this point in the history
  • Loading branch information
sirugh authored Jul 16, 2019
2 parents deaa1bd + 7172a3f commit b420f2b
Show file tree
Hide file tree
Showing 156 changed files with 5,168 additions and 2,798 deletions.
2 changes: 1 addition & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
save-prefix "^"
save-prefix "~"
3 changes: 3 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ARG ENVFILEPATH
# copy configuration env file from host file system to venia-concept .env for build
COPY ${ENVFILEPATH} ./packages/venia-concept/.env

# run yarn again to reestablish workspace symlinks
RUN yarn install --frozen-lockfile

# build the app
RUN yarn run build

Expand Down
11 changes: 7 additions & 4 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apk --no-cache --virtual add \
python \
make \
g++ \
yarn
yarn

# copy just the dependency files and configs needed for install
COPY packages/peregrine/package.json ./packages/peregrine/package.json
Expand All @@ -26,9 +26,12 @@ COPY packages ./packages
# copy configuration env file from host file system to venia-concept .env for build
COPY ./docker/.env.docker.prod ./packages/venia-concept/.env

ENV NODE_ENV=production
# run yarn again to reestablish workspace symlinks
RUN yarn install --frozen-lockfile

ENV NODE_ENV=production
# build the app
RUN yarn run build
RUN yarn run build


# MULTI-STAGE BUILD
Expand All @@ -41,6 +44,6 @@ RUN chown -R node:node /usr/src/app
COPY --from=build /usr/src/app .
USER node
EXPOSE 8080
ENV NODE_ENV=production
ENV NODE_ENV=production
# command to run application
CMD [ "yarn", "stage:venia" ]
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ services:
restart: unless-stopped

pwa:
hostname: ${PWA_STUDIO_PUBLIC_PATH}
hostname: ${DEV_SERVER_HOST}
# build pwa using the Dockerfile from the PWD
build:
context: .
dockerfile: Dockerfile.dev
args:
HOST: ${PWA_STUDIO_PUBLIC_PATH}
args:
HOST: ${DEV_SERVER_HOST}
ENVFILEPATH: ${ENVFILEPATH}
# list of directories and files on the host system to volume mount into the container
# changes made to files in the container and on the host file system are mapped to one another
Expand All @@ -42,7 +42,7 @@ services:
- nginx-proxy
environment:
# environment variables consumed by the nginx-proxy service
VIRTUAL_HOST: ${PWA_STUDIO_PUBLIC_PATH}
VIRTUAL_PORT: ${PWA_STUDIO_PORTS_DEVELOPMENT}
VIRTUAL_HOST: ${DEV_SERVER_HOST}
VIRTUAL_PORT: ${DEV_SERVER_PORT}
expose:
- ${PWA_STUDIO_PORTS_DEVELOPMENT}
- ${DEV_SERVER_PORT}
17 changes: 9 additions & 8 deletions docker/.env.docker.dev
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
########## .env.docker ########################################################
#
# See packages/venia-concept/.env.dist file for full option details
# See packages/pwa-buildpack/envVarDefinitions.json file for full option details
#
###############################################################################

DEV_SERVER_HOST=pwa-docker.localhost
PWA_STUDIO_PUBLIC_PATH=pwa-docker.localhost
PWA_STUDIO_PORTS_DEVELOPMENT=8080
ENABLE_SERVICE_WORKER_DEBUGGING=0
PWA_STUDIO_HOT_RELOAD_WITH_POLLING=0
MAGENTO_BACKEND_URL=https://release-dev-231-npzdaky-zddsyhrdimyra.us-4.magentosite.cloud/
MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST=0
UPWARD_JS_UPWARD_PATH=venia-upward.yml
DEV_SERVER_PORT=8080
DEV_SERVER_SERVICE_WORKER_ENABLED=0
DEV_SERVER_WATCH_OPTIONS_USE_POLLING=0
MAGENTO_BACKEND_URL=https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/
CUSTOM_ORIGIN_ENABLED=0
UPWARD_JS_UPWARD_PATH=upward.yml
UPWARD_JS_BIND_LOCAL=1
UPWARD_JS_LOG_URL=1
BRAINTREE_TOKEN=sandbox_8yrzsvtm_s2bg8fs563crhqzk
CHECKOUT_BRAINTREE_TOKEN=sandbox_8yrzsvtm_s2bg8fs563crhqzk
9 changes: 5 additions & 4 deletions docker/.env.docker.prod
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
########## .env.docker ########################################################
#
# See packages/venia-concept/.env.dist file for full option details
# See packages/pwa-buildpack/envVarDefinitions.json file for full option details
#
###############################################################################

NODE_ENV=production
PORT=8080
PWA_STUDIO_PUBLIC_PATH=localhost
STAGING_SERVER_HOST=localhost
# magento graphql backend set to production mode
MAGENTO_BACKEND_URL=redacted
MAGENTO_BUILDPACK_PROVIDE_SECURE_HOST=0
UPWARD_JS_UPWARD_PATH=venia-upward.yml
UPWARD_JS_UPWARD_PATH=upward.yml
CUSTOM_ORIGIN_ENABLED=0
UPWARD_JS_BIND_LOCAL=1
UPWARD_JS_LOG_URL=1
BRAINTREE_TOKEN=redacted
CHECKOUT_BRAINTREE_TOKEN=redacted
6 changes: 3 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ After `docker/run-docker` is executed from the root of the repository, the defau

## Configure a custom domain

The domain is configurable. Just set `PWA_STUDIO_PUBLIC_PATH` key to the new domain under `docker/.env.docker`, or pass a custom .env file with the `PWA_STUDIO_PUBLIC_PATH` key set. All required fields can be found in `docker/.env.docker`. See how to pass the custom .env file below.
The domain is configurable. Just set the `DEV_SERVER_HOST` key to the new domain under `docker/.env.docker`, or pass a custom .env file with the `DEV_SERVER_HOST` key set. All required fields can be found in `docker/.env.docker`. For staging and production environments, use `STAGING_SERVER_HOST`. See how to pass the custom .env file below.

## Pass custom .env file configuration through cli args (optional)

To use a custom .env file for configuration, pass it to the `run-docker` script like so: `docker/run-docker -e path-from-project-root`. This file will take the place of the default `.env.docker` file.

## Service Workers and Hot Reloading

Service workers are disabled by default when running the `docker/run-docker` script, but they can easily be turned on by changing the default value of `ENABLE_SERVICE_WORKER_DEBUGGING=0` to `ENABLE_SERVICE_WORKER_DEBUGGING=1` in `.env.docker`.
Service workers are disabled by default when running the `docker/run-docker` script, but they can easily be turned on by changing the default value of `DEV_SERVER_SERVICE_WORKER_ENABLED=0` to `DEV_SERVER_SERVICE_WORKER_ENABLED=1` in `.env.docker`.

Hot reloading is enabled by default when running the `docker/run-docker` script and automatically refreshes the browser on changes made in the container as well as on the host machine, ie your local file system.

Expand All @@ -36,4 +36,4 @@ For more details check out the [dev tools docs](https://bit.ly/2tTGWc0).

### Hot Reloading is not working

If you find that hot reloading is not working for you the webpack docs recommend using [polling](https://webpack.js.org/configuration/watch/#watchoptionspoll) as watching does not work with network file systems and machines in VirtualBox. To enable polling, set `PWA_STUDIO_HOT_RELOAD_WITH_POLLING=1` in `.env.docker`.
If you find that hot reloading is not working for you the webpack docs recommend using [polling](https://webpack.js.org/configuration/watch/#watchoptionspoll) as watching does not work with network file systems and machines in VirtualBox. To enable polling, set `DEV_SERVER_WATCH_OPTIONS_USE_POLLING=1` in `.env.docker`.
6 changes: 3 additions & 3 deletions docker/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ isexe@^2.0.0:
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=

lodash@^4.17.4:
version "4.17.11"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
version "4.17.14"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba"
integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==

make-dir@^1.0.0:
version "1.3.0"
Expand Down
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ const jestConfig = {
'graphql-cli-validate-magento-pwa-queries',
'GraphQL CLI Plugin',
() => ({
testEnvironment: 'node'
testEnvironment: 'node',
moduleNameMapper: {
'./magento-compatibility':
'<rootDir>/magento-compatibility.js'
}
})
)
],
Expand Down
18 changes: 3 additions & 15 deletions now-build.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#!/bin/bash -xe

cd ../../
# We set NODE_ENV=production here, instead of in the now.json file. It's not
# obvious, but this build script runs _after_ yarn install. If
# NODE_ENV=production is set _during_ yarn install, it won't install
# devDependencies. So we need to wait until install is done before setting
# NODE_ENV=production to optimize the build step.
export NODE_ENV="production"

# This step will happen _twice_ in yarn deploy: once for the static deploy and
# once to compile the lambda. So instead of a full build, this command runs a
# streamlined build to make only what is essential for deploy.
yarn concurrently 'yarn workspace @magento/pwa-buildpack run build' 'yarn workspace @magento/peregrine run build:esm'
# For the Venia build, any environment variables not set in now.json or other
# scripts are filled in by copying the default .env file here.
cp packages/venia-concept/.env.dist packages/venia-concept/.env
yarn workspace @magento/venia-concept run build:prod
# No .env file generation is necessary, since the only required variable without
# a default, MAGENTO_BACKEND_URL, is set in the build environment by now.json.
yarn run build
4 changes: 2 additions & 2 deletions now.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"env": {
"UPWARD_JS_BIND_LOCAL": "false",
"IMAGE_OPTIMIZING_ORIGIN": "backend",
"MAGENTO_BACKEND_URL": "https://master-7rqtwti-xjmpcdjpe6kzm.us-4.magentosite.cloud/",
"MAGENTO_BACKEND_URL": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/",
"NODE_ENV": "production"
},
"build": {
"env": {
"MAGENTO_BACKEND_URL": "https://master-7rqtwti-xjmpcdjpe6kzm.us-4.magentosite.cloud/"
"MAGENTO_BACKEND_URL": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/"
}
},
"builds": [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"scripts": {
"build": "yarn workspaces run build",
"build:ci": "yarn workspaces run build:ci",
"build:dev": "yarn workspaces run build:dev",
"clean:all": "yarn workspaces run clean && rimraf ./node_modules",
"clean:dist": "yarn workspaces run clean",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "graphql-cli-validate-magento-pwa-queries",
"version": "1.0.0",
"publishConfig": {
"access": "public"
},
"description": "graphql-cli plugin for validating all queries in a Magento 2 PWA project",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions packages/peregrine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
"main": "dist/index.js",
"scripts": {
"build": "concurrently --raw yarn:build:cjs yarn:build:esm",
"build:ci": "yarn run -s build:esm",
"build:cjs": "BABEL_ENV=production babel src --out-dir dist --root-mode 'upward' --source-maps",
"build:dev": "yarn run build",
"build:dev": "yarn run -s build",
"build:esm": "BABEL_ENV=development babel src --out-dir esm --root-mode 'upward' --source-maps",
"clean": "rimraf dist esm",
"prepublishOnly": "yarn run clean && yarn run build",
"prebuild": "yarn run -s clean",
"prepublishOnly": "yarn run build",
"storybook": "start-storybook -p 9001 -c .storybook",
"storybook:build": "build-storybook -c .storybook -o storybook-dist",
"watch": "yarn run clean && concurrently --raw yarn:watch:cjs yarn:watch:esm",
Expand Down
5 changes: 4 additions & 1 deletion packages/peregrine/src/Toasts/useToastContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { createContext, useContext, useReducer } from 'react';
import withLogger from '../util/withLogger';
/**
* The state of the toast store.
* @typedef {Object} ToastState
Expand Down Expand Up @@ -61,6 +62,8 @@ const reducer = (prevState = initialState, action = {}) => {

const ToastContext = createContext();

const wrappedReducer = withLogger(reducer);

/**
* A context provider that provides the toast state object and the dispatch
* function.
Expand All @@ -72,7 +75,7 @@ const ToastContext = createContext();
* </ToastContextProvider>
*/
export const ToastContextProvider = ({ children }) => {
const store = useReducer(reducer, initialState);
const store = useReducer(wrappedReducer, initialState);
return (
<ToastContext.Provider value={store}>{children}</ToastContext.Provider>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/peregrine/src/hooks/useQueryResult.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useMemo, useReducer } from 'react';
import withLogger from '../util/withLogger';

const initialState = {
data: null,
Expand Down Expand Up @@ -34,6 +35,7 @@ const reducer = (state, { payload, type }) => {
}
}
};
const wrappedReducer = withLogger(reducer);

/**
* A [React Hook]{@link https://reactjs.org/docs/hooks-intro.html} that contains
Expand All @@ -56,7 +58,7 @@ export const useQueryResult = () => {
* @param {QueryResultState} state The current state
* @param {QueryResultAction} action A QueryResultAction object
*/
const [state, dispatch] = useReducer(reducer, initialState);
const [state, dispatch] = useReducer(wrappedReducer, initialState);

/**
* Set the state data
Expand Down
21 changes: 21 additions & 0 deletions packages/peregrine/src/util/withLogger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Logs action type, payload, and result state to the browser console.
* @param {*} reducer a reducing function to wrap with logging
* @returns {Function} a wrapped reducer function
*/
const withLogger = reducer => (state, action) => {
const result = reducer(state, action);

console.groupCollapsed(action.type);
console.group('payload');
console.log(action.payload);
console.groupEnd();
console.group('next state');
console.log(result);
console.groupEnd();
console.groupEnd();

return result;
};

export default withLogger;
3 changes: 3 additions & 0 deletions packages/pwa-buildpack/__mocks__/@magento/express-sharp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const middleware = jest.fn();
const expressSharp = (module.exports = jest.fn().mockReturnValue(middleware));
expressSharp.__mockMiddleware = middleware;
5 changes: 5 additions & 0 deletions packages/pwa-buildpack/__mocks__/apicache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const middleware = jest.fn();
module.exports = {
middleware: jest.fn().mockReturnValue(middleware),
__mockMiddleware: middleware
};
10 changes: 10 additions & 0 deletions packages/pwa-buildpack/bin/buildpack
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env node

require('yargs')
.commandDir('../dist/cli')
.demandCommand(
1,
'Invoke buildpack with a subcommand (eg. `buildpack create-env-file`) and the arguments to that subcommand.'
)
.strict()
.help().argv;
Loading

0 comments on commit b420f2b

Please sign in to comment.