-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsign-pledge.bat
103 lines (89 loc) · 2.78 KB
/
sign-pledge.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
@if (@X)==(@Y) @end /* necessary for embedded JS
@echo off
:: Check if git is available
for /f "tokens=*" %%i in ('git 2^>^&1 1^>NUL') do (
(
echo You must have git installed to sign this pledge.
echo https://git-scm.com/
) 1>&2
pause
exit /B 1
)
set EDITION=
for /f "tokens=*" %%i in ('git tag -l --points-at HEAD 2^> nul') do set EDITION=%%i
if "%EDITION%"=="" (
(
echo This is not an official edition of The Berneout Pledge! Please visit
echo https://github.com/berneout/berneout-pledge for the latest edition!
) 1>&2
pause
exit /B 1
)
set /p USER=Enter you GitHub user name, without @:
echo.
echo ########################################################################
echo.
setlocal EnableDelayedExpansion
:: The 2 empty lines here are required to put \n in a variable
set LF=^
set PLEDGE=
for /f "tokens=1* delims=]" %%A in ('type "pledge" ^| find /n /v ""') do (
set "LINE=%%B"
if "!LINE:~0,7!"=="Signed:" (
:: Remove last \n temporarily
set "PLEDGE=!PLEDGE:~0,-1!"
echo !PLEDGE!
echo ########################################################################
echo # To sign the pledge, type your name between slashes like /Casey Yao/. #
echo # If you don't want to sign, press Control + C to exit. #
echo ########################################################################
echo.
:: Re-add the removed \n
set "PLEDGE=!PLEDGE!!LF!"
set /p SIGNATURE=Signed:
:: Use embedded Javascript to get the ISO-8106 timestamp
for /f "tokens=*" %%i in ('cscript //E:jscript //nologo "%~f0" %*') do set TIMESTAMP=%%i
)
if "!LINE!" neq "" (
set "LINE=!LINE:{{{PLEDGE}}}=The Berneout Pledge %EDITION%!"
set "LINE=!LINE:{{{GITHUB_USER_NAME}}}=%USER%!"
for /f "delims=" %%Z in ("!TIMESTAMP!") do set "LINE=!LINE:{{{TIMESTAMP}}}=%%Z!"
for /f "delims=" %%Z in ("!SIGNATURE!") do set "LINE=!LINE:{{{SIGNATURE}}}=%%Z!"
)
set "PLEDGE=!PLEDGE!!LINE!!LF!"
)
:: Remove the duplicated trailing \n
set "PLEDGE=!PLEDGE:~0,-1!"
echo !PLEDGE!> pledge
echo.
call git add pledge
call git rm -f sign-pledge.sh
:: Delay the removal of the file, otherwise the script will stop execution
call git rm -f --cached sign-pledge.bat
call git rm -f README.md
call git commit -m "Customize for @%USER%"
echo.
echo You have signed The Berneout Pledge %EDITION%!
echo.
echo Two more steps to go:
echo.
echo 1. Create the repository github.com/%USER%/berneout-pledge.
echo.
echo 2. Push this Git repository there.
echo.
pause
del /f sign-pledge.bat
goto :eof
*/
function pad(number) {
return number < 10 ? ('0' + number) : number;
}
var date = new Date();
var isoString = date.getUTCFullYear() +
'-' + pad(date.getUTCMonth()+1) +
'-' + pad(date.getUTCDate()) +
'T' + pad(date.getUTCHours()) +
':' + pad(date.getUTCMinutes()) +
':' + pad(date.getUTCSeconds()) +
'Z';
WScript.echo(isoString);