mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 14:02:41 +00:00
Swapping working. Splitting into separate JS bundles doesn't seem to work.
This commit is contained in:
@@ -199,7 +199,7 @@ const BrewRenderer = createClass({
|
|||||||
<RenderWarnings />
|
<RenderWarnings />
|
||||||
<NotificationPopup />
|
<NotificationPopup />
|
||||||
</div>
|
</div>
|
||||||
<link href={`${this.props.renderer == 'legacy' ? '/themes/5ePhbLegacy.style.css' : '/themes/5ePhb.style.css'}`} rel='stylesheet'/>
|
<link href={`${this.props.renderer == 'legacy' ? '/themes/Legacy/5ePHB/style.css' : '/themes/V3/5ePHB/style.css'}`} rel='stylesheet'/>
|
||||||
{/* Apply CSS from Style tab and render pages from Markdown tab */}
|
{/* Apply CSS from Style tab and render pages from Markdown tab */}
|
||||||
{this.state.isMounted
|
{this.state.isMounted
|
||||||
&&
|
&&
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ const createClass = require('create-react-class');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
|
//Import all themes
|
||||||
|
|
||||||
const SnippetsLegacy = require('./snippetsLegacy/snippets.js');
|
const Themes = {};
|
||||||
const SnippetsV3 = require('./snippets/snippets.js');
|
Themes['Legacy_5ePHB'] = require('themes/Legacy/5ePHB/snippets.js');
|
||||||
|
Themes['V3_5ePHB'] = require('themes/V3/5ePHB/snippets.js');
|
||||||
|
|
||||||
const execute = function(val, brew){
|
const execute = function(val, brew){
|
||||||
if(_.isFunction(val)) return val(brew);
|
if(_.isFunction(val)) return val(brew);
|
||||||
@@ -31,10 +33,33 @@ const Snippetbar = createClass({
|
|||||||
|
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
renderer : this.props.renderer
|
renderer : this.props.renderer,
|
||||||
|
snippets : []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentDidMount : async function() {
|
||||||
|
const rendererPath = this.props.renderer == 'V3' ? 'V3' : "Legacy";
|
||||||
|
const themePath = this.props.theme ?? '5ePHB';
|
||||||
|
console.log(Themes);
|
||||||
|
console.log(Themes[`${rendererPath}_${themePath}`]);
|
||||||
|
const snippets = Themes[`${rendererPath}_${themePath}`];
|
||||||
|
this.setState({
|
||||||
|
snippets : snippets
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidUpdate : async function(prevProps) {
|
||||||
|
if(prevProps.renderer != this.props.renderer) {
|
||||||
|
const rendererPath = this.props.renderer == 'V3' ? 'V3' : "Legacy";
|
||||||
|
const themePath = this.props.theme ?? '5ePHB';
|
||||||
|
const snippets = Themes[`${rendererPath}_${themePath}`];
|
||||||
|
this.setState({
|
||||||
|
snippets : snippets
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
handleSnippetClick : function(injectedText){
|
handleSnippetClick : function(injectedText){
|
||||||
this.props.onInject(injectedText);
|
this.props.onInject(injectedText);
|
||||||
},
|
},
|
||||||
@@ -42,10 +67,7 @@ const Snippetbar = createClass({
|
|||||||
renderSnippetGroups : function(){
|
renderSnippetGroups : function(){
|
||||||
let snippets = [];
|
let snippets = [];
|
||||||
|
|
||||||
if(this.props.renderer === 'V3')
|
snippets = this.state.snippets.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
||||||
snippets = SnippetsV3.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
|
||||||
else
|
|
||||||
snippets = SnippetsLegacy.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
|
||||||
|
|
||||||
return _.map(snippets, (snippetGroup)=>{
|
return _.map(snippets, (snippetGroup)=>{
|
||||||
return <SnippetGroup
|
return <SnippetGroup
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const assetTransform = require('vitreum/transforms/asset.js');
|
|||||||
const babel = require('@babel/core');
|
const babel = require('@babel/core');
|
||||||
const less = require('less');
|
const less = require('less');
|
||||||
|
|
||||||
const babelify = async (code)=>(await babel.transformAsync(code, { presets: ['@babel/preset-env', '@babel/preset-react'], plugins: ['@babel/plugin-transform-runtime'] })).code;
|
const babelify = async (code)=>(await babel.transformAsync(code, { presets: [["@babel/preset-env", { "exclude": ["proposal-dynamic-import"] }], '@babel/preset-react'], plugins: ['@babel/plugin-transform-runtime'] })).code;
|
||||||
|
|
||||||
const transforms = {
|
const transforms = {
|
||||||
'.js' : (code, filename, opts)=>babelify(code),
|
'.js' : (code, filename, opts)=>babelify(code),
|
||||||
@@ -25,18 +25,18 @@ const build = async ({ bundle, render, ssr })=>{
|
|||||||
await fs.outputFile('./build/homebrew/bundle.js', bundle);
|
await fs.outputFile('./build/homebrew/bundle.js', bundle);
|
||||||
await fs.outputFile('./build/homebrew/ssr.js', ssr);
|
await fs.outputFile('./build/homebrew/ssr.js', ssr);
|
||||||
await fs.copy('./themes/fonts', './build/fonts');
|
await fs.copy('./themes/fonts', './build/fonts');
|
||||||
let src = './themes/5ePhbLegacy.style.less';
|
let src = './themes/Legacy/5ePHB/style.less';
|
||||||
//Parse brew theme files
|
//Parse brew theme files
|
||||||
less.render(fs.readFileSync(src).toString(), {
|
less.render(fs.readFileSync(src).toString(), {
|
||||||
compress : !isDev
|
compress : !isDev
|
||||||
}, function(e, output) {
|
}, function(e, output) {
|
||||||
fs.outputFile('./build/themes/5ePhbLegacy.style.css', output.css);
|
fs.outputFile('./build/themes/Legacy/5ePHB/style.css', output.css);
|
||||||
});
|
});
|
||||||
src = './themes/5ePhb.style.less';
|
src = './themes/V3/5ePHB/style.less';
|
||||||
less.render(fs.readFileSync(src).toString(), {
|
less.render(fs.readFileSync(src).toString(), {
|
||||||
compress : !isDev
|
compress : !isDev
|
||||||
}, function(e, output) {
|
}, function(e, output) {
|
||||||
fs.outputFile('./build/themes/5ePhb.style.css', output.css);
|
fs.outputFile('./build/themes/V3/5ePHB/style.css', output.css);
|
||||||
});
|
});
|
||||||
// await less.render(lessCode, {
|
// await less.render(lessCode, {
|
||||||
// compress : !dev,
|
// compress : !dev,
|
||||||
@@ -59,16 +59,43 @@ const build = async ({ bundle, render, ssr })=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.emptyDirSync('./build');
|
fs.emptyDirSync('./build');
|
||||||
pack('./client/homebrew/homebrew.jsx', {
|
|
||||||
paths : ['./shared'],
|
|
||||||
libs : Proj.libs,
|
|
||||||
dev : isDev && build,
|
|
||||||
transforms
|
|
||||||
})
|
|
||||||
.then(build)
|
|
||||||
.catch(console.error);
|
|
||||||
|
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
let bundles = await pack('./client/homebrew/homebrew.jsx', {
|
||||||
|
paths : ['./shared','./'],
|
||||||
|
libs : Proj.libs,
|
||||||
|
dev : isDev && build,
|
||||||
|
transforms
|
||||||
|
});
|
||||||
|
build(bundles);
|
||||||
|
|
||||||
|
// Possible method for generating separate bundles for snippets: factor-bundle first sending all common files to bundle.js, then again using default settings, keeping only snippet bundles
|
||||||
|
// await fs.outputFile('./build/junk.js', '');
|
||||||
|
// await fs.outputFile('./build/themes/Legacy/5ePHB/snippets.js', '');
|
||||||
|
//
|
||||||
|
// const files = ['./client/homebrew/homebrew.jsx','./themes/Legacy/5ePHB/snippets.js'];
|
||||||
|
//
|
||||||
|
// bundles = await pack(files, {
|
||||||
|
// dedupe: false,
|
||||||
|
// plugin : [['factor-bundle', { outputs: [ './build/junk.js','./build/themes/Legacy/5ePHB/snippets.js'], threshold : function(row, groups) {
|
||||||
|
// console.log(groups);
|
||||||
|
// if (groups.some(group => /.*homebrew.jsx$/.test(group))) {
|
||||||
|
// console.log("found homebrewery")
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// return this._defaultThreshold(row, groups);
|
||||||
|
// }}]],
|
||||||
|
// paths : ['./shared','./','./build'],
|
||||||
|
// libs : Proj.libs,
|
||||||
|
// dev : isDev && build,
|
||||||
|
// transforms
|
||||||
|
// });
|
||||||
|
// build(bundles);
|
||||||
|
//
|
||||||
|
|
||||||
|
})().catch(console.error);
|
||||||
|
|
||||||
//In development set up a watch server and livereload
|
//In development set up a watch server and livereload
|
||||||
if(isDev){
|
if(isDev){
|
||||||
livereload('./build');
|
livereload('./build');
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const splitTextStyleAndMetadata = (brew)=>{
|
|||||||
const index = brew.text.indexOf('```\n\n');
|
const index = brew.text.indexOf('```\n\n');
|
||||||
const metadataSection = brew.text.slice(12, index - 1);
|
const metadataSection = brew.text.slice(12, index - 1);
|
||||||
const metadata = yaml.load(metadataSection);
|
const metadata = yaml.load(metadataSection);
|
||||||
Object.assign(brew, _.pick(metadata, ['title', 'description', 'tags', 'systems', 'renderer']));
|
Object.assign(brew, _.pick(metadata, ['title', 'description', 'tags', 'systems', 'renderer', 'theme']));
|
||||||
brew.text = brew.text.slice(index + 5);
|
brew.text = brew.text.slice(index + 5);
|
||||||
}
|
}
|
||||||
if(brew.text.startsWith('```css')) {
|
if(brew.text.startsWith('```css')) {
|
||||||
@@ -60,6 +60,7 @@ const splitTextStyleAndMetadata = (brew)=>{
|
|||||||
brew.style = brew.text.slice(7, index - 1);
|
brew.style = brew.text.slice(7, index - 1);
|
||||||
brew.text = brew.text.slice(index + 5);
|
brew.text = brew.text.slice(index + 5);
|
||||||
}
|
}
|
||||||
|
_.defaults(brew, {'renderer' : 'legacy', 'theme' : '5ePHB'});
|
||||||
};
|
};
|
||||||
|
|
||||||
app.use('/', serveCompressedStaticAssets(`${__dirname}/build`));
|
app.use('/', serveCompressedStaticAssets(`${__dirname}/build`));
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const mergeBrewText = (brew)=>{
|
|||||||
`\`\`\`\n\n` +
|
`\`\`\`\n\n` +
|
||||||
`${text}`;
|
`${text}`;
|
||||||
}
|
}
|
||||||
const metadata = _.pick(brew, ['title', 'description', 'tags', 'systems', 'renderer']);
|
const metadata = _.pick(brew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme']);
|
||||||
text = `\`\`\`metadata\n` +
|
text = `\`\`\`metadata\n` +
|
||||||
`${yaml.dump(metadata)}\n` +
|
`${yaml.dump(metadata)}\n` +
|
||||||
`\`\`\`\n\n` +
|
`\`\`\`\n\n` +
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
/* Main Font, serif */
|
/* Main Font, serif */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookSanity;
|
font-family: BookSanity;
|
||||||
src: url('../fonts/5e legacy/Bookinsanity.woff2');
|
src: url('../../../fonts/5e legacy/Bookinsanity.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookSanity;
|
font-family: BookSanity;
|
||||||
src: url('../fonts/5e legacy/Bookinsanity Bold.woff2');
|
src: url('../../../fonts/5e legacy/Bookinsanity Bold.woff2');
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookSanity;
|
font-family: BookSanity;
|
||||||
src: url('../fonts/5e legacy/Bookinsanity Italic.woff2');
|
src: url('../../../fonts/5e legacy/Bookinsanity Italic.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookSanity;
|
font-family: BookSanity;
|
||||||
src: url('../fonts/5e legacy/Bookinsanity Bold Italic.woff2');
|
src: url('../../../fonts/5e legacy/Bookinsanity Bold Italic.woff2');
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
@@ -27,19 +27,19 @@
|
|||||||
/* Notes and Tables, sans-serif */
|
/* Notes and Tables, sans-serif */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySans;
|
font-family: ScalySans;
|
||||||
src: url('../fonts/5e legacy/Scaly Sans.woff2');
|
src: url('../../../fonts/5e legacy/Scaly Sans.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySansSmallCaps;
|
font-family: ScalySansSmallCaps;
|
||||||
src: url('../fonts/5e legacy/Scaly Sans Caps.woff2');
|
src: url('../../../fonts/5e legacy/Scaly Sans Caps.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: WalterTurncoat;
|
font-family: WalterTurncoat;
|
||||||
src: url('../fonts/5e legacy/WalterTurncoat-Regular.woff2');
|
src: url('../../../fonts/5e legacy/WalterTurncoat-Regular.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
/* Headers */
|
/* Headers */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: MrJeeves;
|
font-family: MrJeeves;
|
||||||
src: url('../fonts/5e legacy/Mr Eaves Small Caps.woff2');
|
src: url('../../../fonts/5e legacy/Mr Eaves Small Caps.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
/* Fancy Drop Cap */
|
/* Fancy Drop Cap */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: Solberry;
|
font-family: Solberry;
|
||||||
src: url('../fonts/5e legacy/Solbera Imitation.woff2');
|
src: url('../../../fonts/5e legacy/Solbera Imitation.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
/* Main Font, serif */
|
/* Main Font, serif */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookInsanityRemake;
|
font-family: BookInsanityRemake;
|
||||||
src: url('../fonts/5e/Bookinsanity.woff2');
|
src: url('../../../fonts/5e/Bookinsanity.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookInsanityRemake;
|
font-family: BookInsanityRemake;
|
||||||
src: url('../fonts/5e/Bookinsanity Bold.woff2');
|
src: url('../../../fonts/5e/Bookinsanity Bold.woff2');
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookInsanityRemake;
|
font-family: BookInsanityRemake;
|
||||||
src: url('../fonts/5e/Bookinsanity Italic.woff2');
|
src: url('../../../fonts/5e/Bookinsanity Italic.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: BookInsanityRemake;
|
font-family: BookInsanityRemake;
|
||||||
src: url('../fonts/5e/Bookinsanity Bold Italic.woff2');
|
src: url('../../../fonts/5e/Bookinsanity Bold Italic.woff2');
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
@@ -27,37 +27,37 @@
|
|||||||
/* Notes and Tables, sans-serif */
|
/* Notes and Tables, sans-serif */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySansRemake;
|
font-family: ScalySansRemake;
|
||||||
src: url('../fonts/5e/Scaly Sans.woff2');
|
src: url('../../../fonts/5e/Scaly Sans.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySansRemake;
|
font-family: ScalySansRemake;
|
||||||
src: url('../fonts/5e/Scaly Sans Bold.woff2');
|
src: url('../../../fonts/5e/Scaly Sans Bold.woff2');
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySansRemake;
|
font-family: ScalySansRemake;
|
||||||
src: url('../fonts/5e/Scaly Sans Italic.woff2');
|
src: url('../../../fonts/5e/Scaly Sans Italic.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySansRemake;
|
font-family: ScalySansRemake;
|
||||||
src: url('../fonts/5e/Scaly Sans Bold Italic.woff2');
|
src: url('../../../fonts/5e/Scaly Sans Bold Italic.woff2');
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: ScalySansSmallCapsRemake;
|
font-family: ScalySansSmallCapsRemake;
|
||||||
src: url('../fonts/5e/Scaly Sans Caps.woff2');
|
src: url('../../../fonts/5e/Scaly Sans Caps.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: WalterTurncoat;
|
font-family: WalterTurncoat;
|
||||||
src: url('../fonts/5e/WalterTurncoat-Regular.woff2');
|
src: url('../../../fonts/5e/WalterTurncoat-Regular.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
/* Headers */
|
/* Headers */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: MrEavesRemake;
|
font-family: MrEavesRemake;
|
||||||
src: url('../fonts/5e/Mr Eaves Small Caps.woff2');
|
src: url('../../../fonts/5e/Mr Eaves Small Caps.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
/* Fancy Drop Cap */
|
/* Fancy Drop Cap */
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: SolberaImitationRemake; //Tweaked 5e version
|
font-family: SolberaImitationRemake; //Tweaked 5e version
|
||||||
src: url('../fonts/5e/Solbera Imitation Tweak.woff2');
|
src: url('../../../fonts/5e/Solbera Imitation Tweak.woff2');
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user