Merge pull request #4921 from artoscinote/ma_SCI_7187

Support compiling webpacker content from addons [SCI-7187]
This commit is contained in:
artoscinote 2023-02-07 10:24:18 +01:00 committed by GitHub
commit 5a93cd1a12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 3 deletions

View file

@ -40,6 +40,11 @@ import contentUiCss from '!!raw-loader!tinymce/skins/ui/tinymce-5/content.min.cs
const contentPStyle = `p { margin: 0; padding: 0; font-family: 'Lato' }`;
const contentStyle = [contentCss, contentUiCss, contentPStyle].map((s) => s.toString()).join('\n');
// Optional pre-initialization method
if (typeof(window.preTinyMceInit) === 'function') {
window.preTinyMceInit();
}
window.TinyMCE = (() => {
function initHighlightjs() {
$('[class*=language]').each((i, block) => {
@ -185,7 +190,7 @@ window.TinyMCE = (() => {
table autosave autoresize link advlist codesample autolink lists
charmap anchor searchreplace wordcount visualblocks visualchars
insertdatetime nonbreaking save directionality customimageuploader
marvinjs custom_image_toolbar help quickbars
marvinjs custom_image_toolbar help quickbars ${window.extraTinyMcePlugins ? window.extraTinyMcePlugins : ''}
`;
// if (typeof (MarvinJsEditor) !== 'undefined') plugins += ' marvinjsplugin';
@ -212,7 +217,7 @@ window.TinyMCE = (() => {
insert: { title: 'Insert', items: 'link codesample inserttable | charmap hr | nonbreaking anchor | insertdatetime customimageuploader marvinjs' },
},
menubar: 'file edit view insert format table',
toolbar: 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | link | forecolor backcolor | codesample | customimageuploader marvinjs | help',
toolbar: window.customTinyMceToolbar || 'undo redo restoredraft | insert | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | link | forecolor backcolor | codesample | customimageuploader marvinjs | help',
plugins,
autoresize_bottom_margin: 20,
placeholder: options.placeholder,

View file

@ -1,9 +1,39 @@
const { environment } = require('@rails/webpacker')
const { VueLoaderPlugin } = require('vue-loader')
const vue = require('./loaders/vue')
const { execSync } = require('child_process');
const { basename, resolve } = require('path');
const { readdirSync } = require('fs');
environment.loaders.delete('nodeModules')
environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())
environment.loaders.prepend('vue', vue)
module.exports = environment
// Engine pack loading based on https://github.com/rails/webpacker/issues/348#issuecomment-635480949
// Get paths to all engines' folders
const enginePaths = execSync('ls -d $PWD/addons/*').toString().split('\n').filter((p) => !!p);
enginePaths.forEach((path) => {
const packsFolderPath = `${path}/app/javascript/packs`;
let entryFiles;
try {
entryFiles = readdirSync(packsFolderPath);
console.log(`Found packs in ${path}`);
} catch {
console.log(`No packs in ${path}`);
return;
}
entryFiles.forEach((file) => {
// File name without .js
const name = basename(file, '.js');
const entryPath = `${packsFolderPath}/${file}`;
environment.entry.set(name, entryPath);
});
// Otherwise babel won't transpile the file
environment.loaders.get('babel').include.push(`${path}/app/javascript`);
});
module.exports = environment;

11
engines_yarn_install.js Normal file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env node
const { spawn, execSync } = require('child_process');
const enginePaths = execSync('ls -d $PWD/addons/*').toString().split('\n').filter((p) => !!p);
enginePaths.forEach(enginePath => {
spawn('yarn', ['install'], {
env: process.env,
cwd: enginePath,
stdio: 'inherit'
});
});

View file

@ -20,6 +20,7 @@
"flow": "flow",
"lint": "eslint ."
},
"postinstall": "./engines_yarn_install.js",
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-transform-react-jsx-source": "^7.0.0",