@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,102 @@
1
+ # Reverse-proxy scripts
2
+
3
+ ## Introduction
4
+
5
+ These scripts are used for setting up and running a reverse proxy for multiple packages using NGINX.
6
+ The configuration provided runs several endpoint proxies using SSL:
7
+
8
+ | endpoint | target | description |
9
+ | ------------------------------ | ---------------- | -------------------- |
10
+ | / (root) | `localhost:8080` | frontend application |
11
+ | /api/mkanon | `localhost:9000` | mKanon API |
12
+ | /api/styleguide | `localhost:4000` | Styleguide API |
13
+ | /api/content-management-system | `localhost:1337` | Headless CMS API |
14
+
15
+ > **NOTE: This configuration will also redirect all `http` traffic to `https`.**
16
+
17
+ ## Prerequisites
18
+
19
+ You may need to install the following packages on your system first:
20
+
21
+ - openssl
22
+ - nginx
23
+
24
+ ## Quick start
25
+
26
+ After the initial setup as described in the section below, run the "./run_proxy.sh" script providing
27
+ the backend access token for the CMS as in the example:
28
+
29
+ ```console
30
+ ./run_proxy.sh [--help]
31
+ ```
32
+
33
+ In order to stop the server run the script with the following flag:
34
+
35
+ ```console
36
+ ./run_proxy.sh --stop
37
+ ```
38
+
39
+ ## Setting up development environment
40
+
41
+ 1. Start the needed applications:
42
+
43
+ | application | port | notes |
44
+ | -------------- | ---- | ---------------------------------------------------------------------------- |
45
+ | frontend | 8080 | run the application start script - make sure the port is `8080` |
46
+ | Headless CMS | 1337 | generate [Strapi API Token](http://localhost:1337/admin/settings/api-tokens) |
47
+ | Styleguide API | 4000 | use `yarn start:local` in `packages/styleguide-api` |
48
+ | mKanon API | 9000 | run the external development server |
49
+
50
+ 2. Generate certificates:
51
+
52
+ Run the following script:
53
+
54
+ ```console
55
+ ./generate_certificates.sh --passphrase="mservices"
56
+ ```
57
+
58
+ Then, follow the instructions shown by the script.
59
+
60
+ > **NOTE: The instructions provided are Windows specific.**
61
+
62
+ 3. Add a new hosts entry:
63
+
64
+ > **NOTE: The following method is Windows specific - this step can be skipped.**
65
+
66
+ Run the following command in elevated (administrator) PowerShell:
67
+
68
+ ```console
69
+ Add-Content -Path $Env:SystemRoot\System32\drivers\etc\hosts -Value "127.0.0.1 development.local"
70
+ ```
71
+
72
+ By doing this, you ensure resolution of `development.local` address to `localhost`.
73
+
74
+ 4. Run proxy server:
75
+
76
+ ```console
77
+ ./run_proxy.sh [--help]
78
+ ```
79
+
80
+ A backend access token for Strapi CMS can be provided to the script using either the `BACKEND_ACCESS_TOKEN` environment variable, or using the `--token` flag as above.
81
+
82
+ 5. Test the frontend:
83
+
84
+ Open [development.local](https://development.local/) in your browser.
85
+
86
+ 6. Test the backend:
87
+
88
+ Make a request to any of the backend endpoints (in this example, we are using Strapi):
89
+
90
+ ```console
91
+ # should reply 'HTTP/1.1 204 No Content'
92
+ curl --location --insecure --head development.local/content-management-system/\_health
93
+ ```
94
+
95
+ 7. You should now be able to access the services at the following addresses:
96
+
97
+ | service | URL |
98
+ | ---------------- | ------------------------------------------------------------------------------------------------------------ |
99
+ | frontend | [development.local/](https://development.local) |
100
+ | mKanon API | [development.local/api/mkanon](https://development.local/api/mkanon) |
101
+ | Styleguide API | [development.local/api/styleguide](https://development.local/api/styleguide) |
102
+ | Headless CMS API | [development.local/api/content-management-system/](https://development.local/api/content-management-system/) |
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname $0)/configuration.sh" || exit 1
4
+
5
+ rm -rf "$CERTFICATES_DIRECTORY/*.{crt,csr,key,ext}"
6
+ rm -rf "$CERTFICATES_DIRECTORY/*.{pem,srl,pfx}"
7
+
8
+ rm -rf "$(dirname $0)/nginx_domain_ssl_reverse_proxy.conf"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ export CERTFICATES_DIRECTORY="$(dirname $0)/certificates"
4
+ export CERTFICATE_AUTHORITY_FILE_NAME="custom_certificate_authority"
5
+ export DOMAIN_NAME="localhost"
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname $0)/../utils.sh" || exit 1
4
+ source "$(dirname $0)/configuration.sh" || exit 1
5
+
6
+ with_underline=$(tput smul)
7
+ without_underline=$(tput rmul)
8
+
9
+ windows_installation_instructions="Import the %s into the Trusted Certificate Authorities of Windows:
10
+
11
+ 1. Open (double-click) both 'custom_certificate_authority.pfx' and 'localhost.crt' files
12
+ 2. Select \"Local Machine\" and Next
13
+ 3. Next again
14
+ 4. Enter the password \"%s\" and then click Next
15
+ 5. Select \"Place all certificates int he following store:\"
16
+ 6. Click on Browse
17
+ 7. Choose \"Trusted Root Certification Authorities\", click on Next
18
+ 8. Click on Finish
19
+
20
+ Now your CA certificate will be automatically trusted by Windows and Chrome.
21
+
22
+ To uninstall the certificate authority:
23
+ 1. Open \"certmgr.msc\"
24
+ 2. Select \"Trusted Root Certification Authorities\" in the left panel
25
+ 3. Open \"Certificates\" in the main window
26
+ 4. Right-click on \"localhost development certificate\" and choose \"delete\"
27
+ \n"
28
+
29
+ macos_installation_instructions="Update the trust settings of each certificate to \"Always trust\" in MacOS:
30
+
31
+ 1. Double click the files \"localhost.crt\" and \"custom_certificate_authority.pem\" and install both
32
+ 2. When asked for key passphrase enter \"%s\"
33
+ 3. Go to \"System > System Keychain > Certificates\"
34
+ 4. Right click on both \"localhost development certificate\" entries
35
+ 5. Expand \"Trust\" section and choose \"Always trust\"
36
+ 6. A small, blue \"+\" icon should be visible next to the certificate
37
+
38
+ To uninstall right-click the \"localhost development certificate\" in \"Keychain Access > Certificates\", and choose \"delete\".
39
+ \n"
40
+
41
+ function usage() {
42
+ cat << END
43
+ Usage:
44
+ ./generate_certificates.sh <--passphrase="passphrase"> [--help]
45
+ Where:
46
+ passphrase - private RSA key passphrase
47
+ help - show usage information and exit
48
+ Description:
49
+ Generates a self-signed TLS certificate using an RSA key pair.
50
+ The script also provides a certificate authority file that
51
+ can be used to trust the local proxy on https connections.
52
+ This process is a prerequisite for running the reverse-proxy server.
53
+ END
54
+ }
55
+
56
+ function main() {
57
+ parse_arguments "$@"
58
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
59
+ usage
60
+ exit 0
61
+ elif [ -z ${PROCESS_ARGUMENTS['--passphrase']} ]; then
62
+ printf "Passphrase not provided. Run with '--help' for more information.\n"
63
+ exit 1
64
+ fi
65
+
66
+ if ! [ -d "$CERTFICATES_DIRECTORY" ]; then
67
+ mkdir "$CERTFICATES_DIRECTORY"
68
+ fi
69
+
70
+ # Generate private key
71
+ openssl genrsa \
72
+ -des3 \
73
+ -passout "pass:${PROCESS_ARGUMENTS['--passphrase']}" \
74
+ -out "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.key" \
75
+ 2048 || exit 1
76
+
77
+ # Generate root certificate
78
+ openssl req -x509 \
79
+ -new \
80
+ -config "$(dirname $0)/openssl.conf" \
81
+ -passin "pass:${PROCESS_ARGUMENTS['--passphrase']}" \
82
+ -nodes \
83
+ -key "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.key" \
84
+ -sha256 \
85
+ -days 825 \
86
+ -out "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.pem" || exit 1
87
+
88
+ # Create CA-signed certs
89
+
90
+ # Generate a private key
91
+ openssl genrsa \
92
+ -out "$CERTFICATES_DIRECTORY/$DOMAIN_NAME.key" 2048 || exit 1
93
+
94
+ # Create a certificate-signing request
95
+ openssl req -new \
96
+ -config "$(dirname $0)/openssl.conf" \
97
+ -key "$CERTFICATES_DIRECTORY/$DOMAIN_NAME.key" \
98
+ -out "$CERTFICATES_DIRECTORY/$DOMAIN_NAME.csr" || exit 1
99
+
100
+ # Extension configuration
101
+ envsubst '$DOMAIN_NAME' < "\
102
+ $(dirname $0)/localhost.ext.template" > "\
103
+ $CERTFICATES_DIRECTORY/$DOMAIN_NAME.ext"
104
+
105
+ # Create the signed certificate
106
+ openssl x509 -req \
107
+ -in "$CERTFICATES_DIRECTORY/$DOMAIN_NAME.csr" \
108
+ -passin "pass:${PROCESS_ARGUMENTS['--passphrase']}" \
109
+ -CA "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.pem" \
110
+ -CAkey "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.key" \
111
+ -CAcreateserial \
112
+ -out "$CERTFICATES_DIRECTORY/$DOMAIN_NAME.crt" \
113
+ -days 825 \
114
+ -sha256 \
115
+ -extfile "$CERTFICATES_DIRECTORY/$DOMAIN_NAME.ext"
116
+
117
+ # shellcheck disable=2143
118
+ if [[ $(grep -i Microsoft /proc/version) ]]; then
119
+ printf "Generating .pfx file to to be installed on Windows\n"
120
+
121
+ OUTFILE_PFX="$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.pfx"
122
+
123
+ openssl pkcs12 \
124
+ -export \
125
+ -passin "pass:${PROCESS_ARGUMENTS['--passphrase']}" \
126
+ -passout "pass:${PROCESS_ARGUMENTS['--passphrase']}" \
127
+ -out "$OUTFILE_PFX" \
128
+ -inkey "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.key" \
129
+ -in "$CERTFICATES_DIRECTORY/$CERTFICATE_AUTHORITY_FILE_NAME.pem" || exit 1
130
+
131
+ printf "Generated %s file\n\n" "$OUTFILE_PFX"
132
+
133
+ # shellcheck disable=2059
134
+ printf "$windows_installation_instructions" "${PROCESS_ARGUMENTS['--passphrase']}"
135
+ else
136
+ printf "$macos_installation_instructions" "${PROCESS_ARGUMENTS['--passphrase']}"
137
+ fi
138
+ }
139
+
140
+ main "$@"
@@ -0,0 +1,12 @@
1
+ authorityKeyIdentifier=keyid,issuer
2
+ basicConstraints=CA:FALSE
3
+ keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
4
+ subjectAltName = @alt_names
5
+
6
+ [alt_names]
7
+ # Include the domain name here - Common Name may not be honoured by itself
8
+ DNS.1 = ${DOMAIN_NAME}
9
+ # Optionally, add additional domains (example for a subdomain)
10
+ # DNS.2 = subdomain.${DOMAIN_NAME}
11
+ # Optionally, add an IP address (if the connection requires it)
12
+ # IP.1 = 192.168.0.13
@@ -0,0 +1,89 @@
1
+ # nginx configuration that adds SSL support to local development
2
+ events {
3
+ worker_connections 1024;
4
+ }
5
+
6
+ http {
7
+ include /etc/nginx/conf.d/*.conf;
8
+
9
+ upstream frontend {
10
+ server 127.0.0.1:8080;
11
+ }
12
+
13
+ upstream backend {
14
+ server 127.0.0.1:4000;
15
+ }
16
+
17
+ server {
18
+ listen 80;
19
+ return 301 https://$host$request_uri;
20
+ }
21
+
22
+ server {
23
+ listen 443 ssl;
24
+ server_name localhost;
25
+ access_log /var/log/nginx/development.local.access.log;
26
+ ssl_certificate ${CERTFICATES_DIRECTORY}/${DOMAIN_NAME}.crt;
27
+ ssl_certificate_key ${CERTFICATES_DIRECTORY}/${DOMAIN_NAME}.key;
28
+ ssl_protocols TLSv1.2;
29
+ ssl_prefer_server_ciphers on;
30
+ ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
31
+ ssl_ecdh_curve secp384r1;
32
+ ssl_session_cache shared:SSL:10m;
33
+ ssl_session_tickets off;
34
+ resolver 8.8.8.8 8.8.4.4 valid=300s;
35
+ resolver_timeout 5s;
36
+ add_header X-Content-Type-Options nosniff;
37
+ index index.html;
38
+
39
+ location / {
40
+ proxy_set_header Host $http_host;
41
+ proxy_set_header X-Real-IP $remote_addr;
42
+ proxy_set_header X-NginX-Proxy true;
43
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
44
+ proxy_http_version 1.1;
45
+ proxy_redirect off;
46
+ proxy_buffering off;
47
+ proxy_pass http://localhost:8080/;
48
+ }
49
+
50
+ location /api/styleguide/ {
51
+ proxy_set_header Host $http_host;
52
+ proxy_set_header Upgrade $http_upgrade;
53
+ proxy_set_header Connection "upgrade";
54
+ add_header Access-Control-Allow-Origin "*";
55
+ proxy_set_header X-Real-IP $remote_addr;
56
+ proxy_set_header X-NginX-Proxy true;
57
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
58
+ proxy_http_version 1.1;
59
+ proxy_redirect off;
60
+ proxy_pass http://localhost:4000/api/styleguide/;
61
+ }
62
+
63
+ location /api/mkanon/ {
64
+ proxy_set_header Host $http_host;
65
+ proxy_set_header Upgrade $http_upgrade;
66
+ proxy_set_header Connection "upgrade";
67
+ add_header Access-Control-Allow-Origin "*";
68
+ proxy_set_header X-Real-IP $remote_addr;
69
+ proxy_set_header X-NginX-Proxy true;
70
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
71
+ proxy_http_version 1.1;
72
+ proxy_redirect off;
73
+ proxy_pass http://localhost:9000/;
74
+ }
75
+
76
+ location /api/content-management-system/ {
77
+ proxy_set_header Host $http_host;
78
+ proxy_set_header Upgrade $http_upgrade;
79
+ proxy_set_header Connection "upgrade";
80
+ add_header Access-Control-Allow-Origin "*";
81
+ proxy_set_header X-Real-IP $remote_addr;
82
+ proxy_set_header X-NginX-Proxy true;
83
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
84
+ proxy_http_version 1.1;
85
+ proxy_pass_header Authorization;
86
+ proxy_pass http://localhost:1337/api/;
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,21 @@
1
+ [ req ]
2
+ default_bits = 2048
3
+ prompt = no
4
+ default_md = sha256
5
+ req_extensions = req_ext
6
+ distinguished_name = dn
7
+
8
+ [ dn ]
9
+ C = PL
10
+ ST = maz
11
+ L = Warsaw
12
+ O = mServices sp. z o. o.
13
+ OU = Technology
14
+ CN = localhost development certificate
15
+
16
+ [ req_ext ]
17
+ subjectAltName = @alt_names
18
+
19
+ [ alt_names ]
20
+ DNS.1 = localhost
21
+ DNS.2 = development.local
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source "$(dirname "$0")/../utils.sh" || exit 1
4
+ source "$(dirname "$0")/configuration.sh" || exit 1
5
+
6
+ function usage() {
7
+ cat << END
8
+ Usage:
9
+ ${BASH_SOURCE[0]} [--help] [--stop]
10
+ Where:
11
+ help - print usage information and exit
12
+ stop - stop the NGINX server and exit
13
+
14
+ Description:
15
+ Starts the NGINX server with the configuration taken from
16
+ 'nginx_domain_ssl_reverse_proxy.conf'.
17
+ END
18
+ }
19
+
20
+ function start_server() {
21
+ printf "Generating NGINX config from template...\n"
22
+ envsubst '$CERTFICATES_DIRECTORY,$DOMAIN_NAME' < nginx_domain_ssl_reverse_proxy.conf.template > nginx_domain_ssl_reverse_proxy.conf
23
+
24
+ printf "Starting the reverse proxy server. Logs will be stored in '/var/log/nginx/'\n"
25
+ sudo mkdir -p /var/log/nginx
26
+ sudo chmod -R 755 /var/log/nginx
27
+ sudo nginx -c "$(pwd)"/nginx_domain_ssl_reverse_proxy.conf
28
+ }
29
+
30
+ function stop_server() {
31
+ printf "Stopping NGINX server...\n"
32
+ sudo nginx -s stop 2> /dev/null
33
+ }
34
+
35
+ function main() {
36
+ parse_arguments "$@"
37
+ if [ ${PROCESS_ARGUMENTS['--help']} ]; then
38
+ usage
39
+ exit 0
40
+ elif [ ${PROCESS_ARGUMENTS['--stop']} ]; then
41
+ stop_server
42
+ exit 0
43
+ fi
44
+
45
+ start_server
46
+ }
47
+
48
+ main "$@"