@commercetools-frontend/application-cli 1.0.1 → 1.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/application-cli",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Internal CLI to manage Merchant Center application deployments across various environments.",
5
5
  "keywords": [
6
6
  "commercetools",
@@ -20,18 +20,18 @@
20
20
  "README.md"
21
21
  ],
22
22
  "dependencies": {
23
- "@commercetools-frontend/application-config": "21.3.4",
23
+ "@commercetools-frontend/application-config": "21.21.2",
24
24
  "@manypkg/find-root": "1.1.0",
25
25
  "@manypkg/get-packages": "1.1.3",
26
- "cosmiconfig": "7.0.1",
27
- "dotenv": "16.0.0",
26
+ "cosmiconfig": "8.0.0",
27
+ "dotenv": "16.0.3",
28
28
  "execa": "6.1.0",
29
29
  "listr": "0.14.3",
30
30
  "listr-verbose-renderer": "0.6.0",
31
31
  "lodash.lowerfirst": "4.3.1",
32
32
  "mri": "1.2.0",
33
33
  "node-fetch": "2.6.7",
34
- "prettier": "2.6.2",
34
+ "prettier": "2.8.1",
35
35
  "prompts": "2.4.2",
36
36
  "rcfile": "1.0.3"
37
37
  },
package/src/bin/cli.js CHANGED
@@ -18,7 +18,9 @@ const cwd = process.cwd();
18
18
  'application-index-upload-script-out-file': 'upload-index.sh',
19
19
  'application-assets-upload-script-out-file': 'upload-assets.sh',
20
20
  'application-index-out-file': 'application.html',
21
+ 'skip-menu': false,
21
22
  },
23
+ boolean: ['skip-menu'],
22
24
  });
23
25
  const cliCommands = cliFlags._;
24
26
 
@@ -46,6 +48,7 @@ Options:
46
48
  --application-index-upload-script-out-file <path> (optional) The name of the the application index upload script file. Defaults to upload-index.sh.
47
49
  --application-assets-upload-script-out-file <path> (optional) The name of the the assets upload script file. Defaults to upload-assets.sh.
48
50
  --ci-assets-root-path <path> (optional) A replacement value for the scripts root path only used on CI (e.g. '--ci-assets-root-path=/root/') used in generated scripts.
51
+ --skip-menu (optional) If provided, it will skip uploading the 'menu.json'.
49
52
 
50
53
  Command:
51
54
  compile-menu Compile the menu links of an application into a 'menu.json'. This is only required for internal applications
@@ -84,6 +84,7 @@ async function compileApplicationAssets({ cliFlags, bucketRegion, paths }) {
84
84
  applicationName: cliFlags['application-name'],
85
85
  }),
86
86
  assetsPath: paths.assetsPath,
87
+ skipMenu: cliFlags['skip-menu'],
87
88
  });
