dev-status.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. Print GIT status using `git status --porcelain -sb` command.
  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. let status;
  29. // Check if repository's directory already exists.
  30. if ( directories.indexOf( dependency ) > -1 ) {
  31. try {
  32. status = git.getStatus( repositoryAbsolutePath );
  33. writeln( `\x1b[1m\x1b[36m${ dependency }\x1b[0m\n${ status.trim() }` );
  34. } catch ( error ) {
  35. writeError( error );
  36. }
  37. }
  38. }
  39. } else {
  40. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  41. }
  42. };