Skip to content

Commit

Permalink
add custom button to linkUI of CKEditor5
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeerten committed Nov 13, 2020
1 parent ee074a2 commit 85ff439
Show file tree
Hide file tree
Showing 75 changed files with 3,635 additions and 1,890 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"extends": ["./node_modules/@kunstmaan/eslint-config/index.js"],
"rules": {
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["gulpfile.babel.js", "./groundcontrol/**/*.js"]}]
}
},
"ignorePatterns": ["**/AdminBundle/Resources/ui/js/*.js"]
}
5 changes: 4 additions & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": ["./node_modules/@kunstmaan/stylelint-config/index.js"],
"rules": {
}
},
"ignoreFiles": [
"**/*.js"
]
}
153 changes: 105 additions & 48 deletions groundcontrol/admin-bundle.tasks.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
/* eslint-env node */

import gulp from 'gulp';
import path from 'path';
import CKEditorWebpackPlugin from '@ckeditor/ckeditor5-dev-webpack-plugin';
import { styles } from '@ckeditor/ckeditor5-dev-utils';
import TerserPlugin from 'terser-webpack-plugin';

import consoleArguments from './console-arguments';

import createEslintTask from './tasks/eslint';
import createStylelintTask from './tasks/stylelint';
import createCopyTask from './tasks/copy';
import {createCssLocalTask, createCssOptimizedTask} from './tasks/css';
import { createCssLocalTask, createCssOptimizedTask } from './tasks/css';
import createScriptsTask from './tasks/scripts';
import createBundleTask, {getBabelLoaderOptions} from './tasks/bundle';

import createBundleTask, { getBabelLoaderOptions } from './tasks/bundle';

export const adminBundle = {
config: {
srcPath: './src/Kunstmaan/AdminBundle/Resources/ui/',
distPath: './src/Kunstmaan/AdminBundle/Resources/public/',
publicPath: '/bundles/kunstmaanadmin'
publicPath: '/bundles/kunstmaanadmin',
},
tasks: {}
tasks: {},
};

adminBundle.tasks.eslint = createEslintTask({
src: `${adminBundle.config.srcPath}jsnext/**/*.js`,
failAfterError: !consoleArguments.continueAfterTestError
failAfterError: !consoleArguments.continueAfterTestError,
});

adminBundle.tasks.stylelint = createStylelintTask({
src: `${adminBundle.config.srcPath}scssnext/**/*.scss`,
});

adminBundle.tasks.copy = gulp.parallel(
createCopyTask({src: [`${adminBundle.config.srcPath}img/**`], dest: `${adminBundle.config.distPath}img`}),
createCopyTask({src: [`${adminBundle.config.srcPath}icons/**`], dest: `${adminBundle.config.distPath}icons`})
createCopyTask({
src: [`${adminBundle.config.srcPath}img/**`],
dest: `${adminBundle.config.distPath}img`,
}),
createCopyTask({
src: [`${adminBundle.config.srcPath}icons/**`],
dest: `${adminBundle.config.distPath}icons`,
}),
);

adminBundle.tasks.cssLocal = createCssLocalTask({src: `${adminBundle.config.srcPath}scss/*.scss`, dest: `${adminBundle.config.distPath}css`});
adminBundle.tasks.cssNextLocal = createCssLocalTask({src: `${adminBundle.config.srcPath}scssnext/*.scss`, dest: `${adminBundle.config.distPath}cssnext`});


adminBundle.tasks.cssLocal = createCssLocalTask({
src: `${adminBundle.config.srcPath}scss/*.scss`,
dest: `${adminBundle.config.distPath}css`,
});
adminBundle.tasks.cssNextLocal = createCssLocalTask({
src: `${adminBundle.config.srcPath}scssnext/*.scss`,
dest: `${adminBundle.config.distPath}cssnext`,
});

adminBundle.tasks.cssOptimized = createCssOptimizedTask({src: `${adminBundle.config.srcPath}scss/*.scss`, dest: `${adminBundle.config.distPath}css`});
adminBundle.tasks.cssNextOptimized = createCssOptimizedTask({src: `${adminBundle.config.srcPath}scssnext/*.scss`, dest: `${adminBundle.config.distPath}cssnext`});
adminBundle.tasks.cssOptimized = createCssOptimizedTask({
src: `${adminBundle.config.srcPath}scss/*.scss`,
dest: `${adminBundle.config.distPath}css`,
});
adminBundle.tasks.cssNextOptimized = createCssOptimizedTask({
src: `${adminBundle.config.srcPath}scssnext/*.scss`,
dest: `${adminBundle.config.distPath}cssnext`,
});

