8
0

extensions.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. const basePath = bender.config.applications.ckeditor.basePath;
  10. /**
  11. * AMD tools related to CKEditor.
  12. */
  13. bender.amd = {
  14. getModulePath( name ) {
  15. if ( name != 'ckeditor' ) {
  16. // Resolve shortened feature names to `featureName/featureName`.
  17. if ( name.indexOf( '/' ) < 0 ) {
  18. name = name + '/' + name;
  19. }
  20. // Add the prefix to shortened paths like `core/editor` (will be `ckeditor5-core/editor`).
  21. // Don't add the prefix to the main file and files frok ckeditor5/ module.
  22. if ( !( /^ckeditor5\//.test( name ) ) ) {
  23. name = 'ckeditor5-' + name;
  24. }
  25. }
  26. return basePath + name + '.js';
  27. },
  28. define( name, deps, body ) {
  29. if ( arguments.length == 2 ) {
  30. body = deps;
  31. deps = [];
  32. }
  33. const depsPaths = deps.map( bender.amd.getModulePath );
  34. define( bender.amd.getModulePath( name ), depsPaths, function() {
  35. const loadedDeps = Array.from( arguments ).map( ( module ) => module.default );
  36. return {
  37. default: body.apply( this, loadedDeps )
  38. };
  39. } );
  40. },
  41. /**
  42. * Gets an object which holds the CKEditor modules guaranteed to be loaded before tests start.
  43. *
  44. * @params {...String} module The name of the module to load.
  45. * @returns {Object} The object that will hold the loaded modules.
  46. */
  47. require() {
  48. const modules = {};
  49. const done = bender.defer();
  50. const names = Array.from( arguments );
  51. const modulePaths = names.map( bender.amd.getModulePath );
  52. require( modulePaths, function() {
  53. for ( let i = 0; i < names.length; i++ ) {
  54. modules[ names[ i ] ] = arguments[ i ].default;
  55. }
  56. // Finally give green light for tests to start.
  57. done();
  58. }/*, ( err ) => {
  59. debugger;
  60. }*/ );
  61. return modules;
  62. }
  63. };
  64. } )();