@salesforce/pwa-kit-create-app 3.0.0-preview.1 → 3.0.0-preview.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,7 +71,11 @@ module.exports = {
71
71
  {
72
72
  host: '{{answers.project.commerce.shortCode}}.api.commercecloud.salesforce.com',
73
73
  path: 'api'
74
- }
74
+ }{{~#if answers.project.commerce.instanceUrl}},
75
+ {
76
+ host: '{{answers.project.commerce.instanceUrl}}',
77
+ path: 'ocapi'
78
+ }{{/if}}
75
79
  ]
76
80
  }
77
81
  }
@@ -0,0 +1,22 @@
1
+ /*
2
+ Hello there! This is a demonstration of how to override a file from the base template.
3
+
4
+ It's necessary that the module export interface remain consistent,
5
+ as other files in the base template rely on constants.js, thus we
6
+ import the underlying constants.js, modifies it and re-export it.
7
+ */
8
+
9
+ import {
10
+ DEFAULT_LIMIT_VALUES,
11
+ DEFAULT_SEARCH_PARAMS
12
+ } from '{{preset.templateSource.id}}/app/constants'
13
+
14
+ // original value is 25
15
+ DEFAULT_LIMIT_VALUES[0] = 3
16
+ DEFAULT_SEARCH_PARAMS.limit = 3
17
+
18
+ export const CUSTOM_HOME_TITLE = '🎉 Hello Extensible React Template!'
19
+
20
+ export {DEFAULT_LIMIT_VALUES, DEFAULT_SEARCH_PARAMS}
21
+
22
+ export * from '{{preset.templateSource.id}}/app/constants'
@@ -0,0 +1,160 @@
1
+ /*
2
+ * Copyright (c) 2023, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+ import React, { useEffect } from 'react'
8
+ import { useIntl, FormattedMessage } from 'react-intl'
9
+ import { useLocation } from 'react-router-dom'
10
+
11
+ // Components
12
+ import { Box, Button, SimpleGrid, Stack, Link } from '@chakra-ui/react'
13
+
14
+ // Project Components
15
+ import Hero from '{{preset.templateSource.id}}/app/components/hero'
16
+ import Seo from '{{preset.templateSource.id}}/app/components/seo'
17
+ import Section from '{{preset.templateSource.id}}/app/components/section'
18
+ import ProductScroller from '{{preset.templateSource.id}}/app/components/product-scroller'
19
+
20
+ // Others
21
+ import { getAssetUrl } from '@salesforce/pwa-kit-react-sdk/ssr/universal/utils'
22
+
23
+ //Hooks
24
+ import useEinstein from '{{preset.templateSource.id}}/app/hooks/use-einstein'
25
+
26
+ // Constants
27
+ import {
28
+ MAX_CACHE_AGE,
29
+ HOME_SHOP_PRODUCTS_CATEGORY_ID,
30
+ HOME_SHOP_PRODUCTS_LIMIT,
31
+ CUSTOM_HOME_TITLE
32
+ } from '../../constants'
33
+
34
+ import { useServerContext } from '@salesforce/pwa-kit-react-sdk/ssr/universal/hooks'
35
+ import { useProductSearch } from '@salesforce/commerce-sdk-react'
36
+
37
+ /**
38
+ * This is the home page for Retail React App.
39
+ * The page is created for demonstration purposes.
40
+ * The page renders SEO metadata and a few promotion
41
+ * categories and products, data is from local file.
42
+ */
43
+ const Home = () => {
44
+ const intl = useIntl()
45
+ const einstein = useEinstein()
46
+ const { pathname } = useLocation()
47
+
48
+ // useServerContext is a special hook introduced in v3 PWA Kit SDK.
49
+ // It replaces the legacy `getProps` and provide a react hook interface for SSR.
50
+ // it returns the request and response objects on the server side,
51
+ // and these objects are undefined on the client side.
52
+ const { res } = useServerContext()
53
+ if (res) {
54
+ res.set('Cache-Control', `max-age=${MAX_CACHE_AGE}`)
55
+ }
56
+
57
+ const { data: productSearchResult, isLoading } = useProductSearch({
58
+ parameters: {
59
+ refine: [`cgid=${HOME_SHOP_PRODUCTS_CATEGORY_ID}`, 'htype=master'],
60
+ limit: HOME_SHOP_PRODUCTS_LIMIT
61
+ }
62
+ })
63
+
64
+ /**************** Einstein ****************/
65
+ useEffect(() => {
66
+ einstein.sendViewPage(pathname)
67
+ }, [])
68
+
69
+ return (
70
+ <Box data-testid="home-page" layerStyle="page">
71
+ <Seo
72
+ title="Home Page"
73
+ description="Commerce Cloud Retail React App"
74
+ keywords="Commerce Cloud, Retail React App, React Storefront"
75
+ />
76
+
77
+ <Hero
78
+ title={CUSTOM_HOME_TITLE}
79
+ img=\{{
80
+ src: getAssetUrl('static/img/hero.png'),
81
+ alt: 'npx pwa-kit-create-app'
82
+ }}
83
+ actions={
84
+ <Stack spacing=\{{ base: 4, sm: 6 }} direction=\{{ base: 'column', sm: 'row' }}>
85
+ <Button
86
+ as={Link}
87
+ href="https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/getting-started.html"
88
+ target="_blank"
89
+ width=\{{ base: 'full', md: 'inherit' }}
90
+ paddingX={7}
91
+ _hover=\{{ textDecoration: 'none' }}
92
+ >
93
+ <FormattedMessage
94
+ defaultMessage="Get started"
95
+ id="home.link.get_started"
96
+ />
97
+ </Button>
98
+ </Stack>
99
+ }
100
+ />
101
+
102
+ {productSearchResult && (
103
+ <Section
104
+ padding={4}
105
+ paddingTop={16}
106
+ title={intl.formatMessage({
107
+ defaultMessage: 'Shop Products',
108
+ id: 'home.heading.shop_products'
109
+ })}
110
+ subtitle={intl.formatMessage(
111
+ {
112
+ defaultMessage:
113
+ 'This section contains content from the catalog. {docLink} on how to replace it.',
114
+ id: 'home.description.shop_products',
115
+ description:
116
+ '{docLink} is a html button that links the user to https://sfdc.co/business-manager-manage-catalogs'
117
+ },
118
+ {
119
+ docLink: (
120
+ <Link
121
+ target="_blank"
122
+ href={'https://sfdc.co/business-manager-manage-catalogs'}
123
+ textDecoration={'none'}
124
+ position={'relative'}
125
+ _after=\{{
126
+ position: 'absolute',
127
+ content: `""`,
128
+ height: '2px',
129
+ bottom: '-2px',
130
+ margin: '0 auto',
131
+ left: 0,
132
+ right: 0,
133
+ background: 'gray.700'
134
+ }}
135
+ _hover=\{{ textDecoration: 'none' }}
136
+ >
137
+ {intl.formatMessage({
138
+ defaultMessage: 'Read docs',
139
+ id: 'home.link.read_docs'
140
+ })}
141
+ </Link>
142
+ )
143
+ }
144
+ )}
145
+ >
146
+ <Stack pt={8} spacing={16}>
147
+ <ProductScroller
148
+ products={productSearchResult?.hits}
149
+ isLoading={isLoading}
150
+ />
151
+ </Stack>
152
+ </Section>
153
+ )}
154
+ </Box>
155
+ )
156
+ }
157
+
158
+ Home.getTemplateName = () => 'home'
159
+
160
+ export default Home
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2023, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+
8
+ import React from 'react'
9
+
10
+ const MyNewRoute = () => {
11
+ return <h1 style={{textAlign: 'center', fontSize: '4rem'}}>hello new route!</h1>
12
+ }
13
+
14
+ export default MyNewRoute
@@ -5,10 +5,34 @@
5
5
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
6
  */
