Browse Source

Small improvements for the snippet adapter.

Kamil Piechaczek 6 years ago
parent
commit
eb6ab50192
2 changed files with 8 additions and 6 deletions
  1. 2 2
      scripts/docs/build-docs.js
  2. 6 4
      scripts/docs/snippetadapter.js

+ 2 - 2
scripts/docs/build-docs.js

@@ -17,7 +17,7 @@ const skipValidation = process.argv.includes( '--skip-validation' );
 const production = process.argv.includes( '--production' );
 const watch = process.argv.includes( '--watch' );
 const verbose = process.argv.includes( '--verbose' );
-const whitelistedSnippets = process.argv.find( item => item.startsWith( '--whitelisted-snippet=' ) );
+const whitelistedSnippets = process.argv.find( item => item.startsWith( '--snippets=' ) );
 
 buildDocs();
 
@@ -54,7 +54,7 @@ function runUmberto( options ) {
 		skipValidation: options.skipValidation,
 		snippetOptions: {
 			production: options.production,
-			whitelistedSnippets: whitelistedSnippets ? whitelistedSnippets.replace( '--whitelisted-snippet=', '' ).split( ',' ) : []
+			whitelistedSnippets: whitelistedSnippets ? whitelistedSnippets.replace( '--snippets=', '' ).split( ',' ) : []
 		},
 		skipApi: options.skipApi,
 		verbose: options.verbose,

+ 6 - 4
scripts/docs/snippetadapter.js

@@ -21,7 +21,7 @@ const DEFAULT_LANGUAGE = 'en';
  * @param {Set.<Snippet>} snippets Snippet collection extracted from documentation files.
  * @param {Object} options
  * @param {Boolean} options.production Whether to build snippets in production mode.
- * @param {Array.<String>>} options.whitelistedSnippets An array that contains glob patterns
+ * @param {Array.<String>>|undefined} options.whitelistedSnippets An array that contains glob patterns.
  * @param {Object.<String, Function>} umbertoHelpers
  * @returns {Promise}
  */
@@ -75,7 +75,9 @@ module.exports = function snippetAdapter( snippets, options, umbertoHelpers ) {
 	}
 
 	// Remove snippets that do not match to patterns specified in `options.whitelistedSnippets`.
-	filterWhitelistedSnippets( snippets, options.whitelistedSnippets );
+	if ( options.whitelistedSnippets ) {
+		filterWhitelistedSnippets( snippets, options.whitelistedSnippets );
+	}
 
 	console.log( 'Number of snippets that will be built:', snippets.size );
 
@@ -139,7 +141,7 @@ module.exports = function snippetAdapter( snippets, options, umbertoHelpers ) {
 					// CSS may not be generated by Webpack if a snippet's JS file didn't import any CSS files.
 					const wasCSSGenerated = fs.existsSync( path.join( snippetData.outputPath, snippetData.snippetName, 'snippet.css' ) );
 
-					// If the snippet is a dependency, append JS and CSS to HTML save to disk and continue.
+					// If the snippet is a dependency, append JS and CSS to HTML, save to disk and continue.
 					if ( snippetData.requiredFor ) {
 						let htmlFile = fs.readFileSync( snippetData.snippetSources.html ).toString();
 
@@ -194,7 +196,7 @@ module.exports = function snippetAdapter( snippets, options, umbertoHelpers ) {
  * Removes snippets that names do not match to patterns specified in `whitelistedSnippets` array.
  *
  * @param {Set.<Snippet>} snippets Snippet collection extracted from documentation files.
- * @param {Array.<String>} whitelistedSnippets Snippet patterns that should be built.
+ * @param {Array.<String>|undefined} whitelistedSnippets Snippet patterns that should be built.
  */
 function filterWhitelistedSnippets( snippets, whitelistedSnippets ) {
 	if ( !whitelistedSnippets.length ) {