diff --git a/.netlify/build-deploy-preview.sh b/.netlify/build-deploy-preview.sh index 794c45edbd6..24feb4c7416 100755 --- a/.netlify/build-deploy-preview.sh +++ b/.netlify/build-deploy-preview.sh @@ -20,8 +20,16 @@ mv platform/viewer/dist/* .netlify/www/pwa -v # yarn run build:package # Build && Move Docz Output -yarn run build:ui:deploy-preview +# Using local yarn install to prevent Gatsby from needing to access +# node_modules above the platform/ui folder +cd platform/ui +yarn install +yarn run build +cd ../.. mkdir -p ./.netlify/www/ui mv platform/ui/.docz/dist/* .netlify/www/ui -v +# Cache all of the node_module dependencies in +# extensions, modules, and platform packages +yarn run lerna:cache echo 'Nothing left to see here. Go home, folks.' diff --git a/build-deploy-preview.sh b/build-deploy-preview.sh deleted file mode 100755 index 498ce45edef..00000000000 --- a/build-deploy-preview.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# Set directory to location of this script -# https://stackoverflow.com/a/3355423/1867984 -cd "$(dirname "$0")" -cd .. # Up to project root - -# Helpful to verify which versions we're using -echo 'My yarn version is... ' - -yarn -v -node -v - -# Make sure we can hit yarn packages -# yarn global bin -# yarn config get prefix -# yarn config set prefix ~/.yarn -# export PATH="$PATH:`yarn global bin`" - -echo '~~ Revving our engines' - -yarn list - -echo 'shouldnt be required' - -yarn global add lerna - -yarn list - -# Build && Move PWA Output -# yarn run build:ci -# mkdir -p ./.netlify/www/pwa -# mv platform/viewer/dist/* .netlify/www/pwa -v - -# Build && Move script output -# yarn run build:package - -# Build && Move Docz Output -yarn run build:ui -mkdir -p ./.netlify/www/ui -mv platform/ui/.docz/dist/* .netlify/www/ui -v - -echo 'Nothing left to see here. Go home, folks.' - -# Build using react-scripts -# npx cross-env PUBLIC_URL=/demo APP_CONFIG=config/netlify.js react-scripts --max_old_space_size=4096 build diff --git a/lerna-debug.log b/lerna-debug.log deleted file mode 100644 index e1724452fb6..00000000000 --- a/lerna-debug.log +++ /dev/null @@ -1,12 +0,0 @@ -0 silly argv { _: [ 'run' ], -0 silly argv stream: true, -0 silly argv lernaVersion: '3.22.0', -0 silly argv '$0': -0 silly argv '/Users/jamesapetts/cornerstonejs/Viewers/node_modules/.bin/lerna', -0 silly argv script: 'dev:viewer' } -1 notice cli v3.22.0 -2 verbose rootPath /Users/jamesapetts/cornerstonejs/Viewers -3 info versioning independent -4 error JSONError: Unexpected token < in JSON at position 871 while parsing near '...ne-core": "^2.3.0",<<<<<<< HEAD "co...' in platform/core/package.json -4 error at module.exports (/Users/jamesapetts/cornerstonejs/Viewers/node_modules/parse-json/index.js:26:19) -4 error at parse (/Users/jamesapetts/cornerstonejs/Viewers/node_modules/load-json-file/index.js:15:9) diff --git a/netlify-lerna-cache.sh b/netlify-lerna-cache.sh new file mode 100755 index 00000000000..dd22f428989 --- /dev/null +++ b/netlify-lerna-cache.sh @@ -0,0 +1,26 @@ +#!/bin/sh +NODE_MODULES_CACHE="./node_modules" +LERNA_CACHE="$NODE_MODULES_CACHE/lerna-cache" + +echo "Running netlify-lerna-cache.sh" +mkdir -p "$NODE_MODULES_CACHE/lerna-cache" + +cache_deps() { + PACKAGES=$(ls -1 $1) + + for PKG in $PACKAGES + do + PKG_NODE_MODULES="$1/$PKG/node_modules" + if [ -d $PKG_NODE_MODULES ]; + then + mv $PKG_NODE_MODULES $LERNA_CACHE/$PKG + echo "Cached node modules for $PKG" + else + echo "Unable to cache node modules for $PKG" + fi + done +} + +cache_deps platform +cache_deps extensions +cache_deps modes \ No newline at end of file diff --git a/netlify-lerna-restore.sh b/netlify-lerna-restore.sh new file mode 100755 index 00000000000..44ce19487af --- /dev/null +++ b/netlify-lerna-restore.sh @@ -0,0 +1,27 @@ +#!/bin/sh +NODE_MODULES_CACHE="./node_modules" +LERNA_CACHE="$NODE_MODULES_CACHE/lerna-cache" + +echo "Running netlify-lerna-restore.sh" +mkdir -p "$NODE_MODULES_CACHE/lerna-cache" +echo "$NODE_MODULES_CACHE/lerna-cache/*" + +restore_deps() { + PACKAGES=$(ls -1 $1) + + for PKG in $PACKAGES + do + PKG_CACHE="$LERNA_CACHE/$PKG" + if [ -d $PKG_CACHE ]; + then + mv $PKG_CACHE $1/$PKG/node_modules + echo "Restored node modules for $PKG" + else + echo "Unable to restore cache for $PKG" + fi + done +} + +restore_deps platform +restore_deps extensions +restore_deps modes \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index 89ea6667753..cebb22d90a5 100644 --- a/netlify.toml +++ b/netlify.toml @@ -8,6 +8,11 @@ # managed by CircleCI and deployed to our Google Hosting # +[build] + base = "" + publish = ".netlify/www/" + command = ".netlify/build-deploy-preview.sh" + # NODE_VERSION in root `.nvmrc` takes priority # YARN_FLAGS: https://www.netlify.com/docs/build-gotchas/#yarn [build.environment] @@ -17,19 +22,13 @@ YARN_VERSION = "1.22.0" RUBY_VERSION = "2.6.2" YARN_FLAGS = "--no-ignore-optional --pure-lockfile" + NETLIFY_RESTORE = "1" # Production context: all deploys from the Production branch set in your site's # deploy contexts will inherit these settings. [context.production] ignore = "exit 0" # Never build production; We'll let our CI do that -# Deploy Preview context: all deploys generated from a pull/merge request will -# inherit these settings. -[context.deploy-preview] - base = "" - publish = ".netlify/www/" - command = ".netlify/build-deploy-preview.sh" - [[headers]] # Define which paths this specific [[headers]] block will cover. for = "/*" diff --git a/package.json b/package.json index 6f41764325e..76c77ab7bc2 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,9 @@ "docs:preview": "lerna run docs:preview --stream", "docs:publish": "chmod +x ./build-and-publish-docs.sh && ./build-and-publish-docs.sh", "release": "yarn run lerna:version && yarn run lerna:publish", + "lerna:cache": "[ $NETLIFY_RESTORE = 1 ] && ./netlify-lerna-cache.sh || :", + "lerna:restore": "[ $NETLIFY_RESTORE = 1 ] && ./netlify-lerna-restore.sh || :", + "preinstall": "yarn lerna:restore", "lerna:version": "npx lerna version prerelease --force-publish", "lerna:publish": "lerna publish from-package --canary --dist-tag canary", "link-list": "npm ls --depth=0 --link=true" diff --git a/platform/ui/gatsby-node.js b/platform/ui/gatsby-node.js index 308d067abeb..0efa56fe8cf 100644 --- a/platform/ui/gatsby-node.js +++ b/platform/ui/gatsby-node.js @@ -4,12 +4,11 @@ const PnpWebpackPlugin = require(`pnp-webpack-plugin`); // Required until Webpac exports.onCreateWebpackConfig = args => { args.actions.setWebpackConfig({ + node: { fs: 'empty' }, resolve: { plugins: [PnpWebpackPlugin], // Note the '..' in the path because docz gatsby project lives in the '.docz' directory modules: [ - // monorepo root - path.resolve(__dirname, '../../../node_modules'), // platform/ui path.resolve(__dirname, '../node_modules'), // .docz