Skip to content

Commit

Permalink
update Spartacus bootstrap to spartacus 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mpern committed Apr 25, 2021
1 parent 167da33 commit 02c0f47
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 128 deletions.
54 changes: 27 additions & 27 deletions js-storefront/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ then
fi

NG_VERSION="$(ng version | grep '@angular-devkit/core' | awk '{ print $2 }')"
if case $NG_VERSION in 10*) false;; *) true;; esac; then
if case $NG_VERSION in 10.*) false;; *) true;; esac; then
error "Wrong angular version, please use Angular 10 (@angular/cli@v10-lts)"
exit 1
fi
Expand All @@ -58,26 +58,20 @@ ng new "$NAME" \
--packageManager=yarn
(
cd "$NAME" || exit 1
progress "Adding Spartacus"
ng add @spartacus/schematics --pwa --ssr
# yarn install
progress "Setting up SmartEdit support"
INJECTOR="../../core-customize/hybris/bin/modules/smartedit/smarteditaddon/acceleratoraddon/web/webroot/_ui/shared/common/js/webApplicationInjector.js"
if [ -f "$INJECTOR" ]; then
cp "$INJECTOR" "src/assets"
else
warning "webApplicationInjector.js not found"
warning "Please copy into the src/assets folder to enable SmartEdit"
fi
progress "Adding Spartacus (PWA and SSR enabled)"
echo "> Recommended minimal features: Cart, Product, SmartEdit"
ng add @spartacus/schematics \
--pwa \
--ssr \
--useMetaTags
progress "Applying optimizations"
cp -r "../bootstrap/.vscode" .
angular="$(grep -i '@angular/animations' package.json | awk '{ print $2 }')"
mkdir "patches"
for template in ../bootstrap/patches/*.tmpl; do
output="$(basename "$template")"
output="patches/$(printf "%s" "$output" | sed 's/\.[^.]*$//')"
sed "s/\$NAME/$NAME/g" "$template" > "$output.1"
sed "s/\$ANGULAR/$angular/g" "$output.1" > "$output"
mkdir -p "patches"
for template in ../bootstrap/patches/*.patch; do
output="patches/$(basename "$template")"
sed "s/@NAME@/$NAME/g" "$template" > "$output.1"
sed "s/@ANGULAR@/$angular/g" "$output.1" > "$output"
rm "$output.1"
done
for patch in patches/*.patch; do
Expand All @@ -93,19 +87,25 @@ if [ -f "manifest.json" ]; then
fi
cat > manifest.json <<-EOF
{
"applications": [{
"name": "$NAME",
"path": "$NAME",
"ssr": {
"enabled": true,
"path": "dist/$NAME/server/main.js"
"applications": [
{
"name": "$NAME",
"path": "$NAME",
"ssr": {
"enabled": true,
"path": "dist/$NAME/server/main.js"
},
"csr": {
"webroot": "dist/$NAME/browser/"
}
}
}]
],
"nodeVersion": "12"
}
EOF
progress "FINISHED"
echo "Next steps:"
echo "- Update the baseSite.context with the correct baseSite, currency etc."
echo " https://sap.github.io/spartacus-docs/building-the-spartacus-storefront-from-libraries/#checking-appmodulets-for-base-url-and-other-settings"
echo "- (optional) Update smartedit whitelisting in src/index.html"
echo " https://help.sap.com/viewer/9d346683b0084da2938be8a285c0c27a/LATEST/en-US/fb742b29cf3c4e81aac7c131c0441172.html"
echo "- Update smartedit whitelisting in spartacus-configuration.module.ts"
echo " https://sap.github.io/spartacus-docs/smartEdit-setup-instructions-for-spartacus/#configuring-smartedit-to-work-with-spartacus-32-or-newer"
11 changes: 0 additions & 11 deletions js-storefront/bootstrap/patches/angular.json.patch.tmpl

This file was deleted.

34 changes: 0 additions & 34 deletions js-storefront/bootstrap/patches/app.module.ts.patch.tmpl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
--- src/environments/environment.prod.ts 2021-01-20 15:18:00.000000000 +0100
+++ src/environments/environment.prod.ts 2021-01-08 09:54:53.000000000 +0100
--- src/environments/environment.prod.ts 2021-04-23 11:57:19.000000000 +0200
+++ src/environments/environment.prod.ts 2021-04-23 12:17:50.000000000 +0200
@@ -1,3 +1,4 @@
export const environment = {
- production: true
+ production: true,
+ occBaseUrl: null
};
--- src/environments/environment.ts 2021-01-20 15:18:00.000000000 +0100
+++ src/environments/environment.ts 2021-01-08 09:54:51.000000000 +0100
--- src/environments/environment.ts 2021-04-23 11:57:19.000000000 +0200
+++ src/environments/environment.ts 2021-04-23 12:17:59.000000000 +0200
@@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.

Expand Down
11 changes: 11 additions & 0 deletions js-storefront/bootstrap/patches/index.html.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- src/index.html 2021-04-23 12:00:23.000000000 +0200
+++ src/index.html 2021-04-23 12:27:23.000000000 +0200
@@ -6,7 +6,7 @@
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
- <meta name="occ-backend-base-url" content="https://localhost:9002"/>
+ <meta name="occ-backend-base-url" content="OCC_BACKEND_BASE_URL_VALUE"/>
<meta name="media-backend-base-url" content="MEDIA_BACKEND_BASE_URL_VALUE"/>
<link rel="manifest" href="manifest.webmanifest">
<meta name="theme-color" content="#1976d2">
16 changes: 0 additions & 16 deletions js-storefront/bootstrap/patches/index.html.patch.tmpl

This file was deleted.

25 changes: 25 additions & 0 deletions js-storefront/bootstrap/patches/package.json.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--- package.json 2021-04-23 12:00:23.000000000 +0200
+++ package.json 2021-04-23 13:03:20.000000000 +0200
@@ -3,18 +3,19 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
- "start": "ng serve",
- "build": "ng build",
+ "start": "ng serve --ssl",
+ "build": "yarn run build:ssr",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
- "dev:ssr": "ng run @NAME@:serve-ssr",
+ "dev:ssr": "cross-env NODE_TLS_REJECT_UNAUTHORIZED=0 ng run @NAME@:serve-ssr",
"serve:ssr": "node dist/@NAME@/server/main.js",
"build:ssr": "ng build --prod && ng run @NAME@:server:production",
"prerender": "ng run @NAME@:prerender"
},
"private": true,
"dependencies": {
+ "cross-env": "^7.0.3",
"@angular/animations": @ANGULAR@
"@angular/common": @ANGULAR@
"@angular/compiler": @ANGULAR@
25 changes: 0 additions & 25 deletions js-storefront/bootstrap/patches/package.json.patch.tmpl

This file was deleted.

11 changes: 0 additions & 11 deletions js-storefront/bootstrap/patches/server.ts.patch.tmpl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--- src/app/spartacus/spartacus-configuration.module.ts 2021-04-23 12:00:23.000000000 +0200
+++ src/app/spartacus/spartacus-configuration.module.ts 2021-04-25 09:54:23.000000000 +0200
@@ -1,18 +1,35 @@
import { NgModule } from '@angular/core';
import { translationChunksConfig, translations } from "@spartacus/assets";
+import { OccConfig } from '@spartacus/core';
import { provideConfig } from "@spartacus/core";
import { defaultCmsContentProviders, layoutConfig, mediaConfig } from "@spartacus/storefront";
+import { environment } from 'src/environments/environment';
+
+const occConfig: OccConfig = { backend: { occ: {} } };
+// only provide the `occ.baseUrl` key if it is explicitly configured, otherwise the value of
+// <meta name="occ-backend-base-url" > is ignored.
+// This in turn breaks the deployment in CCv2.
+// https://github.com/SAP/spartacus/issues/5886
+occConfig.backend.occ.prefix = '/occ/v2/'
+if (environment.occBaseUrl) {
+ occConfig.backend.occ.baseUrl = environment.occBaseUrl;
+}

@NgModule({
declarations: [],
imports: [
],
providers: [provideConfig(layoutConfig), provideConfig(mediaConfig), ...defaultCmsContentProviders, provideConfig({
- backend: {
- occ: {
- }
+ backend: occConfig.backend,
+ smartEdit: {
+ storefrontPreviewRoute: 'cx-preview',
+ //TODO: adjust origins as necessary
+ allowOrigin: 'localhost:9002, *.*.model-t.cc.commerce.ondemand.com:443',
},
context: {
+ urlParameters: ['baseSite', 'language', 'currency'],
+ //TODO: configure baseSite
+ // baseSite: ['electronics-spa'],
currency: ['USD'],
language: ['en'],
},

0 comments on commit 02c0f47

Please sign in to comment.