Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed more flexible usage of docs generator by supporting variable injections via snippetOptions.definitions #1528

Merged
merged 4 commits into from
Feb 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions scripts/docs/snippetadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module.exports = function snippetAdapter( data ) {
entry: data.snippetSource.js,
outputPath,
language: snippetConfig.language,
production: data.options.production
production: data.options.production,
definitions: data.options.definitions || {}
} );

let promise;
Expand Down Expand Up @@ -83,6 +84,14 @@ module.exports = function snippetAdapter( data ) {
};

function getWebpackConfig( config ) {
// Stringify all definitions values. The `DefinePlugin` injects definition values as they are so we need to stringify them,
// so they will become real strings in the generated code. See https://webpack.js.org/plugins/define-plugin/ for more information.
const definitions = {};

for ( const definitionKey in config.definitions ) {
definitions[ definitionKey ] = JSON.stringify( config.definitions[ definitionKey ] );
}

return {
mode: config.production ? 'production' : 'development',

Expand Down Expand Up @@ -117,7 +126,8 @@ function getWebpackConfig( config ) {
new webpack.BannerPlugin( {
banner: bundler.getLicenseBanner(),
raw: true
} )
} ),
new webpack.DefinePlugin( definitions )
],

// Configure the paths so building CKEditor 5 snippets work even if the script
Expand Down