|
@@ -5,6 +5,8 @@
|
|
|
|
|
|
|
|
/* eslint-env node */
|
|
/* eslint-env node */
|
|
|
|
|
|
|
|
|
|
+const cwd = process.cwd();
|
|
|
|
|
+
|
|
|
const path = require( 'path' );
|
|
const path = require( 'path' );
|
|
|
const fs = require( 'fs' );
|
|
const fs = require( 'fs' );
|
|
|
const chalk = require( 'chalk' );
|
|
const chalk = require( 'chalk' );
|
|
@@ -12,22 +14,32 @@ const glob = require( 'glob' );
|
|
|
const mkdirp = require( 'mkdirp' );
|
|
const mkdirp = require( 'mkdirp' );
|
|
|
const postcss = require( 'postcss' );
|
|
const postcss = require( 'postcss' );
|
|
|
const webpack = require( 'webpack' );
|
|
const webpack = require( 'webpack' );
|
|
|
|
|
+const Table = require( 'cli-table' );
|
|
|
const { tools, styles } = require( '@ckeditor/ckeditor5-dev-utils' );
|
|
const { tools, styles } = require( '@ckeditor/ckeditor5-dev-utils' );
|
|
|
const { version } = require( '../../package.json' );
|
|
const { version } = require( '../../package.json' );
|
|
|
|
|
|
|
|
const DESTINATION_DIRECTORY = path.join( __dirname, '..', '..', 'build', 'content-styles' );
|
|
const DESTINATION_DIRECTORY = path.join( __dirname, '..', '..', 'build', 'content-styles' );
|
|
|
|
|
+const CONTENT_STYLES_GUIDE_PATH = path.join( __dirname, '..', '..', 'docs', 'builds', 'guides', 'integration', 'content-styles.md' );
|
|
|
|
|
+const CONTENT_STYLES_DETAILS_PATH = path.join( __dirname, 'content-styles-details.json' );
|
|
|
|
|
+
|
|
|
const DOCUMENTATION_URL = 'https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/content-styles.html';
|
|
const DOCUMENTATION_URL = 'https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/content-styles.html';
|
|
|
|
|
+
|
|
|
const VARIABLE_DEFINITION_REGEXP = /(--[\w-]+):\s+(.*);/g;
|
|
const VARIABLE_DEFINITION_REGEXP = /(--[\w-]+):\s+(.*);/g;
|
|
|
const VARIABLE_USAGE_REGEXP = /var\((--[\w-]+)\)/g;
|
|
const VARIABLE_USAGE_REGEXP = /var\((--[\w-]+)\)/g;
|
|
|
-const CONTENT_STYLES_GUIDE_PATH = path.join( __dirname, '..', '..', 'docs', 'builds', 'guides', 'integration', 'content-styles.md' );
|
|
|
|
|
|
|
+
|
|
|
|
|
+const contentStylesDetails = require( CONTENT_STYLES_DETAILS_PATH );
|
|
|
|
|
+
|
|
|
|
|
+// An array of objects with plugins used to generate the current version of the content styles.
|
|
|
|
|
+let foundModules;
|
|
|
|
|
|
|
|
const contentRules = {
|
|
const contentRules = {
|
|
|
selector: [],
|
|
selector: [],
|
|
|
variables: [],
|
|
variables: [],
|
|
|
atRules: {}
|
|
atRules: {}
|
|
|
};
|
|
};
|
|
|
-const packagesPath = path.join( process.cwd(), 'packages' );
|
|
|
|
|
-const shouldUpdateGuide = process.argv.includes( '--commit' );
|
|
|
|
|
|
|
+
|
|
|
|
|
+const packagesPath = path.join( cwd, 'packages' );
|
|
|
|
|
+const shouldCommitChanges = process.argv.includes( '--commit' );
|
|
|
|
|
|
|
|
logProcess( 'Gathering all CKEditor 5 modules...' );
|
|
logProcess( 'Gathering all CKEditor 5 modules...' );
|
|
|
|
|
|
|
@@ -44,7 +56,7 @@ getCkeditor5ModulePaths()
|
|
|
return checkWhetherIsCKEditor5Plugin( modulePath )
|
|
return checkWhetherIsCKEditor5Plugin( modulePath )
|
|
|
.then( isModule => {
|
|
.then( isModule => {
|
|
|
if ( isModule ) {
|
|
if ( isModule ) {
|
|
|
- ckeditor5Modules.push( path.join( process.cwd(), modulePath ) );
|
|
|
|
|
|
|
+ ckeditor5Modules.push( path.join( cwd, modulePath ) );
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
@@ -58,7 +70,9 @@ getCkeditor5ModulePaths()
|
|
|
|
|
|
|
|
return mkdirp( DESTINATION_DIRECTORY ).then( () => generateCKEditor5Source( ckeditor5Modules ) );
|
|
return mkdirp( DESTINATION_DIRECTORY ).then( () => generateCKEditor5Source( ckeditor5Modules ) );
|
|
|
} )
|
|
} )
|
|
|
- .then( () => {
|
|
|
|
|
|
|
+ .then( ckeditor5Modules => {
|
|
|
|
|
+ foundModules = ckeditor5Modules;
|
|
|
|
|
+
|
|
|
logProcess( 'Building the editor...' );
|
|
logProcess( 'Building the editor...' );
|
|
|
const webpackConfig = getWebpackConfig();
|
|
const webpackConfig = getWebpackConfig();
|
|
|
|
|
|
|
@@ -162,12 +176,40 @@ getCkeditor5ModulePaths()
|
|
|
.then( () => {
|
|
.then( () => {
|
|
|
console.log( `Content styles have been extracted to ${ path.join( DESTINATION_DIRECTORY, 'content-styles.css' ) }` );
|
|
console.log( `Content styles have been extracted to ${ path.join( DESTINATION_DIRECTORY, 'content-styles.css' ) }` );
|
|
|
|
|
|
|
|
- if ( !shouldUpdateGuide ) {
|
|
|
|
|
|
|
+ logProcess( 'Looking for new plugins...' );
|
|
|
|
|
+
|
|
|
|
|
+ const newPlugins = findNewPlugins( foundModules, contentStylesDetails.plugins );
|
|
|
|
|
+
|
|
|
|
|
+ if ( newPlugins.length ) {
|
|
|
|
|
+ console.log( 'Found new plugins.' );
|
|
|
|
|
+ displayNewPluginsTable( newPlugins );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.log( 'Previous and current versions of the content styles stylesheet were generated with the same set of plugins.' );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( !shouldCommitChanges ) {
|
|
|
logProcess( 'Done.' );
|
|
logProcess( 'Done.' );
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
return Promise.resolve();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ( newPlugins.length ) {
|
|
|
|
|
+ logProcess( 'Updating the content styles details file...' );
|
|
|
|
|
+
|
|
|
|
|
+ tools.updateJSONFile( CONTENT_STYLES_DETAILS_PATH, json => {
|
|
|
|
|
+ const newPluginsObject = {};
|
|
|
|
|
+
|
|
|
|
|
+ for ( const data of foundModules ) {
|
|
|
|
|
+ const modulePath = normalizePath( data.modulePath.replace( cwd + path.sep, '' ) );
|
|
|
|
|
+ newPluginsObject[ modulePath ] = data.pluginName;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ json.plugins = newPluginsObject;
|
|
|
|
|
+
|
|
|
|
|
+ return json;
|
|
|
|
|
+ } );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
logProcess( 'Updating the content styles guide...' );
|
|
logProcess( 'Updating the content styles guide...' );
|
|
|
|
|
|
|
|
const promises = [
|
|
const promises = [
|
|
@@ -184,11 +226,12 @@ getCkeditor5ModulePaths()
|
|
|
.then( () => {
|
|
.then( () => {
|
|
|
logProcess( 'Saving and committing...' );
|
|
logProcess( 'Saving and committing...' );
|
|
|
|
|
|
|
|
- const contentStyleFile = CONTENT_STYLES_GUIDE_PATH.replace( process.cwd() + path.sep, '' );
|
|
|
|
|
|
|
+ const contentStyleGuide = CONTENT_STYLES_GUIDE_PATH.replace( cwd + path.sep, '' );
|
|
|
|
|
+ const contentStyleDetails = CONTENT_STYLES_DETAILS_PATH.replace( cwd + path.sep, '' );
|
|
|
|
|
|
|
|
// Commit the documentation.
|
|
// Commit the documentation.
|
|
|
- if ( exec( `git diff --name-only ${ contentStyleFile }` ).trim().length ) {
|
|
|
|
|
- exec( `git add ${ contentStyleFile }` );
|
|
|
|
|
|
|
+ if ( exec( `git diff --name-only ${ contentStyleGuide } ${ contentStyleDetails }` ).trim().length ) {
|
|
|
|
|
+ exec( `git add ${ contentStyleGuide } ${ contentStyleDetails }` );
|
|
|
exec( 'git commit -m "Docs (ckeditor5): Updated the content styles stylesheet."' );
|
|
exec( 'git commit -m "Docs (ckeditor5): Updated the content styles stylesheet."' );
|
|
|
|
|
|
|
|
console.log( 'Successfully updated the content styles guide.' );
|
|
console.log( 'Successfully updated the content styles guide.' );
|
|
@@ -227,7 +270,7 @@ function getCkeditor5ModulePaths() {
|
|
|
* @returns {Promise.<Boolean>}
|
|
* @returns {Promise.<Boolean>}
|
|
|
*/
|
|
*/
|
|
|
function checkWhetherIsCKEditor5Plugin( modulePath ) {
|
|
function checkWhetherIsCKEditor5Plugin( modulePath ) {
|
|
|
- return readFile( path.join( process.cwd(), modulePath ) )
|
|
|
|
|
|
|
+ return readFile( path.join( cwd, modulePath ) )
|
|
|
.then( content => {
|
|
.then( content => {
|
|
|
const pluginName = path.basename( modulePath, '.js' );
|
|
const pluginName = path.basename( modulePath, '.js' );
|
|
|
|
|
|
|
@@ -278,7 +321,8 @@ function generateCKEditor5Source( ckeditor5Modules ) {
|
|
|
|
|
|
|
|
sourceFileContent.push( '];' );
|
|
sourceFileContent.push( '];' );
|
|
|
|
|
|
|
|
- return writeFile( path.join( DESTINATION_DIRECTORY, 'source.js' ), sourceFileContent.join( '\n' ) );
|
|
|
|
|
|
|
+ return writeFile( path.join( DESTINATION_DIRECTORY, 'source.js' ), sourceFileContent.join( '\n' ) )
|
|
|
|
|
+ .then( () => ckeditor5Modules );
|
|
|
|
|
|
|
|
function capitalize( value ) {
|
|
function capitalize( value ) {
|
|
|
return value.charAt( 0 ).toUpperCase() + value.slice( 1 );
|
|
return value.charAt( 0 ).toUpperCase() + value.slice( 1 );
|
|
@@ -536,6 +580,50 @@ function transformCssRules( rules ) {
|
|
|
.join( '\n' );
|
|
.join( '\n' );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Returns an object that contains objects with new plugins.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {Array.<Object>} currentPlugins
|
|
|
|
|
+ * @param {Array.<Object>} previousPlugins
|
|
|
|
|
+ * @returns {{Array.<Object>}}
|
|
|
|
|
+ */
|
|
|
|
|
+function findNewPlugins( currentPlugins, previousPlugins ) {
|
|
|
|
|
+ const newPlugins = [];
|
|
|
|
|
+
|
|
|
|
|
+ for ( const data of currentPlugins ) {
|
|
|
|
|
+ // Use relative paths.
|
|
|
|
|
+ const modulePath = normalizePath( data.modulePath.replace( cwd + path.sep, '' ) );
|
|
|
|
|
+
|
|
|
|
|
+ if ( !previousPlugins[ modulePath ] ) {
|
|
|
|
|
+ newPlugins.push( data );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return newPlugins;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Displays a table with new plugins.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {Array.<Object>} newPlugins
|
|
|
|
|
+ */
|
|
|
|
|
+function displayNewPluginsTable( newPlugins ) {
|
|
|
|
|
+ const table = new Table( {
|
|
|
|
|
+ head: [ 'Plugin name', 'Module path' ],
|
|
|
|
|
+ style: { compact: true }
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ for ( const data of newPlugins ) {
|
|
|
|
|
+ table.push( [ data.pluginName, data.modulePath ] );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log( table.toString() + '\n' );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function normalizePath( modulePath ) {
|
|
|
|
|
+ return modulePath.split( path.sep ).join( path.posix.sep );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function exec( command ) {
|
|
function exec( command ) {
|
|
|
return tools.shExec( command, { verbosity: 'error' } );
|
|
return tools.shExec( command, { verbosity: 'error' } );
|
|
|
}
|
|
}
|