Sfoglia il codice sorgente

Added boilerplate files to local templates. Copying them during repository initialization.

Szymon Kupś 10 anni fa
parent
commit
6bffe72c00

+ 2 - 0
dev/tasks/templates/CHANGES.md

@@ -0,0 +1,2 @@
+Changelog
+====================

+ 2 - 0
dev/tasks/templates/CONTRIBUTING.md

@@ -0,0 +1,2 @@
+Contributing
+============

+ 2 - 0
dev/tasks/templates/LICENSE.md

@@ -0,0 +1,2 @@
+Software License Agreement
+==========================

+ 2 - 0
dev/tasks/templates/README.md

@@ -0,0 +1,2 @@
+Development Repository
+===================================

+ 8 - 1
dev/tasks/tests/dev-tasks.js

@@ -45,7 +45,9 @@ describe( 'dev-tasks', () => {
 			initializeRepository: sinon.stub( git, 'initializeRepository' ),
 			updateJSONFile: sinon.stub( tools, 'updateJSONFile' ),
 			getStatus: sinon.stub( git, 'getStatus' ),
-			updateBoilerplate: sinon.stub( git, 'updateBoilerplate' )
+			updateBoilerplate: sinon.stub( git, 'updateBoilerplate' ),
+			copyTemplateFiles: sinon.stub( tools, 'copyTemplateFiles' ),
+			initialCommit: sinon.stub( git, 'initialCommit' )
 		};
 	}
 
@@ -146,9 +148,14 @@ describe( 'dev-tasks', () => {
 				expect( spies.getPluginGitHubUrl.calledOnce ).to.equal( true );
 				expect( spies.initializeRepository.calledOnce ).to.equal( true );
 				expect( spies.initializeRepository.firstCall.args[ 0 ] ).to.equal( repositoryPath );
+				expect( spies.copyTemplateFiles.calledOnce ).to.equal( true );
+				expect( spies.copyTemplateFiles.firstCall.args[ 0 ] ).to.equal( repositoryPath );
 				expect( spies.updateJSONFile.calledTwice ).to.equal( true );
 				expect( spies.updateJSONFile.firstCall.args[ 0 ] ).to.equal( path.join( repositoryPath, 'package.json' ) );
 				expect( spies.updateJSONFile.secondCall.args[ 0 ] ).to.equal( path.join( mainRepositoryPath, 'package.json' ) );
+				expect( spies.initialCommit.calledOnce ).to.equal( true );
+				expect( spies.initialCommit.firstCall.args[ 0 ] ).to.equal( pluginName );
+				expect( spies.initialCommit.firstCall.args[ 1 ] ).to.equal( repositoryPath );
 				expect( spies.linkDirectories.calledOnce ).to.equal( true );
 				expect( spies.linkDirectories.firstCall.args[ 0 ] ).to.equal( repositoryPath );
 				expect( spies.linkDirectories.firstCall.args[ 1 ] ).to.equal( path.join( mainRepositoryPath, 'node_modules', pluginName ) );

+ 19 - 0
dev/tasks/tests/git.js

@@ -214,5 +214,24 @@ describe( 'utils', () => {
 				expect( shExecStub.thirdCall.args[ 0 ] ).to.equal( updateCommands.join( ' && ' )  );
 			} );
 		} );
+
+		describe( 'initialCommit', () => {
+			it( 'should be defined', () => expect( git.initialCommit ).to.be.a( 'function' ) );
+			it( 'should execute commit commands', () => {
+				const shExecStub = sinon.stub( tools, 'shExec' );
+				const pluginName = 'ckeditor5-plugin-name';
+				const repositoryPath = '/path/to/repo';
+				const commitCommands = [
+					`cd ${ repositoryPath }`,
+					`git commit -am "Initial commit for ${ pluginName }."`
+				];
+				toRestore.push( shExecStub );
+
+				git.initialCommit( pluginName, repositoryPath );
+
+				expect( shExecStub.calledOnce ).to.equal( true );
+				expect( shExecStub.firstCall.args[ 0 ] ).to.equal( commitCommands.join( ' && ' ) );
+			} );
+		} );
 	} );
 } );

