@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
package/utils.sh
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck disable=SC2001
|
|
3
|
+
|
|
4
|
+
# Usage (assuming the script is located in 'scripts' subdirectory
|
|
5
|
+
# of the project, where package is installed):
|
|
6
|
+
#
|
|
7
|
+
# source "$(dirname "$0")/../node_modules/@mservicestech/scripts/utils.sh" || exit 1
|
|
8
|
+
# by default the script will look for esbuild in './node_modules/.bin/esbuild'
|
|
9
|
+
# you can change it by setting ESBUILD_BINARY variable
|
|
10
|
+
# export ESBUILD_BINARY='./node_modules/.bin/esbuild'
|
|
11
|
+
#
|
|
12
|
+
# transpile --input="your-script.ts"
|
|
13
|
+
#
|
|
14
|
+
# if you want to use 'tsc' instead of 'esbuild':
|
|
15
|
+
#
|
|
16
|
+
# transpile --compiler="tsc" --input="your-script.ts"
|
|
17
|
+
# if you want to change compiler globally for all runs of transpile function,
|
|
18
|
+
# set the DESIGN_SYSTEM_GLOBAL_COMPILER variable, for example:
|
|
19
|
+
# export DESIGN_SYSTEM_GLOBAL_COMPILER=tsc # or export DESIGN_SYSTEM_GLOBAL_COMPILER=esbuild
|
|
20
|
+
ESBUILD_BINARY="${ESBUILD_BINARY:-./node_modules/.bin/esbuild}"
|
|
21
|
+
|
|
22
|
+
ESBUILD_BASIC_OPTIONS="--log-level=error"
|
|
23
|
+
|
|
24
|
+
# Should be set to Node's current LTS version
|
|
25
|
+
TARGET_NODE_VERSION="node24.0"
|
|
26
|
+
|
|
27
|
+
GREEN='\033[0;32m'
|
|
28
|
+
RED='\033[0;31m'
|
|
29
|
+
YELLOW='\033[0;33m'
|
|
30
|
+
NO_COLOR='\033[0m'
|
|
31
|
+
|
|
32
|
+
function should_skip() {
|
|
33
|
+
local input_file=$1
|
|
34
|
+
local output_file=$2
|
|
35
|
+
|
|
36
|
+
if [ -f "$output_file" ] && [ "$input_file" -ot "$output_file" ]; then
|
|
37
|
+
return 0
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
return 1
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Exits a script cleanly, killing the whole process tree
|
|
44
|
+
# it is able to skip killing child processes if needed (for example when running type checking)
|
|
45
|
+
function clean_exit() {
|
|
46
|
+
local should_not_kill_child_processes_and_exit=${DESIGN_SYSTEM_PREVENT_CHILD_PROCESS_KILL_AND_EXIT_ON_FAILURE:-false}
|
|
47
|
+
trap "exit" INT TERM
|
|
48
|
+
if [ "$should_not_kill_child_processes_and_exit" != "true" ]; then
|
|
49
|
+
trap "kill 0" EXIT
|
|
50
|
+
exit ${1:-0}
|
|
51
|
+
fi
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# Runs a JavaScript (CommonJS) script
|
|
55
|
+
function run_script() {
|
|
56
|
+
local -r script_path="$1"
|
|
57
|
+
local runtime=${DESIGN_SYSTEM_JAVASCRIPT_RUNTIME:-node}
|
|
58
|
+
|
|
59
|
+
shift
|
|
60
|
+
|
|
61
|
+
${runtime} "$script_path" "$@" || clean_exit 1
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Compiles TypeScript file to CommonJS JavaScript file (file.ts → file.js)
|
|
65
|
+
#
|
|
66
|
+
# Usage:
|
|
67
|
+
# transpile path with one of two copilers (tsc || esbuild)
|
|
68
|
+
# to pick the correct commpiler use flag --compiler [--compiler="tsc"]
|
|
69
|
+
#
|
|
70
|
+
# Note:
|
|
71
|
+
# - esbuild is a default compiler for this function
|
|
72
|
+
# - esbuild will bundle all files into one
|
|
73
|
+
# - tsc will not bundle files and will generate one .js file per each .ts file
|
|
74
|
+
# used in the transpilation
|
|
75
|
+
# - both compilers will always transpile to CommonJS format
|
|
76
|
+
function transpile() {
|
|
77
|
+
# Defaults to 'esbuild' if no global compiler is set
|
|
78
|
+
local compiler=${DESIGN_SYSTEM_GLOBAL_COMPILER:-esbuild}
|
|
79
|
+
|
|
80
|
+
# Compiler-specific arguments
|
|
81
|
+
local tsc_arguments=""
|
|
82
|
+
local esbuild_arguments=""
|
|
83
|
+
|
|
84
|
+
# Flag to force transpile, defaults to 'false'
|
|
85
|
+
local global_force_transpile=${DESIGN_SYSTEM_GLOBAL_FORCE_TRANSPILE:false}
|
|
86
|
+
local force_transpile=false
|
|
87
|
+
|
|
88
|
+
# Script input file, defaults to empty
|
|
89
|
+
local input=""
|
|
90
|
+
|
|
91
|
+
# Parse command line arguments
|
|
92
|
+
while test $# -gt 0; do
|
|
93
|
+
case "$1" in
|
|
94
|
+
--tsc-compiler-arguments*)
|
|
95
|
+
# Extracts 'tsc' specific arguments
|
|
96
|
+
tsc_arguments=$(echo "$1" | sed -e 's/^[^=]*=//g')
|
|
97
|
+
shift
|
|
98
|
+
;;
|
|
99
|
+
--esbuild-compiler-arguments*)
|
|
100
|
+
# Extracts 'esbuild' specific arguments
|
|
101
|
+
esbuild_arguments=$(echo "$1" | sed -e 's/^[^=]*=//g')
|
|
102
|
+
shift
|
|
103
|
+
;;
|
|
104
|
+
--compiler*)
|
|
105
|
+
# Sets the compiler
|
|
106
|
+
compiler=$(echo "$1" | sed -e 's/^[^=]*=//g')
|
|
107
|
+
shift
|
|
108
|
+
;;
|
|
109
|
+
--input*)
|
|
110
|
+
# Sets the input script name
|
|
111
|
+
input=$(echo "$1" | sed -e 's/^[^=]*=//g')
|
|
112
|
+
shift
|
|
113
|
+
;;
|
|
114
|
+
--force-transpile)
|
|
115
|
+
# Forces transpiling
|
|
116
|
+
force_transpile=true
|
|
117
|
+
shift
|
|
118
|
+
;;
|
|
119
|
+
*)
|
|
120
|
+
break
|
|
121
|
+
;;
|
|
122
|
+
esac
|
|
123
|
+
done
|
|
124
|
+
|
|
125
|
+
if [ -z "$input" ]; then
|
|
126
|
+
echo "Error: No input provided."
|
|
127
|
+
echo "Usage: transpile --input=<input file> [other_arguments]"
|
|
128
|
+
exit 1
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
# Sets the script_name from --input or first positional argument
|
|
132
|
+
local script_name=$input
|
|
133
|
+
|
|
134
|
+
local pad_dots='...............................................................'
|
|
135
|
+
local pad_spaces=' '
|
|
136
|
+
printf "Transpiling %s %s" "$script_name" "${pad_dots:${#script_name}}"
|
|
137
|
+
printf " (%s) %s" "$compiler" "${pad_spaces:${#compiler}}"
|
|
138
|
+
|
|
139
|
+
local output_file="${script_name%.*}.js"
|
|
140
|
+
|
|
141
|
+
if [ "$force_transpile" != true ] && [ "$global_force_transpile" != true ] && should_skip "$script_name" "$output_file"; then
|
|
142
|
+
printf " SKIPPED\n"
|
|
143
|
+
return
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
case "$compiler" in
|
|
147
|
+
tsc*)
|
|
148
|
+
# 'lib' should be set to the highest value from all the values in
|
|
149
|
+
# the tsconfig.json used in the design system's build process
|
|
150
|
+
# in design system's tsconfig.json
|
|
151
|
+
#
|
|
152
|
+
# 'target' should be set to the same value as 'target' field value
|
|
153
|
+
# in design system's tsconfig.json
|
|
154
|
+
# Warning: when using the 'tsc' compiler (not a default one), a .js
|
|
155
|
+
# file will be generated for each .ts module. You might need to clean it up
|
|
156
|
+
tsc -skipLibCheck -esModuleInterop \
|
|
157
|
+
--module "commonjs" \
|
|
158
|
+
--moduleResolution "node" \
|
|
159
|
+
--resolveJsonModule \
|
|
160
|
+
--lib "es2021" \
|
|
161
|
+
--target "es2017" \
|
|
162
|
+
--jsx "react" $tsc_arguments "$script_name" || clean_exit 1
|
|
163
|
+
;;
|
|
164
|
+
esbuild*)
|
|
165
|
+
# Note: 'prettier' is always an external dependency when transpiling
|
|
166
|
+
# using esbuild. Prettier API is used in writeFileFormatted
|
|
167
|
+
# and writeFileSyncFormatted functions from @mservicestech/utils package.
|
|
168
|
+
# Without defining Prettier as external dependency, esbuild cannot
|
|
169
|
+
# properly bundle scripts using Prettier API to CommonJS format.
|
|
170
|
+
#
|
|
171
|
+
# remove file suffix
|
|
172
|
+
${ESBUILD_BINARY} ${ESBUILD_BASIC_OPTIONS} "$script_name" \
|
|
173
|
+
--bundle \
|
|
174
|
+
--loader:.js=js \
|
|
175
|
+
--loader:.jsx=jsx \
|
|
176
|
+
--loader:.ts=ts \
|
|
177
|
+
--loader:.tsx=tsx \
|
|
178
|
+
--loader:.mjs=js \
|
|
179
|
+
--resolve-extensions=.mjs,.js,.ts,.tsx \
|
|
180
|
+
--platform=node \
|
|
181
|
+
--target="$TARGET_NODE_VERSION" \
|
|
182
|
+
--outfile="$output_file" \
|
|
183
|
+
--external:prettier \
|
|
184
|
+
--format=cjs $esbuild_arguments || clean_exit 1
|
|
185
|
+
;;
|
|
186
|
+
*)
|
|
187
|
+
echo "Unknown compiler: $compiler"
|
|
188
|
+
clean_exit 1
|
|
189
|
+
;;
|
|
190
|
+
esac
|
|
191
|
+
|
|
192
|
+
printf " %bDONE%b\n" "${GREEN}" "${NO_COLOR}"
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
# inspired by: https://stackoverflow.com/a/55556407/963881
|
|
196
|
+
#
|
|
197
|
+
# usage:
|
|
198
|
+
# source ./node_modules/@mservicestech/scripts/utils.sh && token_set <name> <keys> - <values>
|
|
199
|
+
#
|
|
200
|
+
# iterating over values: '${<name>[@]}'
|
|
201
|
+
# iterating over keys: '${!<name>[@]}'
|
|
202
|
+
#
|
|
203
|
+
# where:
|
|
204
|
+
# name - a name for associative array environment variable to be created
|
|
205
|
+
# keys - a list of key names sepearated by spaces
|
|
206
|
+
# values - values for the respective keys, sepearated by spaces
|
|
207
|
+
#
|
|
208
|
+
# example:
|
|
209
|
+
# token_set MY_TOKEN firstKey secondKey thirdKey - firstValue secondValue thridValue
|
|
210
|
+
function token_set() {
|
|
211
|
+
local token_name="$1"
|
|
212
|
+
declare -g -A "$token_name"
|
|
213
|
+
shift
|
|
214
|
+
|
|
215
|
+
# read the object from arguments
|
|
216
|
+
local token_keys=()
|
|
217
|
+
while [[ "$1" != "-" ]]; do
|
|
218
|
+
token_keys+=("$1")
|
|
219
|
+
shift
|
|
220
|
+
done
|
|
221
|
+
shift
|
|
222
|
+
local token_values=("$@")
|
|
223
|
+
|
|
224
|
+
for ((index = 0; index < ${#token_keys[@]}; index++)); do
|
|
225
|
+
eval "$token_name[${token_keys[$index]}]=${token_values[$index]}"
|
|
226
|
+
done
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function run_build_scripts_typecheck() {
|
|
230
|
+
start_time=$(date +%s)
|
|
231
|
+
TEMPORARY_LOG_FILE_PATH="scripts_typecheck.log"
|
|
232
|
+
|
|
233
|
+
# Build scripts with tsc to get results of type checking
|
|
234
|
+
export DESIGN_SYSTEM_GLOBAL_COMPILER="tsc --noEmit"
|
|
235
|
+
export DESIGN_SYSTEM_GLOBAL_FORCE_TRANSPILE="true"
|
|
236
|
+
export DESIGN_SYSTEM_PREVENT_CHILD_PROCESS_KILL_AND_EXIT_ON_FAILURE="true"
|
|
237
|
+
|
|
238
|
+
yarn build:scripts | tee -a "$TEMPORARY_LOG_FILE_PATH" || true
|
|
239
|
+
|
|
240
|
+
# Count the number of compile errors and remove leading spaces from the count
|
|
241
|
+
compile_errors_count=$(grep "error TS" "$TEMPORARY_LOG_FILE_PATH" | wc -l | tr -d ' ')
|
|
242
|
+
|
|
243
|
+
# Delete log file
|
|
244
|
+
rm -f "$TEMPORARY_LOG_FILE_PATH"
|
|
245
|
+
end_time=$(date +%s)
|
|
246
|
+
elapsed_time=$((end_time - start_time))
|
|
247
|
+
elapsed="[$((elapsed_time / 60))m:$((elapsed_time % 60))s]"
|
|
248
|
+
|
|
249
|
+
# Exit with error if there are any compile errors
|
|
250
|
+
if [ "$compile_errors_count" -gt 0 ]; then
|
|
251
|
+
if [ "$compile_errors_count" -eq 1 ]; then
|
|
252
|
+
echo "There is 1 compile error $elapsed"
|
|
253
|
+
else
|
|
254
|
+
echo "There are $compile_errors_count compile errors $elapsed"
|
|
255
|
+
fi
|
|
256
|
+
exit 1
|
|
257
|
+
else
|
|
258
|
+
echo "No compile errors $elapsed"
|
|
259
|
+
fi
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
# description:
|
|
263
|
+
# parses process arguments into an associative array
|
|
264
|
+
# usage:
|
|
265
|
+
# parse_arguments <variable arguments>
|
|
266
|
+
# where:
|
|
267
|
+
# variable arguments - all the arguments passed to the script
|
|
268
|
+
function parse_arguments() {
|
|
269
|
+
unset PROCESS_ARGUMENTS
|
|
270
|
+
declare -g -A "PROCESS_ARGUMENTS"
|
|
271
|
+
while [ $# -gt 0 ]; do
|
|
272
|
+
local argument_name=$(cut -d '=' -f 1 <<< "$1")
|
|
273
|
+
local argument_value=$(cut -d '=' -f 2- <<< "$1")
|
|
274
|
+
|
|
275
|
+
if [ "$argument_name" = "$argument_value" ]; then
|
|
276
|
+
unset argument_value
|
|
277
|
+
fi
|
|
278
|
+
|
|
279
|
+
PROCESS_ARGUMENTS[$argument_name]="${argument_value:-true}"
|
|
280
|
+
shift
|
|
281
|
+
done
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
# description:
|
|
285
|
+
# Adds an override of default esbuild's behaviour of exporting a class with getters
|
|
286
|
+
# instead of plain object.
|
|
287
|
+
# usage:
|
|
288
|
+
# fix_exports --object=<object name> --file=<file name>
|
|
289
|
+
# where:
|
|
290
|
+
# object name - a default export class object name in cjs file
|
|
291
|
+
# file name - a cjs file path to fix exports in
|
|
292
|
+
function fix_exports() {
|
|
293
|
+
parse_arguments "$@"
|
|
294
|
+
|
|
295
|
+
printf "module.exports = %s;\n" "${PROCESS_ARGUMENTS['--object']}" >> "\
|
|
296
|
+
${PROCESS_ARGUMENTS['--file']}"
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
# description:
|
|
300
|
+
# A family of logging functions for different scenarios
|
|
301
|
+
# usage:
|
|
302
|
+
# logger_[raw|debug|info|warn|error] "<message>"
|
|
303
|
+
# where:
|
|
304
|
+
# message - a message to be logged according to selected severity
|
|
305
|
+
alias logger_raw=echo
|
|
306
|
+
|
|
307
|
+
function logger_log() {
|
|
308
|
+
printf "%s %s\n" "$(date +"%Y-%m-%d %T")" "$1"
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function logger_debug() {
|
|
312
|
+
logger_log "debug: $1"
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function logger_info() {
|
|
316
|
+
local color=$GREEN
|
|
317
|
+
if [[ $CI == "true" ]]; then
|
|
318
|
+
color=$NO_COLOR
|
|
319
|
+
fi
|
|
320
|
+
printf "$color%s$NO_COLOR\n" "$(logger_log "info: $1")"
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function logger_warn() {
|
|
324
|
+
local color=$YELLOW
|
|
325
|
+
if [[ $CI == "true" ]]; then
|
|
326
|
+
color=$NO_COLOR
|
|
327
|
+
fi
|
|
328
|
+
printf "$color%s$NO_COLOR\n" "$(logger_log "warn: $1")"
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function logger_error() {
|
|
332
|
+
local color=$RED
|
|
333
|
+
if [[ $CI == "true" ]]; then
|
|
334
|
+
color=$NO_COLOR
|
|
335
|
+
fi
|
|
336
|
+
printf "$color%s$NO_COLOR\n" "$(logger_log "error: $1")"
|
|
337
|
+
}
|