-
Notifications
You must be signed in to change notification settings - Fork 101
/
init.bat
60 lines (46 loc) · 2.16 KB
/
init.bat
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
@echo off
setlocal enabledelayedexpansion
:: Check if a codelab name was provided
if "%~1"=="" (
echo USAGE: %0 ^<CODELAB_NAME^>
echo.
exit /b 1
)
:: Get current directory
set "SCRIPT_DIR=%~dp0"
:: Codelab name from first argument
set "CODELAB_NAME=%~1"
:: Get Git username (requires Git for Windows to be installed)
for /f "delims=" %%a in ('git config user.name') do set "AUTHOR_NAME=%%a"
:: Define file paths
set "MARKDOWN_TEMPLATE=%SCRIPT_DIR%markdown\template\markdown.template"
set "PACKAGE_JSON_TEMPLATE=%SCRIPT_DIR%markdown\template\package.json"
set "CODELAB_MARKDOWN_FILE=%SCRIPT_DIR%markdown\%CODELAB_NAME%\%CODELAB_NAME%.md"
set "CODELAB_PACKAGE_JSON=%SCRIPT_DIR%markdown\%CODELAB_NAME%\package.json"
:: Validate template files exist
if not exist "%MARKDOWN_TEMPLATE%" (
echo ERROR: Markdown template not found
exit /b 1
)
if not exist "%PACKAGE_JSON_TEMPLATE%" (
echo ERROR: Package.json template not found
exit /b 1
)
:: Create directory for codelab
mkdir "%SCRIPT_DIR%markdown\%CODELAB_NAME%"
xcopy /E /I "%SCRIPT_DIR%markdown\template\*" "%SCRIPT_DIR%markdown\%CODELAB_NAME%"
del "%SCRIPT_DIR%markdown\%CODELAB_NAME%\markdown-iguide.template"
:: Rename markdown template
move "%SCRIPT_DIR%markdown\%CODELAB_NAME%\markdown.template" "%CODELAB_MARKDOWN_FILE%"
:: Replace placeholders in markdown file
powershell -Command "(Get-Content '%CODELAB_MARKDOWN_FILE%') | ForEach-Object { $_ -replace 'CODELAB_NAME.*', '%CODELAB_NAME%' -replace 'AUTHOR_NAME.*', '%AUTHOR_NAME%' } | Set-Content '%CODELAB_MARKDOWN_FILE%'"
:: Replace placeholders in package.json
powershell -Command "(Get-Content '%CODELAB_PACKAGE_JSON%') | ForEach-Object { $_ -replace 'CODELAB_NAME', '%CODELAB_NAME%' } | Set-Content '%CODELAB_PACKAGE_JSON%'"
echo Markdown file created! Find it at %CD%\markdown\%CODELAB_NAME%
:: Check for required commands
where claat >nul 2>nul
if errorlevel 1 echo Note: claat does not exist. Please install it if you would like to run the codelab locally.
where go >nul 2>nul
if errorlevel 1 echo Note: go does not exist. Please install it if you would like to run the codelab locally.
:: Change to the codelab directory
cd "%SCRIPT_DIR%markdown\%CODELAB_NAME%"