diff --git a/packages/sitecore-jss-cli/src/create/index.test.ts b/packages/sitecore-jss-cli/src/create/index.test.ts
index 6cc2aca451..f8df6904ad 100644
--- a/packages/sitecore-jss-cli/src/create/index.test.ts
+++ b/packages/sitecore-jss-cli/src/create/index.test.ts
@@ -3,11 +3,56 @@ import { expect } from 'chai';
import {
applyNameToPackageJson,
applyHostNameToSitecoreConfig,
- applyNameToSitecoreConfig,
applyNameReplacement,
} from './index';
describe('applyNameReplacement', () => {
+ const mockConfig = (appName: string, customPath?: string) => {
+ return `
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <${appName}GraphQLEndpoint url="${customPath ? customPath : '/api/'}${appName}">
+
+
+
+
+ ${
+ customPath ? customPath : '/sitecore/templates/Project/'
+ }${appName}
+
+
+
+
+ ${appName}GraphQLEndpoint>
+
+
+
+
+
+ `;
+ };
+
it('should replace name', () => {
const result = applyNameReplacement('this is a test.', 'test', 'passing test');
expect(result).to.equal('this is a passing test.');
@@ -41,23 +86,55 @@ describe('applyNameReplacement', () => {
const result = applyNameReplacement('this is a te$+.', 'te$+', 'passing test');
expect(result).to.equal('this is a passing test.');
});
-});
-describe('applyNameToPackageJson', () => {
- it('should apply name using defaults', () => {
- const result = applyNameToPackageJson(
- {
- name: 'FooName',
- config: { appName: 'FooAppName', sitecoreDistPath: 'na', graphQLEndpointPath: 'na' },
- },
- 'bar'
+ it('should apply name using replaceName', () => {
+ const config = mockConfig('FooApp', '/somewhere/else/');
+ const result = applyNameReplacement(config, 'FooApp', 'Bar');
+ expect(result).to.match(/ {
+ const config = mockConfig('FooApp', '/somewhere/else/');
+ const result = applyNameReplacement(config, 'BarApp', 'Bar');
+ expect(result).to.not.match(/ {
it('should apply name using replaceName', () => {
const result = applyNameToPackageJson(
{
@@ -65,7 +142,6 @@ describe('applyNameToPackageJson', () => {
config: {
appName: 'FooAppName',
sitecoreDistPath: '/somewhere/dist/FooAppName',
- graphQLEndpointPath: '/somewhere/api/FooAppName',
},
},
'bar',
@@ -74,7 +150,6 @@ describe('applyNameToPackageJson', () => {
expect(result.name).to.equal('bar');
expect(result.config.appName).to.equal('bar');
expect(result.config.sitecoreDistPath).to.equal('/somewhere/dist/bar');
- expect(result.config.graphQLEndpointPath).to.equal('/somewhere/api/bar');
});
it('should not apply name using replaceName if no match', () => {
@@ -102,7 +177,8 @@ describe('applyNameToPackageJson', () => {
name: 'FooName',
config: { appName: 'FooAppName' },
},
- 'bar'
+ 'bar',
+ 'JssTestWeb'
);
expect(result.config.sitecoreDistPath).to.be.undefined;
expect(result.config.graphQLEndpointPath).to.be.undefined;
@@ -131,120 +207,3 @@ describe('applyHostNameToSitecoreConfig', () => {
expect(result).to.match(/ {
- const mockConfig = (appName: string, customPath?: string) => {
- return `
-
-
-
-
-
-
-
-
-
-
-
-
-
- <${appName}GraphQLEndpoint url="${customPath ? customPath : '/api/'}${appName}">
-
-
-
-
- ${
- customPath ? customPath : '/sitecore/templates/Project/'
- }${appName}
-
-
-
-
- ${appName}GraphQLEndpoint>
-
-
-
-
-
- `;
- };
-
- it('should apply name using defaults', () => {
- const config = mockConfig('FooApp', '/somewhere/else/');
- const result = applyNameToSitecoreConfig(config, 'Bar');
- expect(result).to.match(/ {
- const config = mockConfig('FooApp', '/somewhere/else/');
- const result = applyNameToSitecoreConfig(config, 'Bar', 'FooApp');
- expect(result).to.match(/ {
- const config = mockConfig('FooApp', '/somewhere/else/');
- const result = applyNameToSitecoreConfig(config, 'Bar', 'BarApp');
- expect(result).to.not.match(//g, `${name}GraphQLEndpoint>`);
-
- // replace GraphQL templates path
- configXml = configXml.replace(
- /(\/sitecore\/templates\/Project\/)[^<]+(<\/templates>)/g,
- `$1${name}$2`
- );
- return configXml;
-}
-
/**
* @param {string} projectFolder Project folder
* @param {string} name App name
* @param {string} hostName App hostname
- * @param {string} [replaceName] Optional token which will enable "name replacement mode" on project files. If omitted, default/conventional values are used.
+ * @param {string} replaceName Name value to replace
*/
export function applyNameToProject(
projectFolder: string,
name: string,
hostName: string,
- replaceName?: string
+ replaceName: string
) {
// Apply name to package.json file
console.log(chalk.cyan(`Applying name ${name} to package.json...`));
@@ -145,7 +90,7 @@ export function applyNameToProject(
console.log(
chalk.cyan(`Applying name ${name} and hostName ${hostName} to ${sitecoreConfigPath}...`)
);
- configXml = applyNameToSitecoreConfig(configXml, name, replaceName);
+ configXml = applyNameReplacement(configXml, replaceName, name);
configXml = applyHostNameToSitecoreConfig(configXml, hostName);
fs.unlinkSync(sitecoreConfigPath);
diff --git a/samples/angular/jss-create.js b/samples/angular/jss-create.js
index 3acc13da4e..79835a10a5 100644
--- a/samples/angular/jss-create.js
+++ b/samples/angular/jss-create.js
@@ -18,7 +18,7 @@ const { applyNameToProject } = require('@sitecore-jss/sitecore-jss-cli/dist/cjs/
module.exports = function createJssProject(argv, nextSteps) {
console.log(`Executing create script: ${__filename}...`);
- applyNameToProject(__dirname, argv.name, argv.hostName);
+ applyNameToProject(__dirname, argv.name, argv.hostName, 'JssAngularWeb');
// Replace app name in Angular-specific locations
function replaceAngularAppNameInFile(filePath) {
diff --git a/samples/react/jss-create.js b/samples/react/jss-create.js
index 6976e95e25..d40334f8fb 100644
--- a/samples/react/jss-create.js
+++ b/samples/react/jss-create.js
@@ -18,7 +18,7 @@ const { applyNameToProject } = require('@sitecore-jss/sitecore-jss-cli/dist/cjs/
module.exports = function createJssProject(argv, nextSteps) {
console.log(`Executing create script: ${__filename}...`);
- applyNameToProject(__dirname, argv.name, argv.hostName);
+ applyNameToProject(__dirname, argv.name, argv.hostName, 'JssReactWeb');
if (!argv.fetchWith) {
nextSteps.push(
diff --git a/samples/vue/jss-create.js b/samples/vue/jss-create.js
index 7f2df910b9..96fccecc12 100644
--- a/samples/vue/jss-create.js
+++ b/samples/vue/jss-create.js
@@ -18,7 +18,7 @@ const { applyNameToProject } = require('@sitecore-jss/sitecore-jss-cli/dist/cjs/
module.exports = function createJssProject(argv, nextSteps) {
console.log(`Executing create script: ${__filename}...`);
- applyNameToProject(__dirname, argv.name, argv.hostName);
+ applyNameToProject(__dirname, argv.name, argv.hostName, 'JssVueWeb');
if (!argv.fetchWith) {
nextSteps.push(