7
7
 
8
- import {routes} from '{{preset.templateSource.id}}/app/routes'
9
- {{!-- TODO: The configure routes should be an optional opt-in provided from the SDK. --}}
8
+ import React from 'react'
9
+ import loadable from '@loadable/component'
10
+ import { getConfig } from '@salesforce/pwa-kit-runtime/utils/ssr-config'
11
+
12
+ // Components
13
+ import { Skeleton } from '@chakra-ui/react'
10
14
  import {configureRoutes} from '{{preset.templateSource.id}}/app/utils/routes-utils'
11
- import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
15
+ import { routes as _routes } from '{{preset.templateSource.id}}/app/routes'
16
+
17
+ const fallback = <Skeleton height="75vh" width="100%" />
18
+
19
+ // Create your pages here and add them to the routes array
20
+ // Use loadable to split code into smaller js chunks
21
+ const Home = loadable(() => import('./pages/home'), { fallback })
22
+ const MyNewRoute = loadable(() => import('./pages/my-new-route'))
23
+
24
+ const routes = [
25
+ {
26
+ path: '/',
27
+ component: Home,
28
+ exact: true
29
+ },
30
+ {
31
+ path: '/my-new-route',
32
+ component: MyNewRoute
33
+ },
34
+ ..._routes
35
+ ]
12
36
 
13
37
  {{!-- export default routes --}}
