-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_react.ps1
41 lines (34 loc) · 1 KB
/
build_react.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
param (
[string]$app_dir = "backend_app\resources",
[string]$react_dir = "react_app",
[Switch]$clean
)
$build_dir = "$react_dir\build"
$meta_dir = "$app_dir\static\meta"
$templates_dir = "$app_dir\templates"
Remove-Item -Recurse -Force $build_dir -ErrorAction SilentlyContinue
Set-Location $react_dir
try
{
if (-Not(Test-Path "node_modules"))
{
npm install
}
npm run build
Set-Location ..
}
catch
{
Set-Location ..
exit
}
if ($clean.IsPresent)
{
Remove-Item -Recurse -Force "$app_dir\static" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$app_dir\templates" -ErrorAction SilentlyContinue
}
Copy-Item "$build_dir\static" "$app_dir" -Recurse -Force
New-Item -Path "$templates_dir"-ItemType Directory -Force | Out-Null
New-Item -Path "$meta_dir"-ItemType Directory -Force | Out-Null
Copy-Item -Path (Get-Item -Path "$build_dir\*" -Exclude 'static') -Destination "$meta_dir" -Force
Move-Item -Path "$meta_dir\*.html" -Destination "$templates_dir" -Force