| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- 'use strict';
- /* eslint-env node */
- const fs = require( 'fs' );
- const path = require( 'path' );
- const postcss = require( 'postcss' );
- const postCssImport = require( 'postcss-import' );
- module.exports = postcss.plugin( 'postcss-ckeditor-theme-importer', options => {
- const themeName = options.themePath.split( '/' ).slice( -1 );
- console.log( `Using theme "${ themeName }".` );
- return root => {
- const fileName = path.basename( root.source.input.file );
- const packageName = getPackageName( root.source.input.file );
- const relativeFilePath = path.relative( __dirname, root.source.input.file );
- const themeFile = path.resolve( __dirname, options.themePath, 'theme', packageName, fileName );
- if ( fs.existsSync( themeFile ) ) {
- console.log( `Found a corresponding theme file for ${ relativeFilePath }. Including.` );
- return new Promise( resolve => {
- fs.readFile( themeFile, 'utf8', ( err, data ) => {
- const processor = postcss( {
- plugins: [
- postCssImport()
- ]
- } );
- return processor.process( data, { from: themeFile } )
- .then( result => {
- root.append( result.css );
- root.append( '\n' );
- resolve();
- } );
- } );
- } );
- } else {
- console.log( `Theme file for ${ relativeFilePath } not found in theme "${ themeName }".` );
- }
- };
- } );
- function getPackageName( path ) {
- const match = path.match( /ckeditor5-[^/]+/ );
- if ( match ) {
- return match[ 0 ];
- } else {
- return null;
- }
- }
- // function CKThemeLogger() {
- // return ( root ) => {
- // root.prepend( `/* ${ root.source.input.file } */` );
- // };
- // }
- // const CKRaiseSpecificity = postcss.plugin( 'postcss-ck-specificity', ( opts ) => {
- // opts = opts || {};
- // return ( root, result ) => {
- // root.walkRules( rule => {
- // if ( rule.selector.match( /^\.ck-/g ) ) {
- // rule.selector = 'body ' + rule.selector;
- // }
- // } );
- // };
- // } );
|