dev-boilerplate-update.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. const tools = require( './tools' );
  7. const git = require( './git' );
  8. const path = require( 'path' );
  9. /**
  10. * 1. Get CKEditor5 dependencies from package.json file.
  11. * 2. Scan workspace for repositories that match dependencies from package.json file.
  12. * 3. Fetch and merge boilerplate remote.
  13. *
  14. * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  15. * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
  16. * @param {Object} options grunt options.
  17. * @param {Function} writeln Function for log output.
  18. * @param {Function} writeError Function of error output
  19. */
  20. module.exports = ( ckeditor5Path, packageJSON, options, writeln, writeError ) => {
  21. const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
  22. // Get all CKEditor dependencies from package.json.
  23. const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
  24. if ( dependencies ) {
  25. const directories = tools.getCKE5Directories( workspaceAbsolutePath );
  26. for ( let dependency in dependencies ) {
  27. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  28. // Check if repository's directory already exists.
  29. if ( directories.indexOf( dependency ) > -1 ) {
  30. try {
  31. writeln( `Updating boilerplate in ${ dependency }...` );
  32. git.updateBoilerplate( repositoryAbsolutePath );
  33. } catch ( error ) {
  34. writeError( error );
  35. }
  36. }
  37. }
  38. } else {
  39. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  40. }
  41. };