8
0
Pārlūkot izejas kodu

Modified gulp create-package task to ask for package description and fill template files with actual data.

Szymon Kupś 9 gadi atpakaļ
vecāks
revīzija
8904ee25c2

+ 21 - 4
dev/tasks/dev/tasks/create-package.js

@@ -35,7 +35,13 @@ module.exports = ( ckeditor5Path, workspaceRoot ) => {
 			'.jshintrc',
 			'.jscsrc',
 			'.gitattributes',
-			'./dev/tasks/dev/templates'
+			'dev/tasks/dev/templates/.gitignore',
+			'dev/tasks/dev/templates/CHANGES.md',
+			'dev/tasks/dev/templates/CONTRIBUTING.md',
+			'dev/tasks/dev/templates/gulpfile.js',
+			'dev/tasks/dev/templates/LICENSE.md',
+			'dev/tasks/dev/templates/package.json',
+			'dev/tasks/dev/templates/README.md'
 		],
 		'tests/': [
 			'tests/.jshintrc'
@@ -43,8 +49,8 @@ module.exports = ( ckeditor5Path, workspaceRoot ) => {
 		'dev/': [
 			'dev/.jshintrc'
 		],
-		'dev/tasks/lint': [
-			'dev/tasks/lint'
+		'dev/tasks/lint/': [
+			'dev/tasks/lint/tasks.js'
 		]
 	};
 
@@ -52,6 +58,7 @@ module.exports = ( ckeditor5Path, workspaceRoot ) => {
 	let repositoryPath;
 	let packageVersion;
 	let gitHubUrl;
+	let packageDescription;
 
 	return inquiries.getPackageName()
 		.then( result => {
@@ -68,19 +75,29 @@ module.exports = ( ckeditor5Path, workspaceRoot ) => {
 		.then( result => {
 			gitHubUrl = result;
 
+			return inquiries.getPackageDescription();
+		} )
+		.then( result => {
+			packageDescription = result;
+
 			log.out( `Initializing repository ${ repositoryPath }...` );
 			git.initializeRepository( repositoryPath );
 
 			log.out( `Copying files into ${ repositoryPath }...` );
 
 			for ( let destination in fileStructure ) {
-				tools.copy( fileStructure[ destination ], path.join( repositoryPath, destination ) );
+				tools.copyTemplateFiles( fileStructure[ destination ], path.join( repositoryPath, destination ), {
+					'{{AppName}}': packageName,
+					'{{GitHubRepositoryPath}}': gitHubUrl,
+					'{{ProjectDescription}}': packageDescription
+				} );
 			}
 
 			log.out( `Updating package.json files...` );
 			tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
 				json.name = packageName;
 				json.version = packageVersion;
+				json.description = packageDescription;
 
 				return json;
 			} );

+ 11 - 0
dev/tasks/dev/utils/inquiries.js

@@ -51,5 +51,16 @@ module.exports = {
 				resolve( answers.gitHubUrl );
 			} );
 		} );
+	},
+
+	getPackageDescription( ) {
+		return new Promise( ( resolve ) => {
+			inquirer.prompt( [ {
+				name: 'description',
+				message: 'Package description:'
+			} ], ( answers ) => {
+				resolve( answers.description || '' );
+			} );
+		} );
 	}
 };

+ 6 - 2
dev/tests/dev/create-package.js

@@ -15,7 +15,8 @@ const inquiries = require( '../../tasks/dev/utils/inquiries' );
 const git = require( '../../tasks/dev/utils/git' );
 const path = require( 'path' );
 
-describe( 'dev-package-create', () => {
+describe( 'dev-create-package', () => {
+	const emptyFn = () => { };
 	let spies;
 
 	const mainRepositoryPath = '/path/to/repository';
@@ -24,6 +25,7 @@ describe( 'dev-package-create', () => {
 	const packageName = 'package-name';
 	const packageVersion = '0.0.1';
 	const gitHubUrl = 'ckeditor5/package-name';
+	const packageDescription = 'Package description.';
 
 	beforeEach( () => createSpies() );
 	afterEach( () => restoreSpies() );
@@ -35,9 +37,10 @@ describe( 'dev-package-create', () => {
 			getPackageName: sinon.stub( inquiries, 'getPackageName' ).returns( new Promise( ( r ) => r( packageName ) ) ),
 			getPackageVersion: sinon.stub( inquiries, 'getPackageVersion' ).returns( new Promise( ( r ) => r( packageVersion ) ) ),
 			getPackageGitHubUrl: sinon.stub( inquiries, 'getPackageGitHubUrl' ).returns( new Promise( ( r ) => r( gitHubUrl ) ) ),
+			getPackageDescription: sinon.stub( inquiries, 'getPackageDescription' ).returns( new Promise( ( r ) => r( packageDescription ) ) ),
 			initializeRepository: sinon.stub( git, 'initializeRepository' ),
 			updateJSONFile: sinon.stub( tools, 'updateJSONFile' ),
-			copy: sinon.stub( tools, 'copy' ),
+			copy: sinon.stub( tools, 'copyTemplateFiles' ),
 			initialCommit: sinon.stub( git, 'initialCommit' )
 		};
 	}
@@ -58,6 +61,7 @@ describe( 'dev-package-create', () => {
 			expect( spies.getPackageName.calledOnce ).to.equal( true );
 			expect( spies.getPackageVersion.calledOnce ).to.equal( true );
 			expect( spies.getPackageGitHubUrl.calledOnce ).to.equal( true );
+			expect( spies.getPackageDescription.calledOnce ).to.equal( true );
 			expect( spies.initializeRepository.calledOnce ).to.equal( true );
 			expect( spies.initializeRepository.firstCall.args[ 0 ] ).to.equal( repositoryPath );
 			expect( spies.copy.called ).to.equal( true );