create-sitecore-jss 22.2.0-canary.7 → 22.2.0-canary.70

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 (108) hide show
  1. package/dist/bin.js +17 -43
  2. package/dist/common/processes/next.js +4 -1
  3. package/dist/common/processes/transform.js +2 -12
  4. package/dist/common/prompts/base.js +0 -13
  5. package/dist/common/prompts/proxy.js +35 -0
  6. package/dist/common/prompts/sxp.js +16 -2
  7. package/dist/common/utils/helpers.js +27 -2
  8. package/dist/init-runner.js +1 -1
  9. package/dist/initializers/angular/prompts.js +4 -4
  10. package/dist/initializers/angular-xmcloud/index.js +21 -7
  11. package/dist/initializers/node-xmcloud-proxy/index.js +2 -1
  12. package/dist/templates/angular/.env +4 -5
  13. package/dist/templates/angular/.eslintrc +1 -0
  14. package/dist/templates/angular/gitignore +5 -0
  15. package/dist/templates/angular/package.json +0 -2
  16. package/dist/templates/angular/scripts/config/plugins/fallback.ts +0 -1
  17. package/dist/templates/angular/scripts/generate-component-factory.ts +8 -0
  18. package/dist/templates/angular/scripts/generate-config.ts +25 -6
  19. package/dist/templates/angular/scripts/update-graphql-fragment-data.ts +21 -30
  20. package/dist/templates/angular/server.bundle.ts +3 -23
  21. package/dist/templates/angular/server.exports.ts +13 -0
  22. package/dist/templates/angular/src/app/JssState.ts +2 -9
  23. package/dist/templates/angular/src/app/app.module.ts +5 -4
  24. package/dist/templates/angular/src/app/app.server.module.ts +9 -6
  25. package/dist/templates/angular/src/app/i18n/jss-translation-client-loader.service.ts +15 -7
  26. package/dist/templates/angular/src/app/i18n/jss-translation-server-loader.service.ts +14 -2
  27. package/dist/templates/angular/src/app/jss-context.server-side.service.ts +4 -2
  28. package/dist/templates/angular/src/app/jss-context.service.ts +14 -11
  29. package/dist/templates/angular/src/app/jss-graphql.service.ts +7 -7
  30. package/dist/templates/angular/src/app/layout/jss-layout.service.ts +2 -2
  31. package/dist/templates/angular/src/app/lib/dictionary-service-factory.ts +4 -1
  32. package/dist/templates/angular/src/app/lib/graphql-client-factory/config.ts +21 -0
  33. package/dist/templates/angular/src/app/lib/graphql-client-factory/index.ts +16 -0
  34. package/dist/templates/angular/src/app/lib/layout-service-factory.ts +1 -1
  35. package/dist/templates/angular/src/app/routing/layout/layout.component.ts +10 -9
  36. package/dist/templates/angular/src/environments/gitignore +2 -1
  37. package/dist/templates/angular-sxp/.env +2 -0
  38. package/dist/templates/angular-sxp/scripts/config/plugins/disconnected.ts +4 -2
  39. package/dist/templates/angular-sxp/src/app/components/graph-ql-layout/graph-ql-layout.component.ts +1 -1
  40. package/dist/templates/angular-xmcloud/.env +8 -2
  41. package/dist/templates/angular-xmcloud/angular.json +0 -1
  42. package/dist/templates/angular-xmcloud/scripts/bootstrap.ts +28 -0
  43. package/dist/templates/angular-xmcloud/scripts/config/plugins/xmcloud.ts +16 -0
  44. package/dist/templates/angular-xmcloud/scripts/generate-metadata.ts +25 -0
  45. package/dist/templates/angular-xmcloud/server.exports.ts +24 -0
  46. package/dist/templates/angular-xmcloud/src/app/components/app-components.shared.module.ts +21 -0
  47. package/dist/templates/angular-xmcloud/src/app/components/column-splitter/column-splitter.component.html +5 -0
  48. package/dist/templates/angular-xmcloud/src/app/components/column-splitter/column-splitter.component.ts +40 -0
  49. package/dist/templates/angular-xmcloud/src/app/components/container/container.component.html +14 -0
  50. package/dist/templates/angular-xmcloud/src/app/components/container/container.component.ts +30 -0
  51. package/dist/templates/angular-xmcloud/src/app/components/image/image.component.html +36 -0
  52. package/dist/templates/angular-xmcloud/src/app/components/image/image.component.ts +67 -0
  53. package/dist/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html +15 -0
  54. package/dist/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts +41 -0
  55. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation-item.component.html +23 -0
  56. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation-item.component.ts +65 -0
  57. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation.component.html +21 -0
  58. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation.component.ts +49 -0
  59. package/dist/templates/angular-xmcloud/src/app/components/page-content/page-content.component.html +5 -0
  60. package/dist/templates/angular-xmcloud/src/app/components/page-content/page-content.component.ts +39 -0
  61. package/dist/templates/angular-xmcloud/src/app/components/partial-design-dynamic-placeholder/partial-design-dynamic-placeholder.component.html +1 -0
  62. package/dist/templates/angular-xmcloud/src/app/components/partial-design-dynamic-placeholder/partial-design-dynamic-placeholder.component.ts +15 -0
  63. package/dist/templates/angular-xmcloud/src/app/components/promo/promo.component.html +21 -0
  64. package/dist/templates/angular-xmcloud/src/app/components/promo/promo.component.ts +13 -0
  65. package/dist/templates/angular-xmcloud/src/app/components/richtext/richtext.component.html +7 -12
  66. package/dist/templates/angular-xmcloud/src/app/components/richtext/richtext.component.ts +6 -1
  67. package/dist/templates/angular-xmcloud/src/app/components/row-splitter/row-splitter.component.html +11 -0
  68. package/dist/templates/angular-xmcloud/src/app/components/row-splitter/row-splitter.component.ts +35 -0
  69. package/dist/templates/angular-xmcloud/src/app/components/sxa.component.ts +4 -4
  70. package/dist/templates/angular-xmcloud/src/app/components/title/title.component.html +10 -0
  71. package/dist/templates/angular-xmcloud/src/app/components/title/title.component.ts +56 -0
  72. package/dist/templates/angular-xmcloud/src/app/jss-link.service.ts +55 -0
  73. package/dist/templates/angular-xmcloud/src/app/lib/config.ts +2 -0
  74. package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory/config.ts +58 -0
  75. package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.html +38 -0
  76. package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.ts +104 -0
  77. package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.component.html +3 -0
  78. package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.module.ts +10 -0
  79. package/dist/templates/angular-xmcloud/src/assets/styles/basic/_header.scss +3 -1
  80. package/dist/templates/angular-xmcloud/src/assets/styles/main.scss +10 -0
  81. package/dist/templates/angular-xmcloud/src/assets/styles/sass/components/_component-image.scss +1 -1
  82. package/dist/templates/nextjs/package.json +1 -1
  83. package/dist/templates/nextjs/scripts/config/plugins/fallback.ts +0 -1
  84. package/dist/templates/nextjs/scripts/generate-config.ts +8 -1
  85. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/component-props.ts +2 -1
  86. package/dist/templates/nextjs-styleguide/scripts/config/plugins/disconnected.ts +1 -0
  87. package/dist/templates/nextjs-sxa/src/assets/sass/components/_component-image.scss +1 -1
  88. package/dist/templates/nextjs-sxa/src/assets/sass/components/common/_alignment.scss +66 -7
  89. package/dist/templates/nextjs-sxa/src/components/Container.tsx +6 -14
  90. package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/component-themes.ts +2 -1
  91. package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/preview-mode.ts +2 -1
  92. package/dist/templates/node-headless-ssr-experience-edge/gitignore +19 -0
  93. package/dist/templates/node-headless-ssr-proxy/gitignore +19 -0
  94. package/dist/templates/node-headless-ssr-proxy/src/config.ts +3 -3
  95. package/dist/templates/node-headless-ssr-proxy/src/httpAgents.ts +2 -2
  96. package/dist/templates/node-headless-ssr-proxy/src/index.ts +9 -2
  97. package/dist/templates/node-xmcloud-proxy/.env +7 -1
  98. package/dist/templates/node-xmcloud-proxy/README.md +1 -1
  99. package/dist/templates/node-xmcloud-proxy/gitignore +33 -0
  100. package/dist/templates/node-xmcloud-proxy/package.json +3 -2
  101. package/dist/templates/node-xmcloud-proxy/src/config.ts +9 -3
  102. package/dist/templates/node-xmcloud-proxy/src/index.ts +54 -5
  103. package/dist/templates/node-xmcloud-proxy/src/types.ts +10 -42
  104. package/dist/templates/react/scripts/generate-config.js +10 -3
  105. package/dist/templates/vue/scripts/generate-config.js +5 -0
  106. package/package.json +2 -2
  107. package/dist/templates/angular/src/app/lib/graphql-client-factory.ts +0 -28
  108. package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory.ts +0 -44
