This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
create-jss-project.ps1
82 lines (71 loc) · 2.65 KB
/
create-jss-project.ps1
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
$ErrorActionPreference = "Stop"
##
## This script is used to add / initialize a JSS project using 'create-sitecore-jss'
## when this template is instantiated. It can be safely deleted.
##
Function Add-JssProject {
Write-Host "Adding JSS sample to solution via 'npx create-sitecore-jss..."
if ($null -eq (Get-Command "npm" -ErrorAction SilentlyContinue)) {
Write-Host "You must install node.js, see https://nodejs.org/" -ForegroundColor Red
Exit 1
}
$JSSNPMVersion = "latest"
if ($null -eq (Get-Command "jss" -ErrorAction SilentlyContinue)) {
Write-Host "Installing Sitecore JSS CLI" -ForegroundColor Green
npm install -g @sitecore-jss/sitecore-jss-cli@$JSSNPMVersion
}
Push-Location src
try {
$projectName = "xmcloudpreview"
Write-Host "Creating JSS Project for $projectName" -ForegroundColor Green
# JSS project name transformed by our dotnet new template symbols
$jssProjectName = "xmcloudpreview"
if ($jssProjectName -ne $projectName) {
Write-Host "Transformed to valid JSS project name $jssProjectName" -ForegroundColor Yellow
}
# Construct 'create-sitecore-jss' arguments based on input and defaults
$createArgs = @(
#"--yes",
"create-sitecore-jss@$JSSNPMVersion",
"--destination", $jssProjectName,
"--appName", $jssProjectName
)
# Both of these values are replaced by parameters from template.json
$jssCreateParams = "--templates nextjs,nextjs-styleguide"
$createArgs += $jssCreateParams.Split(' ')
npx @createArgs
Move-Item -Force $jssProjectName rendering | Out-Null
Push-Location rendering
try {
jss setup `
--instancePath "..\..\docker\deploy\platform\" `
--layoutServiceHost "https://xmcloudcm.localhost" `
--apiKey "B2F8A9B9-7203-4DCF-9314-8B28B043347E" `
--deployUrl "https://xmcloudcm.localhost/sitecore/api/jss/import" `
--deploySecret "10F1C44A496B45478640DD36F80C18C9" `
--nonInteractive `
--skipValidation | Out-Null
Update-JssProjectFiles
}
finally {
Pop-Location
}
}
finally {
Pop-Location
}
Write-Host "Done!"
}
Function Update-JssProjectFiles {
Write-Host "Updating JSS sample for containerized environment" -ForegroundColor Green
# Update .gitignore
# Values will be consistent across developers and deployment secret is an env var
$gitignore = ".\.gitignore"
Set-Content -Path $gitignore -Value (
Get-Content $gitignore |
Select-String -NotMatch "# sitecore|scjssconfig.json|\*.deploysecret.config"
)
## Remove config patches since the dotnet new template provides them
Remove-Item -Recurse -Force .\sitecore\config
}
Add-JssProject