8
0

dev-status.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @license Copyright (c) 2003-2016, 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 {String} workspaceRoot Relative path to workspace root.
  17. * @param {Function} writeln Function for log output.
  18. * @param {Function} writeError Function of error output
  19. */
  20. module.exports = ( ckeditor5Path, packageJSON, workspaceRoot, writeln, writeError ) => {
  21. const workspaceAbsolutePath = path.join( ckeditor5Path, 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. if ( directories.length ) {
  27. for ( let dependency in dependencies ) {
  28. const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
  29. let status;
  30. // Check if repository's directory already exists.
  31. if ( directories.indexOf( dependency ) > -1 ) {
  32. try {
  33. status = git.getStatus( repositoryAbsolutePath );
  34. writeln( `\x1b[1m\x1b[36m${ dependency }\x1b[0m\n${ status.trim() }` );
  35. } catch ( error ) {
  36. writeError( error );
  37. }
  38. }
  39. }
  40. } else {
  41. writeln( 'No CKEditor5 plugins in development mode.' );
  42. }
  43. } else {
  44. writeln( 'No CKEditor5 dependencies found in package.json file.' );
  45. }
  46. };