-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
108 changed files
with
5,374 additions
and
6,685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 1,5 @@ | ||
#BUILD_ARCHIVE_ROOT=archivecontent/files | ||
#CONTENT_ARCHIVE_ROOT=archivecontent/files | ||
#BUILD_STUMTPTOWN_ROOT=stumptown/packaged | ||
|
||
# To build only a subset of documents (which is much faster) you can | ||
# use command line options with the cli. But if you don't want to type | ||
# --locales=en-us every time, you can set: | ||
#BUILD_LOCALES=en-us | ||
# If you don't want to type --foldersearch=^web every time you can set: | ||
#BUILD_FOLDERSEARCHES=^web | ||
|
||
# Note that all these filters are *union* meaning | ||
# `BUILD_LOCALES=en-us,sv-se` for example will match 'en-us' OR 'sv-se' | ||
|
||
# See documentation in docs/envvars.md for more information about this | ||
#BUILD_FLAW_LEVELS=broken_links:error, macros:ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,114 @@ | ||
require("dotenv").config(); | ||
|
||
const { | ||
FLAW_LEVELS, | ||
DEFAULT_FLAW_LEVELS, | ||
VALID_FLAW_CHECKS, | ||
FILES, | ||
FOLDERSEARCH, | ||
NO_PROGRESSBAR, | ||
FIX_FLAWS, | ||
FIX_FLAWS_DRY_RUN, | ||
FIX_FLAWS_VERBOSE, | ||
} = require("./constants"); | ||
|
||
const options = Object.freeze({ | ||
flawLevels: parseFlawLevels(DEFAULT_FLAW_LEVELS), | ||
files: parseFiles(FILES), | ||
folderSearch: parseFoldersearch(FOLDERSEARCH), | ||
noProgressbar: NO_PROGRESSBAR, | ||
fixFlaws: FIX_FLAWS, | ||
fixFlawsDryRun: FIX_FLAWS_DRY_RUN, | ||
fixFlawsVerbose: FIX_FLAWS_VERBOSE, | ||
}); | ||
|
||
function parseFiles(filesStringList) { | ||
// The get-diff-action, which we use in the "PR Builds" CI, | ||
// will make this a massive string that looks like | ||
// this: `'content/files/en-us/a/index.html','content/files/en-us/a/index.html'` | ||
// so we need to turn that into an array: | ||
// ["content/files/en-us/a/index.html", "content/files/en-us/b/index.html"]` | ||
// Note, when you use get-diff-action in GitHub Actions, it's a comma | ||
// but if you use the manualy `git diff --name-only ...` on your command | ||
// line it's a newline. | ||
return new Set( | ||
filesStringList | ||
.split(/[,\n]/) | ||
.map((item) => { | ||
// Remove any single or double-quote bookends. | ||
return item.replace(/^(['"])(.*)\1$/, "$2"); | ||
}) | ||
.filter((s) => s) | ||
); | ||
} | ||
|
||
function parseFoldersearch(searchpattern) { | ||
if (searchpattern) { | ||
// TODO: Consider turning it into a regex if there are * or $ or ^ in it | ||
return searchpattern.toLowerCase(); | ||
} | ||
return null; | ||
} | ||
|
||
// Override based on env vars but only for options that are *not* | ||
// exclusive to building everyhing. | ||
function parseFlawLevels(flawChecks) { | ||
const checks = flawChecks | ||
.split(",") | ||
.map((x) => x.trim()) | ||
.filter((x) => x) | ||
.map((x) => x.split(":").map((s) => s.trim())); | ||
|
||
// Check that it doesn't contain more than 1 wildcard, | ||
// because that'd make no sense. | ||
const wildcards = checks.filter((tuple) => tuple[0] === "*"); | ||
if (wildcards.length > 1) { | ||
throw new Error(`Can only be 1 wild card (not: ${wildcards})`); | ||
} | ||
|
||
// Put any wildcards (e.g. '*:warn') first | ||
checks.sort((a, b) => { | ||
if (a[0] === "*" && b[0] !== "*") { | ||
return -1; | ||
} else if (a[0] !== "*" && b[0] === "*") { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
|
||
const checked = new Map(); | ||
|
||
// Unless specified, set 'ignore' on all of them first. | ||
for (const check of VALID_FLAW_CHECKS) { | ||
checked.set(check, FLAW_LEVELS.IGNORE); | ||
} | ||
|
||
const levelValues = Object.values(FLAW_LEVELS); | ||
|
||
for (const tuple of checks) { | ||
if (tuple.length !== 2) { | ||
throw new Error(`Not a tuple pair of 2 (${tuple})`); | ||
} | ||
const [identifier, level] = tuple; | ||
if (!levelValues.includes(level)) { | ||
throw new Error(`Invalid level: '${level}' (only ${levelValues})`); | ||
} | ||
if (identifier === "*") { | ||
for (const check of VALID_FLAW_CHECKS) { | ||
checked.set(check, level); | ||
} | ||
} else if (!VALID_FLAW_CHECKS.has(identifier)) { | ||
throw new Error( | ||
`Unrecognized flaw identifier: '${identifier}' (only ${[ | ||
...VALID_FLAW_CHECKS, | ||
]})` | ||
); | ||
} else { | ||
checked.set(identifier, level); | ||
} | ||
} | ||
|
||
return checked; | ||
} | ||
|
||
module.exports = options; |
Oops, something went wrong.