+ 17 - 0
dev/tasks/tests/tools.js

@@ -216,5 +216,22 @@ describe( 'utils', () => {
 				expect( shExecStub.firstCall.args[ 0 ] ).to.equal( `cd ${ path } && grunt githooks` );
 			} );
 		} );
+
+		describe( 'copyTemplateFiles', () => {
+			it( 'should be defined', () => expect( tools.copyTemplateFiles ).to.be.a( 'function' ) );
+			it( 'should copy template files', () => {
+				const path = require( 'path' );
+				const TEMPLATE_PATH = './dev/tasks/templates';
+				const templatesPath = path.resolve( TEMPLATE_PATH );
+				const shExecStub = sinon.stub( tools, 'shExec' );
+				const repositoryPath = '/path/to/repository';
+				toRestore.push( shExecStub );
+
+				tools.copyTemplateFiles( repositoryPath );
+
+				expect( shExecStub.calledOnce ).to.equal( true );
+				expect( shExecStub.firstCall.args[ 0 ] ).to.equal( `cp ${ path.join( templatesPath, '*.md' ) } ${ repositoryPath }` );
+			} );
+		} );
 	} );
 } );

+ 7 - 1
dev/tasks/utils/dev-plugin-create.js

@@ -53,6 +53,9 @@ module.exports = ( ckeditor5Path, workspaceRoot, writeln ) => {
 			writeln( `Initializing repository ${ repositoryPath }...` );
 			git.initializeRepository( repositoryPath );
 
+			writeln( `Copying template files to ${ repositoryPath }...` );
+			tools.copyTemplateFiles( repositoryPath );
+
 			writeln( `Updating package.json files...` );
 			tools.updateJSONFile( path.join( repositoryPath, 'package.json' ), ( json ) => {
 				json.name = pluginName;
@@ -70,13 +73,16 @@ module.exports = ( ckeditor5Path, workspaceRoot, writeln ) => {
 				return json;
 			} );
 
+			writeln( `Creating initial commit...` );
+			git.initialCommit( pluginName, repositoryPath );
+
 			writeln( `Linking ${ pluginName } to node_modules...` );
 			tools.linkDirectories( repositoryPath, path.join( ckeditor5Path, 'node_modules', pluginName ) );
 
 			writeln( `Running npm install in ${ pluginName }.` );
 			tools.npmInstall( repositoryPath );
 
-			writeln( `Installing GIT hooks in ${ pluginName }.` );
+			writeln( `Installing Git hooks in ${ pluginName }.` );
 			tools.installGitHooks( repositoryPath );
 		} );
 };

+ 15 - 0
dev/tasks/utils/git.js

@@ -152,5 +152,20 @@ module.exports = {
 		];
 
 		tools.shExec( updateCommands.join( ' && ' ) );
+	},
+
+	/**
+	 * Creates initial commit on repository under specified path.
+	 *
+	 * @param {String} pluginName
+	 * @param {String} repositoryPath
+	 */
+	initialCommit( pluginName, repositoryPath ) {
+		const commitCommands = [
+			`cd ${ repositoryPath }`,
+			`git commit -am "Initial commit for ${ pluginName }."`
+		];
+
+		tools.shExec( commitCommands.join( ' && ' ) );
 	}
 };

+ 12 - 0
dev/tasks/utils/tools.js

@@ -4,6 +4,7 @@ let dirtyFiles,
 	ignoreList;
 
 const dependencyRegExp = /^ckeditor5-/;
+const TEMPLATE_PATH = './dev/tasks/templates';
 
 module.exports = {
 	/**
@@ -254,5 +255,16 @@ module.exports = {
 	 */
 	installGitHooks( path ) {
 		this.shExec( `cd ${ path } && grunt githooks` );
+	},
+
+	/**
+	 * Copies template files to specified destination.
+	 *
+	 * @param {String} destination
+	 */
+	copyTemplateFiles( destination ) {
+		const path = require( 'path' );
+		const templatesPath = path.resolve( TEMPLATE_PATH );
+		this.shExec( `cp ${ path.join( templatesPath, '*.md' ) } ${ destination }` );
 	}
 };