create-sitecore-jss 20.0.0-canary.78

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.
Files changed (166) hide show
  1. package/LICENSE.MD +202 -0
  2. package/dist/InitializerFactory.js +49 -0
  3. package/dist/common/Initializer.js +2 -0
  4. package/dist/common/args/base.js +2 -0
  5. package/dist/common/args/styleguide.js +2 -0
  6. package/dist/common/prompts/base.js +40 -0
  7. package/dist/common/prompts/styleguide.js +28 -0
  8. package/dist/common/steps/index.js +13 -0
  9. package/dist/common/steps/install.js +46 -0
  10. package/dist/common/steps/next.js +60 -0
  11. package/dist/common/steps/transform.js +185 -0
  12. package/dist/common/utils/cmd.js +39 -0
  13. package/dist/common/utils/helpers.js +92 -0
  14. package/dist/index.js +91 -0
  15. package/dist/init-runner.js +50 -0
  16. package/dist/initializers/nextjs/args.js +2 -0
  17. package/dist/initializers/nextjs/index.js +65 -0
  18. package/dist/initializers/nextjs/prompts.js +19 -0
  19. package/dist/initializers/nextjs/remove-dev-dependencies.js +24 -0
  20. package/dist/initializers/nextjs-styleguide/index.js +49 -0
  21. package/dist/templates/nextjs/.env +49 -0
  22. package/dist/templates/nextjs/.eslintrc +25 -0
  23. package/dist/templates/nextjs/.gitattributes +11 -0
  24. package/dist/templates/nextjs/.gitignore +33 -0
  25. package/dist/templates/nextjs/.graphql-let.yml +10 -0
  26. package/dist/templates/nextjs/.prettierignore +1 -0
  27. package/dist/templates/nextjs/.prettierrc +8 -0
  28. package/dist/templates/nextjs/LICENSE.txt +202 -0
  29. package/dist/templates/nextjs/README.md +3 -0
  30. package/dist/templates/nextjs/next-env.d.ts +6 -0
  31. package/dist/templates/nextjs/next.config.js +56 -0
  32. package/dist/templates/nextjs/package.json +88 -0
  33. package/dist/templates/nextjs/public/favicon.ico +0 -0
  34. package/dist/templates/nextjs/public/sc_logo.svg +20 -0
  35. package/dist/templates/nextjs/scripts/bootstrap.ts +40 -0
  36. package/dist/templates/nextjs/scripts/fetch-graphql-introspection-data.ts +49 -0
  37. package/dist/templates/nextjs/scripts/generate-component-factory.ts +95 -0
  38. package/dist/templates/nextjs/scripts/generate-config.ts +85 -0
  39. package/dist/templates/nextjs/scripts/generate-plugins.ts +103 -0
  40. package/dist/templates/nextjs/scripts/scaffold-component.ts +89 -0
  41. package/dist/templates/nextjs/scripts/templates/component-factory.ts +119 -0
  42. package/dist/templates/nextjs/scripts/templates/component-src.ts +27 -0
  43. package/dist/templates/nextjs/scripts/utils.ts +59 -0
  44. package/dist/templates/nextjs/sitecore/config/{{appName}}.config +151 -0
  45. package/dist/templates/nextjs/src/Layout.tsx +53 -0
  46. package/dist/templates/nextjs/src/Navigation.tsx +27 -0
  47. package/dist/templates/nextjs/src/NotFound.tsx +19 -0
  48. package/dist/templates/nextjs/src/assets/app.css +28 -0
  49. package/dist/templates/nextjs/src/components/ContentBlock.tsx +24 -0
  50. package/dist/templates/nextjs/src/lib/component-props/index.ts +23 -0
  51. package/dist/templates/nextjs/src/lib/data-fetcher.ts +16 -0
  52. package/dist/templates/nextjs/src/lib/dictionary-service-factory.ts +30 -0
  53. package/dist/templates/nextjs/src/lib/layout-service-factory.ts +25 -0
  54. package/dist/templates/nextjs/src/lib/next-config/plugins/graphql.js +32 -0
  55. package/dist/templates/nextjs/src/lib/next-config/plugins/monorepo.js +27 -0
  56. package/dist/templates/nextjs/src/lib/page-props-factory/index.ts +50 -0
  57. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/componentProps.ts +38 -0
  58. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/normalMode.ts +75 -0
  59. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/previewMode.ts +27 -0
  60. package/dist/templates/nextjs/src/lib/page-props.ts +16 -0
  61. package/dist/templates/nextjs/src/lib/sitemap-fetcher/index.ts +25 -0
  62. package/dist/templates/nextjs/src/lib/sitemap-fetcher/plugins/graphqlSitemapService.ts +36 -0
  63. package/dist/templates/nextjs/src/pages/404.tsx +5 -0
  64. package/dist/templates/nextjs/src/pages/[[...path]].tsx +91 -0
  65. package/dist/templates/nextjs/src/pages/_app.tsx +19 -0
  66. package/dist/templates/nextjs/src/pages/_error.tsx +35 -0
  67. package/dist/templates/nextjs/src/pages/api/editing/data/[key].ts +24 -0
  68. package/dist/templates/nextjs/src/pages/api/editing/render.ts +30 -0
  69. package/dist/templates/nextjs/src/temp/.gitignore +3 -0
  70. package/dist/templates/nextjs/src/temp/GraphQLIntrospectionResult.json +22216 -0
  71. package/dist/templates/nextjs/tsconfig.json +42 -0
  72. package/dist/templates/nextjs/tsconfig.scripts.json +6 -0
  73. package/dist/templates/nextjs-styleguide/data/component-content/.gitignore +0 -0
  74. package/dist/templates/nextjs-styleguide/data/component-content/Styleguide/ContentReuse/LoremIpsumContentBlock/en.yml +9 -0
  75. package/dist/templates/nextjs-styleguide/data/content/.gitignore +0 -0
  76. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ContentListField/Item1/en.yml +6 -0
  77. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ContentListField/Item2/en.yml +6 -0
  78. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ItemLinkField/Item1/en.yml +6 -0
  79. package/dist/templates/nextjs-styleguide/data/content/Styleguide/ItemLinkField/Item2/en.yml +6 -0
  80. package/dist/templates/nextjs-styleguide/data/dictionary/en.yml +4 -0
  81. package/dist/templates/nextjs-styleguide/data/dictionary/{{language}}.yml +4 -0
  82. package/dist/templates/nextjs-styleguide/data/media/files/jss.pdf +0 -0
  83. package/dist/templates/nextjs-styleguide/data/media/img/jss_logo.png +0 -0
  84. package/dist/templates/nextjs-styleguide/data/media/img/sc_logo.png +0 -0
  85. package/dist/templates/nextjs-styleguide/data/routes/en.yml +63 -0
  86. package/dist/templates/nextjs-styleguide/data/routes/graphql/en.yml +27 -0
  87. package/dist/templates/nextjs-styleguide/data/routes/graphql/sample-1/en.yml +9 -0
  88. package/dist/templates/nextjs-styleguide/data/routes/graphql/sample-2/en.yml +9 -0
  89. package/dist/templates/nextjs-styleguide/data/routes/styleguide/custom-route-type/en.yml +12 -0
  90. package/dist/templates/nextjs-styleguide/data/routes/styleguide/en.yml +246 -0
  91. package/dist/templates/nextjs-styleguide/data/routes/styleguide/{{language}}.yml +25 -0
  92. package/dist/templates/nextjs-styleguide/data/routes/{{language}}.yml +4 -0
  93. package/dist/templates/nextjs-styleguide/package.json +13 -0
  94. package/dist/templates/nextjs-styleguide/scripts/disconnected-mode-proxy.ts +48 -0
  95. package/dist/templates/nextjs-styleguide/scripts/scaffold-component.ts +130 -0
  96. package/dist/templates/nextjs-styleguide/scripts/templates/component-manifest.ts +30 -0
  97. package/dist/templates/nextjs-styleguide/sitecore/definitions/component-content.sitecore.ts +117 -0
  98. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/ContentBlock.sitecore.ts +19 -0
  99. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Checkbox.sitecore.ts +23 -0
  100. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-ContentList.sitecore.ts +32 -0
  101. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Custom.sitecore.ts +23 -0
  102. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Date.sitecore.ts +23 -0
  103. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-File.sitecore.ts +20 -0
  104. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Image.sitecore.ts +23 -0
  105. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-ItemLink.sitecore.ts +32 -0
  106. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Link.sitecore.ts +25 -0
  107. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Number.sitecore.ts +20 -0
  108. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-RichText.sitecore.ts +28 -0
  109. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/fields/Styleguide-FieldUsage-Text.sitecore.ts +28 -0
  110. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-ConnectedDemo.sitecore.ts +18 -0
  111. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-IntegratedDemo.sitecore.graphql +71 -0
  112. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-IntegratedDemo.sitecore.ts +25 -0
  113. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/graphql/GraphQL-Layout.sitecore.ts +15 -0
  114. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-ComponentParams.sitecore.ts +20 -0
  115. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-CustomRouteType.sitecore.ts +31 -0
  116. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Reuse.sitecore.ts +20 -0
  117. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Tabs-Tab.sitecore.ts +23 -0
  118. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout-Tabs.sitecore.ts +20 -0
  119. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Layout.sitecore.ts +15 -0
  120. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Multilingual.sitecore.ts +26 -0
  121. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-RouteFields.sitecore.ts +22 -0
  122. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Section.sitecore.ts +16 -0
  123. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-SitecoreContext.sitecore.ts +19 -0
  124. package/dist/templates/nextjs-styleguide/sitecore/definitions/components/styleguide/Styleguide-Tracking.sitecore.ts +19 -0
  125. package/dist/templates/nextjs-styleguide/sitecore/definitions/config.js +5 -0
  126. package/dist/templates/nextjs-styleguide/sitecore/definitions/content.sitecore.ts +117 -0
  127. package/dist/templates/nextjs-styleguide/sitecore/definitions/dictionary.sitecore.ts +52 -0
  128. package/dist/templates/nextjs-styleguide/sitecore/definitions/placeholders.sitecore.ts +21 -0
  129. package/dist/templates/nextjs-styleguide/sitecore/definitions/routes.sitecore.ts +88 -0
  130. package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-ContentList-Template.sitecore.ts +12 -0
  131. package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-Explanatory-Component.sitecore.ts +20 -0
  132. package/dist/templates/nextjs-styleguide/sitecore/definitions/templates/Styleguide-ItemLink-Template.sitecore.ts +13 -0
  133. package/dist/templates/nextjs-styleguide/src/Navigation.tsx +41 -0
  134. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Checkbox.tsx +52 -0
  135. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ContentList.tsx +58 -0
  136. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Custom.tsx +25 -0
  137. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Date.tsx +55 -0
  138. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-File.tsx +30 -0
  139. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Image.tsx +58 -0
  140. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-ItemLink.tsx +50 -0
  141. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Link.tsx +46 -0
  142. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Number.tsx +34 -0
  143. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-RichText.tsx +35 -0
  144. package/dist/templates/nextjs-styleguide/src/components/fields/Styleguide-FieldUsage-Text.tsx +43 -0
  145. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-ConnectedDemo.dynamic.graphql +69 -0
  146. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-ConnectedDemo.dynamic.tsx +148 -0
  147. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-IntegratedDemo.tsx +130 -0
  148. package/dist/templates/nextjs-styleguide/src/components/graphql/GraphQL-Layout.tsx +37 -0
  149. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-ComponentParams.tsx +47 -0
  150. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-CustomRouteType.tsx +37 -0
  151. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Reuse.tsx +45 -0
  152. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Tabs-Tab.tsx +41 -0
  153. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout-Tabs.tsx +111 -0
  154. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Layout.tsx +68 -0
  155. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Multilingual.tsx +50 -0
  156. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-RouteFields.tsx +37 -0
  157. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Section.tsx +22 -0
  158. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-SitecoreContext.tsx +25 -0
  159. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Specimen.tsx +41 -0
  160. package/dist/templates/nextjs-styleguide/src/components/styleguide/Styleguide-Tracking.tsx +341 -0
  161. package/dist/templates/nextjs-styleguide/src/lib/component-props/styleguide.ts +11 -0
  162. package/dist/templates/nextjs-styleguide/src/lib/next-config/plugins/disconnected.js +43 -0
  163. package/dist/templates/nextjs-styleguide/src/lib/next-config/plugins/styleguide.js +10 -0
  164. package/dist/templates/nextjs-styleguide/src/lib/sitemap-fetcher/plugins/disconnectedSitemapService.ts +46 -0
  165. package/dist/templates/nextjs-styleguide/src/pages/_app.tsx +33 -0
  166. package/package.json +61 -0
