@commercetools-frontend/mc-scripts 21.7.0 → 21.9.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.
Files changed (152) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -42
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +1 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  6. package/{build/config/application-runtime.js → application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js} +2 -2
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  8. package/application-runtime/package.json +4 -0
  9. package/bin/cli.js +1 -1
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +1 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +361 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +361 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +345 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +7 -1
  17. package/config/create-webpack-config-for-production.js +7 -1
  18. package/config/vendors-to-transpile.js +5 -1
  19. package/dist/build-5357ad26.cjs.prod.js +224 -0
  20. package/dist/build-9b6d7eee.cjs.dev.js +224 -0
  21. package/dist/build-c483e87f.esm.js +209 -0
  22. package/dist/build-vite-3b82522e.cjs.dev.js +151 -0
  23. package/dist/build-vite-93abdc95.esm.js +139 -0
  24. package/dist/build-vite-b7cd993a.cjs.prod.js +151 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +1 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +30 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +30 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +22 -0
  30. package/dist/compile-html-4361a0b3.esm.js +77 -0
  31. package/dist/compile-html-d6331c35.cjs.prod.js +87 -0
  32. package/dist/compile-html-d9e731aa.cjs.dev.js +87 -0
  33. package/dist/config-sync-6b31d972.esm.js +840 -0
  34. package/dist/config-sync-a478bc0f.cjs.dev.js +864 -0
  35. package/dist/config-sync-f07734e4.cjs.prod.js +859 -0
  36. package/{build/config/create-postcss-config.js → dist/create-postcss-config-04243dea.esm.js} +27 -25
  37. package/dist/create-postcss-config-760e2dc5.cjs.dev.js +90 -0
  38. package/dist/create-postcss-config-ddc3abee.cjs.prod.js +90 -0
  39. package/dist/create-webpack-config-for-development-76fdab59.cjs.prod.js +419 -0
  40. package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-d93ae4b2.esm.js} +94 -57
  41. package/dist/create-webpack-config-for-development-dfd1c174.cjs.dev.js +419 -0
  42. package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-9290479a.esm.js} +120 -54
  43. package/dist/create-webpack-config-for-production-bc8c1f37.cjs.dev.js +469 -0
  44. package/dist/create-webpack-config-for-production-d652ad1a.cjs.prod.js +469 -0
  45. package/dist/declarations/src/application-runtime.d.ts +1 -0
  46. package/dist/declarations/src/cli.d.ts +4 -0
  47. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  48. package/dist/declarations/src/commands/build.d.ts +2 -0
  49. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  50. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  51. package/dist/declarations/src/commands/login.d.ts +2 -0
  52. package/dist/declarations/src/commands/serve.d.ts +2 -0
  53. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/start.d.ts +2 -0
  55. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  56. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  57. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  58. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  59. package/dist/declarations/src/config/moment-locales.d.ts +2 -0
  60. package/dist/declarations/src/config/paths.d.ts +12 -0
  61. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  62. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  63. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  64. package/dist/declarations/src/generated/core.d.ts +710 -0
  65. package/dist/declarations/src/generated/settings.d.ts +2485 -0
  66. package/dist/declarations/src/index.d.ts +3 -0
  67. package/dist/declarations/src/postcss.d.ts +1 -0
  68. package/dist/declarations/src/types.d.ts +82 -0
  69. package/dist/declarations/src/utils/auth.d.ts +6 -0
  70. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  71. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  72. package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
  73. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  74. package/dist/declarations/src/version.d.ts +2 -0
  75. package/dist/declarations/src/vite-plugins/vite-plugin-custom-application.d.ts +4 -0
  76. package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
  77. package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -0
  78. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  79. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  80. package/dist/declarations/src/webpack.d.ts +2 -0
  81. package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
  82. package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
  83. package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
  84. package/dist/login-7b7ae27e.esm.js +155 -0
  85. package/dist/login-b13f26e7.cjs.dev.js +165 -0
  86. package/dist/login-c11fb977.cjs.prod.js +165 -0
  87. package/dist/package-4b4fcf02.cjs.prod.js +139 -0
  88. package/dist/package-4c3e3fb7.cjs.dev.js +139 -0
  89. package/dist/package-8e6305bd.esm.js +137 -0
  90. package/dist/paths-16823f56.cjs.dev.js +55 -0
  91. package/dist/paths-76b66e74.cjs.prod.js +55 -0
  92. package/dist/paths-ed23d5a1.esm.js +46 -0
  93. package/dist/serve-12de323b.cjs.dev.js +70 -0
  94. package/dist/serve-784f4fcd.cjs.prod.js +70 -0
  95. package/dist/serve-d6b437b1.esm.js +62 -0
  96. package/dist/start-1b7dad90.cjs.prod.js +209 -0
  97. package/dist/start-45ca01f2.cjs.dev.js +209 -0
  98. package/dist/start-600d06a3.esm.js +194 -0
  99. package/dist/start-vite-22de08dc.cjs.dev.js +151 -0
  100. package/dist/start-vite-dc046cba.esm.js +138 -0
  101. package/dist/start-vite-fe13330b.cjs.prod.js +151 -0
  102. package/dist/user-agent-5f8ec93d.cjs.prod.js +106 -0
  103. package/dist/user-agent-ca628320.esm.js +94 -0
  104. package/dist/user-agent-ee57c98a.cjs.dev.js +106 -0
  105. package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
  106. package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
  107. package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
  108. package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +110 -0
  109. package/dist/vite-plugin-svgr-eb8524fa.esm.js +85 -0
  110. package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +110 -0
  111. package/package.json +56 -50
  112. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
  113. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
  114. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  115. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
  116. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
  117. package/postcss/package.json +4 -0
  118. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
  119. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
  120. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  121. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
  122. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
  123. package/webpack/package.json +4 -0
  124. package/build/bin/cli.js +0 -264
  125. package/build/commands/build-vite.js +0 -91
  126. package/build/commands/build.js +0 -140
  127. package/build/commands/compile-html.js +0 -53
  128. package/build/commands/config-sync.js +0 -176
  129. package/build/commands/login.js +0 -60
  130. package/build/commands/serve.js +0 -37
  131. package/build/commands/start-vite.js +0 -138
  132. package/build/commands/start.js +0 -108
  133. package/build/config/paths.js +0 -38
  134. package/build/config/vendors-to-transpile.js +0 -3
  135. package/build/config/webpack-dev-server.config.js +0 -69
  136. package/build/index.js +0 -16
  137. package/build/utils/auth.js +0 -34
  138. package/build/utils/auth.spec.js +0 -61
  139. package/build/utils/create-custom-application.settings.graphql +0 -8
  140. package/build/utils/credentials-storage.js +0 -72
  141. package/build/utils/credentials-storage.spec.js +0 -69
  142. package/build/utils/fetch-custom-application.settings.graphql +0 -36
  143. package/build/utils/fetch-user-organizations.core.graphql +0 -9
  144. package/build/utils/get-config-diff.js +0 -308
  145. package/build/utils/get-config-diff.spec.js +0 -285
  146. package/build/utils/graphql-requests.js +0 -105
  147. package/build/utils/graphql-requests.spec.js +0 -159
  148. package/build/utils/require-graphql.js +0 -15
  149. package/build/utils/update-custom-application.settings.graphql +0 -13
  150. package/build/utils/user-agent.js +0 -15
  151. package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
  152. package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable react-hooks/rules-of-hooks */