88
89
  const parsedApplicationAssetsUploadScriptFile = path.parse(
89
90
  cliFlags['application-assets-upload-script-out-file']
@@ -124,32 +125,42 @@ async function compileEnvironmentApplicationIndexes({
124
125
  applicationName: cliFlags['application-name'],
125
126
  });
126
127
 
128
+ const environmentVariablesForCompilation = {
129
+ ...loadDotenvFiles({
130
+ dotenvPath: paths.dotenvPath,
131
+ cloudEnvironment,
132
+ }),
133
+ // The trailing slash is important to indicate to the CSP directive that all the resources
134
+ // under that path should be allowed.
135
+ MC_CDN_URL: `${cdnUrl}/`,
136
+ ...(cliFlags['mc-url']
137
+ ? {
138
+ MC_URL: cliFlags['mc-url'],
139
+ }
140
+ : {}),
141
+ ...(cliFlags['mc-api-url']
142
+ ? {
143
+ MC_API_URL: cliFlags['mc-api-url'],
144
+ }
145
+ : {}),
146
+ // Will be used by the Application Kit for Sentry and exposed on `window.app.revision`.
147
+ REVISION: cliFlags['build-revision'],
148
+ };
149
+
150
+ /// Sentry and GTM is disabled on branch deployments
151
+ if (cliFlags['pr-number']) {
152
+ process.env.TRACKING_SENTRY = null;
153
+ process.env.TRACKING_GTM = null;
154
+ environmentVariablesForCompilation.TRACKING_SENTRY = null;
155
+ environmentVariablesForCompilation.TRACKING_GTM = null;
156
+ }
157
+
127
158
  // Compile the application using the loaded environment values
128
159
  const compileResult = await execa('mc-scripts', ['compile-html'], {
129
160
  encoding: 'utf8',
130
161
  preferLocal: true,
131
162
  extendEnv: true,
132
- env: {
133
- ...loadDotenvFiles({
134
- dotenvPath: paths.dotenvPath,
135
- cloudEnvironment,
136
- }),
137
- // The trailing slash is important to indicate to the CSP directive that all the resources
138
- // under that path should be allowed.
139
- MC_CDN_URL: `${cdnUrl}/`,
140
- ...(cliFlags['mc-url']
141
- ? {
142
- MC_URL: cliFlags['mc-url'],
143
- }
144
- : {}),
145
- ...(cliFlags['mc-api-url']
146
- ? {
147
- MC_API_URL: cliFlags['mc-api-url'],
148
- }
149
- : {}),
150
- // Will be used by the Application Kit for Sentry and exposed on `window.app.revision`.
151
- REVISION: cliFlags['build-revision'],
152
- },
163
+ env: environmentVariablesForCompilation,
153
164
  });
154
165
 
155
166
  if (compileResult.failed) {
@@ -1,4 +1,8 @@
1
- function createApplicationAssetsUploadScript({ bucketUrl, assetsPath }) {
1
+ function createApplicationAssetsUploadScript({
2
+ bucketUrl,
3
+ assetsPath,
4
+ skipMenu,
5
+ }) {
2
6
  const uploadScriptContent = `#!/usr/bin/env bash
3
7
 
4
8
  set -e
@@ -13,6 +17,7 @@ set -e
13
17
  # 5. The '-n' will skip uploading existing files and prevents them to
14
18
  # be overwritten
15
19
  echo "Uploading static assets to bucket ${bucketUrl}"
20
+
16
21
  gsutil -m \\
17
22
  -h "Cache-Control: public, max-age=31536000, no-transform" \\
18
23
  cp -z js,css \\
@@ -20,39 +25,33 @@ gsutil -m \\
20
25
  ${assetsPath}/public/{*.css,*.js,*.js.map,*.png,*.html,robots.txt} \\
21
26
  "${bucketUrl}"
22
27
 
23
- echo "Uploading menu.json to bucket ${bucketUrl}"
24
- # NOTE: somehow the 'cache-control:private' doesn't work.
25
- # I mean, the file is uploaded with the correct metadata but when I fetch
26
- # the file the response contains the header
27
- # 'cache-control: public, max-age=31536000, no-transform', even though the
28
- # documentation clearly states that by marking the header as 'private' will
29
- # disable the cache (for publicly readable objects).
30
- # https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#cache-control
31
- # However, I found out that, by requesting the file with any RANDOM
32
- # query parameter, will instruct the storage to return a 'fresh' object
33
- # (without any cache control).
34
- # Unofficial source: https://stackoverflow.com/a/49052895
35
- # This seems to be the 'easiest' option to 'disable' the cache for public
36
- # objects. Other alternative approaces are:
37
- # * make the object private with some simple ACL (private objects are not cached)
38
- # * suffix the file name with e.g. the git SHA, so we have different files
39
- # for each upload ('index.html.template-\${CIRCLE_SHA1}'). The server knows
40
- # the git SHA on runtime and can get the correct file when it starts.
41
- # * find out why the 'private' cache control does not work
42
- gsutil \\
43
- -h "Content-Type: application/json" \\
44
- -h "Cache-Control: private, max-age=0, no-transform" \\
45
- cp -z json \\
46
- ${assetsPath}/menu.json \\
47
- ${bucketUrl}
48
-
49
- if [[ -f "${assetsPath}/public/licenses.csv" ]]; then
50
- echo "Uploading licenses.csv to bucket ${bucketUrl}"
28
+ if ${skipMenu}; then
29
+ echo "Skipping menu.json upload"
30
+ else
31
+ echo "Uploading menu.json to bucket ${bucketUrl}"
32
+ # NOTE: somehow the 'cache-control:private' doesn't work.
33
+ # I mean, the file is uploaded with the correct metadata but when I fetch
34
+ # the file the response contains the header
35
+ # 'cache-control: public, max-age=31536000, no-transform', even though the
36
+ # documentation clearly states that by marking the header as 'private' will
37
+ # disable the cache (for publicly readable objects).
38
+ # https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#cache-control
39
+ # However, I found out that, by requesting the file with any RANDOM
40
+ # query parameter, will instruct the storage to return a 'fresh' object
41
+ # (without any cache control).
42
+ # Unofficial source: https://stackoverflow.com/a/49052895
43
+ # This seems to be the 'easiest' option to 'disable' the cache for public
44
+ # objects. Other alternative approaces are:
45
+ # * make the object private with some simple ACL (private objects are not cached)
46
+ # * suffix the file name with e.g. the git SHA, so we have different files
47
+ # for each upload ('index.html.template-\${CIRCLE_SHA1}'). The server knows
48
+ # the git SHA on runtime and can get the correct file when it starts.
49
+ # * find out why the 'private' cache control does not work
51
50
  gsutil \\
52
- -h "Content-Type: text/csv" \\
51
+ -h "Content-Type: application/json" \\
53
52
  -h "Cache-Control: private, max-age=0, no-transform" \\
54
- cp -z csv \\
55
- ${assetsPath}/public/licenses.csv \\
53
+ cp -z json \\
54
+ ${assetsPath}/menu.json \\
56
55
  ${bucketUrl}
57
56
  fi
58
57
  `;