This repository was archived by the owner on Nov 21, 2024. It is now read-only.
forked from Sitecore/jss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjss-create.js
More file actions
39 lines (32 loc) · 1.51 KB
/
jss-create.js
File metadata and controls
39 lines (32 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const path = require('path');
const { applyNameToProject } = require('@sitecore-jss/sitecore-jss-cli/dist/create');
/**
* This function is invoked by `jss create` when an app based on this template is created.
* It should perform tasks necessary to instantiate the app according to the argv, which
* correspond to the allowed arguments of `jss create`.
*
* Note: npm packages for the new app are already installed before this script is run.
* Note: this file is deleted in the new app after it has been run.
*
* @param {object} argv Arguments passed to `jss create` script
* @param {string[]} nextSteps Array of default 'next steps' to show at the console
* @returns {string[]} The next steps to display to the console user (enables customization from this script)
*/
module.exports = function createJssProject(argv, nextSteps) {
console.log(`Executing create script: ${__filename}...`);
applyNameToProject(__dirname, argv.name, argv.hostName);
// Replace app name in Angular-specific locations
function replaceAngularAppNameInFile(filePath) {
const fullFilePath = path.join(__dirname, filePath);
if (fs.existsSync(fullFilePath)) {
let cliConfig = fs.readFileSync(fullFilePath, 'utf8');
cliConfig = cliConfig.replace(/JssAngularWeb/g, argv.name);
fs.writeFileSync(fullFilePath, cliConfig);
}
}
replaceAngularAppNameInFile('angular.json');
replaceAngularAppNameInFile('scripts/bootstrap.ts');
replaceAngularAppNameInFile('package.json');
return nextSteps;
};