package/dist/bin.js CHANGED
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.main = exports.promptDestination = exports.getDestinations = exports.parseArgs = void 0;
38
+ exports.main = exports.promptDestination = exports.getDestination = exports.parseArgs = void 0;
39
39
  const fs_1 = __importDefault(require("fs"));
40
40
  const path_1 = __importStar(require("path"));
41
41
  const chalk_1 = __importDefault(require("chalk"));
@@ -43,7 +43,6 @@ const inquirer_1 = __importDefault(require("inquirer"));
43
43
  const init_runner_1 = require("./init-runner");
44
44
  const minimist_1 = __importDefault(require("minimist"));
45
45
  const common_1 = require("./common");
46
- const helpers_1 = require("./common/utils/helpers");
47
46
  const parseArgs = () => {
48
47
  // parse any command line arguments passed into `init sitecore-jss`
49
48
  // to pass to the generator prompts and skip them.
@@ -71,7 +70,7 @@ const parseArgs = () => {
71
70
  return args;
72
71
  };
73
72
  exports.parseArgs = parseArgs;
74
- const getDestinations = (args, templates) => __awaiter(void 0, void 0, void 0, function* () {
73
+ const getDestination = (args, templates) => __awaiter(void 0, void 0, void 0, function* () {
75
74
  if (templates.length === 0) {
76
75
  throw new Error('Unable to get destinations, provided templates are empty');
77
76
  }
@@ -83,30 +82,9 @@ const getDestinations = (args, templates) => __awaiter(void 0, void 0, void 0, f
83
82
  ? defaultBaseDestination
84
83
  : yield (0, exports.promptDestination)('Where would you like your new app created?', defaultBaseDestination);
85
84
  }
86
- // work with node-proxy destination if needed
87
- const proxyApp = templates.find((template) => template.match(helpers_1.proxyAppMatcher));
88
- if (proxyApp) {
89
- // put the proxy alongside main app by default
90
- const defaultProxyDestination = (0, helpers_1.getDefaultProxyDestination)(destination, proxyApp);
91
- let proxyAppDestination = args.proxyAppDestination;
92
- if (!proxyAppDestination) {
93
- proxyAppDestination = args.yes
94
- ? defaultProxyDestination
95
- : yield (0, exports.promptDestination)('Where would you like your proxy app created?', defaultProxyDestination);
96
- }
97
- while (path_1.default.resolve(proxyAppDestination) === path_1.default.resolve(destination)) {
98
- proxyAppDestination = yield (0, exports.promptDestination)('Proxy app and base app cannot be located in the same folder. Please input another path for proxy', defaultProxyDestination);
99
- }
100
- return {
101
- destination,
102
- proxyAppDestination,
103
- };
104
- }
105
- return {
106
- destination,
107
- };
85
+ return destination;
108
86
  });
109
- exports.getDestinations = getDestinations;
87
+ exports.getDestination = getDestination;
110
88
  const promptDestination = (prompt, defaultDestination) => __awaiter(void 0, void 0, void 0, function* () {
111
89
  return (yield inquirer_1.default.prompt({
112
90
  type: 'input',
@@ -153,24 +131,20 @@ const main = (args) => __awaiter(void 0, void 0, void 0, function* () {
153
131
  });
154
132
  templates.push(answer.template);
155
133
  }
156
- const destinations = yield (0, exports.getDestinations)(args, templates);
157
- for (const destination of [destinations.destination, destinations.proxyAppDestination]) {
158
- if (!destination)
159
- continue;
160
- if (!args.force && fs_1.default.existsSync(destination) && fs_1.default.readdirSync(destination).length > 0) {
161
- const answer = yield inquirer_1.default.prompt({
162
- type: 'confirm',
163
- name: 'continue',
164
- message: `Directory '${destination}' not empty. Are you sure you want to continue?`,
165
- });
166
- if (!answer.continue) {
167
- process.exit();
168
- }
169
- }
170
- else {
171
- args.force = true;
134
+ const destination = yield (0, exports.getDestination)(args, templates);
135
+ if (!args.force && fs_1.default.existsSync(destination) && fs_1.default.readdirSync(destination).length > 0) {
136
+ const answer = yield inquirer_1.default.prompt({
137
+ type: 'confirm',
138
+ name: 'continue',
139
+ message: `Directory '${destination}' not empty. Are you sure you want to continue?`,
140
+ });
141
+ if (!answer.continue) {
142
+ process.exit();
172
143
  }
173
144
  }
145
+ else {
146
+ args.force = true;
147
+ }
174
148
  if (!args.yes) {
175
149
  if (args.prePushHook === null) {
176
150
  const answer = yield inquirer_1.default.prompt({
@@ -188,7 +162,7 @@ const main = (args) => __awaiter(void 0, void 0, void 0, function* () {
188
162
  }
189
163
  }
190
164
  try {
191
- yield (0, init_runner_1.initRunner)(templates.slice(), Object.assign(Object.assign(Object.assign({}, args), destinations), { templates }));
165
+ yield (0, init_runner_1.initRunner)(templates.slice(), Object.assign(Object.assign({}, args), { destination, templates }));
192
166
  }
193
167
  catch (error) {
194
168
  console.log(chalk_1.default.red('An error occurred: ', error));
@@ -20,6 +20,9 @@ const chalk_1 = __importDefault(require("chalk"));
20
20
  * @param {string[]} nextStepsArr next steps to be performed after app is created
21
21
  */
22
22
  const nextSteps = (appNames, nextStepsArr) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const successMessage = appNames.length > 1
24
+ ? `JSS applications ${chalk_1.default.green(appNames.join(', '))} are ready!`
25
+ : `JSS application ${chalk_1.default.green(appNames[0])} is ready!`;
23
26
  console.log(chalk_1.default.red(' -/oyhdmNNNNmdhyo/- '));
24
27
  console.log(chalk_1.default.red(' :sdMMMMMMMMMMMMMMMMMMMMds: '));
25
28
  console.log(chalk_1.default.red(' :yNMMMMMMMMMMMMMMMMMMMMMMMMMMNy: '));
@@ -51,7 +54,7 @@ const nextSteps = (appNames, nextStepsArr) => __awaiter(void 0, void 0, void 0,
51
54
  console.log(chalk_1.default.white(' / // /\\ \\_\\ \\ '));
52
55
  console.log(chalk_1.default.white(' \\___/___/___/'));
53
56
  console.log();
54
- console.log(`JSS application(s) ${chalk_1.default.green(appNames.join(', '))} is ready!`);
57
+ console.log(successMessage);
55
58
  console.log();
56
59
  console.log(chalk_1.default.yellow('Next steps:'));
57
60
  nextStepsArr.forEach((step) => {
@@ -187,11 +187,6 @@ const populateEjsData = (answers, destination) => {
187
187
  getPascalCaseName: helpers_1.getPascalCaseName,
188
188
  getAppPrefix: helpers_1.getAppPrefix,
189
189
  } });
190
- // When SPA application and XM Cloud proxy is used we need to calculate relative path between SPA app and proxy to apply that in EJS template
191
- // Absolute path can't be used across all the machines
192
- if (answers.proxyAppDestination) {
193
- ejsData.helper.relativeProxyAppDestination = `${path_1.default.relative(path_1.default.resolve(answers.destination), path_1.default.resolve(answers.proxyAppDestination))}${path_1.sep}`;
194
- }
195
190
  return ejsData;
196
191
  };
197
192
  exports.populateEjsData = populateEjsData;
@@ -209,16 +204,11 @@ exports.populateEjsData = populateEjsData;
209
204
  */
210
205
  const transform = (templatePath, answers, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
211
206
  const { isFileForCopy, isFileForSkip, fileForCopyRegExp = FILE_FOR_COPY_REGEXP } = options;
212
- let destination = undefined;
213
- // allow proxy app to be installed separately alongside base app
214
- if (templatePath.match(/.*node-.+-proxy$/g) && answers.proxyAppDestination) {
215
- destination = answers.proxyAppDestination;
216
- }
217
- const destinationPath = path_1.default.resolve(destination || answers.destination);
207
+ const destinationPath = path_1.default.resolve(answers.destination);
218
208
  if (!answers.appPrefix) {
219
209
  answers.appPrefix = false;
220
210
  }
221
- const ejsData = (0, exports.populateEjsData)(answers, destination);
211
+ const ejsData = (0, exports.populateEjsData)(answers);
222
212
  // the templates to be run through ejs render or copied directly
223
213
  const files = glob_1.default.sync('**/*', { cwd: templatePath, dot: true, nodir: true });
224
214
  for (const file of files) {
@@ -38,19 +38,6 @@ exports.clientAppPrompts = [
38
38
  return !answers.appName;
39
39
  },
40
40
  },
41
- {
42
- type: 'list',
43
- name: 'fetchWith',
44
- message: 'How would you like to fetch Layout and Dictionary data?',
45
- choices: Object.values(FetchWith),
46
- default: exports.DEFAULT_FETCHWITH,
47
- when: (answers) => {
48
- if (answers.yes && !answers.fetchWith) {
49
- answers.fetchWith = exports.DEFAULT_FETCHWITH;
50
- }
51
- return !answers.fetchWith;
52
- },
53
- },
54
41
  ];
55
42
  const missingAddonMsg = (source, missingAddon) => chalk_1.default.yellow(`Warning: ${source} add-on cannot be used without the ${missingAddon} add-on. This may cause unexpected results.`);
56
43
  exports.missingAddonMsg = missingAddonMsg;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.proxyPrompts = exports.FALLBACK_PROXYNAME = void 0;
7
+ const helpers_1 = require("../utils/helpers");
8
+ const path_1 = __importDefault(require("path"));
9
+ exports.FALLBACK_PROXYNAME = 'sitecore-jss-proxy-app';
10
+ /**
11
+ * Set of CLI prompts for an SXP app
12
+ */
13
+ exports.proxyPrompts = [
14
+ {
15
+ type: 'input',
16
+ name: 'proxyAppDestination',
17
+ message: 'Where would you like your proxy app created?',
18
+ default: (answers) => {
19
+ // default proxy destination should be under same root as main app
20
+ return (0, helpers_1.getDefaultProxyDestination)(answers.destination, answers.proxyName || exports.FALLBACK_PROXYNAME);
21
+ },
22
+ when: (answers) => {
23
+ if (answers.yes && !answers.proxyAppDestination) {
24
+ answers.proxyAppDestination = (0, helpers_1.getDefaultProxyDestination)(answers.destination, answers.proxyName || exports.FALLBACK_PROXYNAME);
25
+ }
26
+ return !answers.proxyAppDestination;
27
+ },
28
+ validate: (input, answers) => {
29
+ if (path_1.default.resolve(input) === path_1.default.resolve(answers.destination)) {
30
+ return 'Paths for main app and proxy cannot match. Please choose another destination';
31
+ }
32
+ return true;
33
+ },
34
+ },
35
+ ];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sxpPrompts = void 0;
4
+ const base_1 = require("./base");
4
5
  /**
5
6
  * Set of CLI prompts for an SXP app
6
7
  */
@@ -9,12 +10,25 @@ exports.sxpPrompts = [
9
10
  type: 'input',
10
11
  name: 'hostName',
11
12
  message: 'What is your Sitecore hostname (used if deployed to Sitecore)?',
12
- default: (answers) => `${answers.appName}.dev.local`,
13
+ default: (answers) => `${answers.appName || base_1.DEFAULT_APPNAME}.dev.local`,
13
14
  when: (answers) => {
14
15
  if (answers.yes && !answers.hostName) {
15
- answers.hostName = `${answers.appName}.dev.local`;
16
+ answers.hostName = `${answers.appName || base_1.DEFAULT_APPNAME}.dev.local`;
16
17
  }
17
18
  return !answers.hostName;
18
19
  },
19
20
  },
21
+ {
22
+ type: 'list',
23
+ name: 'fetchWith',
24
+ message: 'How would you like to fetch Layout and Dictionary data?',
25
+ choices: Object.values(base_1.FetchWith),
26
+ default: base_1.DEFAULT_FETCHWITH,
27
+ when: (answers) => {
28
+ if (answers.yes && !answers.fetchWith) {
29
+ answers.fetchWith = base_1.DEFAULT_FETCHWITH;
30
+ }
31
+ return !answers.fetchWith;
32
+ },
33
+ },
20
34
  ];
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -12,10 +35,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
36
  };
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.removeFile = exports.writeFileToPath = exports.getAppPrefix = exports.getBaseTemplates = exports.getAllTemplates = exports.sortKeys = exports.saveConfiguration = exports.writeJsonFile = exports.openJsonFile = exports.getPascalCaseName = exports.isDevEnvironment = exports.getDefaultProxyDestination = exports.proxyAppMatcher = void 0;
38
+ exports.removeFile = exports.writeFileToPath = exports.getAppPrefix = exports.getBaseTemplates = exports.getAllTemplates = exports.sortKeys = exports.saveConfiguration = exports.writeJsonFile = exports.openJsonFile = exports.getPascalCaseName = exports.isDevEnvironment = exports.getRelativeProxyDestination = exports.getDefaultProxyDestination = exports.proxyAppMatcher = void 0;
16
39
  const chalk_1 = __importDefault(require("chalk"));
17
40
  const fs_1 = __importDefault(require("fs"));
18
- const path_1 = __importDefault(require("path"));
41
+ const path_1 = __importStar(require("path"));
19
42
  const InitializerFactory_1 = require("../../InitializerFactory");
20
43
  // matched for proxy templates
21
44
  exports.proxyAppMatcher = /node-headless.+|node-xmcloud.+/g;
@@ -27,6 +50,8 @@ exports.proxyAppMatcher = /node-headless.+|node-xmcloud.+/g;
27
50
  */
28
51
  const getDefaultProxyDestination = (mainAppDestination, proxyName) => path_1.default.join(mainAppDestination, '..', proxyName);
29
52
  exports.getDefaultProxyDestination = getDefaultProxyDestination;
53
+ const getRelativeProxyDestination = (mainDestination, proxyDestination) => `${path_1.default.relative(path_1.default.resolve(mainDestination), path_1.default.resolve(proxyDestination))}${path_1.sep}`;
54
+ exports.getRelativeProxyDestination = getRelativeProxyDestination;
30
55
  /**
31
56
  * Determines whether you are in a dev environment.
32
57
  * It's `true` if you are inside the monorepo
@@ -53,7 +53,7 @@ const initRunner = (initializers, args) => __awaiter(void 0, void 0, void 0, fun
53
53
  }
54
54
  args.silent || console.log(chalk_1.default.cyan(`Initializing '${init}'...`));
55
55
  const response = yield initializer.init(args);
56
- // App names can be multiple if the base template requires to setup additional standalone app (e.g. XM Cloud proxy)
56
+ // We can have multiple appNames if base template requires to setup an additional standalone app (e.g. XM Cloud proxy)
57
57
  appNames.add(response.appName);
58
58
  nextStepsArr = [...nextStepsArr, ...((_a = response.nextSteps) !== null && _a !== void 0 ? _a : [])];
59
59
  // process any returned initializers
@@ -11,14 +11,14 @@ exports.prompts = [
11
11
  default: false,
12
12
  when: (answers) => {
13
13
  // don't prompt if --yes or angular-xmcloud template was specified
14
- if (answers.yes) {
15
- return false;
16
- }
17
- else if (answers.templates.includes('angular-xmcloud') &&
14
+ if (answers.templates.includes('angular-xmcloud') &&
18
15
  !answers.templates.includes('angular-sxp')) {
19
16
  answers.xmcloud = true;
20
17
  return false;
21
18
  }
19
+ if (answers.yes) {
20
+ return false;
21
+ }
22
22
  return true;
23
23
  },
24
24
  },
@@ -31,29 +31,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
34
37
  Object.defineProperty(exports, "__esModule", { value: true });
35
38
  const path_1 = __importStar(require("path"));
36
39
  const common_1 = require("../../common");
40
+ const proxy_1 = require("../../common/prompts/proxy");
41
+ const inquirer_1 = __importDefault(require("inquirer"));
37
42
  const helpers_1 = require("../../common/utils/helpers");
38
43
  class AngularXmCloudInitializer {
39
44
  get isBase() {
40
45
  return false;
41
46
  }
42
47
  init(args) {
43
- var _a, _b;
48
+ var _a, _b, _c, _d;
44
49
  return __awaiter(this, void 0, void 0, function* () {
45
50
  const pkg = (0, common_1.openJsonFile)(`${args.destination}${path_1.sep}package.json`);
46
51
  const addInitializers = [];
47
- // when installing proxy alongside main app, have a separate path ready
48
- if (!args.proxyAppDestination) {
49
- args.proxyAppDestination = (0, helpers_1.getDefaultProxyDestination)(args.destination, 'node-xmcloud-proxy');
50
- }
52
+ // angular-xmcloud requires node-xmcloud-proxy
51
53
  if (!args.templates.includes('node-xmcloud-proxy')) {
52
54
  addInitializers.push('node-xmcloud-proxy');
53
55
  }
54
- const mergedArgs = Object.assign(Object.assign({}, args), { appName: args.appName || ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.config) === null || _a === void 0 ? void 0 : _a.appName) || common_1.DEFAULT_APPNAME, appPrefix: args.appPrefix || ((_b = pkg === null || pkg === void 0 ? void 0 : pkg.config) === null || _b === void 0 ? void 0 : _b.prefix) || false });
56
+ // ensure args.proxyAppDestination is populated
57
+ const promptArgs = {
58
+ yes: args.yes,
59
+ destination: args.destination,
60
+ proxyName: 'node-xmcloud-proxy',
61
+ proxyAppDestination: args.proxyAppDestination,
62
+ };
63
+ const proxyDetails = yield inquirer_1.default.prompt(proxy_1.proxyPrompts, promptArgs);
64
+ args.proxyAppDestination = proxyDetails.proxyAppDestination;
65
+ const finalArgs = Object.assign(Object.assign(Object.assign(Object.assign({}, args), { appName: args.appName || ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.config) === null || _a === void 0 ? void 0 : _a.appName) || common_1.DEFAULT_APPNAME, appPrefix: args.appPrefix || ((_b = pkg === null || pkg === void 0 ? void 0 : pkg.config) === null || _b === void 0 ? void 0 : _b.prefix) || false }), proxyDetails), { relativeProxyAppDestination: (0, helpers_1.getRelativeProxyDestination)(args.destination, args.proxyAppDestination) });
55
66
  const templatePath = path_1.default.resolve(__dirname, '../../templates/angular-xmcloud');
56
- yield (0, common_1.transform)(templatePath, mergedArgs);
67
+ yield (0, common_1.transform)(templatePath, finalArgs);
68
+ if (args.templates.includes('angular-sxp') || ((_d = (_c = pkg.config) === null || _c === void 0 ? void 0 : _c.templates) === null || _d === void 0 ? void 0 : _d.includes('angular-sxp'))) {
69
+ console.log((0, common_1.incompatibleAddonsMsg)('angular-xmcloud', 'angular-sxp'));
70
+ }
57
71
  const response = {
58
72
  nextSteps: [],
59
73
  appName: args.appName || common_1.DEFAULT_APPNAME,
@@ -21,7 +21,8 @@ class AngularXmCloudInitializer {
21
21
  init(args) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  const templatePath = path_1.default.resolve(__dirname, '../../templates/node-xmcloud-proxy');
24
- yield (0, common_1.transform)(templatePath, args);
24
+ const modifiedArgs = Object.assign(Object.assign({}, args), { destination: args.proxyAppDestination || args.destination });
25
+ yield (0, common_1.transform)(templatePath, modifiedArgs);
25
26
  const response = {
26
27
  appName: 'node-xmcloud-proxy',
27
28
  };
@@ -1,3 +1,5 @@
1
+ # ====== Sitecore Preview / Delivery Edge ======
2
+
1
3
  # Your Sitecore API key is needed to build the app. Typically, the API key is
2
4
  # defined in `scjssconfig.json` (as `sitecore.apiKey`). This file may not exist
3
5
  # when building locally (if you've never run `jss setup`), or when building in a
@@ -17,15 +19,12 @@ SITECORE_API_HOST=
17
19
  # the resolved Sitecore API hostname + the `graphQLEndpointPath` defined in your `package.json`.
18
20
  GRAPH_QL_ENDPOINT=
19
21
 
22
+ # ==============================================
23
+
20
24
  # Your Sitecore site name.
21
25
  # Uses your `package.json` config `appName` if empty.
22
26
  SITECORE_SITE_NAME=
23
27
 
24
- <% if (!locals.xmcloud) { -%>
25
- # The way in which layout and dictionary data is fetched from Sitecore
26
- FETCH_WITH=<%- fetchWith %>
27
- <% } -%>
28
-
29
28
  # Your default app language.
30
29
  DEFAULT_LANGUAGE=
31
30
 
@@ -20,6 +20,7 @@
20
20
  "plugin:@angular-eslint/template/process-inline-templates"
21
21
  ],
22
22
  "rules": {
23
+ "@angular-eslint/no-host-metadata-property": "off",
23
24
  "@angular-eslint/component-selector": [
24
25
  "error",
25
26
  {
@@ -9,10 +9,15 @@ scjssconfig.json
9
9
  /dist-server
10
10
  /tmp
11
11
  /out-tsc
12
+ /.angular
12
13
 
13
14
  # dependencies
14
15
  /node_modules
15
16
 
17
+ # local env files
18
+ .env.local
19
+ .env.*.local
20
+
16
21
  # IDEs and editors
17
22
  /.idea
18
23
  .project
@@ -81,7 +81,6 @@
81
81
  "@sitecore-jss/sitecore-jss-angular-schematics": "~22.2.0-canary",
82
82
  "@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
83
83
  "@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
84
- "@types/isomorphic-fetch": "0.0.35",
85
84
  "@types/jasmine": "~3.6.7",
86
85
  "@types/jasminewd2": "~2.0.8",
87
86
  "@types/node": "~20.14.10",
@@ -99,7 +98,6 @@
99
98
  "eslint-plugin-import": "2.29.1",
100
99
  "eslint-plugin-jsdoc": "48.7.0",
101
100
  "eslint-plugin-prefer-arrow": "1.2.3",
102
- "isomorphic-fetch": "^3.0.0",
103
101
  "jasmine-core": "~3.7.1",
104
102
  "jasmine-spec-reporter": "~6.0.0",
105
103
  "karma": "^6.3.2",
@@ -12,7 +12,6 @@ class FallbackPlugin implements ConfigPlugin {
12
12
  async exec(config: JssConfig) {
13
13
  return Object.assign({}, config, {
14
14
  defaultLanguage: config.defaultLanguage || 'en',
15
- sitecoreApiKey: config.sitecoreApiKey || 'no-api-key-set',
16
15
  <% if (!locals.xmcloud) { -%>
17
16
  layoutServiceConfigurationName: config.layoutServiceConfigurationName || 'default',
18
17
  <% } -%>
@@ -79,12 +79,14 @@ function generateComponentFactory() {
79
79
  const registrations: string[] = [];
80
80
  const lazyRegistrations: string[] = [];
81
81
  const declarations: string[] = [];
82
+ const components: string[] = [];
82
83
 
83
84
  packages.forEach((p) => {
84
85
  const variables = p.components
85
86
  .map((c) => {
86
87
  registrations.push(`{ name: '${c.componentName}', type: ${c.moduleName} },`);
87
88
  declarations.push(`${c.moduleName},`);
89
+ components.push(c.componentName);
88
90
 
89
91
  return c.moduleName;
90
92
  })
@@ -118,6 +120,8 @@ function generateComponentFactory() {
118
120
  const componentName = componentClassMatch[1];
119
121
  const importVarName = `${componentName}Component`;
120
122
 
123
+ components.push(componentName);
124
+
121
125
  // check for lazy loading needs
122
126
  const moduleFilePath = path.join(componentRootPath, componentFolder, `${componentFolder}.module.ts`);
123
127
  const isLazyLoaded = fs.existsSync(moduleFilePath);
@@ -144,6 +148,10 @@ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
144
148
  import { AppComponentsSharedModule } from './app-components.shared.module';
145
149
  ${imports.join('\n')}
146
150
 
151
+ export const components = [
152
+ ${components.map((c) => `'${c}'`).join(',\n ')}
153
+ ];
154
+
147
155
  @NgModule({
148
156
  imports: [
149
157
  AppComponentsSharedModule,
@@ -1,3 +1,4 @@
1
+ import 'dotenv/config';
1
2
  import * as fs from 'fs';
2
3
  import * as path from 'path';
3
4
  import { constantCase } from 'constant-case';
@@ -23,8 +24,16 @@ const defaultConfigValue: JssConfig = {
23
24
  defaultServerRoute: '/',
24
25
  };
25
26
 
26
- generateConfig('src/environments/environment.js', defaultConfigValue, { production: false });
27
- generateConfig('src/environments/environment.prod.js', defaultConfigValue, { production: true });
27
+ async function main() {
28
+ await generateConfig('src/environments/environment.js', defaultConfigValue, {
29
+ production: false,
30
+ });
31
+ await generateConfig('src/environments/environment.prod.js', defaultConfigValue, {
32
+ production: true,
33
+ });
34
+ }
35
+
36
+ main();
28
37
 
29
38
  /**
30
39
  * Generates the JSS config based on config plugins (under ./config/plugins)
@@ -38,7 +47,15 @@ export function generateConfig(
38
47
  defaultConfig: JssConfig = defaultConfigValue,
39
48
  configOverrides?: { [key: string]: unknown }
40
49
  ) {
41
- jssConfigFactory
50
+ // Handle undefined values
51
+ defaultConfig = Object.keys(defaultConfig).reduce((acc, key) => {
52
+ return {
53
+ ...acc,
54
+ [key]: defaultConfig[key] || '',
55
+ };
56
+ }, {});
57
+
58
+ return jssConfigFactory
42
59
  .create(defaultConfig)
43
60
  .then((config) => {
44
61
  writeConfig(Object.assign(config, configOverrides), outputPath);
@@ -67,9 +84,11 @@ export function writeConfig(config: JssConfig, outputPath?: string) {
67
84
 
68
85
  // Set base configuration values, allowing override with environment variables
69
86
  Object.keys(config).forEach((prop) => {
70
- configText += `config.${prop} = process.env.${constantCase(prop)} || "${config[prop]
71
- ?.toString()
72
- .trim()}";\n`;
87
+ // Handle undefined values
88
+ const value = config[prop] || '';
89
+ configText += `config.${prop} = process.env.${constantCase(
90
+ prop
91
+ )} || "${value.toString().trim()}";\n`;
73
92
  });
74
93
 
75
94
  configText += `module.exports.environment = config;`;
@@ -1,6 +1,6 @@
1
- import * as fetch from 'isomorphic-fetch';
2
1
  import * as fs from 'fs';
3
- import { generateConfig } from './generate-config';
2
+ import clientFactory from 'lib/graphql-client-factory';
3
+ import { getGraphQLClientFactoryConfig } from 'lib/graphql-client-factory/config';
4
4
 
5
5
  // Apollo Client supports caching GraphQL responses, which can greatly reduce network traffic needs.
6
6
  // In order to work correctly with interfaces in GraphQL, it needs to know some basic information about
@@ -9,28 +9,23 @@ import { generateConfig } from './generate-config';
9
9
  //
10
10
  // The `jss graphql:update` command should be executed when Sitecore templates related to the site are altered.
11
11
 
12
- generateConfig('src/environments/environment.js');
12
+ import './generate-config';
13
13
 
14
- let jssConfig;
14
+ const clientFactoryConfig = getGraphQLClientFactoryConfig();
15
15
 
16
- try {
17
- jssConfig = require('../src/environments/environment').environment;
18
- } catch (e) {
19
- console.error(
20
- 'Unable to require JSS config. Ensure `jss setup` has been run, and the app has been started at least once after setup.'
21
- );
22
- console.error(e);
23
- process.exit(1);
24
- }
16
+ console.log(`Updating GraphQL fragment type data from ${clientFactoryConfig.endpoint}...`);
25
17
 
26
- console.log(`Updating GraphQL fragment type data from ${jssConfig.graphQLEndpoint}...`);
27
-
28
- fetch(jssConfig.graphQLEndpoint, {
29
- method: 'POST',
30
- headers: { 'Content-Type': 'application/json', sc_apikey: jssConfig.sitecoreApiKey },
31
- body: JSON.stringify({
32
- query: `
33
- {
18
+ clientFactory()
19
+ .request<{
20
+ [key: string]: unknown;
21
+ __schema: {
22
+ kind: string;
23
+ name: string;
24
+ types: { possibleTypes?: { name: string } }[];
25
+ };
26
+ }>(
27
+ `
28
+ {
34
29
  __schema {
35
30
  types {
36
31
  kind
@@ -41,22 +36,18 @@ fetch(jssConfig.graphQLEndpoint, {
41
36
  }
42
37
  }
43
38
  }
44
- `,
45
- }),
46
- })
47
- .then((result) => result.json())
39
+ `
40
+ )
48
41
  .then((result) => {
49
42
  // here we're filtering out any type information unrelated to unions or interfaces
50
- const filteredData = result.data.__schema.types.filter(
51
- (type: { possibleTypes: Array<string> }) => type.possibleTypes !== null
52
- );
43
+ const filteredData = result.__schema.types.filter((type) => type.possibleTypes !== null);
53
44
 
54
45
  const filteredResult = { ...result };
55
- filteredResult.data.__schema.types = filteredData;
46
+ filteredResult.__schema.types = filteredData;
56
47
 
57
48
  fs.writeFile(
58
49
  './src/graphql-fragment-types.ts',
59
- `export default ${JSON.stringify(filteredResult.data, null, 2)}`,
50
+ `export default ${JSON.stringify(filteredResult, null, 2)}`,
60
51
  (err) => {
61
52
  if (err) {
62
53
  console.error('Error writing GraphQLFragmentTypes file', err);