@mservices-tech/scripts 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +153 -0
- package/LICENSE +7 -0
- package/README.md +56 -0
- package/add_sandbox_upstream/add_sandbox_upstream.sh +32 -0
- package/buildUsingEsbuild/buildUsingEsbuild.js +54 -0
- package/bump_version/.versionrc.js +20 -0
- package/bump_version/bump_version.sh +93 -0
- package/clean/clean.sh +61 -0
- package/copy_package_build_to_project/copy_package_build_to_project.sh +46 -0
- package/delete_and_fetch_git_tags/delete_and_fetch_git_tags.sh +35 -0
- package/docker/docker.sh +68 -0
- package/docker/docker_utils.sh +143 -0
- package/download_design_system_package/download_design_system_package.sh +41 -0
- package/enrich_changelog_with_dependency_changes/enrich_changelog_with_dependency_changes.sh +289 -0
- package/find_all_javascript_files/find_all_javascript_files.sh +76 -0
- package/find_and_parse_environmental_variable_files/find_and_parse_environmental_variable_files.sh +180 -0
- package/find_references/find_references.sh +50 -0
- package/generateIndexFilesFromTemplate/generateIndexFilesFromTemplate.js +419 -0
- package/get_package_info/get_package_info.sh +103 -0
- package/git_user_stats/git_user_stats.sh +95 -0
- package/index.js +1 -0
- package/is_branch_rebased/is_branch_rebased.sh +44 -0
- package/last_release_commits/last_release_commits.sh +101 -0
- package/list_all_installed_dependencies/list_all_installed_dependencies.sh +40 -0
- package/package.json +14 -0
- package/prepare_obligatory_package_files/prepare_obligatory_package_files.sh +61 -0
- package/publish/publish.sh +89 -0
- package/removeGitHashesFromMarkdownFile/removeGitHashesFromMarkdownFile.js +50 -0
- package/remove_all_node_modules/remove_all_node_modules.sh +26 -0
- package/remove_all_scripts_in_single_workspace/remove_all_scripts_in_single_workspace.sh +62 -0
- package/reverse_proxy/README.md +102 -0
- package/reverse_proxy/clean.sh +8 -0
- package/reverse_proxy/configuration.sh +5 -0
- package/reverse_proxy/generate_certificates.sh +140 -0
- package/reverse_proxy/localhost.ext.template +12 -0
- package/reverse_proxy/nginx_domain_ssl_reverse_proxy.conf.template +89 -0
- package/reverse_proxy/openssl.conf +21 -0
- package/reverse_proxy/reverse_proxy.sh +48 -0
- package/runShellScript/runShellScript.js +49 -0
- package/source_environment_variables/source_environment_variables.sh +38 -0
- package/sync_sandbox_with_upstream/sync_sandbox_with_upstream.sh +53 -0
- package/testIncorrectValues/testIncorrectValues.js +51 -0
- package/typescript_usage_statistics/typescript_usage_statistics.sh +35 -0
- package/utils.sh +337 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -eo pipefail
|
|
4
|
+
|
|
5
|
+
source "$(dirname "$0")/../utils.sh" || exit 1
|
|
6
|
+
|
|
7
|
+
readonly PACKAGE_JSON="package.json"
|
|
8
|
+
readonly CHANGELOG_FILE="CHANGELOG.md"
|
|
9
|
+
readonly VERSION_TAG_PATTERN="[0-9]+\.[0-9]+\.[0-9]+"
|
|
10
|
+
readonly TEMP_CHANGES_FILE=".dependency-changes.md"
|
|
11
|
+
VERBOSE=false
|
|
12
|
+
|
|
13
|
+
function error_exit() {
|
|
14
|
+
logger_error "$1" >&2
|
|
15
|
+
exit "${2:-1}"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function debug_log() {
|
|
19
|
+
if [ "$VERBOSE" = true ]; then
|
|
20
|
+
logger_debug "$1" >&2
|
|
21
|
+
fi
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function usage() {
|
|
25
|
+
cat << END
|
|
26
|
+
Usage:
|
|
27
|
+
./enrich_changelog_with_dependency_changes.sh [--help] [--verbose] [--include-dev-dependencies]
|
|
28
|
+
Where:
|
|
29
|
+
help - whether to print usage information and exit
|
|
30
|
+
verbose - enable verbose logging for debugging
|
|
31
|
+
include-dev-dependencies - include dev dependencies in changelog (optional)
|
|
32
|
+
Description:
|
|
33
|
+
This script enriches CHANGELOG.md with dependency changes by comparing
|
|
34
|
+
the current package.json with the one from the previous release.
|
|
35
|
+
END
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function validate_environment() {
|
|
39
|
+
debug_log "Validating environment..."
|
|
40
|
+
[ -f "$PACKAGE_JSON" ] || error_exit "package.json not found in current directory"
|
|
41
|
+
[ -f "$CHANGELOG_FILE" ] || error_exit "CHANGELOG.md not found in current directory"
|
|
42
|
+
command -v jq > /dev/null 2>&1 || error_exit "jq is required but not installed"
|
|
43
|
+
command -v git > /dev/null 2>&1 || error_exit "git is required but not installed"
|
|
44
|
+
debug_log "Environment validation complete"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function get_package_name() {
|
|
48
|
+
local full_name
|
|
49
|
+
full_name=$(jq -r '.name' package.json | cut -d'/' -f2)
|
|
50
|
+
echo "${full_name/-development/}"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function get_last_tag() {
|
|
54
|
+
local package_name="$1"
|
|
55
|
+
git tag --list --sort=-v:refname | grep -E "^${package_name}-${VERSION_TAG_PATTERN}$" | grep -v "\-rc" | head -n 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function extract_dependencies() {
|
|
59
|
+
local package_json="$1"
|
|
60
|
+
local dependencies_type="$2"
|
|
61
|
+
jq -r ".$dependencies_type // {}" "$package_json"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function extract_version() {
|
|
65
|
+
local package_json="$1"
|
|
66
|
+
jq -r '.version' "$package_json"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function generate_dependency_diff() {
|
|
70
|
+
local old_dependencies="$1"
|
|
71
|
+
local new_dependencies="$2"
|
|
72
|
+
local dependency_type="$3"
|
|
73
|
+
|
|
74
|
+
# Create temporary files for JSON processing
|
|
75
|
+
local temp_dir
|
|
76
|
+
temp_dir=$(mktemp -d)
|
|
77
|
+
|
|
78
|
+
local old_json="${temp_dir}/old.json"
|
|
79
|
+
local new_json="${temp_dir}/new.json"
|
|
80
|
+
local old_pairs="${temp_dir}/old_pairs.txt"
|
|
81
|
+
local new_pairs="${temp_dir}/new_pairs.txt"
|
|
82
|
+
|
|
83
|
+
echo "$old_dependencies" > "$old_json"
|
|
84
|
+
echo "$new_dependencies" > "$new_json"
|
|
85
|
+
|
|
86
|
+
jq -r 'to_entries[] | "\(.key)|\(.value)"' "$old_json" > "$old_pairs"
|
|
87
|
+
jq -r 'to_entries[] | "\(.key)|\(.value)"' "$new_json" > "$new_pairs"
|
|
88
|
+
|
|
89
|
+
local changes=""
|
|
90
|
+
local -i updated_count=0
|
|
91
|
+
local -i removed_count=0
|
|
92
|
+
local -i added_count=0
|
|
93
|
+
|
|
94
|
+
# Compare versions and detect changes
|
|
95
|
+
while IFS='|' read -r key old_version; do
|
|
96
|
+
if [ -n "$key" ]; then
|
|
97
|
+
local new_version
|
|
98
|
+
new_version=$(grep "^${key}|" "$new_pairs" | cut -d'|' -f2)
|
|
99
|
+
|
|
100
|
+
if [ -z "$new_version" ]; then
|
|
101
|
+
changes="${changes}- **${key}**: ${old_version} → Removed\n"
|
|
102
|
+
((removed_count++))
|
|
103
|
+
elif [ "$old_version" != "$new_version" ]; then
|
|
104
|
+
changes="${changes}- **${key}**: ${old_version} → ${new_version}\n"
|
|
105
|
+
((updated_count++))
|
|
106
|
+
fi
|
|
107
|
+
fi
|
|
108
|
+
done < "$old_pairs"
|
|
109
|
+
|
|
110
|
+
# Check for newly added dependencies
|
|
111
|
+
while IFS='|' read -r key new_version; do
|
|
112
|
+
if [ -n "$key" ]; then
|
|
113
|
+
if ! grep -q "^${key}|" "$old_pairs"; then
|
|
114
|
+
changes="${changes}- **${key}**: Not Present → ${new_version}\n"
|
|
115
|
+
((added_count++))
|
|
116
|
+
fi
|
|
117
|
+
fi
|
|
118
|
+
done < "$new_pairs"
|
|
119
|
+
|
|
120
|
+
# Cleanup temp files
|
|
121
|
+
rm -rf "$temp_dir"
|
|
122
|
+
|
|
123
|
+
if [ "$VERBOSE" = true ]; then
|
|
124
|
+
debug_log "=== $dependency_type Dependencies Summary ==="
|
|
125
|
+
debug_log "Updated: $updated_count"
|
|
126
|
+
debug_log "Added: $added_count"
|
|
127
|
+
debug_log "Removed: $removed_count"
|
|
128
|
+
debug_log "Total Changes: $((updated_count + added_count + removed_count))"
|
|
129
|
+
debug_log "=================================="
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
if [ -n "$changes" ]; then
|
|
133
|
+
printf "%b" "$changes"
|
|
134
|
+
fi
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function get_package_path() {
|
|
138
|
+
local package_dir
|
|
139
|
+
package_dir=$(dirname "$(readlink -f "./package.json")")
|
|
140
|
+
local git_root
|
|
141
|
+
git_root=$(git rev-parse --show-toplevel)
|
|
142
|
+
echo "${package_dir#"$git_root"/}"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function is_rc_version() {
|
|
146
|
+
local version="$1"
|
|
147
|
+
[[ "$version" == *"-rc"* ]]
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function main() {
|
|
151
|
+
parse_arguments "$@"
|
|
152
|
+
if [ "${PROCESS_ARGUMENTS['--help']}" ]; then
|
|
153
|
+
usage
|
|
154
|
+
exit 0
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
if [ "${PROCESS_ARGUMENTS['--verbose']}" ]; then
|
|
158
|
+
VERBOSE=true
|
|
159
|
+
debug_log "Verbose mode enabled"
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
local INCLUDE_DEV_DEPENDENCIES=false
|
|
163
|
+
if [ "${PROCESS_ARGUMENTS['--include-dev-dependencies']}" ]; then
|
|
164
|
+
INCLUDE_DEV_DEPENDENCIES=true
|
|
165
|
+
debug_log "Including dev dependencies"
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
validate_environment
|
|
169
|
+
|
|
170
|
+
logger_info "Starting changelog enrichment process..."
|
|
171
|
+
|
|
172
|
+
local current_version
|
|
173
|
+
current_version=$(jq -r '.version' package.json)
|
|
174
|
+
|
|
175
|
+
if is_rc_version "$current_version"; then
|
|
176
|
+
logger_info "Current version ${current_version} is a release candidate. Skipping dependency diff."
|
|
177
|
+
exit 0
|
|
178
|
+
fi
|
|
179
|
+
|
|
180
|
+
local package_name
|
|
181
|
+
package_name=$(get_package_name)
|
|
182
|
+
logger_info "Processing package: $package_name"
|
|
183
|
+
|
|
184
|
+
local package_path
|
|
185
|
+
package_path=$(get_package_path)
|
|
186
|
+
debug_log "Package path: $package_path"
|
|
187
|
+
|
|
188
|
+
local last_tag
|
|
189
|
+
last_tag=$(get_last_tag "$package_name")
|
|
190
|
+
|
|
191
|
+
if [ -z "$last_tag" ]; then
|
|
192
|
+
logger_warn "No previous non-RC release found. Skipping dependency diff."
|
|
193
|
+
exit 0
|
|
194
|
+
fi
|
|
195
|
+
|
|
196
|
+
logger_info "Found last tag: $last_tag"
|
|
197
|
+
|
|
198
|
+
local temp_dir
|
|
199
|
+
temp_dir=$(mktemp -d)
|
|
200
|
+
trap 'rm -rf "${temp_dir}"' EXIT
|
|
201
|
+
debug_log "Created temporary directory: $temp_dir"
|
|
202
|
+
|
|
203
|
+
git show "${last_tag}:${package_path}/${PACKAGE_JSON}" > "${temp_dir}/${PACKAGE_JSON}"
|
|
204
|
+
debug_log "Extracted old package.json from tag ${last_tag}"
|
|
205
|
+
|
|
206
|
+
logger_info "Starting dependency comparison..."
|
|
207
|
+
|
|
208
|
+
local old_dependencies new_dependencies old_version new_version
|
|
209
|
+
old_dependencies=$(extract_dependencies "${temp_dir}/${PACKAGE_JSON}" "dependencies")
|
|
210
|
+
new_dependencies=$(extract_dependencies "./${PACKAGE_JSON}" "dependencies")
|
|
211
|
+
|
|
212
|
+
old_version=$(extract_version "${temp_dir}/${PACKAGE_JSON}")
|
|
213
|
+
new_version=$(extract_version "./${PACKAGE_JSON}")
|
|
214
|
+
logger_info "Comparing versions: $old_version → $new_version"
|
|
215
|
+
|
|
216
|
+
debug_log "Processing regular dependencies..."
|
|
217
|
+
dependency_changes=$(generate_dependency_diff "$old_dependencies" "$new_dependencies" "Regular")
|
|
218
|
+
|
|
219
|
+
local dev_dependency_changes=""
|
|
220
|
+
if [ "$INCLUDE_DEV_DEPENDENCIES" = true ]; then
|
|
221
|
+
local old_dev_dependencies new_dev_dependencies
|
|
222
|
+
old_dev_dependencies=$(extract_dependencies "${temp_dir}/${PACKAGE_JSON}" "devDependencies")
|
|
223
|
+
new_dev_dependencies=$(extract_dependencies "./${PACKAGE_JSON}" "devDependencies")
|
|
224
|
+
debug_log "Processing dev dependencies..."
|
|
225
|
+
dev_dependency_changes=$(generate_dependency_diff "$old_dev_dependencies" "$new_dev_dependencies" "Dev")
|
|
226
|
+
fi
|
|
227
|
+
|
|
228
|
+
if [ -n "$dependency_changes" ] || [ -n "$dev_dependency_changes" ]; then
|
|
229
|
+
logger_info "Found dependency changes, generating markdown..." >&2
|
|
230
|
+
{
|
|
231
|
+
if [ -n "$dependency_changes" ] && [ -n "$dev_dependency_changes" ]; then
|
|
232
|
+
echo -e "### Dependency Updates"
|
|
233
|
+
echo -e "\n#### Dependencies\n$dependency_changes"
|
|
234
|
+
echo -e "\n#### Dev Dependencies\n$dev_dependency_changes"
|
|
235
|
+
elif [ -n "$dependency_changes" ]; then
|
|
236
|
+
echo -e "### Dependency Updates\n"
|
|
237
|
+
echo -e "$dependency_changes"
|
|
238
|
+
elif [ -n "$dev_dependency_changes" ]; then
|
|
239
|
+
echo -e "### Dependency Updates"
|
|
240
|
+
echo -e "\n#### Dev Dependencies\n$dev_dependency_changes"
|
|
241
|
+
fi
|
|
242
|
+
echo "" # Add empty line at the end
|
|
243
|
+
} > "$TEMP_CHANGES_FILE"
|
|
244
|
+
|
|
245
|
+
local temp_changelog
|
|
246
|
+
temp_changelog=$(mktemp)
|
|
247
|
+
|
|
248
|
+
# Process the changelog file and insert dependency changes after the first version header
|
|
249
|
+
awk -v changes_file="$TEMP_CHANGES_FILE" '
|
|
250
|
+
BEGIN { found_first = 0; printed_changes = 0 }
|
|
251
|
+
{
|
|
252
|
+
if ($0 ~ /^#{1,3} [0-9]+\.[0-9]+\.[0-9]+/) {
|
|
253
|
+
if (!found_first) {
|
|
254
|
+
print $0
|
|
255
|
+
found_first = 1
|
|
256
|
+
} else {
|
|
257
|
+
if (!printed_changes) {
|
|
258
|
+
system("cat " changes_file)
|
|
259
|
+
printed_changes = 1
|
|
260
|
+
}
|
|
261
|
+
print $0
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
print $0
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
END {
|
|
268
|
+
if (!printed_changes) {
|
|
269
|
+
system("cat " changes_file)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
' "$CHANGELOG_FILE" > "$temp_changelog"
|
|
273
|
+
|
|
274
|
+
if [ -s "$temp_changelog" ]; then
|
|
275
|
+
mv "$temp_changelog" "$CHANGELOG_FILE"
|
|
276
|
+
logger_info "Successfully inserted dependency changes in changelog" >&2
|
|
277
|
+
else
|
|
278
|
+
logger_error "Temporary changelog is empty, keeping original file" >&2
|
|
279
|
+
rm -f "$temp_changelog"
|
|
280
|
+
exit 1
|
|
281
|
+
fi
|
|
282
|
+
|
|
283
|
+
rm -f "$TEMP_CHANGES_FILE"
|
|
284
|
+
else
|
|
285
|
+
logger_info "No dependency changes detected" >&2
|
|
286
|
+
fi
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
main "$@"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
source "$(dirname $0)/../utils.sh" || exit 1
|
|
4
|
+
|
|
5
|
+
usage() {
|
|
6
|
+
cat << END
|
|
7
|
+
Usage:
|
|
8
|
+
${BASH_SOURCE[0]} [--help] <--mode> [--extension]
|
|
9
|
+
Where:
|
|
10
|
+
help - print usage information and exit
|
|
11
|
+
mode - what to do with the files, pass 'find' or 'delete'
|
|
12
|
+
extension - extension to search for, default 'js'
|
|
13
|
+
Description:
|
|
14
|
+
Runs a search for all the JavaScript files inside the
|
|
15
|
+
current location, excluding certain patterns such as
|
|
16
|
+
'node_modules' and 'build' directories.
|
|
17
|
+
END
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function print_file() {
|
|
21
|
+
local extension="$1"
|
|
22
|
+
local file_name="$2"
|
|
23
|
+
printf "Found JavaScript file with .$extension extension: %s\n" "$file_name"
|
|
24
|
+
}
|
|
25
|
+
export -f print_file
|
|
26
|
+
|
|
27
|
+
function delete_file() {
|
|
28
|
+
local extension="$1"
|
|
29
|
+
local file_name="$2"
|
|
30
|
+
printf "Deleting JavaScript file with .$extension extension: %s\n" "$file_name"
|
|
31
|
+
rm "$file_name"
|
|
32
|
+
}
|
|
33
|
+
export -f delete_file
|
|
34
|
+
|
|
35
|
+
function main() {
|
|
36
|
+
parse_arguments "$@"
|
|
37
|
+
if [ ${PROCESS_ARGUMENTS['--help']} ]; then
|
|
38
|
+
usage
|
|
39
|
+
exit 0
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
if [ ${PROCESS_ARGUMENTS['--mode']} == "find" ]; then
|
|
43
|
+
local -r search_results_handler_function=print_file
|
|
44
|
+
elif [ ${PROCESS_ARGUMENTS['--mode']} == "delete" ]; then
|
|
45
|
+
local -r search_results_handler_function=delete_file
|
|
46
|
+
else
|
|
47
|
+
printf "Mode not provided. Run with '--help' for more information.\n"
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
local -r JAVASCRIPT_FILES_EXTENSION="${PROCESS_ARGUMENTS['--extension']:-js}"
|
|
52
|
+
|
|
53
|
+
find . -name "*.""$JAVASCRIPT_FILES_EXTENSION" \
|
|
54
|
+
-not -path "*/node_modules/*" \
|
|
55
|
+
-not -path "./.yarn/*" \
|
|
56
|
+
-not -path "./.git/*" \
|
|
57
|
+
-not -path "./packages/design-system/build/*" \
|
|
58
|
+
-not -path "./packages/design-system/src/bin/*" \
|
|
59
|
+
-not -path "./packages/design-system/src/web-components/*" \
|
|
60
|
+
-not -path "./packages/design-system/src/libs/*" \
|
|
61
|
+
-not -path "./packages/design-system/plugins/*" \
|
|
62
|
+
-not -path "./packages/eslint-config-node/build/*" \
|
|
63
|
+
-not -path "./packages/eslint-config/build/*" \
|
|
64
|
+
-not -path "./packages/styleguide-api/build/*" \
|
|
65
|
+
-not -path "./packages/styleguide-api/public/*" \
|
|
66
|
+
-not -path "./packages/templates/build/*" \
|
|
67
|
+
-not -path "./packages/templates/.next/*" \
|
|
68
|
+
-not -path "./packages/styleguide/.next/*" \
|
|
69
|
+
-not -path "./packages/styleguide/.netlify/*" \
|
|
70
|
+
-not -path "./packages/styleguide/build/*" \
|
|
71
|
+
-not -path "./packages/styleguide/public/*" \
|
|
72
|
+
-not -path "./packages/styleguide/src/mocks/mkanon/*" \
|
|
73
|
+
-exec bash -c "$search_results_handler_function $JAVASCRIPT_FILES_EXTENSION \$0" {} \;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main "$@"
|
package/find_and_parse_environmental_variable_files/find_and_parse_environmental_variable_files.sh
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
source "$(dirname $0)/../utils.sh" || exit 1
|
|
4
|
+
|
|
5
|
+
usage() {
|
|
6
|
+
cat << END
|
|
7
|
+
Usage:
|
|
8
|
+
${BASH_SOURCE[0]} [--validate] [--help]
|
|
9
|
+
Where:
|
|
10
|
+
help - display this help
|
|
11
|
+
validate - validate .env files having example files to ensure that they are in sync
|
|
12
|
+
Description:
|
|
13
|
+
Script for linting .env* files and validating .env files having example files to ensure that they are in sync.
|
|
14
|
+
END
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function find_env_files() {
|
|
18
|
+
declare -g ALL_ENV_FILES=$(find . -type f -name ".env*" -not -path "*node_modules/*" -not -path "*build/*" -not -path "*.next/*" -not -path "*.git/*")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function evaluate_description() {
|
|
22
|
+
local description="$1"
|
|
23
|
+
local current_line_number="$2"
|
|
24
|
+
local logger_message="$3"
|
|
25
|
+
local validity=$(echo $description | grep -E '.*## @type [{].{3,}[}] @description .{3,}')
|
|
26
|
+
|
|
27
|
+
if [[ $validity == "" ]]; then
|
|
28
|
+
echo -e "\e[31mError in line $ENV_FILE:$current_line_number: $logger_message\e[0m"
|
|
29
|
+
echo $line
|
|
30
|
+
DESIGN_SYSTEM_LINTER_EXIT_CODE=1
|
|
31
|
+
fi
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function evaluate_comment() {
|
|
35
|
+
|
|
36
|
+
local comment="$1"
|
|
37
|
+
local current_line_number="$2"
|
|
38
|
+
local validity=$(echo $comment | grep -E '^# .*|^## .*')
|
|
39
|
+
|
|
40
|
+
if [[ $validity == "" ]]; then
|
|
41
|
+
echo -e "\e[33mWarining in line $ENV_FILE:$current_line_number: comment should be in format # <comment body>\e[0m"
|
|
42
|
+
echo $line
|
|
43
|
+
DESIGN_SYSTEM_LINTER_EXIT_CODE=1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function lint_env_file() {
|
|
49
|
+
|
|
50
|
+
declare -g ENV_FILE="$1"
|
|
51
|
+
shopt -s extglob
|
|
52
|
+
|
|
53
|
+
local previous_IFS=$IFS
|
|
54
|
+
local current_line_number=0
|
|
55
|
+
local previous_line=""
|
|
56
|
+
|
|
57
|
+
while IFS= read -r line; do
|
|
58
|
+
((current_line_number++))
|
|
59
|
+
|
|
60
|
+
if [[ $line == *"## "* ]]; then
|
|
61
|
+
evaluate_description "$line" "$current_line_number" "comment should be in format ## @type {<type>} @description <description>, remember to include description as well as type in the convention of your project programming language"
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
if [[ $line == !(#)"#"!(#)* ]]; then
|
|
65
|
+
evaluate_comment "$line" "$current_line_number"
|
|
66
|
+
previous_line=$line
|
|
67
|
+
continue
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
if [[ $line == *"="* ]]; then
|
|
71
|
+
|
|
72
|
+
local variable_name_regex="*([alnum]|_)*"
|
|
73
|
+
local before_equal_sign=${line%=*}
|
|
74
|
+
|
|
75
|
+
if [[ $before_equal_sign != $variable_name_regex ]]; then
|
|
76
|
+
echo -e "\e[33mError in line $ENV_FILE:$current_line_number: variable name should be in uppercase and underscore format\n\e[0m"
|
|
77
|
+
echo $line
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
evaluate_description "$previous_line" "$current_line_number" "each variable should have a description in format ## @type {<type>} @description <description>, remember to include description as well as type in the convention of your project programming language"
|
|
81
|
+
fi
|
|
82
|
+
|
|
83
|
+
previous_line=$line
|
|
84
|
+
done < "$ENV_FILE"
|
|
85
|
+
|
|
86
|
+
IFS=$previous_IFS
|
|
87
|
+
shopt -u extglob
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function extract_variables_from_file() {
|
|
91
|
+
|
|
92
|
+
local env_file="$1"
|
|
93
|
+
local previous_IFS=$IFS
|
|
94
|
+
local collect_variables=""
|
|
95
|
+
|
|
96
|
+
while IFS= read -r line; do
|
|
97
|
+
|
|
98
|
+
if [[ $line == !(#)"#"!(#)* ]]; then
|
|
99
|
+
continue
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
if [[ $line == *"="* ]]; then
|
|
103
|
+
local before_equal_sign=${line%=\"*}
|
|
104
|
+
before_equal_sign=${before_equal_sign%=*}
|
|
105
|
+
collect_variables+=" $before_equal_sign"
|
|
106
|
+
fi
|
|
107
|
+
done < "$env_file"
|
|
108
|
+
|
|
109
|
+
IFS=$previous_IFS
|
|
110
|
+
|
|
111
|
+
echo $collect_variables
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function validate_env_file() {
|
|
115
|
+
local example_env_file="$1"
|
|
116
|
+
local env_file=${example_env_file%.example*}
|
|
117
|
+
|
|
118
|
+
variables_in_example_file=$(extract_variables_from_file "$example_env_file")
|
|
119
|
+
variables_in_env_file=$(extract_variables_from_file "$env_file")
|
|
120
|
+
|
|
121
|
+
files_diffrences=$(echo ${variables_in_example_file[@]} ${variables_in_env_file[@]} | tr ' ' '\n' | sort | uniq --unique)
|
|
122
|
+
|
|
123
|
+
if [ -z "$files_diffrences" ]; then
|
|
124
|
+
echo -e "\e[32mFiles are in sync\e[0m"
|
|
125
|
+
else
|
|
126
|
+
DESIGN_SYSTEM_LINTER_EXIT_CODE=1
|
|
127
|
+
echo -e "\e[31mError: $env_file is not in sync with $example_env_file, missing variables: $files_diffrences\e[0m"
|
|
128
|
+
fi
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function main() {
|
|
132
|
+
|
|
133
|
+
declare -g DESIGN_SYSTEM_LINTER_EXIT_CODE=0
|
|
134
|
+
local should_validate=false
|
|
135
|
+
|
|
136
|
+
parse_arguments "$@"
|
|
137
|
+
if [ ${PROCESS_ARGUMENTS['--help']} ]; then
|
|
138
|
+
usage
|
|
139
|
+
exit 0
|
|
140
|
+
fi
|
|
141
|
+
|
|
142
|
+
if [ ${PROCESS_ARGUMENTS['--validate']} ]; then
|
|
143
|
+
should_validate=true
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
find_env_files
|
|
147
|
+
|
|
148
|
+
local example_env_files_array
|
|
149
|
+
|
|
150
|
+
for file in $ALL_ENV_FILES; do
|
|
151
|
+
|
|
152
|
+
if [[ $file == *".example" ]]; then
|
|
153
|
+
example_env_files_array+=" $file"
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
echo "Linting $file"
|
|
157
|
+
lint_env_file "$file"
|
|
158
|
+
|
|
159
|
+
done
|
|
160
|
+
|
|
161
|
+
if [[ $should_validate == true ]]; then
|
|
162
|
+
for file in $example_env_files_array; do
|
|
163
|
+
|
|
164
|
+
local example_env_file=$file
|
|
165
|
+
local env_file=${example_env_file%.example*}
|
|
166
|
+
|
|
167
|
+
if [ ! -f "$env_file" ]; then
|
|
168
|
+
continue
|
|
169
|
+
fi
|
|
170
|
+
|
|
171
|
+
echo "Validatting $file"
|
|
172
|
+
validate_env_file "$file"
|
|
173
|
+
|
|
174
|
+
done
|
|
175
|
+
fi
|
|
176
|
+
|
|
177
|
+
exit $DESIGN_SYSTEM_LINTER_EXIT_CODE
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
main "$@"
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
source "$(dirname $0)/../utils.sh" || exit 1
|
|
4
|
+
|
|
5
|
+
usage() {
|
|
6
|
+
cat << END
|
|
7
|
+
Usage:
|
|
8
|
+
${BASH_SOURCE[0]} [--help] <--query>
|
|
9
|
+
Where:
|
|
10
|
+
help - print usage information and exit
|
|
11
|
+
query - the string to find, case insensitive
|
|
12
|
+
Description:
|
|
13
|
+
Finds all instances of a word and its variations
|
|
14
|
+
inside current directory. Excludes certain patterns such
|
|
15
|
+
as 'node_modules' and 'build' directiories.
|
|
16
|
+
END
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function main() {
|
|
20
|
+
parse_arguments "$@"
|
|
21
|
+
if [ ${PROCESS_ARGUMENTS['--help']} ]; then
|
|
22
|
+
usage
|
|
23
|
+
exit 0
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
if ! [ ${PROCESS_ARGUMENTS['--query']} ]; then
|
|
27
|
+
printf "No query provided. Run with '--help' for more information."
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
grep ${PROCESS_ARGUMENTS['--query']} \
|
|
32
|
+
--recursive \
|
|
33
|
+
--line-number \
|
|
34
|
+
--ignore-case \
|
|
35
|
+
--only-matching \
|
|
36
|
+
--exclude-dir=node_modules \
|
|
37
|
+
--exclude-dir=build \
|
|
38
|
+
--exclude-dir=.next \
|
|
39
|
+
--exclude-dir=.git \
|
|
40
|
+
--include=*.ts \
|
|
41
|
+
--include=*.tsx \
|
|
42
|
+
--include=*.md \
|
|
43
|
+
--include=*.mdx \
|
|
44
|
+
--include=*.json \
|
|
45
|
+
--include=*.yml \
|
|
46
|
+
--include=.env* \
|
|
47
|
+
--include=*.sh
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main "$@"
|