@@ -0,0 +1,130 @@
1
+ /*
2
+ Component Scaffolding Script
3
+ This is a script that enables scaffolding a new JSS component using `jss scaffold <ComponentName>`.
4
+ The default convention is that component names must start with a capital letter, and can contain
5
+ letters, number, underscores, or dashes.
6
+
7
+ If the <ComponentName> parameter includes a path, it must be relative to the src/components folder.
8
+ For example, `jss scaffold search/SearchBox` will create a component called `SearchBox` in
9
+ `src/components/search/SearchBox.tsx`. Specifying a relative path is optional, and just providing
10
+ the name is ok.
11
+
12
+ Edit this script if you wish to use your own conventions for component storage in your JSS app.
13
+ */
14
+
15
+ /* eslint-disable no-throw-literal,no-console */
16
+
17
+ import fs from 'fs';
18
+ import path from 'path';
19
+ import chalk from 'chalk';
20
+ import generateComponentSrc from './templates/component-src';
21
+ import generateComponentManifest from './templates/component-manifest';
22
+
23
+ const componentManifestDefinitionsPath = 'sitecore/definitions/components';
24
+
25
+ const componentRootPath = 'src/components';
26
+
27
+ // Matches component names that start with a capital letter, and contain only letters, number,
28
+ // underscores, or dashes. Optionally, the component name can be preceded by a relative path
29
+ const nameParamFormat = new RegExp(/^((?:[\w-]+\/)*)([A-Z][\w-]+)$/);
30
+ const componentArg = process.argv[2];
31
+
32
+ if (!componentArg) {
33
+ throw 'Component name was not passed. Usage: jss scaffold <ComponentName>';
34
+ }
35
+
36
+ const regExResult = nameParamFormat.exec(componentArg);
37
+
38
+ if (regExResult === null) {
39
+ throw `Component name should start with an uppercase letter and contain only letters, numbers,
40
+ dashes, or underscores. If specifying a path, it must be relative to src/components`;
41
+ }
42
+
43
+ const componentPath = regExResult[1];
44
+ const componentName = regExResult[2];
45
+ const filename = `${componentName}.tsx`;
46
+
47
+ const componentOutputPath = scaffoldFile(
48
+ componentRootPath,
49
+ generateComponentSrc(componentName),
50
+ filename
51
+ );
52
+
53
+ let manifestOutputPath = null;
54
+ if (fs.existsSync(componentManifestDefinitionsPath)) {
55
+ const filename = `${componentName}.sitecore.ts`;
56
+
57
+ manifestOutputPath = scaffoldFile(
58
+ componentManifestDefinitionsPath,
59
+ generateComponentManifest(componentName),
60
+ filename
61
+ );
62
+ } else {
63
+ console.log(
64
+ chalk.red(`Not scaffolding manifest because ${componentManifestDefinitionsPath}
65
+ did not exist. This is normal for Sitecore-first workflow.`)
66
+ );
67
+ }
68
+ console.log(
69
+ chalk.green(`
70
+ Scaffolding of ${componentName} complete.
71
+ Next steps:`)
72
+ );
73
+
74
+ if (manifestOutputPath) {
75
+ console.log(`* Define the component's data in ${chalk.green(manifestOutputPath)}`);
76
+ } else {
77
+ console.log(
78
+ `* Scaffold the component in Sitecore using '${chalk.green(
79
+ `jss deploy component ${componentName} --allowedPlaceholders placeholder-for-component`
80
+ )}, or create the rendering item and datasource template yourself.`
81
+ );
82
+ }
83
+ if (componentOutputPath) {
84
+ console.log(`* Implement the React component in ${chalk.green(componentOutputPath)}`);
85
+ }
86
+ if (manifestOutputPath) {
87
+ console.log(
88
+ `* Add the component to a route layout (/data/routes) and test it with ${chalk.green(
89
+ 'jss start'
90
+ )}`
91
+ );
92
+ } else {
93
+ console.log(
94
+ `* Deploy your app with the new component to Sitecore (${chalk.green(
95
+ 'jss deploy:watch'
96
+ )} or ${chalk.green('jss deploy files')})`
97
+ );
98
+ console.log(`* Add the component to a route using Sitecore Experience Editor, and test it.`);
99
+ }
100
+
101
+ /**
102
+ * Force to use `crlf` line endings, we are using `crlf` across the project.
103
+ * Replace: `lf` (\n), `cr` (\r)
104
+ * @param {string} content
105
+ */
106
+ function editLineEndings(content: string) {
107
+ return content.replace(/\r|\n/gm, '\r\n');
108
+ }
109
+
110
+ /**
111
+ * Creates a file relative to the specified path if the file doesn't exist. Creates directories as needed.
112
+ * @param {string} rootPath - the root path
113
+ * @param {string} fileContent - the file content
114
+ * @param {string} filename - the filename
115
+ * @returns the new file's filepath
116
+ */
117
+ function scaffoldFile(rootPath: string, fileContent: string, filename: string): string | null {
118
+ const outputDir = path.join(rootPath, componentPath);
119
+ const outputFile = path.join(outputDir, filename);
120
+
121
+ if (fs.existsSync(outputFile)) {
122
+ console.log(chalk.red(`Skipping creating ${outputFile}; already exists.`));
123
+ return null;
124
+ }
125
+
126
+ fs.mkdirSync(outputDir, { recursive: true });
127
+ fs.writeFileSync(outputFile, editLineEndings(fileContent), 'utf8');
128
+ console.log(chalk.green(`File ${outputFile} has been scaffolded.`));
129
+ return outputFile;
130
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Generates manifest API boilerplate for a component under `sitecore/definitions/components`
3
+ * @param componentName - the component name
4
+ * @returns component manifest boilerplate as a string
5
+ */
6
+ function generateComponentManifest(componentName: string): string {
7
+ return `// eslint-disable-next-line no-unused-vars
8
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
9
+
10
+ /**
11
+ * Adds the ${componentName} component to the disconnected manifest.
12
+ * This function is invoked by convention (*.sitecore.ts) when 'jss manifest' is run.
13
+ * @param {Manifest} manifest Manifest instance to add components to
14
+ */
15
+ export default function ${componentName}(manifest: Manifest): void {
16
+ manifest.addComponent({
17
+ name: '${componentName}',
18
+ icon: SitecoreIcon.DocumentTag,
19
+ fields: [{ name: 'heading', type: CommonFieldTypes.SingleLineText }],
20
+ /*
21
+ If the component implementation uses <Placeholder> or withPlaceholder to expose a placeholder,
22
+ register it here, or components added to that placeholder will not be returned by Sitecore:
23
+ placeholders: ['exposed-placeholder-name']
24
+ */
25
+ });
26
+ }
27
+ `;
28
+ }
29
+
30
+ export default generateComponentManifest;
@@ -0,0 +1,117 @@
1
+ import {
2
+ Manifest,
3
+ ItemDefinition,
4
+ mergeFs,
5
+ MergeFsResult,
6
+ } from '@sitecore-jss/sitecore-jss-dev-tools';
7
+ import path from 'path';
8
+ import fs from 'fs';
9
+
10
+ /**
11
+ * Adds shared datasource items (content data shared between components on different routes) the disconnected manifest.
12
+ * Component content items are conventionally defined in /data/component-content, similar to route items.
13
+ * This function is invoked by convention (*.sitecore.js) when `jss manifest` is run.
14
+ * @param {Manifest} manifest
15
+ * @returns {Promise}
16
+ */
17
+ export default function addComponentContentToManifest(manifest: Manifest): Promise<void> {
18
+ const rootItemName = 'Components';
19
+ const startPath = './data/component-content'; // relative to process invocation (i.e. where package.json lives)
20
+
21
+ if (!fs.existsSync(startPath)) return Promise.resolve();
22
+
23
+ return mergeFs(startPath)
24
+ .then((result) => {
25
+ const items = convertToItems(
26
+ result,
27
+ path.resolve(startPath),
28
+ rootItemName,
29
+ manifest.language
30
+ );
31
+ return items;
32
+ })
33
+ .then((contentData) => {
34
+ if (contentData) {
35
+ manifest.addContent(contentData);
36
+ }
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Maps filesystem content data into manifest content item data.
42
+ * @param {MergeFsResult} data Filesystem data (files and folders under current path)
43
+ * @param {string} basePath The base physical path to calculate relative item paths from
44
+ * @param {string} rootItemName Name of the root item to place non-content items under in Sitecore. Normally $siteRoot/Content.
45
+ * @param {string} language Language the manifest is being created in. Conventionally affects the expected filename.
46
+ * @returns {ItemDefinition}
47
+ */
48
+ function convertToItems(
49
+ data: MergeFsResult,
50
+ basePath: string,
51
+ rootItemName: string,
52
+ language: string
53
+ ): ItemDefinition {
54
+ const itemPath = convertPhsyicalPathToItemRelativePath(data.path, basePath);
55
+ const name = itemPath.substr(itemPath.lastIndexOf('/') + 1);
56
+
57
+ let result;
58
+
59
+ const contentItemPattern = new RegExp(`^${language}\\.(yaml|yml|json)$`, 'i');
60
+
61
+ const contentFileData = data.files.find((f) => contentItemPattern.test(f.filename));
62
+
63
+ if (contentFileData && contentFileData.contents) {
64
+ // the path has a valid content item definition
65
+ result = contentFileData.contents;
66
+
67
+ // Set the path to the item when imported in Sitecore.
68
+ // NOTE: Importing to any Sitecore path the import user has rights to is allowed; '$site/Content' is a convention only.
69
+ result.path = itemPath;
70
+
71
+ // content item name defaults to parent folder name if not explicit
72
+ if (!result.name) {
73
+ result.name = name;
74
+ }
75
+ } else if (data.folders.length > 0) {
76
+ // The path does not have a content item definition (i.e. en.yml),
77
+ // but it does have child folders (which may contain valid content items)
78
+ // it will be defined as a Folder item in Sitecore.
79
+ result = {
80
+ path: itemPath,
81
+ name: name || rootItemName,
82
+ displayName: name || rootItemName,
83
+ template: 'Folder',
84
+ children: [],
85
+ };
86
+ }
87
+
88
+ // recursively process child paths
89
+ if (data.folders.length > 0) {
90
+ result.children = data.folders
91
+ .map((folder) => convertToItems(folder, basePath, rootItemName, language))
92
+ .filter((item) => item); // remove null results
93
+ }
94
+
95
+ return result;
96
+ }
97
+
98
+ /**
99
+ * Converts a physical filesystem path into a relative Sitecore item path.
100
+ * i.e. if physicalPath = /var/log and basePath = /var, this returns /log.
101
+ * @param {string} physicalPath
102
+ * @param {string} basePath
103
+ */
104
+ function convertPhsyicalPathToItemRelativePath(physicalPath: string, basePath: string) {
105
+ const targetPathSeparator = '/';
106
+
107
+ // normalize path separators to /
108
+ const normalizedPath = physicalPath.replace(basePath, '').replace(/\\/g, targetPathSeparator);
109
+
110
+ if (!normalizedPath) {
111
+ return targetPathSeparator;
112
+ }
113
+
114
+ return normalizedPath.indexOf(targetPathSeparator) > 0
115
+ ? `${targetPathSeparator}${normalizedPath}`
116
+ : normalizedPath;
117
+ }
@@ -0,0 +1,19 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the ContentBlock component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when `jss manifest` is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function ContentBlock(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'ContentBlock',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>ContentBlock',
12
+ // totally optional, but fun
13
+ icon: SitecoreIcon.DocumentTag,
14
+ fields: [
15
+ { name: 'heading', type: CommonFieldTypes.SingleLineText },
16
+ { name: 'content', type: CommonFieldTypes.RichText },
17
+ ],
18
+ });
19
+ }
@@ -0,0 +1,23 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Checkbox component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageCheckbox(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Checkbox',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Checkbox',
12
+ icon: SitecoreIcon.CheckboxSelected,
13
+ fields: [
14
+ { name: 'checkbox', type: CommonFieldTypes.Checkbox },
15
+ { name: 'checkbox2', type: CommonFieldTypes.Checkbox },
16
+ ],
17
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
18
+ // inheritance adds fields defined on the base template(s) implicitly to this component
19
+ inherits: [
20
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
21
+ ],
22
+ });
23
+ }
@@ -0,0 +1,32 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+ import packageJson from '../../../../package.json';
3
+
4
+ /**
5
+ * Adds the Styleguide-FieldUsage-ContentList component to the disconnected manifest.
6
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
7
+ * @param {Manifest} manifest Manifest instance to add components to
8
+ */
9
+ export default function StyleguideFieldUsageContentList(manifest: Manifest): void {
10
+ manifest.addComponent({
11
+ name: 'Styleguide-FieldUsage-ContentList',
12
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-ContentList',
13
+ icon: SitecoreIcon.ListStyle_numbered,
14
+ fields: [
15
+ {
16
+ name: 'sharedContentList',
17
+ type: CommonFieldTypes.ContentList,
18
+ // this sets the root path in Sitecore that linked items can be selected from.
19
+ // the path is based on the path the shared items are defined in, under /data/content.
20
+ // Using 'source' is recommended to help content editors find the correct items to refer to,
21
+ // unless they can refer to any item in the whole site.
22
+ source: `dataSource=/sitecore/content/${packageJson.config.appName}/Content/Styleguide/ContentListField`,
23
+ },
24
+ { name: 'localContentList', type: CommonFieldTypes.ContentList },
25
+ ],
26
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
27
+ // inheritance adds fields defined on the base template(s) implicitly to this component
28
+ inherits: [
29
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
30
+ ],
31
+ });
32
+ }
@@ -0,0 +1,23 @@
1
+ import { SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Custom component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageCustom(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Custom',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Custom',
12
+ icon: SitecoreIcon.Gearwheel,
13
+ // NOTE: not using 'CommonFieldTypes' here, because it's a custom field.
14
+ // The 'Integer' field ships with Sitecore; something really custom would need to be
15
+ // implemented as a Sitecore field type as well.
16
+ fields: [{ name: 'customIntField', type: 'Integer' }],
17
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
18
+ // inheritance adds fields defined on the base template(s) implicitly to this component
19
+ inherits: [
20
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
21
+ ],
22
+ });
23
+ }
@@ -0,0 +1,23 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Date component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageDate(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Date',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Date',
12
+ icon: SitecoreIcon.Clock,
13
+ fields: [
14
+ { name: 'date', type: CommonFieldTypes.Date },
15
+ { name: 'dateTime', type: CommonFieldTypes.DateTime },
16
+ ],
17
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
18
+ // inheritance adds fields defined on the base template(s) implicitly to this component
19
+ inherits: [
20
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
21
+ ],
22
+ });
23
+ }
@@ -0,0 +1,20 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-File component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageFile(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-File',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-File',
12
+ icon: SitecoreIcon.FloppyDisk,
13
+ fields: [{ name: 'file', type: CommonFieldTypes.File }],
14
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
15
+ // inheritance adds fields defined on the base template(s) implicitly to this component
16
+ inherits: [
17
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
18
+ ],
19
+ });
20
+ }
@@ -0,0 +1,23 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Image component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageImage(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Image',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Image',
12
+ icon: SitecoreIcon.PhotoPortrait,
13
+ fields: [
14
+ { name: 'sample1', type: CommonFieldTypes.Image },
15
+ { name: 'sample2', type: CommonFieldTypes.Image },
16
+ ],
17
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
18
+ // inheritance adds fields defined on the base template(s) implicitly to this component
19
+ inherits: [
20
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
21
+ ],
22
+ });
23
+ }
@@ -0,0 +1,32 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+ import packageJson from '../../../../package.json';
3
+
4
+ /**
5
+ * Adds the Styleguide-FieldUsage-ItemLink component to the disconnected manifest.
6
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
7
+ * @param {Manifest} manifest Manifest instance to add components to
8
+ */
9
+ export default function StyleguideFieldUsageItemLink(manifest: Manifest): void {
10
+ manifest.addComponent({
11
+ name: 'Styleguide-FieldUsage-ItemLink',
12
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-ItemLink',
13
+ icon: SitecoreIcon.Link,
14
+ fields: [
15
+ {
16
+ name: 'sharedItemLink',
17
+ type: CommonFieldTypes.ItemLink,
18
+ // this sets the root path in Sitecore that linked items can be selected from.
19
+ // the path is based on the path the shared items are defined in, under /data/content.
20
+ // Using 'source' is recommended to help content editors find the correct items to refer to,
21
+ // unless they can refer to any item in the whole site.
22
+ source: `dataSource=/sitecore/content/${packageJson.config.appName}/Content/Styleguide/ItemLinkField`,
23
+ },
24
+ { name: 'localItemLink', type: CommonFieldTypes.ItemLink },
25
+ ],
26
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
27
+ // inheritance adds fields defined on the base template(s) implicitly to this component
28
+ inherits: [
29
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
30
+ ],
31
+ });
32
+ }
@@ -0,0 +1,25 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Link component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageLink(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Link',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Link',
12
+ icon: SitecoreIcon.Link,
13
+ fields: [
14
+ { name: 'externalLink', type: CommonFieldTypes.GeneralLink },
15
+ { name: 'internalLink', type: CommonFieldTypes.GeneralLink },
16
+ { name: 'emailLink', type: CommonFieldTypes.GeneralLink },
17
+ { name: 'paramsLink', type: CommonFieldTypes.GeneralLink },
18
+ ],
19
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
20
+ // inheritance adds fields defined on the base template(s) implicitly to this component
21
+ inherits: [
22
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
23
+ ],
24
+ });
25
+ }
@@ -0,0 +1,20 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Number component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageNumber(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Number',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Number',
12
+ icon: SitecoreIcon.NumbersField,
13
+ fields: [{ name: 'sample', type: CommonFieldTypes.Number }],
14
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
15
+ // inheritance adds fields defined on the base template(s) implicitly to this component
16
+ inherits: [
17
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
18
+ ],
19
+ });
20
+ }
@@ -0,0 +1,28 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-RichText component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageRichText(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-RichText',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-RichText',
12
+ icon: SitecoreIcon.TextField,
13
+ fields: [
14
+ { name: 'sample', type: CommonFieldTypes.RichText },
15
+ {
16
+ name: 'sample2',
17
+ displayName: 'Customize Name Shown in Sitecore',
18
+ required: true,
19
+ type: CommonFieldTypes.RichText,
20
+ },
21
+ ],
22
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
23
+ // inheritance adds fields defined on the base template(s) implicitly to this component
24
+ inherits: [
25
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
26
+ ],
27
+ });
28
+ }
@@ -0,0 +1,28 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the Styleguide-FieldUsage-Text component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function StyleguideFieldUsageText(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'Styleguide-FieldUsage-Text',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>Styleguide-FieldUsage-Text',
12
+ icon: SitecoreIcon.Text,
13
+ fields: [
14
+ { name: 'sample', type: CommonFieldTypes.SingleLineText },
15
+ {
16
+ name: 'sample2',
17
+ displayName: 'Customize Name Shown in Sitecore',
18
+ required: true,
19
+ type: CommonFieldTypes.SingleLineText,
20
+ },
21
+ ],
22
+ // inherit fields from another template (../templates/Styleguide-Explanatory-Component)
23
+ // inheritance adds fields defined on the base template(s) implicitly to this component
24
+ inherits: [
25
+ '<%- helper.getAppPrefix(appPrefix, appName) %>styleguide-explanatory-component-template',
26
+ ],
27
+ });
28
+ }
@@ -0,0 +1,18 @@
1
+ import { CommonFieldTypes, SitecoreIcon, Manifest } from '@sitecore-jss/sitecore-jss-dev-tools';
2
+
3
+ /**
4
+ * Adds the GraphQL-ConnectedDemo component to the disconnected manifest.
5
+ * This function is invoked by convention (*.sitecore.js) when 'jss manifest' is run.
6
+ * @param {Manifest} manifest Manifest instance to add components to
7
+ */
8
+ export default function GraphQLConnectedDemo(manifest: Manifest): void {
9
+ manifest.addComponent({
10
+ name: 'GraphQL-ConnectedDemo',
11
+ templateName: '<%- helper.getAppPrefix(appPrefix, appName) %>GraphQL-ConnectedDemo',
12
+ icon: SitecoreIcon.GraphConnection_directed,
13
+ fields: [
14
+ { name: 'sample1', type: CommonFieldTypes.SingleLineText },
15
+ { name: 'sample2', type: CommonFieldTypes.GeneralLink },
16
+ ],
17
+ });
18
+ }