mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Setup app to support prod published flow
This commit is contained in:
parent
aa8b729180
commit
b7fbd4e74e
6 changed files with 36 additions and 8 deletions
|
@ -1,9 +1,19 @@
|
||||||
{
|
{
|
||||||
"name": "comments-ui",
|
"name": "@tryghost/comments-ui",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "git@github.com:TryGhost/comments-ui.git",
|
"repository": "git@github.com:TryGhost/comments-ui.git",
|
||||||
"author": "Ghost Foundation",
|
"author": "Ghost Foundation",
|
||||||
|
"unpkg": "umd/comments-ui.umd.js",
|
||||||
|
"files": [
|
||||||
|
"umd/",
|
||||||
|
"LICENSE",
|
||||||
|
"README.md"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public",
|
||||||
|
"registry": "https://registry.npmjs.org/"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sentry/react": "^7.5.0",
|
"@sentry/react": "^7.5.0",
|
||||||
"@testing-library/jest-dom": "5.16.2",
|
"@testing-library/jest-dom": "5.16.2",
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const fs = require('fs');
|
||||||
const rewire = require('rewire');
|
const rewire = require('rewire');
|
||||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||||
const defaults = rewire('react-scripts/scripts/build.js');
|
const defaults = rewire('react-scripts/scripts/build.js');
|
||||||
|
@ -27,3 +28,9 @@ config.module.rules[1].oneOf = config.module.rules[1].oneOf.map((rule) => {
|
||||||
: options))
|
: options))
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fs.copyFile('./public/main.css', './umd/main.css', (err) => {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -23,12 +23,12 @@ function AuthFrame({adminUrl, onLoad}) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CommentsBoxContainer({done}) {
|
function CommentsBoxContainer({done, appVersion}) {
|
||||||
if (!done) {
|
if (!done) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<ShadowRoot>
|
<ShadowRoot appVersion={appVersion}>
|
||||||
<CommentsBox />
|
<CommentsBox />
|
||||||
</ShadowRoot>
|
</ShadowRoot>
|
||||||
);
|
);
|
||||||
|
@ -301,7 +301,7 @@ export default class App extends React.Component {
|
||||||
return (
|
return (
|
||||||
<SentryErrorBoundary dsn={this.props.sentryDsn}>
|
<SentryErrorBoundary dsn={this.props.sentryDsn}>
|
||||||
<AppContext.Provider value={this.getContextFromState()}>
|
<AppContext.Provider value={this.getContextFromState()}>
|
||||||
<CommentsBoxContainer done={done} />
|
<CommentsBoxContainer done={done} appVersion={this.props.appVersion} />
|
||||||
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initSetup.bind(this)}/>
|
<AuthFrame adminUrl={this.props.adminUrl} onLoad={this.initSetup.bind(this)}/>
|
||||||
</AppContext.Provider>
|
</AppContext.Provider>
|
||||||
</SentryErrorBoundary>
|
</SentryErrorBoundary>
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import root from 'react-shadow';
|
import root from 'react-shadow';
|
||||||
|
import {getBundledCssLink} from '../utils/helpers';
|
||||||
|
|
||||||
const ShadowRoot = ({
|
const ShadowRoot = ({
|
||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
|
const cssLink = getBundledCssLink({appVersion: props.appVersion});
|
||||||
const head = (
|
const head = (
|
||||||
<link rel="stylesheet" href="http://localhost:4000/main.css" />
|
<link rel="stylesheet" href={cssLink} />
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -37,8 +37,9 @@ function getSiteData() {
|
||||||
const colorScheme = scriptTag.dataset.colorScheme;
|
const colorScheme = scriptTag.dataset.colorScheme;
|
||||||
const avatarSaturation = scriptTag.dataset.avatarSaturation;
|
const avatarSaturation = scriptTag.dataset.avatarSaturation;
|
||||||
const accentColor = scriptTag.dataset.accentColor;
|
const accentColor = scriptTag.dataset.accentColor;
|
||||||
|
const appVersion = scriptTag.dataset.appVersion;
|
||||||
|
|
||||||
return {siteUrl, apiKey, apiUrl, sentryDsn, postId, adminUrl, colorScheme, avatarSaturation, accentColor};
|
return {siteUrl, apiKey, apiUrl, sentryDsn, postId, adminUrl, colorScheme, avatarSaturation, accentColor, appVersion};
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -58,13 +59,13 @@ function setup({siteUrl}) {
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
// const customSiteUrl = getSiteUrl();
|
// const customSiteUrl = getSiteUrl();
|
||||||
const {siteUrl: customSiteUrl, sentryDsn, postId, adminUrl, colorScheme, avatarSaturation, accentColor} = getSiteData();
|
const {siteUrl: customSiteUrl, sentryDsn, postId, adminUrl, colorScheme, avatarSaturation, accentColor, appVersion} = getSiteData();
|
||||||
const siteUrl = customSiteUrl || window.location.origin;
|
const siteUrl = customSiteUrl || window.location.origin;
|
||||||
setup({siteUrl});
|
setup({siteUrl});
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
{<App adminUrl={adminUrl} siteUrl={siteUrl} customSiteUrl={customSiteUrl} sentryDsn={sentryDsn} postId={postId} colorScheme={colorScheme} avatarSaturation={avatarSaturation} accentColor={accentColor} />}
|
{<App appVersion={appVersion} adminUrl={adminUrl} siteUrl={siteUrl} customSiteUrl={customSiteUrl} sentryDsn={sentryDsn} postId={postId} colorScheme={colorScheme} avatarSaturation={avatarSaturation} accentColor={accentColor} />}
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById(ROOT_DIV_ID)
|
document.getElementById(ROOT_DIV_ID)
|
||||||
);
|
);
|
||||||
|
|
|
@ -104,3 +104,11 @@ export function getInitials(name) {
|
||||||
|
|
||||||
return parts[0].substring(0, 1) + parts[parts.length - 1].substring(0, 1);
|
return parts[0].substring(0, 1) + parts[parts.length - 1].substring(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getBundledCssLink({appVersion}) {
|
||||||
|
if (process.env.NODE_ENV === 'production' && appVersion) {
|
||||||
|
return `https://unpkg.com/@tryghost/comments-ui@~${appVersion}/umd/main.css`;
|
||||||
|
} else {
|
||||||
|
return 'http://localhost:3000/main.css';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue