File: ckeditor-base-replace.js

package info (click to toggle)
ckeditor 4.16.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 258,804 kB
  • sloc: javascript: 239,590; sh: 184; makefile: 64; python: 37; php: 15; xml: 5
file content (36 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
 * @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
 */

/* jshint node: true, browser: false, es3: false, esversion: 6 */

'use strict';

const fs = require( 'fs' );
const uglify = require( 'uglify-js' );
const replace = require( 'replace-in-file' );

module.exports = function( grunt ) {
	grunt.registerTask( 'ckeditor-base-replace', 'Inline core/ckeditor_base.js to into ckeditor.js.', function() {
		const code = fs.readFileSync( './core/ckeditor_base.js', 'utf8' );
		const minified = uglify.minify( code, {
			ie8: true
		} );

		try {
			const results = replace.sync( {
				encoding: 'utf8',
				files: './ckeditor.js',
				from: /\/\/\s+replace_start\n(.|\n|\t|\r)*?\n\/\/\s+replace_end/,
				to: `// replace_start\n${ minified.code }\n// replace_end`
			} );

			console.log( `Replacement successful:` );
			console.log( results );
		}
		catch ( error ) {
			console.error( `Replacement failed: ${ error }` );
		}
	} );
};