@commercetools-frontend/mc-scripts 21.7.0 → 21.8.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 (145) 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 +354 -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 +354 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +338 -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-8582b673.esm.js +209 -0
  20. package/dist/build-9395925a.cjs.prod.js +224 -0
  21. package/dist/build-97278377.cjs.dev.js +224 -0
  22. package/dist/build-vite-6c987a60.cjs.dev.js +109 -0
  23. package/dist/build-vite-76d44332.cjs.prod.js +109 -0
  24. package/dist/build-vite-a9602b19.esm.js +97 -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-0c588a89.cjs.dev.js +93 -0
  31. package/dist/compile-html-4832f8c5.esm.js +83 -0
  32. package/dist/compile-html-7654b5e6.cjs.prod.js +93 -0
  33. package/dist/config-sync-20bc05e8.esm.js +868 -0
  34. package/dist/config-sync-62824317.cjs.prod.js +887 -0
  35. package/dist/config-sync-d52e73f6.cjs.dev.js +892 -0
  36. package/dist/create-postcss-config-4cbe10ab.cjs.dev.js +90 -0
  37. package/dist/create-postcss-config-8ea16440.cjs.prod.js +90 -0
  38. package/{build/config/create-postcss-config.js → dist/create-postcss-config-c1aa3525.esm.js} +27 -25
  39. package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-8a8b84d6.esm.js} +92 -56
  40. package/dist/create-webpack-config-for-development-a5e73092.cjs.prod.js +418 -0
  41. package/dist/create-webpack-config-for-development-e2735e02.cjs.dev.js +418 -0
  42. package/dist/create-webpack-config-for-production-4e7b56c0.cjs.prod.js +468 -0
  43. package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-7dc669e5.esm.js} +117 -52
  44. package/dist/create-webpack-config-for-production-d9bf281c.cjs.dev.js +468 -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/paths.d.ts +12 -0
  60. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  61. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  62. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  63. package/dist/declarations/src/generated/core.d.ts +710 -0
  64. package/dist/declarations/src/generated/settings.d.ts +2383 -0
  65. package/dist/declarations/src/index.d.ts +3 -0
  66. package/dist/declarations/src/postcss.d.ts +1 -0
  67. package/dist/declarations/src/types.d.ts +82 -0
  68. package/dist/declarations/src/utils/auth.d.ts +6 -0
  69. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  70. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  71. package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
  72. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  73. package/dist/declarations/src/version.d.ts +2 -0
  74. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  75. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  76. package/dist/declarations/src/webpack.d.ts +2 -0
  77. package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
  78. package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
  79. package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
  80. package/dist/login-706ccc9a.cjs.prod.js +165 -0
  81. package/dist/login-779552b7.cjs.dev.js +165 -0
  82. package/dist/login-7d94659e.esm.js +155 -0
  83. package/dist/package-a98de907.esm.js +133 -0
  84. package/dist/package-aaf61bf0.cjs.dev.js +135 -0
  85. package/dist/package-b5c040f3.cjs.prod.js +135 -0
  86. package/dist/paths-16823f56.cjs.dev.js +55 -0
  87. package/dist/paths-76b66e74.cjs.prod.js +55 -0
  88. package/dist/paths-ed23d5a1.esm.js +46 -0
  89. package/dist/serve-12de323b.cjs.dev.js +70 -0
  90. package/dist/serve-784f4fcd.cjs.prod.js +70 -0
  91. package/dist/serve-d6b437b1.esm.js +62 -0
  92. package/dist/start-2b953ab0.cjs.dev.js +209 -0
  93. package/dist/start-e3ccd672.cjs.prod.js +209 -0
  94. package/dist/start-e924bd5d.esm.js +194 -0
  95. package/dist/start-vite-737bacca.cjs.dev.js +149 -0
  96. package/dist/start-vite-b0f58ae4.cjs.prod.js +149 -0
  97. package/dist/start-vite-ec5d40b5.esm.js +136 -0
  98. package/dist/user-agent-5da1830b.cjs.dev.js +106 -0
  99. package/dist/user-agent-8044acd6.esm.js +94 -0
  100. package/dist/user-agent-d18809af.cjs.prod.js +106 -0
  101. package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
  102. package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
  103. package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
  104. package/package.json +41 -39
  105. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
  106. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
  107. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  108. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
  109. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
  110. package/postcss/package.json +4 -0
  111. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
  112. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
  113. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  114. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
  115. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
  116. package/webpack/package.json +4 -0
  117. package/build/bin/cli.js +0 -264
  118. package/build/commands/build-vite.js +0 -91
  119. package/build/commands/build.js +0 -140
  120. package/build/commands/compile-html.js +0 -53
  121. package/build/commands/config-sync.js +0 -176
  122. package/build/commands/login.js +0 -60
  123. package/build/commands/serve.js +0 -37
  124. package/build/commands/start-vite.js +0 -138
  125. package/build/commands/start.js +0 -108
  126. package/build/config/paths.js +0 -38
  127. package/build/config/vendors-to-transpile.js +0 -3
  128. package/build/config/webpack-dev-server.config.js +0 -69
  129. package/build/index.js +0 -16
  130. package/build/utils/auth.js +0 -34
  131. package/build/utils/auth.spec.js +0 -61
  132. package/build/utils/create-custom-application.settings.graphql +0 -8
  133. package/build/utils/credentials-storage.js +0 -72
  134. package/build/utils/credentials-storage.spec.js +0 -69
  135. package/build/utils/fetch-custom-application.settings.graphql +0 -36
  136. package/build/utils/fetch-user-organizations.core.graphql +0 -9
  137. package/build/utils/get-config-diff.js +0 -308
  138. package/build/utils/get-config-diff.spec.js +0 -285
  139. package/build/utils/graphql-requests.js +0 -105
  140. package/build/utils/graphql-requests.spec.js +0 -159
  141. package/build/utils/require-graphql.js +0 -15
  142. package/build/utils/update-custom-application.settings.graphql +0 -13
  143. package/build/utils/user-agent.js +0 -15
  144. package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
  145. package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
