description:'Generate HTML partials from source files in fleetdm/fleet repo (e.g. docs in markdown, or queries in YAML), and configure metadata about the generated files so it is available in `sails.config.builtStaticContent`.',
// FUTURE: If we ever need to gather source files from other places or branches, etc, see git history of this file circa 2021-05-19 for an example of a different strategy we might use to do that.
query.remediation='N/A';// « We set this to a string here so that the data type is always string. We use N/A so folks can see there's no remediation and contribute if desired.
// Report any errors that were detected along the way in one fell swoop to avoid endless resubmitting of PRs.
if(queriesWithProblematicRemediations.length>=1){
thrownewError('Failed parsing YAML for query library: The "remediation" of a query should either be absent (undefined) or a single string (not a list of strings). And "remediation" should only be present when a query\'s purpose is "Detection". But one or more queries have an invalid "remediation": '+_.pluck(queriesWithProblematicRemediations,'slug').sort());
thrownewError('Failed parsing YAML for query library: Queries as currently named would result in colliding (duplicate) slugs. To resolve, rename the queries whose names are too similar. Note the duplicates: '+_.pluck(queries,'slug').sort());
// Report any errors that were detected along the way in one fell swoop to avoid endless resubmitting of PRs.
if(queriesWithProblematicContributors.length>=1){
thrownewError('Failed parsing YAML for query library: The "contributors" of a query should be a single string of valid GitHub user names (e.g. "zwass", or "zwass,noahtalerman,mikermcneil"). But one or more queries have an invalid "contributors" value: '+_.pluck(queriesWithProblematicContributors,'slug').sort());
}//•
// Get a distinct list of all GitHub usernames from all of our queries.
// Map all queries to build a list of unique contributor names then build a dictionary of user profile information from the GitHub Users API
builtStaticContent.markdownPages=[];// « dir tree representation that will be injected into Sails app's configuration
letSECTION_REPO_PATHS=['docs/','handbook/'];
for(letsectionRepoPathofSECTION_REPO_PATHS){
letthinTree=awaitsails.helpers.fs.ls.with({
dir:path.join(topLvlRepoPath,sectionRepoPath),
depth:100,
includeDirs:false,
includeSymlinks:false,
});
letrootRelativeUrlPathsSeen=[];
for(letpageSourcePathofthinTree){
// Perform path maths (determine this using sectionRepoPath, etc)
// > Inspired by https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L308-L313
// > And https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L107-L132
thrownewError('Failed compiling markdown content: Files as currently named would result in colliding (duplicate) URLs for the website. To resolve, rename the pages whose names are too similar. Duplicate detected: '+rootRelativeUrlPath);
// > Inspired by https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L265-L273
letlastModifiedAt=Date.now();// TODO
letfallbackTitle=sails.helpers.strings.toSentenceCase(path.basename(pageSourcePath,'.ejs'));// « for clarity (the page isn't a template, necessarily, and this title is just a guess. Display title will, more likely than not, come from a <docmeta> tag -- see the bottom of the original, raw unformatted markdown of any page in the sailsjs docs for an example of how to use docmeta tags)
// If markdown: Compile to HTML and parse docpage metadata
// > Parsing docmeta tags (consider renaming them to just <meta>- or by now there's probably a more standard way of embedding semantics in markdown files; prefer to use that): https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L180-L183
// > Inspired by https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/compile-markdown-tree-from-remote-git-repo.js#L275-L276
// TODO
// Generate HTML file
lethtmlOutputPath='';//TODO
if(dry){
sails.log('Dry run: Would have generated file:',htmlOutputPath);
}else{
// TODO
}
// TODO: Figure out what to do about embedded images (they'll get cached by CDN so probably ok to point at github, but markdown img srcs will break if relative. Also GitHub could just change image URLs whenever.)
// Append to Sails app configuration.
builtStaticContent.markdownPages.push({
url:rootRelativeUrlPath,
title:''||fallbackTitle,// TODO use metadata title if available
lastModifiedAt:lastModifiedAt
});
}//∞ </each source file>
}//∞ </each section repo path>
// Decorate markdownPages tree with easier-to-use properties related to metadata embedded in the markdown and parent/child relationships.
// Note: Maybe skip the parent/child relationships.
// > Inspired by https://github.com/sailshq/sailsjs.com/blob/b53c6e6a90c9afdf89e5cae00b9c9dd3f391b0e7/api/helpers/marshal-doc-page-metadata.js
// > And https://github.com/uncletammy/doc-templater/blob/2969726b598b39aa78648c5379e4d9503b65685e/lib/build-jsmenu.js
// TODO
// Sort siblings in the markdownPages tree so it's ready to use in menus.
// > Note: consider doing this on the frontend-- though there's a reason it was here. See: