@@ -9,6 +9,8 @@ CLI=("git" "npm")
99
1010ACTIONS_WORKFLOW=pages-deploy.yml
1111
12+ RELEASE_HASH=$( git log --grep=" chore(release):" -1 --pretty=" %H" )
13+
1214# temporary file suffixes that make `sed -i` compatible with BSD and Linux
1315TEMP_SUFFIX=" to-delete"
1416
@@ -28,7 +30,7 @@ help() {
2830_sedi () {
2931 regex=$1
3032 file=$2
31- sed -i.$TEMP_SUFFIX " $regex " " $file "
33+ sed -i.$TEMP_SUFFIX -E " $regex " " $file "
3234 rm -f " $file " .$TEMP_SUFFIX
3335}
3436
@@ -50,22 +52,7 @@ _check_status() {
5052}
5153
5254_check_init () {
53- local _has_inited=false
54-
55- if [[ ! -d .github ]]; then # using option `--no-gh`
56- _has_inited=true
57- else
58- if [[ -f .github/workflows/$ACTIONS_WORKFLOW ]]; then
59- # on BSD, the `wc` could contains blank
60- local _count
61- _count=$( find .github/workflows/ -type f -name " *.yml" | wc -l)
62- if [[ ${_count// [[:blank:]]/ } == 1 ]]; then
63- _has_inited=true
64- fi
65- fi
66- fi
67-
68- if $_has_inited ; then
55+ if [[ $( git rev-parse HEAD^1) == " $RELEASE_HASH " ]]; then
6956 echo " Already initialized."
7057 exit 0
7158 fi
@@ -77,22 +64,25 @@ check_env() {
7764 _check_init
7865}
7966
80- checkout_latest_release () {
81- hash=$( git log --grep=" chore(release):" -1 --pretty=" %H" )
82- git reset --hard " $hash "
67+ reset_latest () {
68+ git reset --hard " $RELEASE_HASH "
69+ git clean -fd
70+ git submodule update --init --recursive
8371}
8472
8573init_files () {
8674 if $_no_gh ; then
8775 rm -rf .github
8876 else
89- # # Change the files of `.github`
90- mv .github/workflows/starter/$ACTIONS_WORKFLOW .
77+ # # Change the files of `.github/`
78+ temp=" $( mktemp -d) "
79+ find .github/workflows -type f -name " *$ACTIONS_WORKFLOW *" -exec mv {} " $temp /$ACTIONS_WORKFLOW " \;
9180 rm -rf .github && mkdir -p .github/workflows
92- mv ./$ACTIONS_WORKFLOW .github/workflows/${ACTIONS_WORKFLOW}
81+ mv " $temp /$ACTIONS_WORKFLOW " .github/workflows/" $ACTIONS_WORKFLOW "
82+ rm -rf " $temp "
9383
9484 # # Cleanup image settings in site config
95- _sedi " s/^ cdn:.*/cdn: /;s/^avatar:.*/avatar: /" _config.yml
85+ _sedi " s/(^.* cdn:) .*/\1 /;s/( ^avatar:) .*/\1 /" _config.yml
9686 fi
9787
9888 # remove the other files
@@ -108,12 +98,12 @@ init_files() {
10898commit () {
10999 git add -A
110100 git commit -m " chore: initialize the environment" -q
111- echo -e " \n[INFO] Initialization successful!\n"
101+ echo -e " \n> Initialization successful!\n"
112102}
113103
114104main () {
115105 check_env
116- checkout_latest_release
106+ reset_latest
117107 init_files
118108 commit
119109}
0 commit comments