@@ -11,9 +11,6 @@ const runCliCommand = require('./runCliCommand');
1111const localAssetsTsvPath = './data/localAssets.tsv' ;
1212const tsvDelimeter = '\t' ;
1313
14- // TSV data vars
15-
16-
1714/**
1815 * Flat object with folder path as key and array of file (not folder) names inside.
1916 * For example:
@@ -79,7 +76,7 @@ const crawlDir = (dirToCrawl, filesByFolder, fileMetadata) => {
7976 }
8077 }
8178 else {
82- // Instantiate
79+ // Instantiate key in the object if it doesn't exist
8380 if ( typeof filesByFolder [ dirToCrawl ] === 'undefined' ) {
8481 filesByFolder [ dirToCrawl ] = [ fileName ] ;
8582 }
@@ -97,6 +94,8 @@ const crawlDir = (dirToCrawl, filesByFolder, fileMetadata) => {
9794
9895 // Add the file metadata for inclusion in the TSV
9996 filesByFolder [ dirToCrawl ] . push ( fileName ) ;
97+
98+ // See fileMetadataEntry typedef
10099 fileMetadata [ fullPath ] = {
101100 'productName' : productName ,
102101 'extension' : extension ,
@@ -130,15 +129,19 @@ const processLocalAssetsTsv = (fileMetadata, callback) => {
130129 else {
131130 // Populate tsvRows with data
132131 tsvRows . push ( row ) ;
132+
133133 // Populate tsvFileFullPaths
134+ // Get the column number for the fullPath, in case they get reordered
134135 const fullPathHeaderIndex = tsvHeaders . indexOf ( 'fullPath' ) ;
135136 if ( ! fullPathHeaderIndex ) {
136137 console . error ( 'Couldn\'t get the column id for fullPath in TSV Header' , tsvHeaders ) ;
137138 return ;
138139 }
139140 else {
141+ // Get the value of the for path column
140142 const fullPath = row [ fullPathHeaderIndex ] . trim ( ) ;
141143 if ( fullPath ) {
144+ // Populate an array of fullPaths that are in the TSV so we can figure out what files aren't in the TSV later
142145 tsvFileFullPaths . push ( fullPath ) ;
143146 }
144147 else {
@@ -164,6 +167,7 @@ const processLocalAssetsTsv = (fileMetadata, callback) => {
164167 const rowsToAddToTsv = [ ] ;
165168
166169 localFullFilePaths . forEach ( ( fullPath ) => {
170+ // Check to see if file already exists in the TSV
167171 if ( tsvFileFullPaths . indexOf ( fullPath ) >= 0 ) {
168172 // console.log('Not adding to TSV', fullPath);
169173 return ;
@@ -196,6 +200,7 @@ const processLocalAssetsTsv = (fileMetadata, callback) => {
196200 }
197201
198202 // Set the metadata to the correct column
203+ // Making sure column exists in TSV, indexOf will return -1 if the column doesn't exist
199204 if ( tsvColumnIndex >= 0 ) {
200205 rowToAdd [ tsvColumnIndex ] = currentFileMetadata [ metadataKey ] ;
201206 }
@@ -265,7 +270,7 @@ const processLocalAssetsTsv = (fileMetadata, callback) => {
265270 }
266271 } ) ;
267272 }
268- // Otherwise just create the index page
273+ // There weren't any new rows, just create the index page
269274 else {
270275 console . log ( `No new files to add to the TSV.\n` ) ;
271276 if ( typeof callback === 'function' ) {
0 commit comments