-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Breaking] refactor: drop mc-http-server, make --use-local-assets the…
… default behavior (#1787) * refactor: drop mc-http-server, make --use-local-assets the default behavior * fix: ports * docs: remove references to http-server * docs: keep old pages path but link to other documents * docs: changeset * fix: use transformer-local for starting app locally in production mode with login and logout dev pages * fix(website): links * refactor: add mc-scripts serve command to serve the production-built custom application locally * chore: remove refs to mc-http-server
- Loading branch information
Showing
42 changed files
with
285 additions
and
1,199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
--- | ||
'@commercetools-frontend/mc-http-server': patch | ||
'@commercetools-website/custom-applications': patch | ||
--- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
'merchant-center-application-template-starter': major | ||
'@commercetools-frontend/application-config': major | ||
'@commercetools-frontend/application-shell': major | ||
'@commercetools-frontend/application-shell-connectors': major | ||
'@commercetools-frontend/mc-dev-authentication': major | ||
'@commercetools-frontend/mc-html-template': major | ||
'@commercetools-frontend/mc-scripts': major | ||
'playground': major | ||
'@commercetools-local/visual-testing-app': major | ||
'@commercetools-website/custom-applications': major | ||
--- | ||
|
||
Remove the CLI flag `--use-local-assets`. The default behavior of `mc-scripts compile-html` now is to compile the assets locally, which is the only reasonable thing to do. | ||
|
||
Furthermore, the `@commercetools-frontend/mc-http-server` package has been deprecated and won't be published anymore. | ||
With the `compile-html` command there is no need to have a pre-configured HTTP server anymore. | ||
|
||
When running the `mc-scripts compile-html` command, the `index.html` is compiled for production usage and it lives in the `public` folder, together with the other static assets. This is all you need to deploy your application. | ||
You can decide to [deploy the Custom Application statically to one of the popular cloud providers](https://docs.commercetools.com/custom-applications/deployment/compiling-a-custom-application#deployment), or serve the files on your own using a static server. | ||
|
||
For example, to run locally the Custom Application using the production bundles: | ||
|
||
```console | ||
NODE_ENV=production MC_APP_ENV=development dotenv -- \ | ||
mc-scripts compile-html \ | ||
--transformer @commercetools-frontend/mc-dev-authentication/transformer-local.js | ||
|
||
mc-scripts serve | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
'merchant-center-application-template-starter': patch | ||
'@commercetools-backend/loggers': patch | ||
'@commercetools-frontend/application-components': patch | ||
'@commercetools-frontend/application-shell': patch | ||
'@commercetools-frontend/i18n': patch | ||
'@commercetools-frontend/jest-preset-mc-app': patch | ||
'@commercetools-frontend/mc-scripts': patch | ||
'@commercetools-frontend/react-notifications': patch | ||
'@commercetools-frontend/sdk': patch | ||
'@commercetools-frontend/sentry': patch | ||
'playground': patch | ||
'@commercetools-local/visual-testing-app': patch | ||
'@commercetools-website/custom-applications': patch | ||
'@commercetools-website/components-playground': patch | ||
--- | ||
|
||
update deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ dotenv | |
Vercel | ||
changelogs | ||
commercetools | ||
Intl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const pug = require('pug'); | ||
|
||
const compileLoginView = pug.compileFile( | ||
path.join(__dirname, './views/login.pug') | ||
); | ||
const compileLogoutView = pug.compileFile( | ||
path.join(__dirname, './views/logout.pug') | ||
); | ||
|
||
// Make sure any symlinks in the project folder are resolved: | ||
// https://github.com/facebook/create-react-app/issues/637 | ||
const appDirectory = fs.realpathSync(process.cwd()); | ||
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath); | ||
const paths = { | ||
appPublic: resolveApp('public'), | ||
}; | ||
|
||
// This transformer will generate a development `login` and `logout` HTML files | ||
// and copy them to the application public foder. | ||
// This is necessary to run the application locally in production mode. | ||
module.exports = ({ env }) => { | ||
const loginViewHtml = compileLoginView({ env }); | ||
const logoutViewHtml = compileLogoutView({ env }); | ||
|
||
fs.copyFileSync( | ||
path.join(__dirname, 'views', 'login.css'), | ||
path.join(paths.appPublic, 'login.css') | ||
); | ||
fs.copyFileSync( | ||
path.join(__dirname, 'views', 'login.js'), | ||
path.join(paths.appPublic, 'login.js') | ||
); | ||
fs.copyFileSync( | ||
path.join(__dirname, 'views', 'logout.js'), | ||
path.join(paths.appPublic, 'logout.js') | ||
); | ||
fs.writeFileSync( | ||
path.join(paths.appPublic, 'login.html'), | ||
loginViewHtml, | ||
'utf8' | ||
); | ||
fs.writeFileSync( | ||
path.join(paths.appPublic, 'logout.html'), | ||
logoutViewHtml, | ||
'utf8' | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,23 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fetch = require('node-fetch'); | ||
const { processConfig } = require('@commercetools-frontend/application-config'); | ||
const processHeaders = require('./process-headers'); | ||
const replaceHtmlPlaceholders = require('./utils/replace-html-placeholders'); | ||
|
||
const requiredOptions = ['publicAssetsPath']; | ||
|
||
const trimTrailingSlash = (value) => value.replace(/\/$/, ''); | ||
|
||
/** | ||
* Options: | ||
* - publicAssetsPath | ||
* - useLocalAssets | ||
*/ | ||
module.exports = async function compileHtml(options) { | ||
requiredOptions.forEach((key) => { | ||
if (!options[key]) { | ||
throw new Error(`Missing required option ${key}.`); | ||
} | ||
}); | ||
module.exports = async function compileHtml(indexHtmlTemplatePath) { | ||
const applicationConfig = processConfig(); | ||
const compiledHeaders = processHeaders(applicationConfig); | ||
|
||
if (options.useLocalAssets) { | ||
const indexHtmlContent = fs.readFileSync( | ||
path.join(options.publicAssetsPath, 'index.html.template'), | ||
'utf8' | ||
); | ||
const interpolatedIndexHtmlContent = replaceHtmlPlaceholders( | ||
indexHtmlContent, | ||
applicationConfig.env | ||
); | ||
return { | ||
env: applicationConfig.env, | ||
headers: compiledHeaders, | ||
indexHtmlContent: interpolatedIndexHtmlContent, | ||
}; | ||
} | ||
|
||
// TL;DR; This disables the `Cache-Control` and ensures that we get | ||
// the latest version of the object. | ||
const randomQueryParam = Date.now(); | ||
// Fetch `index.html.template` from remote CDN | ||
const remoteIndexHtmlResponse = await fetch( | ||
`${trimTrailingSlash( | ||
applicationConfig.env.cdnUrl | ||
)}/index.html.template?${randomQueryParam}` | ||
const indexHtmlTemplateContent = fs.readFileSync( | ||
indexHtmlTemplatePath, | ||
'utf8' | ||
); | ||
if (!remoteIndexHtmlResponse.ok) { | ||
const rawResponseError = await remoteIndexHtmlResponse.text(); | ||
const error = new Error(rawResponseError); | ||
return Promise.reject(error); | ||
} | ||
const remoteIndexHtmlContent = await remoteIndexHtmlResponse.text(); | ||
const interpolatedIndexHtmlContent = replaceHtmlPlaceholders( | ||
remoteIndexHtmlContent, | ||
const indexHtmlContent = replaceHtmlPlaceholders( | ||
indexHtmlTemplateContent, | ||
applicationConfig.env | ||
); | ||
return { | ||
env: applicationConfig.env, | ||
headers: compiledHeaders, | ||
indexHtmlContent: interpolatedIndexHtmlContent, | ||
indexHtmlContent, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.