| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const Package = require('dgeni').Package; | 
					
						
							| 
									
										
										
										
											2017-06-21 14:16:56 +01:00
										 |  |  | const glob = require('glob'); | 
					
						
							| 
									
										
										
										
											2017-06-07 22:34:11 +01:00
										 |  |  | const ignore = require('ignore'); | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const path = require('canonical-path'); | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  | const basePackage = require('../angular-base-package'); | 
					
						
							|  |  |  | const contentPackage = require('../content-package'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-07 22:34:11 +01:00
										 |  |  | const { CONTENTS_PATH, GUIDE_EXAMPLES_PATH } = require('../config'); | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | module.exports = new Package('angular-content', [basePackage, contentPackage]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Where do we get the source files?
 | 
					
						
							| 
									
										
										
										
											2017-10-30 21:26:37 +00:00
										 |  |  |   .config(function(readFilesProcessor, collectExamples, renderExamples) { | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |     const gitignoreFilePath = path.resolve(GUIDE_EXAMPLES_PATH, '.gitignore'); | 
					
						
							|  |  |  |     const gitignoreFile = fs.readFileSync(gitignoreFilePath, 'utf8'); | 
					
						
							| 
									
										
										
										
											2017-06-07 22:34:11 +01:00
										 |  |  |     const gitignore = ignore().add(gitignoreFile); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 14:16:56 +01:00
										 |  |  |     const examplePaths = glob.sync('**/*', { cwd: GUIDE_EXAMPLES_PATH, dot: true, ignore: '**/node_modules/**', mark: true }) | 
					
						
							| 
									
										
										
										
											2017-06-07 22:34:11 +01:00
										 |  |  |                             .filter(filePath => filePath !== '.gitignore') // we are not interested in the .gitignore file itself
 | 
					
						
							|  |  |  |                             .filter(filePath => !/\/$/.test(filePath)); // this filter removes the folders, leaving only files
 | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |     const ignoredExamplePaths = []; | 
					
						
							|  |  |  |     const resolvedExamplePaths = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     examplePaths.forEach(filePath => { | 
					
						
							|  |  |  |       // filter out files that match the .gitignore rules
 | 
					
						
							|  |  |  |       if (gitignore.ignores(filePath)) { | 
					
						
							|  |  |  |         ignoredExamplePaths.push(filePath); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         // we need the full paths for the filereader
 | 
					
						
							|  |  |  |         resolvedExamplePaths.push(path.resolve(GUIDE_EXAMPLES_PATH, filePath)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-06-07 22:34:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |     readFilesProcessor.sourceFiles = readFilesProcessor.sourceFiles.concat([ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							| 
									
										
										
										
											2019-04-02 00:12:55 -06:00
										 |  |  |         include: CONTENTS_PATH + '/{start,guide,tutorial}/**/*.md', | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |         fileReader: 'contentFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH + '/marketing', | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/marketing/**/*.{html,md}', | 
					
						
							|  |  |  |         fileReader: 'contentFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/*.md', | 
					
						
							|  |  |  |         exclude: [CONTENTS_PATH + '/index.md'], | 
					
						
							|  |  |  |         fileReader: 'contentFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |         include: resolvedExamplePaths, | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |         fileReader: 'exampleFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/navigation.json', | 
					
						
							|  |  |  |         fileReader: 'jsonFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2018-02-06 17:55:43 +00:00
										 |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/marketing/announcements.json', | 
					
						
							|  |  |  |         fileReader: 'jsonFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/marketing/contributors.json', | 
					
						
							|  |  |  |         fileReader: 'jsonFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/marketing/resources.json', | 
					
						
							|  |  |  |         fileReader: 'jsonFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2017-07-30 13:35:27 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/translations/**/*.md', | 
					
						
							|  |  |  |         fileReader: 'contentFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2020-06-11 13:49:10 +03:00
										 |  |  |       { | 
					
						
							|  |  |  |         basePath: CONTENTS_PATH, | 
					
						
							|  |  |  |         include: CONTENTS_PATH + '/marketing/events.json', | 
					
						
							|  |  |  |         fileReader: 'jsonFileReader' | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |     ]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     collectExamples.exampleFolders.push('examples'); | 
					
						
							| 
									
										
										
										
											2017-09-19 10:15:39 +01:00
										 |  |  |     collectExamples.registerIgnoredExamples(ignoredExamplePaths, gitignoreFilePath); | 
					
						
							| 
									
										
										
										
											2017-10-30 21:26:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     renderExamples.ignoreBrokenExamples = true; | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Configure jsdoc-style tag parsing
 | 
					
						
							|  |  |  |   .config(function(inlineTagProcessor) { | 
					
						
							|  |  |  |     inlineTagProcessor.inlineTagDefinitions.push(require('./inline-tag-defs/anchor')); | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   .config(function(computePathsProcessor) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Replace any path templates inherited from other packages
 | 
					
						
							|  |  |  |     // (we want full and transparent control)
 | 
					
						
							|  |  |  |     computePathsProcessor.pathTemplates = computePathsProcessor.pathTemplates.concat([ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         docTypes: ['content'], | 
					
						
							|  |  |  |         getPath: (doc) => `${doc.id.replace(/\/index$/, '')}`, | 
					
						
							|  |  |  |         outputPathTemplate: '${path}.json' | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       {docTypes: ['navigation-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'}, | 
					
						
							|  |  |  |       {docTypes: ['contributors-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'}, | 
					
						
							| 
									
										
										
										
											2018-02-06 17:55:43 +00:00
										 |  |  |       {docTypes: ['announcements-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'}, | 
					
						
							| 
									
										
										
										
											2020-06-11 13:49:10 +03:00
										 |  |  |       {docTypes: ['resources-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'}, | 
					
						
							|  |  |  |       {docTypes: ['events-json'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'} | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |     ]); | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // We want the content files to be converted
 | 
					
						
							| 
									
										
										
										
											2017-04-27 14:04:51 +01:00
										 |  |  |   .config(function(convertToJsonProcessor, postProcessHtml) { | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |     convertToJsonProcessor.docTypes.push('content'); | 
					
						
							| 
									
										
										
										
											2017-04-27 14:04:51 +01:00
										 |  |  |     postProcessHtml.docTypes.push('content'); | 
					
						
							| 
									
										
										
										
											2017-04-21 13:10:52 +01:00
										 |  |  |   }); |