From 57c54a1a3f2998df29b60ccbfd7d31d7a8d5b482 Mon Sep 17 00:00:00 2001 From: Ivan Zinovyev Date: Tue, 23 Jan 2018 16:46:38 +0300 Subject: [PATCH 1/5] Add iOS build phase scripts --- xcode/aux_scripts/cpd_script.php | 10 +++++ xcode/aux_scripts/download_file.sh | 15 +++++++ xcode/aux_scripts/import_strings.php | 48 ++++++++++++++++++++++ xcode/build_phases/api_generator.sh | 9 ++++ xcode/build_phases/copy_paste_detection.sh | 6 +++ xcode/build_phases/localization.sh | 14 +++++++ 6 files changed, 102 insertions(+) create mode 100644 xcode/aux_scripts/cpd_script.php create mode 100755 xcode/aux_scripts/download_file.sh create mode 100644 xcode/aux_scripts/import_strings.php create mode 100644 xcode/build_phases/api_generator.sh create mode 100644 xcode/build_phases/copy_paste_detection.sh create mode 100644 xcode/build_phases/localization.sh diff --git a/xcode/aux_scripts/cpd_script.php b/xcode/aux_scripts/cpd_script.php new file mode 100644 index 0000000..4516660 --- /dev/null +++ b/xcode/aux_scripts/cpd_script.php @@ -0,0 +1,10 @@ +duplication as $duplication) { + $files = $duplication->xpath('file'); + foreach ($files as $file) { + echo $file['path'].':'.$file['line'].':1: warning: '.$duplication['lines'].' copy-pasted lines from: ' + .implode(', ', array_map(function ($otherFile) { return $otherFile['path'].':'.$otherFile['line']; }, + array_filter($files, function ($f) use (&$file) { return $f != $file; }))).PHP_EOL; + } +} +?> diff --git a/xcode/aux_scripts/download_file.sh b/xcode/aux_scripts/download_file.sh new file mode 100755 index 0000000..9bfcbc7 --- /dev/null +++ b/xcode/aux_scripts/download_file.sh @@ -0,0 +1,15 @@ +file_name=$1 +file_link=$2 + +folder="Downloads" +file_path="./${folder}/${file_name}" + +# make folder if not exist +if ! [ -e ${folder} ]; then + mkdir ${folder} +fi + +# download file if not downloaded +if ! [ -e ${file_path} ]; then + curl -L ${file_link} -o ${file_path} +fi diff --git a/xcode/aux_scripts/import_strings.php b/xcode/aux_scripts/import_strings.php new file mode 100644 index 0000000..14050c9 --- /dev/null +++ b/xcode/aux_scripts/import_strings.php @@ -0,0 +1,48 @@ +$value) { + $ios_strings.='"'.$key.'" = "'.str_replace('%s', '%@', str_replace('"','\"', str_replace("\n", '\n', $value))).'";'.PHP_EOL; + } + $ios_strings = preg_replace('/(\\\\)(u)(\d{4})/', '$1U$3', $ios_strings); + + $lproj = $localization.$languageName.'.lproj/'; + createFolder($lproj); + file_put_contents($lproj.'Localizable.strings', $ios_strings); + + if($isBase) { + createFolder($localization.'Base.lproj/'); + file_put_contents($localization.'Base.lproj/Localizable.strings', $ios_strings); + $ios_swift_strings = 'import Foundation'.PHP_EOL. + 'import LeadKit'.PHP_EOL.PHP_EOL. + '// swiftlint:disable superfluous_disable_command'.PHP_EOL. + '// swiftlint:disable line_length'.PHP_EOL. + '// swiftlint:disable file_length'.PHP_EOL. + '// swiftlint:disable identifier_name'.PHP_EOL.PHP_EOL. + 'extension String {'.PHP_EOL; + foreach ($json as $key=>$value) { + $value_without_linefeed = preg_replace("/\r|\n/", " ", $value); + $ios_swift_strings .= "\t/// ".$value_without_linefeed."\n\t".'static let '.preg_replace_callback('/_(.?)/', function ($m) { return strtoupper($m[1]); }, $key).' = "'.$key.'".localized()'."\n".PHP_EOL; + } + $ios_swift_strings .= '}'.PHP_EOL; + file_put_contents($localization.'String+Localization.swift', $ios_swift_strings); + } + } +?> diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh new file mode 100644 index 0000000..e7566a9 --- /dev/null +++ b/xcode/build_phases/api_generator.sh @@ -0,0 +1,9 @@ +VERSION=$1 +FILE_NAME="api-generator-${VERSION}.jar" + +# download api generator +link="https://dl.bintray.com/touchin/touchin-tools/ru/touchin/api-generator/${VERSION}/${FILE_NAME}" +. build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${link} + +# execute api generator +java -jar "Downloads/${FILE_NAME}" -s common/api -o ${PROJECT_NAME}/Generated -t api-generator-templates/Swift -a generate-client-code diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh new file mode 100644 index 0000000..c987619 --- /dev/null +++ b/xcode/build_phases/copy_paste_detection.sh @@ -0,0 +1,6 @@ +# running CPD +echo ${EXECUTABLE_NAME} +pmd cpd --files ${EXECUTABLE_NAME} --exclude ${EXECUTABLE_NAME}/Generated --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > cpd-output.xml --failOnViolation true + +# running script +php ./build-scripts/xcode/aux_scripts/cpd_script.php -cpd-xml cpd-output.xml diff --git a/xcode/build_phases/localization.sh b/xcode/build_phases/localization.sh new file mode 100644 index 0000000..bb03150 --- /dev/null +++ b/xcode/build_phases/localization.sh @@ -0,0 +1,14 @@ +LOCALIZATION_PATH="${PROJECT_NAME}/Resources/Localization" +STRINGS_FOLDER="common/strings" + +if ! [ -e ${LOCALIZATION_PATH} ]; then + echo "${PROJECT_DIR}/${LOCALIZATION_PATH} path does not exist. Add these folders and try again." + exit 1 +fi + +if ! [ -e "${PROJECT_DIR}/${STRINGS_FOLDER}" ]; then +echo "${PROJECT_DIR}/${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder." + exit 1 +fi + +php build-scripts/xcode/aux_scripts/import_strings.php ${PROJECT_NAME} ${STRINGS_FOLDER} From 55170ce9712a6cb8591c0ac7400278b0fe57d951 Mon Sep 17 00:00:00 2001 From: Ivan Zinovyev Date: Wed, 24 Jan 2018 15:05:43 +0300 Subject: [PATCH 2/5] Update ios api generator script --- xcode/build_phases/api_generator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh index e7566a9..6a6276a 100644 --- a/xcode/build_phases/api_generator.sh +++ b/xcode/build_phases/api_generator.sh @@ -6,4 +6,4 @@ link="https://dl.bintray.com/touchin/touchin-tools/ru/touchin/api-generator/${VE . build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${link} # execute api generator -java -jar "Downloads/${FILE_NAME}" -s common/api -o ${PROJECT_NAME}/Generated -t api-generator-templates/Swift -a generate-client-code +java -jar "Downloads/${FILE_NAME}" --specification-path common/api --output-path ${PROJECT_NAME}/Generated --templates-path api-generator-templates/Swift --action generate-client-code --single-file true From 239040819293e102b688c1c18e0d795700989f99 Mon Sep 17 00:00:00 2001 From: Ivan Zinovyev Date: Wed, 24 Jan 2018 17:07:27 +0300 Subject: [PATCH 3/5] Add swiftlint script --- xcode/build_phases/swiftlint.sh | 1 + 1 file changed, 1 insertion(+) create mode 100644 xcode/build_phases/swiftlint.sh diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh new file mode 100644 index 0000000..21ed981 --- /dev/null +++ b/xcode/build_phases/swiftlint.sh @@ -0,0 +1 @@ +${PODS_ROOT}/SwiftLint/swiftlint autocorrect --path ${PROJECT_NAME} && ${PODS_ROOT}/SwiftLint/swiftlint --path ${PROJECT_NAME} --config ${PROJECT_DIR}/code-quality/.swiftlint.yml From a0a281e725bea2fc20b718cc589126ae649bb1f8 Mon Sep 17 00:00:00 2001 From: Ivan Zinovyev Date: Thu, 25 Jan 2018 14:24:22 +0300 Subject: [PATCH 4/5] Add swiftlint config --- xcode/.swiftlint.yml | 152 ++++++++++++++++++++++++++++++++ xcode/build_phases/swiftlint.sh | 2 +- 2 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 xcode/.swiftlint.yml diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml new file mode 100644 index 0000000..dfad1eb --- /dev/null +++ b/xcode/.swiftlint.yml @@ -0,0 +1,152 @@ +opt_in_rules: + - closure_spacing + - closure_end_indentation + - conditional_returns_on_newline + + - empty_count + - explicit_init + - extension_access_modifier + + - fatal_error_message + - file_header + - first_where + - force_unwrapping + + - implicit_return + + - let_var_whitespace + + - multiline_parameters + + - nimble_operator - discuss + - number_separator + + - object_literal + - overridden_super_call + + - private_outlet + - prohibited_super_call + + - redundant_nil_coalescing + + - unneeded_parentheses_in_closure_argument + + - vertical_parameter_alignment_on_call + +excluded: + - Carthage + - Pods + - Generated + +line_length: 128 + +cyclomatic_complexity: + ignores_case_statements: true + +type_body_length: + - 500 # warning + - 700 # error + +file_length: + warning: 500 + error: 1200 + +function_parameter_count: + error: 5 + +identifier_name: + excluded: + - id + - ok + - URL + - x + - y + - z + +warning_threshold: 1 + +custom_rules: + uiwebview_disabled: + included: ".*.swift" + name: "UIWebView Usage Disabled" + regex: 'UIWebView' + message: "Do not use UIWebView. Use WKWebView Instead. https://developer.apple.com/reference/uikit/uiwebview" + severity: error + + native_print: + name: "print -> DDLog" + regex: '(print|NSLog)\(' + message: "Please use CocoaLumberjack instead `print` and `NSlog`" + severity: error + + zero: + name: "Short .zero" + regex: '\(top: 0, left: 0, bottom: 0, right: 0\)' + message: "Please use short init `.zero`." + severity: error + + private_variable: + name: "Private variable" + regex: '(? Date: Thu, 25 Jan 2018 14:36:52 +0300 Subject: [PATCH 5/5] Fix ios localization script --- xcode/build_phases/localization.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xcode/build_phases/localization.sh b/xcode/build_phases/localization.sh index bb03150..d517aa4 100644 --- a/xcode/build_phases/localization.sh +++ b/xcode/build_phases/localization.sh @@ -2,13 +2,13 @@ LOCALIZATION_PATH="${PROJECT_NAME}/Resources/Localization" STRINGS_FOLDER="common/strings" if ! [ -e ${LOCALIZATION_PATH} ]; then - echo "${PROJECT_DIR}/${LOCALIZATION_PATH} path does not exist. Add these folders and try again." - exit 1 + echo "${PROJECT_DIR}/${LOCALIZATION_PATH} path does not exist. Add these folders and try again." + exit 1 fi if ! [ -e "${PROJECT_DIR}/${STRINGS_FOLDER}" ]; then -echo "${PROJECT_DIR}/${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder." - exit 1 + echo "${PROJECT_DIR}/${STRINGS_FOLDER} path does not exist. Submodule with strings should be named common and contain strings folder." + exit 1 fi php build-scripts/xcode/aux_scripts/import_strings.php ${PROJECT_NAME} ${STRINGS_FOLDER}