From b53e89ac1aacdb09fcbe8a371bdc1f2ce66c5cc0 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Wed, 11 Aug 2021 14:19:17 -0500 Subject: [PATCH 1/7] Reverse order of remove boilerplate directions When following the current order, the component will error after step 1 and it is no longer possible to follow the remaining steps --- samples/nextjs/data/routes/en.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/nextjs/data/routes/en.yml b/samples/nextjs/data/routes/en.yml index e2b8451242..4b6f145f14 100644 --- a/samples/nextjs/data/routes/en.yml +++ b/samples/nextjs/data/routes/en.yml @@ -49,14 +49,15 @@ placeholders:

How to start with an empty app

+

To start with a fresh app with no boilerplate, run jss create nextjs --empty. Note, disconnected mode is not supported this way

To remove all of the default sample content (the Styleguide and GraphQL routes) and start out with an empty JSS app:

    -
  1. Delete /src/components/Styleguide* and /src/components/GraphQL*
  2. -
  3. Delete graphql-let command from bootstrap npm command in package.json until you create .graphql files
  4. -
  5. Delete /sitecore/definitions/components/Styleguide*, /sitecore/definitions/templates/Styleguide*, and /sitecore/definitions/components/GraphQL*
  6. -
  7. Delete /data/component-content/Styleguide
  8. -
  9. Delete /data/content/Styleguide
  10. -
  11. Delete /data/routes/styleguide and /data/routes/graphql
  12. Delete /data/dictionary/*.yml
  13. +
  14. Delete /data/routes/styleguide and /data/routes/graphql
  15. +
  16. Delete /data/content/Styleguide
  17. +
  18. Delete /data/component-content/Styleguide
  19. +
  20. Delete /sitecore/definitions/components/Styleguide*, /sitecore/definitions/templates/Styleguide*, and /sitecore/definitions/components/GraphQL*
  21. +
  22. Delete graphql-let command from bootstrap npm command in package.json until you create .graphql files
  23. +
  24. Delete /src/components/*
From c7a4e94825368766d7bccd7008d5bf0d908a75ac Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Thu, 12 Aug 2021 09:56:28 -0500 Subject: [PATCH 2/7] Update regex to handle jsx style comments & unit test --- .../src/templating/strip.test.ts | 8 +++++++- .../sitecore-jss-dev-tools/src/templating/strip.ts | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/sitecore-jss-dev-tools/src/templating/strip.test.ts b/packages/sitecore-jss-dev-tools/src/templating/strip.test.ts index 60730f8b51..a8bcc6b4bf 100644 --- a/packages/sitecore-jss-dev-tools/src/templating/strip.test.ts +++ b/packages/sitecore-jss-dev-tools/src/templating/strip.test.ts @@ -137,6 +137,10 @@ describe('strip', () => { 'testdir2/test23.js', 'Test81\r\n// #START_STRIP\r\nTest82 Test83\r\n// #END_STRIP\r\nTest84\r\nTest85' ); + stubFileContent( + 'testjsx.ts', + 'return (\r\n<>\r\n{/* #START_STRIP */}\r\nTest86\r\nTest87\r\n{/* #END_STRIP */}\r\nTest88\r\nTest89\r\n\r\n)' + ); globStub.returns([ 'test1.ts', @@ -148,13 +152,14 @@ describe('strip', () => { 'testdir2/test21.ts', 'testdir2/test22.tsx', 'testdir2/test23.js', + 'testjsx.ts', ]); const settings = { stripCode: true }; strip.strip(settings); - expect(writeFileSyncStub.callCount).to.equal(9); + expect(writeFileSyncStub.callCount).to.equal(10); const testCompile = (callIndex: number, filePath: string, content: string) => { expect(writeFileSyncStub.getCall(callIndex).args).to.deep.equal([ @@ -172,6 +177,7 @@ describe('strip', () => { testCompile(6, 'testdir2/test21.ts', 'Test61\r\nTest64\r\nTest65'); testCompile(7, 'testdir2/test22.tsx', 'Test71\r\nTest74\r\nTest75'); testCompile(8, 'testdir2/test23.js', 'Test81\r\nTest84\r\nTest85'); + testCompile(9, 'testjsx.ts', 'return (\r\n<>\r\nTest88\r\nTest89\r\n\r\n)'); globStub.restore(); writeFileSyncStub.restore(); diff --git a/packages/sitecore-jss-dev-tools/src/templating/strip.ts b/packages/sitecore-jss-dev-tools/src/templating/strip.ts index d429e36c8e..90cc3fae11 100644 --- a/packages/sitecore-jss-dev-tools/src/templating/strip.ts +++ b/packages/sitecore-jss-dev-tools/src/templating/strip.ts @@ -12,7 +12,9 @@ const IGNORE_PATTERN = '@(node_modules|dist|.next|out|.generated)/**'; * @returns {RegExp} regExp */ const getStripRegExp = (prefix: string, suffix = 'STRIP') => { - return new RegExp(`// #${prefix}_${suffix}`, 'g'); + const name = `#${prefix}_${suffix}`; + + return new RegExp(`(// ${name})|({\\/\\* ${name} \\*\\/})`, 'g'); }; interface StripSettings { @@ -41,6 +43,11 @@ interface StripSettings { * @default process.cwd() */ cwd?: string; + /** + * Indicates weather jsx style comments should be considered for stripping + * @default true + * @example {/* #START_EMPTY *\/} + */ } /** @@ -79,7 +86,7 @@ export const compile = (file: string, settings: StripSettings) => { /** * Removes part of code which inside the special comments block. - * Compiles each not excluded file starting from current dirrectory (or `settings.sourcePath`). + * Compiles each not excluded file starting from current directory (or `settings.sourcePath`). * @param {StripSettings} settings */ export const strip = (settings: StripSettings = {}) => { From c413ffea99785788d22ca8002d80626993cd1be6 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Thu, 12 Aug 2021 10:46:30 -0500 Subject: [PATCH 3/7] Strip dead links from Layout.tsx when using --empty --- samples/nextjs/src/Layout.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/nextjs/src/Layout.tsx b/samples/nextjs/src/Layout.tsx index 31ace51778..4872cd2081 100644 --- a/samples/nextjs/src/Layout.tsx +++ b/samples/nextjs/src/Layout.tsx @@ -1,6 +1,6 @@ +import { useEffect } from 'react'; import Head from 'next/head'; import Link from 'next/link'; -import { useEffect } from 'react'; import { useI18n } from 'next-localization'; import { Placeholder, @@ -34,15 +34,17 @@ const Navigation = () => { href="https://jss.sitecore.com" target="_blank" rel="noopener noreferrer" - > + > {t('Documentation')} + {/* #START_EMPTY */} {t('Styleguide')} {t('GraphQL')} + {/* #END_EMPTY */} ); @@ -69,7 +71,6 @@ const Layout = ({ context }: LayoutProps): JSX.Element => { {route?.fields?.pageTitle?.value || 'Page'} - {/* VisitorIdentification is necessary for Sitecore Analytics to determine if the visitor is a robot. If Sitecore XP (with xConnect/xDB) is used, this is required or else analytics will not be collected for the JSS app. @@ -80,7 +81,6 @@ const Layout = ({ context }: LayoutProps): JSX.Element => { - {/* root placeholder for the app, which we add components to using route data */}
From 8a99b31732b8ead9d0a5af221e9330fd6bc3cac4 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Thu, 12 Aug 2021 10:52:23 -0500 Subject: [PATCH 4/7] Remove unused type --- packages/sitecore-jss-dev-tools/src/templating/strip.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/sitecore-jss-dev-tools/src/templating/strip.ts b/packages/sitecore-jss-dev-tools/src/templating/strip.ts index 90cc3fae11..735c2ebb17 100644 --- a/packages/sitecore-jss-dev-tools/src/templating/strip.ts +++ b/packages/sitecore-jss-dev-tools/src/templating/strip.ts @@ -43,11 +43,6 @@ interface StripSettings { * @default process.cwd() */ cwd?: string; - /** - * Indicates weather jsx style comments should be considered for stripping - * @default true - * @example {/* #START_EMPTY *\/} - */ } /** From aef914e7c5cffa57336e0149be13eab998ddb4c9 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Thu, 12 Aug 2021 11:29:53 -0500 Subject: [PATCH 5/7] Revert --- samples/nextjs/src/Layout.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/nextjs/src/Layout.tsx b/samples/nextjs/src/Layout.tsx index 4872cd2081..0348802672 100644 --- a/samples/nextjs/src/Layout.tsx +++ b/samples/nextjs/src/Layout.tsx @@ -1,6 +1,6 @@ -import { useEffect } from 'react'; import Head from 'next/head'; import Link from 'next/link'; +import { useEffect } from 'react'; import { useI18n } from 'next-localization'; import { Placeholder, @@ -71,6 +71,7 @@ const Layout = ({ context }: LayoutProps): JSX.Element => { {route?.fields?.pageTitle?.value || 'Page'} + {/* VisitorIdentification is necessary for Sitecore Analytics to determine if the visitor is a robot. If Sitecore XP (with xConnect/xDB) is used, this is required or else analytics will not be collected for the JSS app. @@ -78,6 +79,7 @@ const Layout = ({ context }: LayoutProps): JSX.Element => { VI detection only runs once for a given analytics ID, so this is not a recurring operation once cookies are established. */} + From 24bcf53074a0c833ae7d375b06f2e7c573cab0f1 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Thu, 12 Aug 2021 11:32:35 -0500 Subject: [PATCH 6/7] Revert line --- samples/nextjs/src/Layout.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/nextjs/src/Layout.tsx b/samples/nextjs/src/Layout.tsx index 0348802672..6f2274fce6 100644 --- a/samples/nextjs/src/Layout.tsx +++ b/samples/nextjs/src/Layout.tsx @@ -79,7 +79,6 @@ const Layout = ({ context }: LayoutProps): JSX.Element => { VI detection only runs once for a given analytics ID, so this is not a recurring operation once cookies are established. */} - From 3bd6bf2f4ca71bec9415445686d2b59cfe111287 Mon Sep 17 00:00:00 2001 From: Coby Sher <63015754+CobyPear@users.noreply.github.com> Date: Thu, 12 Aug 2021 14:41:59 -0500 Subject: [PATCH 7/7] Match indentation --- samples/nextjs/src/Layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/nextjs/src/Layout.tsx b/samples/nextjs/src/Layout.tsx index 6f2274fce6..97eb4db777 100644 --- a/samples/nextjs/src/Layout.tsx +++ b/samples/nextjs/src/Layout.tsx @@ -44,7 +44,7 @@ const Navigation = () => { {t('GraphQL')} - {/* #END_EMPTY */} + {/* #END_EMPTY */}
);