Browse Source

Installing npm modules and git hooks during tasks.

Szymon Kupś 10 years ago
parent
commit
5566d745ff

+ 15 - 6
dev/tasks/utils/dev-init.js

@@ -14,7 +14,15 @@ const path = require( 'path' );
  * 2. Check if any of the repositories are already present in the workspace.
  * 		2.1. If repository is present in the workspace, check it out to desired branch if one is provided.
  * 		2.2. If repository is not present in the workspace, clone it and checkout to desired branch if one is provided.
- * 3. Link new repository to node_modules. (do not use npm link, use standard linking instead)
+ * 3. Link each new repository to node_modules. (do not use npm link, use standard linking instead)
+ * 4. Run `npm install` in each repository.
+ * 5. Install Git hooks in each repository.
+ *
+ * @param {String} ckeditor5Path Path to main CKEditor5 repository.
+ * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
+ * @param {Object} options grunt options.
+ * @param {Function} writeln Function for log output.
+ * @param {Function} writeError Function of error output
  */
 module.exports = ( ckeditor5Path, packageJSON, options, writeln, writeError ) => {
 	const workspaceAbsolutePath = path.join( ckeditor5Path, options.workspaceRoot );
@@ -44,14 +52,15 @@ module.exports = ( ckeditor5Path, packageJSON, options, writeln, writeError ) =>
 			try {
 				writeln( `Checking out ${ repositoryURL } to ${ urlInfo.branch }...` );
 				git.checkout( repositoryAbsolutePath, urlInfo.branch );
-			} catch ( error ) {
-				writeError( error );
-			}
 
-			// Link plugin.
-			try {
 				writeln( `Linking ${ repositoryURL }...` );
 				tools.linkDirectories( repositoryAbsolutePath, path.join( ckeditor5Path, 'node_modules' , dependency ) );
+
+				writeln( `Running npm install in ${ repositoryURL }.` );
+				tools.npmInstall( repositoryAbsolutePath );
+
+				writeln( `Installing GIT hooks in ${ repositoryURL }.` );
+				tools.installGitHooks( repositoryAbsolutePath );
 			} catch ( error ) {
 				writeError( error );
 			}

+ 8 - 0
dev/tasks/utils/dev-plugin-create.js

@@ -20,6 +20,8 @@ const path = require( 'path' );
  * 5. Update package.json file in new plugin's repository.
  * 6. Update package.json file in CKEditor5 repository.
  * 7. Link new plugin.
+ * 8. Call `npm install` in plugin repository.
+ * 9. Install Git hooks in plugin repository.
  *
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {Object} options grunt options.
@@ -73,6 +75,12 @@ module.exports = ( ckeditor5Path, options, writeln, writeError ) => {
 
 					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 }.` );
+					tools.installGitHooks( repositoryPath );
 				} catch ( error ) {
 					writeError( error );
 				}

+ 8 - 0
dev/tasks/utils/dev-plugin-install.js

@@ -17,6 +17,8 @@ const path = require( 'path' );
  * 4. Checkout repository to provided branch (or master if no branch is provided).
  * 5. Update package.json file in CKEditor5 repository.
  * 6. Link new plugin.
+ * 7. Call `npm install` in plugin repository.
+ * 8. Install Git hooks in plugin repository.
  *
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {Object} options grunt options.
@@ -61,6 +63,12 @@ module.exports = ( ckeditor5Path, options, writeln, writeError ) => {
 
 					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 }.` );
+					tools.installGitHooks( repositoryPath );
 				} catch ( error ) {
 					writeError( error );
 				}

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

@@ -229,5 +229,13 @@ module.exports = {
 		json = updateFunction( json );
 
 		fs.writeFileSync( path, JSON.stringify( json, null, 2 ), 'utf-8' );
+	},
+
+	npmInstall( path ) {
+		this.shExec( `cd ${ path } && npm install` );
+	},
+
+	installGitHooks( path ) {
+		this.shExec( `cd ${ path } && grunt githooks` );
 	}
 };