adminBundle.tasks.scripts = createScriptsTask({
src: [
Expand All @@ -60,18 +75,19 @@ adminBundle.tasks.scripts = createScriptsTask({
'./node_modules/sortablejs/Sortable.js',
'./node_modules/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js',
'./node_modules/jquery.typewatch/jquery.typewatch.js',
`${adminBundle.config.srcPath}js/**/*.js`
`${adminBundle.config.srcPath}js/**/*.js`,
],
dest: `${adminBundle.config.distPath}js`,
filename: 'admin-bundle.min.js'
filename: 'admin-bundle.min.js',
uglifyJs: !consoleArguments.speedupLocalDevelopment,
});

adminBundle.tasks.bundle = createBundleTask({
config: {
entry: `${adminBundle.config.srcPath}jsnext/app.js`,
output: {
filename: 'admin-bundle.next.js',
path: path.resolve(__dirname, `.${adminBundle.config.distPath}js`)
path: path.resolve(__dirname, `.${adminBundle.config.distPath}js`),
},
devtool: 'cheap-module-source-map',
mode: 'development',
Expand All @@ -87,7 +103,7 @@ adminBundle.tasks.bundle = createBundleTask({
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
use: [ 'raw-loader' ]
use: ['raw-loader'],
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
Expand All @@ -97,27 +113,28 @@ adminBundle.tasks.bundle = createBundleTask({
options: {
injectType: 'singletonStyleTag',
attributes: {
'data-cke': true
}
}
'data-cke': true,
},
},
},
{
loader: 'postcss-loader',
options: styles.getPostCssConfig( {
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
themePath: require.resolve('@ckeditor/ckeditor5-theme-lark'),
},
minify: true
} )
sourceMap: true,
}),
},
]
}
]
],
},
],
},
plugins: [
new CKEditorWebpackPlugin({
// See https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
language: 'en',
additionalLanguages: 'all',
outputDirectory: 'cke-translations',
}),
],
},
Expand All @@ -128,12 +145,15 @@ adminBundle.tasks.bundleOptimized = createBundleTask({
entry: `${adminBundle.config.srcPath}jsnext/app.js`,
output: {
filename: 'admin-bundle.next.js',
path: path.resolve(__dirname, `.${adminBundle.config.distPath}js`)
path: path.resolve(__dirname, `.${adminBundle.config.distPath}js`),

},
devtool: 'source-map',
optimization: {
minimize: true
minimize: true,
minimizer: [new TerserPlugin({
sourceMap: false,
extractComments: false,
})],
},
mode: 'production',
module: {
Expand All @@ -143,25 +163,62 @@ adminBundle.tasks.bundleOptimized = createBundleTask({
exclude: /node_modules/,
loader: 'babel-loader',
query: getBabelLoaderOptions({
optimize: true
})
}
]
}
transpileOnlyForLastChromes: consoleArguments.speedupLocalDevelopment,
}),
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
use: ['raw-loader'],
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
use: [
{
loader: 'style-loader',
options: {
injectType: 'singletonStyleTag',
attributes: {
'data-cke': true,
},
},
},
{
loader: 'postcss-loader',
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve('@ckeditor/ckeditor5-theme-lark'),
},
minify: true,
}),
},
],
},
],
},
plugins: [
new CKEditorWebpackPlugin({
language: 'en',
additionalLanguages: 'all',
outputDirectory: 'cke-translations',
}),
],
},
logStats: true
logStats: true,
});

adminBundle.tasks.bundlePolyfills = createBundleTask({
config: {
entry: ['babel-polyfill', `${adminBundle.config.srcPath}jsnext/polyfills.js`],
output: {
filename: 'admin-bundle-polyfills.js',
path: path.resolve(__dirname, `.${adminBundle.config.distPath}js`)
path: path.resolve(__dirname, `.${adminBundle.config.distPath}js`),
},
devtool: 'source-map',
optimization: {
minimize: true
minimize: true,
minimizer: [new TerserPlugin({
sourceMap: false,
extractComments: false,
})],
},
mode: 'production',
module: {
Expand All @@ -171,11 +228,11 @@ adminBundle.tasks.bundlePolyfills = createBundleTask({
exclude: /node_modules/,
loader: 'babel-loader',
query: getBabelLoaderOptions({
optimize: true
})
}
]
}
optimize: true,
}),
},
],
},
},
logStats: true
logStats: true,
});
18 changes: 10 additions & 8 deletions groundcontrol/tasks/bundle.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import webpack from 'webpack';

/**
* You can let webpack watch the files and rebundle on change, or you can do it
* via gulp. Gulp will probably be easier at first, since you have to configure
* multiple watches for the other src files as well.
*/
export default function createBundleTask({config = undefined, watch = false, logStats = false}) {
export default function createBundleTask({config = undefined, logStats = false}) {
const compiler = webpack(config);
const devMode = config.mode === 'development';

return function bundle(done) {
if (watch) {
compiler.watch({}, handleWebpackResult);
} else {
compiler.run(handleWebpackResult);
}
compiler.run(handleWebpackResult);

function handleWebpackResult(err, stats) {
if (err) {
Expand All @@ -26,11 +24,15 @@ export default function createBundleTask({config = undefined, watch = false, log
const info = stats.toJson();

if (stats.hasErrors()) {
console.error(info.errors);
if (devMode) {
console.error('\x1b[31m%s\x1b[0m: ', info.errors.toString());
} else {
throw Error(info.errors.toString());
}
}

if (stats.hasWarnings()) {
console.warn(info.warnings);
console.warn(info.warnings.toString());
}

if (logStats) {
Expand Down
23 changes: 16 additions & 7 deletions groundcontrol/tasks/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ import gulp from 'gulp';
import uglify from 'gulp-uglify';
import concat from 'gulp-concat';
import debug from 'gulp-debug';
import { noop } from 'gulp-util';

/**
* Temporary scripts task.
* This should be replaced by webpack to bundle the files
*/

export default function createScriptsTask({ src = undefined, dest = undefined, filename = undefined }) {
export default function createScriptsTask({
src = undefined,
dest = undefined,
filename = undefined,
uglifyJs = true,
}) {
return function scriptsLocal() {
return gulp.src(src)
return gulp
.src(src)
.pipe(debug({ title: 'Building' }))
.pipe(uglify({
mangle: {
except: ['jQuery']
}
}))
.pipe(uglifyJs
? uglify({
mangle: {
except: ['jQuery'],
},
})
: noop())
.pipe(concat(filename))
.pipe(gulp.dest(dest));
};
Expand Down

0 comments on commit 85ff439

Please sign in to comment.