8
0

extensions.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* jshint node: false, browser: true, globalstrict: true */
  6. /* globals bender, require, define */
  7. 'use strict';
  8. ( () => {
  9. /**
  10. * AMD tools related to CKEditor.
  11. */
  12. bender.amd = {
  13. getModulePath( name ) {
  14. let appBasePath = bender.basePath;
  15. let ckeditorBasePath = bender.config.applications.ckeditor.basePath;
  16. let moduleBasePath;
  17. // Ugh... make some paths cleanup, because we need to combine these fragments and we don't want to
  18. // duplicate '/'. BTW. if you want to touch this make sure you haven't broken Bender jobs which
  19. // have different bender.basePaths (no trailing '/', unnecessary 'tests/' fragment).
  20. moduleBasePath =
  21. appBasePath
  22. .split( '/' )
  23. .filter( nonEmpty )
  24. // When running a job we need to drop the last parth of the base path, which is "tests".
  25. .slice( 0, -1 )
  26. .concat(
  27. ckeditorBasePath.split( '/' ).filter( nonEmpty )
  28. )
  29. .join( '/' );
  30. if ( name != 'ckeditor' ) {
  31. // Resolve shortened feature names to `featureName/featureName`.
  32. if ( name.indexOf( '/' ) < 0 ) {
  33. name = name + '/' + name;
  34. }
  35. // Add the prefix to shortened paths like `core/editor` (will be `ckeditor5-core/editor`).
  36. // Don't add the prefix to the main file and files frok ckeditor5/ module.
  37. if ( !( /^ckeditor5\//.test( name ) ) ) {
  38. name = 'ckeditor5-' + name;
  39. }
  40. }
  41. return '/' + moduleBasePath + '/' + name + '.js';
  42. },
  43. define( name, deps, body ) {
  44. if ( arguments.length == 2 ) {
  45. body = deps;
  46. deps = [];
  47. }
  48. const depsPaths = deps.map( bender.amd.getModulePath );
  49. define( bender.amd.getModulePath( name ), depsPaths, function() {
  50. const loadedDeps = Array.from( arguments ).map( ( module ) => module.default );
  51. return {
  52. default: body.apply( this, loadedDeps )
  53. };
  54. } );
  55. },
  56. /**
  57. * Gets an object which holds the CKEditor modules guaranteed to be loaded before tests start.
  58. *
  59. * @params {...String} module The name of the module to load.
  60. * @returns {Object} The object that will hold the loaded modules.
  61. */
  62. require() {
  63. const modules = {};
  64. const done = bender.defer();
  65. const names = Array.from( arguments );
  66. const modulePaths = names.map( bender.amd.getModulePath );
  67. require( modulePaths, function() {
  68. for ( let i = 0; i < names.length; i++ ) {
  69. modules[ names[ i ] ] = arguments[ i ].default;
  70. }
  71. // Finally give green light for tests to start.
  72. done();
  73. }/*, ( err ) => {
  74. debugger;
  75. }*/ );
  76. return modules;
  77. }
  78. };
  79. function nonEmpty( str ) {
  80. return !!str.length;
  81. }
  82. } )();