4
- const fs = require('fs-extra');
5
-
6
- const path = require('path');
7
-
8
- const {
9
- build
10
- } = require('vite');
11
-
12
- const pluginGraphql = require('@rollup/plugin-graphql');
13
-
14
- const pluginReact = require('@vitejs/plugin-react').default;
15
-
16
- const {
17
- generateTemplate
18
- } = require('@commercetools-frontend/mc-html-template');
19
-
20
- const {
21
- packageLocation: applicationStaticAssetsPath
22
- } = require('@commercetools-frontend/assets');
23
-
24
- const paths = require('../config/paths');
25
-
26
- const DEFAULT_PORT = parseInt(process.env.HTTP_PORT, 10) || 3001;
27
-
28
- const execute = async () => {
29
- // Ensure the `/public` folder exists.
30
- fs.mkdirSync(paths.appBuild, {
31
- recursive: true
32
- }); // Generate `index.html` (template).
33
-
34
- const appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
35
- const html = generateTemplate({
36
- // Define the module entry point (path relative from the `/public` folder).
37
- // NOTE: that this is different from the development configuration.
38
- scriptImports: [`<script type="module" src="/${appEntryPoint}"></script>`]
39
- }); // Write `index.html` (template) into the `/public` folder.
40
-
41
- fs.writeFileSync(paths.appIndexHtml, html, {
42
- encoding: 'utf8'
43
- });
44
- await build({
45
- root: paths.appRoot,
46
- define: {
47
- 'process.env.DEBUG': JSON.stringify(false),
48
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
49
- },
50
- build: {
51
- outDir: 'public',
52
- assetsDir: '.',
53
- rollupOptions: {
54
- // This is necessary to instruct Vite that the `index.html` (template)
55
- // is located in the `/public` folder.
56
- // NOTE that after the build, Vite will write the `index.html` (template)
57
- // at the `/public/public/index.html` location. See `fs.renameSync` below.
58
- input: paths.appIndexHtml
59
- }
60
- },
61
- server: {
62
- port: DEFAULT_PORT
63
- },
64
- plugins: [pluginGraphql(), pluginReact({
65
- jsxImportSource: '@emotion/react',
66
- babel: {
67
- plugins: ['@emotion/babel-plugin']
68
- }
69
- })]
70
- }); // Rename `/public/public/index.html` to `/public/index.html.template`
71
-
72
- fs.renameSync( // Because of our custom entry point path (`/public/index.html`),
73
- // Vite will write the `index.html` to `/public/public/index.html`.
74
- // We need to move this file to the `/public` folder and rename it
75
- // to `index.html.template` (as expected by the `compile-html` command).
76
- path.join(paths.appBuild, 'public/index.html'), paths.appIndexHtmlTemplate); // Clean up nested folder
77
-
78
- fs.rmdirSync(path.join(paths.appBuild, 'public')); // Copy public assets
79
-
80
- fs.copySync(path.join(applicationStaticAssetsPath, 'html-page'), paths.appBuild, {
81
- dereference: true
82
- });
83
- };
84
-
85
- execute().catch(error => {
86
- if (error && error.message) {
87
- console.error(error.message);
88
- }
89
-
90
- process.exit(1);
91
- });
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable no-console,global-require,import/no-dynamic-require */
4
- // NOTE: `react-dev-utils` does not currently fully support Webpack v5.
5
- // Most of the imports work, however we might bump into some edge cases.
6
- // In any case, once they release a compatible version, we should't have problems.
7
- const path = require('path');
8
-
9
- const fs = require('fs-extra');
10
-
11
- const webpack = require('webpack');
12
-
13
- const chalk = require('react-dev-utils/chalk');
14
-
15
- const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
16
-
17
- const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
18
-
19
- const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
20
-
21
- const printBuildError = require('react-dev-utils/printBuildError');
22
-
23
- const {
24
- packageLocation: applicationStaticAssetsPath
25
- } = require('@commercetools-frontend/assets');
26
-
27
- const paths = require('../config/paths');
28
-
29
- const createWebpackConfigForProduction = require('../config/create-webpack-config-for-production');
30
-
31
- const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild;
32
- const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; // These sizes are pretty large. We'll warn for bundles exceeding them.
33
-
34
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
35
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
36
- const hasWebpackConfig = fs.existsSync(paths.appWebpackConfig); // Warn and crash if required files are missing
37
-
38
- if (!checkRequiredFiles([])) {
39
- process.exit(1);
40
- } // First, read the current file sizes in build directory.
41
- // This lets us display how much they changed later.
42
-
43
-
44
- measureFileSizesBeforeBuild(paths.appBuild).then(previousFileSizes => {
45
- // Remove all content but keep the directory so that
46
- // if you're in it, you don't end up in Trash
47
- fs.emptyDirSync(paths.appBuild); // Copy default files
48
-
49
- copyDefaultFiles(); // Start the webpack build
50
-
51
- return build(previousFileSizes);
52
- }).then(({
53
- stats,
54
- previousFileSizes,
55
- warnings
56
- }) => {
57
- if (warnings.length) {
58
- console.log(chalk.yellow('Compiled with warnings.\n'));
59
- console.log(warnings.join('\n\n'));
60
- console.log(`\nSearch for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`);
61
- console.log(`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`);
62
- } else {
63
- console.log(chalk.green('Compiled successfully.\n'));
64
- }
65
-
66
- console.log('File sizes after gzip:\n');
67
- printFileSizesAfterBuild(stats, previousFileSizes, paths.appBuild, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
68
- console.log();
69
- }, err => {
70
- console.log(chalk.red('Failed to compile.\n'));
71
- printBuildError(err);
72
- process.exit(1);
73
- }).catch(err => {
74
- if (err && err.message) {
75
- console.error(err.message);
76
- }
77
-
78
- process.exit(1);
79
- }); // Create the production build and print the deployment instructions.
80
-
81
- function build(previousFileSizes) {
82
- console.log('Creating an optimized production build...');
83
- const config = hasWebpackConfig ? require(paths.appWebpackConfig) : createWebpackConfigForProduction();
84
- const compiler = webpack(config);
85
- return new Promise((resolve, reject) => {
86
- compiler.run((err, stats) => {
87
- let messages;
88
-
89
- if (err) {
90
- if (!err.message) {
91
- return reject(err);
92
- }
93
-
94
- let errMessage = err.message; // Add additional information for postcss errors
95
-
96
- if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
97
- errMessage += '\nCompileError: Begins at CSS selector ' + err['postcssNode'].selector;
98
- }
99
-
100
- messages = formatWebpackMessages({
101
- errors: [errMessage],
102
- warnings: []
103
- });
104
- } else {
105
- messages = formatWebpackMessages(stats.toJson({
106
- all: false,
107
- warnings: true,
108
- errors: true
109
- }));
110
- }
111
-
112
- if (messages.errors.length) {
113
- // Only keep the first error. Others are often indicative
114
- // of the same problem, but confuse the reader with noise.
115
- if (messages.errors.length > 1) {
116
- messages.errors.length = 1;
117
- }
118
-
119
- return reject(new Error(messages.errors.join('\n\n')));
120
- }
121
-
122
- if (process.env.CI && (typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') && messages.warnings.length) {
123
- console.log(chalk.yellow('\nTreating warnings as errors because process.env.CI = true.\n' + 'Most CI servers set it automatically.\n'));
124
- return reject(new Error(messages.warnings.join('\n\n')));
125
- }
126
-
127
- return resolve({
128
- stats,
129
- previousFileSizes,
130
- warnings: messages.warnings
131
- });
132
- });
133
- });
134
- }
135
-
136
- function copyDefaultFiles() {
137
- fs.copySync(path.join(applicationStaticAssetsPath, 'html-page'), paths.appBuild, {
138
- dereference: true
139
- });
140
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable no-console,global-require,import/no-dynamic-require */
4
- const fs = require('fs');
5
-
6
- const mri = require('mri');
7
-
8
- const chalk = require('react-dev-utils/chalk');
9
-
10
- const {
11
- compileHtml
12
- } = require('@commercetools-frontend/mc-html-template');
13
-
14
- const paths = require('../config/paths');
15
-
16
- const flags = mri(process.argv.slice(2), {
17
- boolean: ['print-security-headers']
18
- });
19
- const appDirectory = fs.realpathSync(process.cwd());
20
-
21
- const generateStatic = async () => {
22
- console.log('Compiling index.html...');
23
- const compiled = await compileHtml(paths.appIndexHtmlTemplate);
24
- fs.writeFileSync(paths.appIndexHtml, compiled.indexHtmlContent, {
25
- encoding: 'utf8'
26
- });
27
-
28
- if (flags.transformer) {
29
- try {
30
- const transformerPath = require.resolve(flags.transformer, {
31
- paths: [appDirectory]
32
- });
33
-
34
- const transformerFn = require(transformerPath);
35
-
36
- transformerFn(compiled);
37
- } catch (error) {
38
- throw new Error(`Could not load transformer module "${flags.transformer}"\n${error.stack}`);
39
- }
40
- } else if (flags['print-security-headers']) {
41
- console.log(JSON.stringify(compiled.headers));
42
- }
43
-
44
- console.log(chalk.green('Compiled successfully.\n'));
45
- };
46
-
47
- generateStatic().catch(error => {
48
- if (error && error.message) {
49
- console.error(error.message);
50
- }
51
-
52
- process.exit(1);
53
- });
@@ -1,176 +0,0 @@
1
- "use strict";
2
-
3
- const omit = require('lodash/omit');
4
-
5
- const prompts = require('prompts');
6
-
7
- const mri = require('mri');
8
-
9
- const chalk = require('chalk');
10
-
11
- const {
12
- processConfig
13
- } = require('@commercetools-frontend/application-config');
14
-
15
- const CredentialsStorage = require('../utils/credentials-storage');
16
-
17
- const {
18
- fetchCustomApplication,
19
- updateCustomApplication,
20
- createCustomApplication,
21
- fetchUserOrganizations
22
- } = require('../utils/graphql-requests');
23
-
24
- const getConfigDiff = require('../utils/get-config-diff');
25
-
26
- const flags = mri(process.argv.slice(2), {
27
- boolean: ['dry-run']
28
- });
29
- const credentialsStorage = new CredentialsStorage();
30
-
31
- const getMcUrlLink = (mcApiUrl, organizationId, applicationId) => {
32
- const mcUrl = mcApiUrl.replace('mc-api', 'mc');
33
- const customAppLink = `${mcUrl}/account/organizations/${organizationId}/custom-applications/owned/${applicationId}`;
34
- return customAppLink;
35
- };
36
-
37
- const configSync = async () => {
38
- const applicationConfig = processConfig();
39
- const {
40
- data: localCustomAppData
41
- } = applicationConfig;
42
- const {
43
- mcApiUrl
44
- } = applicationConfig.env;
45
-
46
- if (!credentialsStorage.isSessionValid(mcApiUrl)) {
47
- throw new Error(`You don't have a valid session for the ${mcApiUrl} environment. Please, run the "mc-scripts login" command to authenticate yourself.`);
48
- }
49
-
50
- const token = credentialsStorage.getToken(mcApiUrl);
51
- const fetchedCustomApplication = await fetchCustomApplication({
52
- mcApiUrl,
53
- token,
54
- entryPointUriPath: localCustomAppData.entryPointUriPath
55
- });
56
-
57
- if (!fetchedCustomApplication) {
58
- const userOrganizations = await fetchUserOrganizations({
59
- mcApiUrl,
60
- token
61
- });
62
- let organizationId, organizationName;
63
-
64
- if (userOrganizations.total === 0) {
65
- throw new Error(`It seems you are not an admin of any Organization. Please make sure to be part of the Administrators team of the Organization you want the Custom Application to be configured to.`);
66
- }
67
-
68
- if (userOrganizations.total === 1) {
69
- const [organization] = userOrganizations.results;
70
- organizationId = organization.id;
71
- organizationName = organization.name;
72
- } else {
73
- const organizationChoices = userOrganizations.results.map(organization => ({
74
- title: organization.name,
75
- value: organization.id
76
- }));
77
- const {
78
- organizationId: selectedOrganizationId
79
- } = await prompts({
80
- type: 'select',
81
- name: 'organizationId',
82
- message: 'Select Organization',
83
- choices: organizationChoices,
84
- initial: 0
85
- });
86
-
87
- if (!selectedOrganizationId) {
88
- throw new Error(`No Organization selected, aborting.`);
89
- }
90
-
91
- organizationId = selectedOrganizationId;
92
- organizationName = organizationChoices.find(({
93
- value
94
- }) => value === organizationId).title;
95
- }
96
-
97
- const {
98
- confirmation
99
- } = await prompts({
100
- type: 'text',
101
- name: 'confirmation',
102
- message: `You are about to create a new Custom Application in the "${organizationName}" organization for the ${mcApiUrl} environment. Are you sure you want to proceed?`,
103
- initial: 'yes'
104
- });
105
-
106
- if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
107
- console.log(chalk.red('Aborted.'));
108
- return;
109
- }
110
-
111
- const data = omit(localCustomAppData, ['id']);
112
-
113
- if (flags['dry-run']) {
114
- console.log(chalk.gray('DRY RUN mode'));
115
- console.log(`A new Custom Application would be created for the Organization ${organizationName} with the following payload:`);
116
- console.log(JSON.stringify(data));
117
- return;
118
- }
119
-
120
- const createdCustomApplication = await createCustomApplication({
121
- mcApiUrl,
122
- token,
123
- organizationId,
124
- data
125
- });
126
- const customAppLink = getMcUrlLink(mcApiUrl, organizationId, createdCustomApplication.id);
127
- console.log(chalk.green(`Custom Application created.\nThe "applicationId" in your local Custom Application config file should be updated with the application ID: ${createdCustomApplication.id}.\nYou can see the Custom Application data in the Merchant Center at ${customAppLink}.`));
128
- return;
129
- }
130
-
131
- const customAppLink = getMcUrlLink(mcApiUrl, fetchedCustomApplication.organizationId, fetchedCustomApplication.application.id);
132
- const configDiff = getConfigDiff(fetchedCustomApplication.application, localCustomAppData);
133
-
134
- if (!configDiff) {
135
- console.log(chalk.green(`Custom Application is already up to date.\nYou can see the Custom Application data in the Merchant Center at ${customAppLink}.`));
136
- return;
137
- }
138
-
139
- console.log(configDiff);
140
- const {
141
- confirmation
142
- } = await prompts({
143
- type: 'text',
144
- name: 'confirmation',
145
- message: `You are about to update the Custom Application "${localCustomAppData.entryPointUriPath}" with the changes above, in the ${mcApiUrl} environment. Are you sure you want to proceed?`,
146
- initial: 'yes'
147
- });
148
-
149
- if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
150
- console.log(chalk.red('Aborted.'));
151
- return;
152
- }
153
-
154
- const data = omit(localCustomAppData, ['id']);
155
-
156
- if (flags['dry-run']) {
157
- console.log(chalk.gray('DRY RUN mode'));
158
- console.log(`The Custom Application ${data.name} would be updated with the following payload:`);
159
- console.log(JSON.stringify(data));
160
- return;
161
- }
162
-
163
- await updateCustomApplication({
164
- mcApiUrl,
165
- token,
166
- organizationId: fetchedCustomApplication.organizationId,
167
- data: omit(localCustomAppData, ['id']),
168
- applicationId: fetchedCustomApplication.application.id
169
- });
170
- console.log(chalk.green(`Custom Application updated.\nYou can see the Custom Application data in the Merchant Center at ${customAppLink}.`));
171
- };
172
-
173
- configSync().catch(error => {
174
- console.log(chalk.red(error));
175
- process.exit(1);
176
- });
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- const prompts = require('prompts');
4
-
5
- const chalk = require('chalk');
6
-
7
- const {
8
- processConfig
9
- } = require('@commercetools-frontend/application-config');
10
-
11
- const CredentialsStorage = require('../utils/credentials-storage');
12
-
13
- const {
14
- getAuthToken
15
- } = require('../utils/auth');
16
-
17
- const credentialsStorage = new CredentialsStorage();
18
-
19
- const login = async () => {
20
- const applicationConfig = processConfig();
21
- const {
22
- mcApiUrl
23
- } = applicationConfig.env;
24
-
25
- if (credentialsStorage.isSessionValid(mcApiUrl)) {
26
- console.log(`You already have a valid session for the ${mcApiUrl} environment.\n`);
27
- return;
28
- }
29
-
30
- const {
31
- email
32
- } = await prompts({
33
- type: 'text',
34
- name: 'email',
35
- message: 'Email'
36
- });
37
- const {
38
- password
39
- } = await prompts({
40
- type: 'invisible',
41
- name: 'password',
42
- message: 'Password (hidden)'
43
- });
44
-
45
- if (!email || !password) {
46
- throw new Error(`Missing email or password values. Aborting.`);
47
- }
48
-
49
- const credentials = await getAuthToken(mcApiUrl, {
50
- email,
51
- password
52
- });
53
- credentialsStorage.setToken(mcApiUrl, credentials);
54
- console.log(chalk.green(`Login successful for the ${mcApiUrl} environment.\n`));
55
- };
56
-
57
- login().catch(error => {
58
- console.log(chalk.red(error));
59
- process.exit(1);
60
- });
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- /* eslint-disable no-console,global-require,import/no-dynamic-require */
4
- const http = require('http');
5
-
6
- const serveHandler = require('serve-handler');
7
-
8
- const paths = require('../config/paths');
9
-
10
- const port = 3001;
11
- const server = http.createServer((request, response) => {
12
- // You pass two more arguments for config and middleware
13
- // More details here: https://github.com/vercel/serve-handler#options
14
- return serveHandler(request, response, {
15
- public: paths.appBuild,
16
- rewrites: [{
17
- source: '/favicon*',
18
- destination: '/favicon.png'
19
- }, {
20
- source: '/login*',
21
- destination: '/login.html'
22
- }, {
23
- source: '/logout',
24
- destination: '/logout.html'
25
- }, {
26
- // Match all routes except for the login, logout, and favicon routes.
27
- // NOTE: this complex glob pattern would not be necessary if the rewrite
28
- // implementation would stop at the first match.
29
- // See https://github.com/vercel/serve-handler/issues/71
30
- source: '{/!(favicon|login|logout)*/**,/!(favicon|login|logout)*}',
31
- destination: '/index.html'
32
- }]
33
- });
34
- });
35
- server.listen(port, () => {
36
- console.log(`Running at http://localhost:${port}`);
37
- });
@@ -1,138 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require('fs-extra');
4
-
5
- const path = require('path');
6
-
7
- const {
8
- createServer
9
- } = require('vite');
10
-
11
- const pluginGraphql = require('@rollup/plugin-graphql');
12
-
13
- const pluginReact = require('@vitejs/plugin-react').default;
14
-
15
- const {
16
- processConfig
17
- } = require('@commercetools-frontend/application-config');
18
-
19
- const {
20
- replaceHtmlPlaceholders,
21
- processHeaders,
22
- generateTemplate
23
- } = require('@commercetools-frontend/mc-html-template');
24
-
25
- const {
26
- createMcDevAuthenticationMiddleware
27
- } = require('@commercetools-frontend/mc-dev-authentication');
28
-
29
- const {
30
- packageLocation: applicationStaticAssetsPath
31
- } = require('@commercetools-frontend/assets');
32
-
33
- const paths = require('../config/paths');
34
-
35
- const DEFAULT_PORT = parseInt(process.env.HTTP_PORT, 10) || 3001;
36
-
37
- const pluginCustomApplication = applicationConfig => {
38
- /**
39
- * @type {import('vite').Plugin}
40
- */
41
- return {
42
- name: 'custom-application',
43
-
44
- /**
45
- * @type {import('vite').ServerHook}
46
- */
47
- configureServer(server) {
48
- return () => {
49
- // Users do not need to have/maintain the `index.html` (as expected by Vite)
50
- // as it's generated and maintained by the Custom Application CLI.
51
- // Therefore, the generated `index.html` (template) is written into the `/public`
52
- // folder so that it's gitignored.
53
- // As a result, we need to make sure to point the URI path to the correct location.
54
- server.middlewares.use((req, res, next) => {
55
- if (req.url === '/index.html') {
56
- req.url = '/public/index.html';
57
- }
58
-
59
- next();
60
- }); // Handle auth routes for internal local development.
61
-
62
- server.middlewares.use(createMcDevAuthenticationMiddleware(applicationConfig));
63
- };
64
- },
65
-
66
- /**
67
- * @type {import('vite').IndexHtmlTransformHook}
68
- */
69
- transformIndexHtml(rawHtml, _ctx) {
70
- const compiledHeaders = processHeaders(applicationConfig);
71
- const enhancedLocalEnv = Object.assign({}, applicationConfig.env, // Now that the app config is defined as a `env.json`, when we start the FE app
72
- // to point to the local backend API by passing the `MC_API_URL` env does not
73
- // work anymore). To make it work again, we can override the `env.json` config
74
- // with the env variable before injecting the values into the index.html.
75
- // NOTE: this is only necessary for development.
76
- process.env.MC_API_URL ? {
77
- mcApiUrl: process.env.MC_API_URL
78
- } : {}); // Resolve the placeholders of the `index.html` (template) file, before serving it.
79
-
80
- const html = replaceHtmlPlaceholders(rawHtml, {
81
- env: enhancedLocalEnv,
82
- headers: compiledHeaders
83
- });
84
- return html;
85
- }
86
-
87
- };
88
- };
89
-
90
- const execute = async () => {
91
- // Load the Custom Application config file first.
92
- const applicationConfig = processConfig(); // Ensure the `/public` folder exists.
93
-
94
- fs.mkdirSync(paths.appBuild, {
95
- recursive: true
96
- }); // Generate `index.html` (template).
97
-
98
- const appEntryPoint = path.relative(paths.appRoot, paths.entryPoint);
99
- const html = generateTemplate({
100
- // Define the module entry point (path relative to the `/public` folder).
101
- // NOTE: that this is different from the production configuration.
102
- scriptImports: [`<script type="module" src="/../${appEntryPoint}"></script>`]
103
- }); // Write `index.html` (template) into the `/public` folder.
104
-
105
- fs.writeFileSync(paths.appIndexHtml, html, {
106
- encoding: 'utf8'
107
- });
108
- const server = await createServer({
109
- root: paths.appRoot,
110
- define: {
111
- 'process.env.DEBUG': JSON.stringify(false),
112
- 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
113
- },
114
- server: {
115
- port: DEFAULT_PORT
116
- },
117
- plugins: [pluginGraphql(), pluginReact({
118
- jsxImportSource: '@emotion/react',
119
- babel: {
120
- plugins: ['@emotion/babel-plugin']
121
- }
122
- }), pluginCustomApplication(applicationConfig)]
123
- });
124
- await server.listen(); // Copy public assets to `/public` folder (even in development).
125
-
126
- fs.copySync(path.join(applicationStaticAssetsPath, 'html-page'), paths.appBuild, {
127
- dereference: true
128
- });
129
- server.printUrls();
130
- };
131
-
132
- execute().catch(error => {
133
- if (error && error.message) {
134
- console.error(error.message);
135
- }
136
-
137
- process.exit(1);
138
- });