14
38
  export default () => {
@@ -71,7 +71,11 @@ module.exports = {
71
71
  {
72
72
  host: '{{answers.project.commerce.shortCode}}.api.commercecloud.salesforce.com',
73
73
  path: 'api'
74
- }
74
+ }{{~#if answers.project.commerce.instanceUrl}},
75
+ {
76
+ host: '{{answers.project.commerce.instanceUrl}}',
77
+ path: 'ocapi'
78
+ }{{/if}}
75
79
  ]
76
80
  }
77
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/pwa-kit-create-app",
3
- "version": "3.0.0-preview.1",
3
+ "version": "3.0.0-preview.3",
4
4
  "description": "Salesforce's project generator tool",
5
5
  "homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-create-app#readme",
6
6
  "bugs": {
@@ -38,13 +38,13 @@
38
38
  "tar": "^6.1.13"
39
39
  },
40
40
  "devDependencies": {
41
- "@salesforce/pwa-kit-dev": "3.0.0-preview.1",
42
- "internal-lib-build": "3.0.0-preview.1",
41
+ "@salesforce/pwa-kit-dev": "3.0.0-preview.3",
42
+ "internal-lib-build": "3.0.0-preview.3",
43
43
  "verdaccio": "^5.22.1"
44
44
  },
45
45
  "engines": {
46
46
  "node": "^16.11.0 || ^18.0.0",
47
47
  "npm": "^8.0.0 || ^9.0.0"
48
48
  },
49
- "gitHead": "457b0179e4cf536e55bf9b21758302ff68ef3ea4"
49
+ "gitHead": "0d435ccfb378e46a536e0eb4da3c9d3364ce89ea"
50
50
  }
@@ -191,7 +191,7 @@ const PRESETS = [
191
191
  description: `
192
192
  Generate a project using custom settings by answering questions about a
193
193
  B2C Commerce instance.
194
-
194
+
195
195
  Use this preset to connect to an existing instance, such as a sandbox.
196
196
  `,
197
197
  shortDescription: 'The Retail app using your own Commerce Cloud instance',
@@ -209,7 +209,7 @@ const PRESETS = [
209
209
  description: `
210
210
  Generate a project using the settings for a special B2C Commerce
211
211
  instance that is used for demo purposes. No questions are asked.
212
-
212
+
213
213
  Use this preset to try out PWA Kit.
214
214
  `,
215
215
  shortDescription: 'The Retail app with demo Commerce Cloud instance',
@@ -270,8 +270,8 @@ const PRESETS = [
270
270
  name: 'Template Minimal Project',
271
271
  description: `
272
272
  Generate a project using a bare-bones TypeScript app template.
273
-
274
- Use this as a TypeScript starting point or as a base on top of
273
+
274
+ Use this as a TypeScript starting point or as a base on top of
275
275
  which to build new TypeScript project templates for Managed Runtime.
276
276
  `,
277
277
  templateSource: {
@@ -683,6 +683,12 @@ const main = async (opts) => {
683
683
  })
684
684
  }
685
685
 
686
+ if (context.answers.project.commerce?.instanceUrl) {
687
+ // Remove protocol since we only use this to setup the OCAPI proxy
688
+ const url = new URL(context.answers.project.commerce.instanceUrl)
689
+ context.answers.project.commerce.instanceUrl = url.hostname
690
+ }
691
+
686
692
  // Inject the packageJSON into the context for extensibile projects.
687
693
  if (context.answers.project.extend) {
688
694
  const pkgJSON = JSON.parse(
@@ -701,6 +707,16 @@ const main = async (opts) => {
701
707
  'extract-default-translations'
702
708
  ].replace('./', `./node_modules/${selectedPreset.templateSource.id}/`)
703
709
  }
710
+ if (pkgJSON?.scripts['compile-translations']) {
711
+ pkgJSON.scripts['compile-translations'] = pkgJSON.scripts[
712
+ 'compile-translations'
713
+ ].replace('./', `./node_modules/${selectedPreset.templateSource.id}/`)
714
+ }
715
+ if (pkgJSON?.scripts['compile-translations:pseudo']) {
716
+ pkgJSON.scripts['compile-translations:pseudo'] = pkgJSON.scripts[
717
+ 'compile-translations:pseudo'
718
+ ].replace('./', `./node_modules/${selectedPreset.templateSource.id}/`)
719
+ }
704
720
 
705
721
  context = merge(
706
722
  context,
@@ -728,7 +744,7 @@ Examples:
728
744
  ${program.name()} --preset "${id}"\n${description}
729
745
  `
730
746
  })}
731
-
747
+
732
748
  `)
733
749
  program
734
750
  .option('--outputDir <path>', `Path to the output directory for the new project`)
Binary file
Binary file
Binary file
Binary file