@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/LICENSE +7 -0
  3. package/README.md +56 -0
  4. package/add_sandbox_upstream/add_sandbox_upstream.sh +32 -0
  5. package/buildUsingEsbuild/buildUsingEsbuild.js +54 -0
  6. package/bump_version/.versionrc.js +20 -0
  7. package/bump_version/bump_version.sh +93 -0
  8. package/clean/clean.sh +61 -0
  9. package/copy_package_build_to_project/copy_package_build_to_project.sh +46 -0
  10. package/delete_and_fetch_git_tags/delete_and_fetch_git_tags.sh +35 -0
  11. package/docker/docker.sh +68 -0
  12. package/docker/docker_utils.sh +143 -0
  13. package/download_design_system_package/download_design_system_package.sh +41 -0
  14. package/enrich_changelog_with_dependency_changes/enrich_changelog_with_dependency_changes.sh +289 -0
  15. package/find_all_javascript_files/find_all_javascript_files.sh +76 -0
  16. package/find_and_parse_environmental_variable_files/find_and_parse_environmental_variable_files.sh +180 -0
  17. package/find_references/find_references.sh +50 -0
  18. package/generateIndexFilesFromTemplate/generateIndexFilesFromTemplate.js +419 -0
  19. package/get_package_info/get_package_info.sh +103 -0
  20. package/git_user_stats/git_user_stats.sh +95 -0
  21. package/index.js +1 -0
  22. package/is_branch_rebased/is_branch_rebased.sh +44 -0
  23. package/last_release_commits/last_release_commits.sh +101 -0
  24. package/list_all_installed_dependencies/list_all_installed_dependencies.sh +40 -0
  25. package/package.json +14 -0
  26. package/prepare_obligatory_package_files/prepare_obligatory_package_files.sh +61 -0
  27. package/publish/publish.sh +89 -0
  28. package/removeGitHashesFromMarkdownFile/removeGitHashesFromMarkdownFile.js +50 -0
  29. package/remove_all_node_modules/remove_all_node_modules.sh +26 -0
  30. package/remove_all_scripts_in_single_workspace/remove_all_scripts_in_single_workspace.sh +62 -0
  31. package/reverse_proxy/README.md +102 -0
  32. package/reverse_proxy/clean.sh +8 -0
  33. package/reverse_proxy/configuration.sh +5 -0
  34. package/reverse_proxy/generate_certificates.sh +140 -0
  35. package/reverse_proxy/localhost.ext.template +12 -0
  36. package/reverse_proxy/nginx_domain_ssl_reverse_proxy.conf.template +89 -0
  37. package/reverse_proxy/openssl.conf +21 -0
  38. package/reverse_proxy/reverse_proxy.sh +48 -0
  39. package/runShellScript/runShellScript.js +49 -0
  40. package/source_environment_variables/source_environment_variables.sh +38 -0
  41. package/sync_sandbox_with_upstream/sync_sandbox_with_upstream.sh +53 -0
  42. package/testIncorrectValues/testIncorrectValues.js +51 -0
  43. package/typescript_usage_statistics/typescript_usage_statistics.sh +35 -0
  44. package/utils.sh +337 -0
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname $0)/../utils.sh" || exit 1
4
+
5
+ function usage() {
6
+ cat << END
7
+ Usage:
8
+ ./bump_version.sh [--help] [--prerelease] [--package-json-transform=transform_string] [--include-dependency-changes] [--dry-run]
9
+ Where:
10
+ help - show usage information and exit
11
+ package-json-transform - optional string with jq transforms that will be applied
12
+ to package.json *before* upgrading version
13
+ prerelease - create a release candidate for the package
14
+ include-dependency-changes - include dependency changes in changelog (default: off)
15
+ dry-run - run standard-version in dry run mode
16
+ Description:
17
+ Bumps semantic version of the package using
18
+ standard-version (https://www.npmjs.com/package/standard-version)
19
+
20
+ Note:
21
+ * assumes standard-version is installed
22
+ in the package that uses bump_version script
23
+ * it does note generate changelog
24
+ * you can override/adjust standard-version .versionrs.js configuration file
25
+ options via command-line parameters
26
+ (see: https://github.com/conventional-changelog/standard-version?tab=readme-ov-file#configuration)
27
+ END
28
+ }
29
+
30
+ function main() {
31
+ parse_arguments "$@"
32
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
33
+ usage
34
+ exit 0
35
+ fi
36
+
37
+ local dry_run_arg=()
38
+ if [ ${PROCESS_ARGUMENTS['--dry-run']} ]; then
39
+ dry_run_arg+=("--dry-run")
40
+ fi
41
+
42
+ if [ ${PROCESS_ARGUMENTS['--package-json-transform']} ]; then
43
+ jq --raw-output "${PROCESS_ARGUMENTS['--package-json-transform']}" package.json > package.json.tmp \
44
+ && mv package.json.tmp package.json
45
+ fi
46
+
47
+ local -r current_script_directory="$(dirname "${BASH_SOURCE[0]}")"
48
+ cp "$current_script_directory"/.versionrc.js .
49
+
50
+ # Set environment variable for changelog enrichment if flag is set
51
+ if [ ${PROCESS_ARGUMENTS['--include-dependency-changes']} ]; then
52
+ export TRACK_DEPENDENCIES=true
53
+ # Ensure the enrichment script is executable
54
+ chmod +x "$current_script_directory/../enrich_changelog_with_dependency_changes/enrich_changelog_with_dependency_changes.sh"
55
+ fi
56
+
57
+ local -r package_name="$(basename "$(pwd)")"
58
+ local -r package_tag_prefix="$package_name-"
59
+ # {{currentTag}} comes from standard-version
60
+ # Example release commit format:
61
+ # chore: Release eslint-config version 1.2.4
62
+ local -r release_commit_message="chore($package_name): Release $package_name version {{currentTag}}"
63
+
64
+ if [ ${PROCESS_ARGUMENTS['--prerelease']} ]; then
65
+ # Sanitize branch name to be semver compliant
66
+ local -r current_branch_name=$(git rev-parse --abbrev-ref HEAD | sed -E -e 's/[^a-zA-Z0-9]+/-/g' -e 's/^-//' -e 's/-$//' -e 's/\./-/g')
67
+ ./node_modules/.bin/standard-version \
68
+ "${dry_run_arg[@]}" \
69
+ --releaseCommitMessageFormat="$release_commit_message" \
70
+ --tag-prefix="$package_tag_prefix" \
71
+ --skip.changelog \
72
+ --prerelease "$current_branch_name-rc"
73
+ else
74
+ release_tags_for_package=$(git tag | grep "$package_tag_prefix""[[:digit:]]")
75
+
76
+ if [[ -z $release_tags_for_package ]]; then
77
+ # No tags found for the package → do the first release
78
+ printf "Doing first release of the package\n"
79
+ ./node_modules/.bin/standard-version \
80
+ "${dry_run_arg[@]}" \
81
+ --first-release \
82
+ --releaseCommitMessageFormat="$release_commit_message" \
83
+ --tag-prefix="$package_tag_prefix"
84
+ else
85
+ ./node_modules/.bin/standard-version \
86
+ "${dry_run_arg[@]}" \
87
+ --releaseCommitMessageFormat="$release_commit_message" \
88
+ --tag-prefix="$package_tag_prefix"
89
+ fi
90
+ fi
91
+ }
92
+
93
+ main "$@"
package/clean/clean.sh ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname "$0")/../utils.sh" || exit 1
4
+
5
+ function usage() {
6
+ cat << END
7
+ Usage:
8
+ ${BASH_SOURCE[0]} [--remove-env] [--dry-run] [--help]
9
+ Where:
10
+ help - whether to print usage information and exit
11
+ remove-env - also remove '.env' files (caution!)
12
+ dry-run - show what would be removed without actually deleting
13
+ Description:
14
+ Removes all untracked files from the repository, with an
15
+ exception of '.env' files, which may contain crucial tokens.
16
+ In order to remove '.env' files too, use an appropriate
17
+ argument switch.
18
+ END
19
+ }
20
+
21
+ function conditional_remove() {
22
+ local file="$1"
23
+ local dry_run="$2"
24
+
25
+ logger_info "Removing $file"
26
+ [ ! $dry_run ] && rm -r "$file"
27
+ }
28
+
29
+ function main() {
30
+ parse_arguments "$@"
31
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
32
+ usage
33
+ exit 0
34
+ fi
35
+
36
+ local dry_run=${PROCESS_ARGUMENTS['--dry-run']}
37
+ local files=$(git clean -Xd --dry-run | sed "s/Would\ remove\ //")
38
+
39
+ if [ $dry_run ]; then
40
+ logger_info "DRY RUN MODE - No files will be deleted"
41
+ fi
42
+
43
+ for file in ${files[@]}; do
44
+ if [ -z ${file%.env*} ]; then
45
+ # This is a .env file - only remove if --remove-env flag is set
46
+ if [ ${PROCESS_ARGUMENTS['--remove-env']} ]; then
47
+ conditional_remove "$file" "$dry_run"
48
+ else
49
+ logger_info "Skipping $file (use --remove-env to remove)"
50
+ fi
51
+ elif [[ "$file" != "node_modules"* ]]; then
52
+ conditional_remove "$file" "$dry_run"
53
+ fi
54
+ done
55
+
56
+ if [ $dry_run ]; then
57
+ logger_info "DRY RUN COMPLETE - No files were deleted"
58
+ fi
59
+ }
60
+
61
+ main "$@"
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname "$0")/../utils.sh" || exit 1
4
+
5
+ function usage() {
6
+ cat << END
7
+ Usage:
8
+ ./copy_to_project.sh [--help] <--node-module-path> <--project-path>
9
+ Where:
10
+ help - show usage information and exit
11
+ node-module-path - relative path of the folder in node_modeles where built project is located
12
+ eg. @mservicestech/utils or @mbank-design/design-system
13
+ project-path - path of project package to which the build should be copied
14
+ Description:
15
+ Copies the built project to the node_modules of project specified
16
+ in --project-path, to the folder specified by --node-module-path
17
+
18
+ Note:
19
+ * assumes the project to copy is already built
20
+ END
21
+ }
22
+
23
+ function main() {
24
+ parse_arguments "$@"
25
+ if [ "${PROCESS_ARGUMENTS['--help']}" ]; then
26
+ usage
27
+ exit 0
28
+ fi
29
+
30
+ if ! [ "${PROCESS_ARGUMENTS['--node-module-path']}" ]; then
31
+ printf "No path in node_modules where files should be copied provided. Run with '--help' for more information.\n"
32
+ exit 0
33
+ fi
34
+
35
+ if ! [ "${PROCESS_ARGUMENTS['--project-path']}" ]; then
36
+ printf "No project path was provided. Pass relative path to target package in --project-path argument. Run with '--help' for more information.\n"
37
+ exit 0
38
+ fi
39
+
40
+ rm -rf "${PROCESS_ARGUMENTS['--project-path']}"/node_modules/"${PROCESS_ARGUMENTS['--node-module-path']}"
41
+ mkdir -p "${PROCESS_ARGUMENTS['--project-path']}"/node_modules/"${PROCESS_ARGUMENTS['--node-module-path']}"
42
+ cp -rp build/* "${PROCESS_ARGUMENTS['--project-path']}"/node_modules/"${PROCESS_ARGUMENTS['--node-module-path']}"
43
+ echo "Sucessfully copied build to: ${PROCESS_ARGUMENTS['--project-path']}"/node_modules/"${PROCESS_ARGUMENTS['--node-module-path']}"
44
+
45
+ }
46
+ main "$@"
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname $0)/../utils.sh" || exit 1
4
+
5
+ function usage() {
6
+ cat << END
7
+ Usage:
8
+ ./delete_and_fetch_git_tags.sh [--help]
9
+ Where:
10
+ help - print usage information and exit
11
+ Description:
12
+ Deletes and fetches all git tags. Run to make sure all local tags match remote
13
+ tags and because our release system depends on tags.
14
+
15
+ Note: this is needed for standard-version (release tool) to work correctly
16
+ and is a workaround for https://github.com/actions/checkout/issues/290
17
+
18
+ Without this script, tags would not be properly added to the release after.
19
+
20
+ It should be run *before* standard-version.
21
+ END
22
+ }
23
+
24
+ function main() {
25
+ parse_arguments "$@"
26
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
27
+ usage
28
+ exit 0
29
+ fi
30
+
31
+ git tag --list | xargs git tag --delete
32
+ git fetch --all --tags
33
+ }
34
+
35
+ main "$@"
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname $0)/../utils.sh" || exit 1
4
+ source "$(dirname $0)/docker_utils.sh" || exit 1
5
+
6
+ usage() {
7
+ cat << END
8
+ Usage:
9
+ ${BASH_SOURCE[0]} [--help] <--action> [--build-directory] [--port-map] [--arguments]
10
+ Where:
11
+ help - print usage information and exit
12
+ action - an action to perform, one of 'build', 'push' or 'run'
13
+ build-directory - the build directory from which to operate, default 'build'
14
+ port-map - a port mapping for the 'run' action, e.g "8080:80"
15
+ arguments - quoted list of arguments to pass into Docker runtime
16
+ organization - a GitHub organization name for tag fetching
17
+ Description:
18
+ Performs a specified action with a docker image. Build, run or
19
+ push the image to the remote repository.
20
+ END
21
+ }
22
+
23
+ function main() {
24
+ parse_arguments "$@"
25
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
26
+ usage
27
+ exit 0
28
+ fi
29
+
30
+ if ! [ ${PROCESS_ARGUMENTS['--action']} ]; then
31
+ printf "No action provided. Run with '--help' for more information.\n"
32
+ exit 1
33
+ fi
34
+ if ! [ ${PROCESS_ARGUMENTS['--organization']} ]; then
35
+ printf "No organization provided. Run with '--help' for more information.\n"
36
+ exit 1
37
+ fi
38
+
39
+ local tag_names
40
+ tag_names=$(get_container_image_names "${PROCESS_ARGUMENTS['--organization']}")
41
+
42
+ if [ -z "$tag_names" ]; then
43
+ printf "No tag names found. Exiting.\n"
44
+ exit 1
45
+ fi
46
+
47
+ case ${PROCESS_ARGUMENTS['--action']} in
48
+ "build")
49
+ docker_build \
50
+ --tag-names="$tag_names" \
51
+ --build-directory="${PROCESS_ARGUMENTS['--build-directory']:-"build"}" \
52
+ --arguments="${PROCESS_ARGUMENTS['--arguments']}"
53
+ ;;
54
+ "push")
55
+ docker_push \
56
+ --tag-names="$tag_names" \
57
+ --arguments="${PROCESS_ARGUMENTS['--arguments']}"
58
+ ;;
59
+ "run")
60
+ docker_run_latest \
61
+ --tag-names="$tag_names" \
62
+ --port-mapping="${PROCESS_ARGUMENTS['--port-map']:-"8080:80"}" \
63
+ --arguments="${PROCESS_ARGUMENTS['--arguments']}"
64
+ ;;
65
+ esac
66
+ }
67
+
68
+ main "$@"
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env bash
2
+ source "$(dirname $0)/../utils.sh" || exit 1
3
+
4
+ # description:
5
+ # creates a list of container image names based on the current project name and version
6
+ # usage:
7
+ # get_container_image_names organization_name
8
+ # returns:
9
+ # a list of container image names separated by spaces
10
+ function get_container_image_names() {
11
+ organization_name="$1"
12
+
13
+ # Project name from package.json, without namespace prefix
14
+ # (e.g. @organization/project-name --> project-name)
15
+ project_name=$(grep name package.json \
16
+ | head -1 \
17
+ | awk --field-separator=: '{ print $2 }' \
18
+ | awk --field-separator=/ '{ print $2 }' \
19
+ | sed 's/[", ]//g')
20
+
21
+ # Package version from package.json
22
+ package_version=$(grep version package.json \
23
+ | head -1 \
24
+ | awk --field-separator=: '{ print $2 }' \
25
+ | sed 's/[", ]//g')
26
+
27
+ container_tags=$(printf "ghcr.io/%s/%s:%s ghcr.io/%s/%s:latest" \
28
+ "$organization_name" "$project_name" "$package_version" \
29
+ "$organization_name" "$project_name")
30
+
31
+ echo "$container_tags"
32
+ }
33
+
34
+ # description:
35
+ # Pushes container images to the container registry
36
+ # Note: it assumes that the user is already logged in into the container registry
37
+ # usage:
38
+ # docker_push --tag-names="<tag name 1> <tag name 2> ..."
39
+ # where:
40
+ # tag names - a list of container image names separated by spaces
41
+ # requirements:
42
+ # GITHUB_USER environment variable must be set
43
+ # NPM_TOKEN environment variable must be set
44
+ # returns:
45
+ # 0 if successful
46
+ # 1 if unsuccessful
47
+ function docker_push() {
48
+ if [ -z "$GITHUB_USER" ]; then printf "You need to define GITHUB_USER variable\n" && return 1; fi
49
+ if [ -z "$NPM_TOKEN" ]; then printf "You need to define NPM_TOKEN variable\n" && return 1; fi
50
+
51
+ parse_arguments "$@"
52
+
53
+ local tag_names="${PROCESS_ARGUMENTS['--tag-names']}"
54
+ printf "Pushing container with tags:\n%s\n" "$(echo "$tag_names" | sed 's/ /\n/g')"
55
+
56
+ docker_command_return_code=-1
57
+ for tag in $tag_names; do
58
+ if [[ "$tag" =~ ^ghcr.io.* ]] || [[ "$tag" =~ ^eu.gcr.io.* ]]; then
59
+ echo "Pushing $tag"
60
+ docker push "$tag"
61
+ docker_command_return_code=$?
62
+ fi
63
+ if [ $docker_command_return_code -ne 0 ]; then
64
+ break
65
+ fi
66
+ done
67
+ exit $docker_command_return_code
68
+ }
69
+
70
+ # description:
71
+ # builds a container image
72
+ # usage:
73
+ # docker_build --tag-names="<tag name 1> <tag name 2> ..." --build-directory="<build directory name>"
74
+ # where:
75
+ # tag names - a list of container image names separated by spaces
76
+ # build directory name - a name of the directory where the build is located
77
+ # requirements:
78
+ # build directory must exist
79
+ # returns:
80
+ # 0 if successful
81
+ # 1 if unsuccessful
82
+ function docker_build() {
83
+
84
+ parse_arguments "$@"
85
+
86
+ local tag_names="${PROCESS_ARGUMENTS['--tag-names']}"
87
+ local build_directory_name="${PROCESS_ARGUMENTS['--build-directory']}"
88
+ local arguments="${PROCESS_ARGUMENTS['--arguments']}"
89
+
90
+ printf "Building container with tags: %s\n" "$(echo "$tag_names" | sed 's/ /\n/g')"
91
+
92
+ if [ ! -d "$build_directory_name" ]; then
93
+ printf "Directory 'build' does not exist. You have to build the application before building the Docker image\n"
94
+ exit 1
95
+ fi
96
+
97
+ docker_command_return_code=-1
98
+ for tag in $tag_names; do
99
+ if [[ "$tag" =~ ^ghcr.io.* ]] || [[ "$tag" =~ ^eu.gcr.io.* ]]; then
100
+ docker build --tag "$tag" --file Dockerfile "$arguments"
101
+ docker_command_return_code=$?
102
+ fi
103
+ if [ $docker_command_return_code -ne 0 ]; then
104
+ break
105
+ fi
106
+ done
107
+ exit $docker_command_return_code
108
+ }
109
+
110
+ # description:
111
+ # runs a container image with the latest tag
112
+ # usage:
113
+ # docker_run_latest --tag-names="<tag name 1> <tag name 2> ..." --port-mapping="<port mapping>" --environment-variables-file="<environment variables file>"
114
+ # where:
115
+ # tag names - a list of container image names separated by spaces
116
+ # port mapping - a port mapping in the format <host port>:<container port>
117
+ # environment variables file - a path to a file with environment variables
118
+ # returns:
119
+ # 0 if successful
120
+ # 1 if unsuccessful
121
+ function docker_run_latest() {
122
+
123
+ parse_arguments "$@"
124
+
125
+ local port_mapping="${PROCESS_ARGUMENTS['--port-mapping']}"
126
+ local environment_variables_file="${PROCESS_ARGUMENTS['--environment-variables-file']}"
127
+ local tag_names="${PROCESS_ARGUMENTS['--tag-names']}"
128
+ local environment_variables_file_flag=""
129
+
130
+ if [ ! -z "$environment_variables_file" ]; then
131
+ environment_variables_file_flag="--env-file $environment_variables_file"
132
+ fi
133
+
134
+ for tag in $tag_names; do
135
+ if [[ "$tag" =~ ^ghcr.io.* ]] && [[ "$tag" =~ :latest$ ]]; then
136
+ printf "Running container with tags: %s\n" "$(echo "$tag_names" | sed 's/ /\n/g')"
137
+ docker run --tty --init --interactive \
138
+ --publish "$port_mapping" \
139
+ "$environment_variables_file_flag" "$arguments" "$tag"
140
+ break
141
+ fi
142
+ done
143
+ }
@@ -0,0 +1,41 @@
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] <--version=<version>>
9
+ Where:
10
+ help - print usage information and exit
11
+ scope - design system package scope
12
+ version - design-system version (e.g. 26.1.0)
13
+ Description:
14
+ Downloads design-system package in 'tgz' format to current location.
15
+ END
16
+ }
17
+
18
+ function main() {
19
+ parse_arguments "$@"
20
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
21
+ usage
22
+ exit 0
23
+ fi
24
+ if ! [ ${PROCESS_ARGUMENTS['--scope']} ]; then
25
+ printf "Package scope was not provided. Run with '--help' for more information."
26
+ exit 1
27
+ fi
28
+
29
+ echo "Getting link..."
30
+ link=$(npm view @${PROCESS_ARGUMENTS['--scope']}/design-system@"${PROCESS_ARGUMENTS['--version']}" dist.tarball)
31
+ echo "Downloading the package..."
32
+ curl \
33
+ --location \
34
+ --header "Authorization: Bearer $NPM_TOKEN" \
35
+ -X GET "$link" \
36
+ --output design-system-"${PROCESS_ARGUMENTS['--version']}".tgz
37
+
38
+ echo "Saved in $(pwd) as design-system-${PROCESS_ARGUMENTS['--version']}.tgz"
39
+ }
40
+
41
+ main "$@"