8
0
Просмотр исходного кода

Implemented changing cwd mechanism when building the snippets.

Kamil Piechaczek 5 лет назад
Родитель
Сommit
7592cf101b
1 измененных файлов с 12 добавлено и 0 удалено
  1. 12 0
      scripts/docs/snippetadapter.js

+ 12 - 0
scripts/docs/snippetadapter.js

@@ -28,6 +28,9 @@ const MULTI_LANGUAGE = 'multi-language';
  * @returns {Promise}
  */
 module.exports = function snippetAdapter( snippets, options, umbertoHelpers ) {
+	const cwd = process.cwd();
+	const ckeditor5path = path.resolve( __dirname, '..', '..' );
+
 	const { getSnippetPlaceholder, getSnippetSourcePaths } = umbertoHelpers;
 	const snippetsDependencies = new Map();
 
@@ -129,6 +132,9 @@ module.exports = function snippetAdapter( snippets, options, umbertoHelpers ) {
 		return promise;
 	}
 
+	// Change the current work directory in order to avoid issues with importing invalid versions of packages.
+	process.chdir( ckeditor5path );
+
 	for ( const config of webpackConfigs ) {
 		promise = promise.then( () => runWebpack( config ) );
 	}
@@ -216,7 +222,13 @@ module.exports = function snippetAdapter( snippets, options, umbertoHelpers ) {
 			}
 		} )
 		.then( () => {
+			process.chdir( cwd );
 			console.log( 'Finished building snippets.' );
+		} )
+		.catch( err => {
+			process.chdir( cwd );
+
+			return Promise.reject( err );
 		} );
 };