Browse Source

Merge pull request #202 from ckeditor/t/122

Forcing period at the end of package description.
Piotrek Koszuliński 9 years ago
parent
commit
c3adb92d91
3 changed files with 65 additions and 2 deletions
  1. 3 2
      dev/tasks/dev/utils/inquiries.js
  2. 18 0
      dev/tasks/dev/utils/sanitize.js
  3. 44 0
      dev/tests/dev/sanitize.js

+ 3 - 2
dev/tasks/dev/utils/inquiries.js

@@ -6,6 +6,7 @@
 'use strict';
 
 const inquirer = require( 'inquirer' );
+const sanitize = require( './sanitize' );
 const DEFAULT_PLUGIN_NAME_PREFIX = 'ckeditor5-';
 const DEFAULT_PLUGIN_VERSION = '0.0.1';
 const DEFAULT_GITHUB_URL_PREFIX = 'ckeditor/';
@@ -68,9 +69,9 @@ module.exports = {
 		return new Promise( ( resolve ) => {
 			inquirer.prompt( [ {
 				name: 'description',
-				message: 'Package description (one sentence):'
+				message: 'Package description (one sentence, must end with period):'
 			} ], ( answers ) => {
-				resolve( answers.description || '' );
+				resolve( sanitize.appendPeriodIfMissing( answers.description || '' ) );
 			} );
 		} );
 	}

+ 18 - 0
dev/tasks/dev/utils/sanitize.js

@@ -0,0 +1,18 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+module.exports = {
+	appendPeriodIfMissing( text ) {
+		text = text.trim();
+
+		if ( text.length > 0 && !text.endsWith( '.' ) ) {
+			text += '.';
+		}
+
+		return text;
+	}
+};

+ 44 - 0
dev/tests/dev/sanitize.js

@@ -0,0 +1,44 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global describe, it */
+
+'use strict';
+
+const sanitize = require( '../../tasks/dev/utils/sanitize' );
+const chai = require( 'chai' );
+const expect = chai.expect;
+
+describe( 'utils', () => {
+	describe( 'sanitize', () => {
+		describe( 'appendPeriodIfMissing', () => {
+			it( 'should be defined', () => expect( sanitize.appendPeriodIfMissing ).to.be.a( 'function' ) );
+
+			it( 'should trim whitespace/new lines to empty string', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( '\n\t\r ' );
+
+				expect( sanitized ).to.equal( '' );
+			} );
+
+			it( 'should add period at the end if missing ', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( 'sometext' );
+
+				expect( sanitized ).to.equal( 'sometext.' );
+			} );
+
+			it( 'should not add period at the end if present', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( 'sometext.' );
+
+				expect( sanitized ).to.equal( 'sometext.' );
+			} );
+
+			it( 'should leave empty string as is', () => {
+				const sanitized = sanitize.appendPeriodIfMissing( '' );
+
+				expect( sanitized ).to.equal( '' );
+			} );
+		} );
+	} );
+} );