Skip to content

Commit

Permalink
Change script to valid grunt task.
Browse files Browse the repository at this point in the history
  • Loading branch information
f1ames authored and jacekbogdanski committed Nov 30, 2020
1 parent 9db2881 commit db8fa15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/ckeditor_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// #### Compressed Code
// Compressed code in ckeditor.js must be be updated on changes in the script.
// Simply run `npm run build-base` after changing this file.
// Simply run `grunt ckeditor-base-replace` after changing this file.

// #### Raw code
// ATTENTION: read the above "Compressed Code" notes when changing this code.
Expand Down
39 changes: 22 additions & 17 deletions dev/tasks/ckeditor-base-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@
/* 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' );

const code = fs.readFileSync( './core/ckeditor_base.js', 'utf8' );
const minified = uglify.minify( code, {
ie8: true
} );
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`
} );
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 }` );
}
console.log( `Replacement successful:` );
console.log( results );
}
catch ( error ) {
console.error( `Replacement failed: ${ error }` );
}
} );
};
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"uglify-js": "^3.12.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-base": "node dev/tasks/ckeditor-base-replace.js"
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ckeditor4",
Expand Down

0 comments on commit db8fa15

Please sign in to comment.