@@ -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
- });
@@ -1,108 +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 webpack = require('webpack');
7
-
8
- const WebpackDevServer = require('webpack-dev-server');
9
-
10
- const chalk = require('react-dev-utils/chalk');
11
-
12
- const clearConsole = require('react-dev-utils/clearConsole');
13
-
14
- const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
15
-
16
- const {
17
- choosePort,
18
- createCompiler,
19
- prepareUrls
20
- } = require('react-dev-utils/WebpackDevServerUtils');
21
-
22
- const openBrowser = require('react-dev-utils/openBrowser');
23
-
24
- const paths = require('../config/paths');
25
-
26
- const createDevServerConfig = require('../config/webpack-dev-server.config');
27
-
28
- const createWebpackConfigForDevelopment = require('../config/create-webpack-config-for-development');
29
-
30
- const useYarn = fs.existsSync(paths.yarnLockFile);
31
- const isInteractive = process.stdout.isTTY; // Whether or not `react-refresh` is enabled, `react-refresh` is not 100% stable at this time,
32
- // which is why it's disabled by default.
33
-
34
- const hasWebpackConfig = fs.existsSync(paths.appWebpackConfig); // Warn and crash if required files are missing
35
-
36
- if (!checkRequiredFiles([])) {
37
- process.exit(1);
38
- } // Tools like Cloud9 rely on this.
39
-
40
-
41
- const DEFAULT_PORT = parseInt(process.env.HTTP_PORT, 10) || 3001;
42
- const HOST = process.env.HOST || '0.0.0.0'; // We attempt to use the default port but if it is busy, we offer the user to
43
- // run on a different port. `detect()` Promise resolves to the next free port.
44
-
45
- choosePort(HOST, DEFAULT_PORT).then(port => {
46
- if (port == null) {
47
- // We have not found a port.
48
- return;
49
- }
50
-
51
- const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
52
-
53
- const appName = require(paths.appPackageJson).name;
54
-
55
- const urls = prepareUrls(protocol, HOST, port); // Get webpack config
56
-
57
- const config = hasWebpackConfig ? require(paths.appWebpackConfig) : createWebpackConfigForDevelopment();
58
- const devSocket = {
59
- warnings: warnings => // eslint-disable-next-line @typescript-eslint/no-use-before-define
60
- devServer.sockWrite(devServer.sockets, 'warnings', warnings),
61
- errors: errors => // eslint-disable-next-line @typescript-eslint/no-use-before-define
62
- devServer.sockWrite(devServer.sockets, 'errors', errors)
63
- }; // Create a webpack compiler that is configured with custom messages.
64
-
65
- const compiler = createCompiler({
66
- appName,
67
- config,
68
- devSocket,
69
- urls,
70
- useYarn,
71
- webpack
72
- }); // Serve webpack assets generated by the compiler over a web sever.
73
-
74
- const serverConfig = createDevServerConfig({
75
- port,
76
- publicPath: config.output.publicPath
77
- });
78
- const devServer = new WebpackDevServer(serverConfig, compiler); // Launch WebpackDevServer.
79
-
80
- devServer.startCallback(() => {
81
- if (isInteractive) {
82
- clearConsole();
83
- }
84
-
85
- console.log(chalk.cyan('Starting the development server...\n'));
86
- openBrowser(urls.localUrlForBrowser);
87
- });
88
- ['SIGINT', 'SIGTERM'].forEach(sig => {
89
- process.on(sig, () => {
90
- devServer.close();
91
- process.exit();
92
- });
93
- });
94
-
95
- if (process.env.CI !== 'true') {
96
- // Gracefully exit when stdin ends
97
- process.stdin.on('end', function () {
98
- devServer.close();
99
- process.exit();
100
- });
101
- }
102
- }).catch(err => {
103
- if (err && err.message) {
104
- console.error(err.message);
105
- }
106
-
107
- process.exit(1);
108
- });
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require('fs');
4
-
5
- const path = require('path');
6
-
7
- const moduleFileExtensions = ['js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx']; // Make sure any symlinks in the project folder are resolved:
8
- // https://github.com/facebook/create-react-app/issues/637
9
-
10
- const appDirectory = fs.realpathSync(process.cwd());
11
-
12
- const resolveApp = relativePath => path.resolve(appDirectory, relativePath); // Resolve file paths in the order given
13
-
14
-
15
- const resolveModule = (resolveFn, filePath) => {
16
- const extension = moduleFileExtensions.find(extension => fs.existsSync(resolveFn(`${filePath}.${extension}`)));
17
-
18
- if (extension) {
19
- return resolveFn(`${filePath}.${extension}`);
20
- }
21
-
22
- return resolveFn(`${filePath}.js`);
23
- }; // Resolve the absolute path of the caller location. This is necessary
24
- // to point to files within that folder.
25
-
26
-
27
- const paths = {
28
- appPackageJson: resolveApp('package.json'),
29
- appBuild: resolveApp('public'),
30
- appIndexHtmlTemplate: resolveApp('public/index.html.template'),
31
- appIndexHtml: resolveApp('public/index.html'),
32
- appWebpackConfig: resolveModule(resolveApp, `webpack.config.${process.env.NODE_ENV === 'production' ? 'prod' : 'dev'}`),
33
- yarnLockFile: resolveApp('yarn.lock'),
34
- appRoot: resolveApp('.'),
35
- entryPoint: resolveModule(resolveApp, 'src/index'),
36
- sourceFolders: [resolveApp('src')]
37
- };
38
- module.exports = paths;
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = [];
@@ -1,69 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- processConfig
5
- } = require('@commercetools-frontend/application-config');
6
-
7
- const {
8
- processHeaders
9
- } = require('@commercetools-frontend/mc-html-template');
10
-
11
- const {
12
- createMcDevAuthenticationMiddleware
13
- } = require('@commercetools-frontend/mc-dev-authentication');
14
-
15
- const applicationConfig = processConfig();
16
- const compiledHeaders = processHeaders(applicationConfig);
17
- const host = process.env.HOST || '0.0.0.0'; // We support configuring the sockjs pathname during development.
18
- // These settings let a developer run multiple simultaneous projects.
19
- // They are used as the connection `hostname`, `pathname` and `port`
20
- // in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
21
- // and `sockPort` options in webpack-dev-server.
22
-
23
- const sockHost = process.env.WDS_SOCKET_HOST;
24
- const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
25
-
26
- const sockPort = process.env.WDS_SOCKET_PORT;
27
-
28
- module.exports = ({
29
- port,
30
- publicPath
31
- }) => ({
32
- client: {
33
- overlay: false,
34
- webSocketURL: {
35
- hostname: sockHost,
36
- pathname: sockPath,
37
- port: sockPort
38
- }
39
- },
40
- // Enable gzip compression of generated files.
41
- compress: true,
42
- devMiddleware: {
43
- // It is important to tell WebpackDevServer to use the same "publicPath" path as
44
- // we specified in the webpack config. When homepage is '.', default to serving
45
- // from the root.
46
- publicPath
47
- },
48
- headers: compiledHeaders,
49
- historyApiFallback: {
50
- // Paths with dots should still use the history fallback.
51
- // See https://github.com/facebookincubator/create-react-app/issues/387.
52
- disableDotRule: true,
53
- index: publicPath
54
- },
55
- host,
56
- hot: true,
57
- https: false,
58
- port,
59
-
60
- setupMiddlewares(middlewares, devServer) {
61
- if (!devServer) {
62
- throw new Error('webpack-dev-server is not defined');
63
- }
64
-
65
- devServer.app.use(createMcDevAuthenticationMiddleware(applicationConfig));
66
- return middlewares;
67
- }
68
-
69
- });
package/build/index.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- const createWebpackConfigForDevelopment = require('./config/create-webpack-config-for-development');
4
-
5
- const createWebpackConfigForProduction = require('./config/create-webpack-config-for-production');
6
-
7
- const vendorsToCompile = require('./config/vendors-to-transpile');
8
-
9
- const createPostcssConfig = require('./config/create-postcss-config');
10
-
11
- module.exports = {
12
- createWebpackConfigForDevelopment,
13
- createWebpackConfigForProduction,
14
- vendorsToCompile,
15
- createPostcssConfig
16
- };
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- const fetch = require('node-fetch');
4
-
5
- const userAgent = require('./user-agent');
6
-
7
- const getAuthToken = async (mcApiUrl, payload) => {
8
- const response = await fetch(`${mcApiUrl}/tokens/cli`, {
9
- method: 'POST',
10
- headers: {
11
- Accept: 'application/json',
12
- 'Content-Type': 'application/json',
13
- 'x-user-agent': userAgent
14
- },
15
- body: JSON.stringify(payload)
16
- });
17
-
18
- if (!response.ok) {
19
- const text = await response.text();
20
- let parsed;
21
-
22
- try {
23
- parsed = JSON.parse(text);
24
- } catch (error) {}
25
-
26
- const errorMessage = parsed ? parsed.message : text;
27
- throw new Error(errorMessage);
28
- }
29
-
30
- const authToken = await response.json();
31
- return authToken;
32
- };
33
-
34
- exports.getAuthToken = getAuthToken;