()
| 37 | // [end-readme] |
| 38 | |
| 39 | async function main() { |
| 40 | if (dryRun) |
| 41 | console.log('This is a dry run! The script will not write any files. Use for debugging.\n') |
| 42 | |
| 43 | // 1. UPDATE MARKDOWN FILES (CONTENT AND REUSABLES) |
| 44 | console.log('Updating Liquid conditionals and versions frontmatter in Markdown files...\n') |
| 45 | for (const file of markdownFiles) { |
| 46 | // A. UPDATE LIQUID CONDITIONALS IN CONTENT |
| 47 | // Create an { old: new } conditionals object so we can get the replacements and |
| 48 | // make the replacements separately and not do both in nested loops. |
| 49 | const content = fs.readFileSync(file, 'utf8') |
| 50 | const contentReplacements = getLiquidReplacements(content, file) |
| 51 | const newContent = makeLiquidReplacements(contentReplacements, content) |
| 52 | |
| 53 | // B. UPDATE FRONTMATTER VERSIONS PROPERTY |
| 54 | const { data } = frontmatter(newContent) |
| 55 | if (data.versions && typeof data.versions !== 'string') { |
| 56 | Object.entries(data.versions).forEach(([plan, value]) => { |
| 57 | // Update legacy versioning while we're here |
| 58 | const valueToUse = value |
| 59 | .replace('2.23', '3.0') |
| 60 | .replace(`>=${oldestSupported}`, '*') |
| 61 | .replace(/>=?2\.20/, '*') |
| 62 | .replace(/>=?2\.19/, '*') |
| 63 | |
| 64 | // Find the relevant version from the master list so we can access the short name. |
| 65 | const versionObj = allVersionKeys.find( |
| 66 | (version) => version.plan === plan || version.shortName === plan |
| 67 | ) |
| 68 | if (!versionObj) { |
| 69 | console.error(`can't find supported version for ${plan}`) |
| 70 | process.exit(1) |
| 71 | } |
| 72 | delete data.versions[plan] |
| 73 | data.versions[versionObj.shortName] = valueToUse |
| 74 | }) |
| 75 | } |
| 76 | |
| 77 | if (dryRun) { |
| 78 | console.log(contentReplacements) |
| 79 | } else { |
| 80 | fs.writeFileSync(file, frontmatter.stringify(newContent, data, { lineWidth: 10000 })) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // 2. UPDATE LIQUID CONDITIONALS IN DATA YAML FILES |
| 85 | console.log('Updating Liquid conditionals in YAML files...\n') |
| 86 | for (const file of yamlFiles) { |
| 87 | const yamlContent = fs.readFileSync(file, 'utf8') |
| 88 | const yamlReplacements = getLiquidReplacements(yamlContent, file) |
| 89 | // Update any `versions` properties in the YAML as well (learning tracks, etc.) |
| 90 | const newYamlContent = makeLiquidReplacements(yamlReplacements, yamlContent) |
| 91 | .replace(/("|')?free-pro-team("|')?:/g, 'fpt:') |
| 92 | .replace(/("|')?enterprise-server("|')?:/g, 'ghes:') |
| 93 | .replace(/("|')?github-ae("|')?:/g, 'ghae:') |
| 94 | |
| 95 | if (dryRun) { |
| 96 | console.log(yamlReplacements) |
no test coverage detected