Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Tools/AddLicense/AddLicense.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

function addLicense() {
local MPL=(
'This Source Code Form is subject to the terms of the Mozilla Public'
'License, v. 2.0. If a copy of the MPL was not distributed with this'
'file, You can obtain one at https://mozilla.org/MPL/2.0/.'
)
local comment=''
local fileType=${1##*.}
local lineNumber=1

# 各種ファイルに適したコメントを生成する処理
if [ "$fileType" == 'axml' ]; then
comment='\\n<!--\n'$(printf ' %s\\n' "${MPL[@]}")'-->\n'
lineNumber=2 # XML 宣言の後に挿入する

elif [ "$fileType" == 'bat' ]; then
comment=$(printf '@REM %s\\n' "${MPL[@]}")

elif [ "$fileType" == 'cs' ]; then
comment=$(printf '// %s\\n' "${MPL[@]}")

elif [ "$fileType" == 'feature' ]; then
comment=$(printf '# %s\\n' "${MPL[@]}")

elif [ "$fileType" == 'resx' ]; then
comment='\\n<!--\n'$(printf ' %s\\n' "${MPL[@]}")'-->\n'
lineNumber=2 # XML 宣言の後に挿入する

elif [ "$fileType" == 'sh' ]; then
comment='\\n'$(printf '# %s\\n' "${MPL[@]}")
lineNumber=2 # Shebang の後に挿入する

elif [ "$fileType" == 'storyboard' ]; then
comment='\\n<!--\n'$(printf ' %s\\n' "${MPL[@]}")'-->\n'
lineNumber=2 # XML 宣言の後に挿入する

elif [ "$fileType" == 'strings' ]; then
comment='\\n/*\n'$(printf ' %s\\n' "${MPL[@]}")'*/\n'

elif [ "$fileType" == 'tf' ]; then
comment=$(printf '# %s\\n' "${MPL[@]}")

elif [ "$fileType" == 'xaml' ]; then
comment='\\n<!--\n'$(printf ' %s\\n' "${MPL[@]}")'-->\n'
lineNumber=2 # XML 宣言の後に挿入する

elif [ "$fileType" == 'xlf' ]; then
comment='\\n<!--\n'$(printf ' %s\\n' "${MPL[@]}")'-->\n'
lineNumber=2 # XML 宣言の後に挿入する

elif [ "$fileType" == 'xml' ]; then
comment='\\n<!--\n'$(printf ' %s\\n' "${MPL[@]}")'-->\n'
lineNumber=2 # XML 宣言の後に挿入する

elif [ "$fileType" == 'yml' ]; then
comment=$(printf '# %s\\n' "${MPL[@]}")
fi

# ライセンスの文言が無いファイルを探し,もしあれば生成したコメントを挿入する
git grep -z -L "${MPL[0]}" -- "$1" | xargs -0 sed -i -e "${lineNumber}i$comment"
}

# 対象ファイル
FILES=(
'*.axml'
'*.bat'
'*.cs'
'*.feature'
'*.resx'
'*.sh'
'*.storyboard'
'*.strings'
'*.tf'
'*.xaml'
'*.xlf'
'*.xml'
'*.yml'
)

for file in "${FILES[@]}"; do
addLicense "$file"
done