diff --git a/lib/patterns.js b/lib/patterns.js index 2d968b81d1..0696818c65 100644 --- a/lib/patterns.js +++ b/lib/patterns.js @@ -38,5 +38,5 @@ module.exports = { // new versioning format patterns adminProduct: /\/admin(\/|$|\?|#)/, enterpriseServer: /\/enterprise-server@/, - getEnterpriseServerNumber: /\/enterprise-server@(\d+\.\d+)/ + getEnterpriseServerNumber: /enterprise-server@(\d+\.\d+)/ } diff --git a/lib/remove-deprecated-frontmatter.js b/lib/remove-deprecated-frontmatter.js index 9842c3eda2..01e073e863 100644 --- a/lib/remove-deprecated-frontmatter.js +++ b/lib/remove-deprecated-frontmatter.js @@ -1,25 +1,22 @@ -module.exports = function removeDeprecatedFrontmatter (data, devCheckout, versionToDeprecate, nextOldestVersion) { - // there are currently different frontmatter conventions for developer docs vs. help docs - if (devCheckout) { - // skip files with no exclude_version frontmatter - if (!data.exclude_version) return data +const { getEnterpriseServerNumber } = require('./patterns') - // remove frontmatter like exclude_version: - "2.13" - if (data.exclude_version.includes(`${versionToDeprecate}`)) { - data.exclude_version = data.exclude_version.filter(version => !version.match(versionToDeprecate)) +module.exports = function removeDeprecatedFrontmatter (file, frontmatterVersions, versionToDeprecate, nextOldestVersion) { + // skip files with no versions or Enterprise Server versions frontmatter + if (!frontmatterVersions) return + if (!frontmatterVersions['enterprise-server']) return - if (!data.exclude_version.length) delete data.exclude_version - } - } else { - // skip files with no versions or Enterprise versions frontmatter - if (!data.versions) return data - if (!data.versions.enterprise) return data + const enterpriseRange = frontmatterVersions['enterprise-server'] - // change frontmatter like enterprise: '>=2.13' to enterprise: '*' - if (data.versions.enterprise === `>=${versionToDeprecate}` || data.versions.enterprise === `>=${nextOldestVersion}`) { - data.versions.enterprise = '*' - } + // skip files with versions frontmatter that applies to all enterprise-server releases + if (enterpriseRange === '*') return + + // get the release numbers alone + const releaseToDeprecate = versionToDeprecate.match(getEnterpriseServerNumber)[1] + const nextOldestRelease = nextOldestVersion.match(getEnterpriseServerNumber)[1] + + // if the release to deprecate is 2.13, and the FM is either '>=2.13' or '>=2.14', + // we can safely change the FM to enterprise-server: '*' + if (enterpriseRange === `>=${releaseToDeprecate}` || enterpriseRange === `>=${nextOldestRelease}`) { + frontmatterVersions['enterprise-server'] = '*' } - - return data } diff --git a/lib/remove-liquid-statements.js b/lib/remove-liquid-statements.js index bc97a3ecb3..3334bcec55 100644 --- a/lib/remove-liquid-statements.js +++ b/lib/remove-liquid-statements.js @@ -25,11 +25,11 @@ module.exports = function removeLiquidStatements (content, versionToDeprecate, n // see tests/fixtures/remove-liquid-statements for examples const regexes = { // remove liquid only - greaterThanVersionToDeprecate: new RegExp(startTag.source + ` if ?(?: page.version == ('|")'?dotcom'?('|") ?or)? page.version ver_gte? ('|")${versionToDeprecate}('|") ` + endTag.source, 'gm'), - andGreaterThanVersionToDeprecate1: new RegExp('(' + startTag.source + ` if .*?) and page.version ver_gte? (?:'|")${versionToDeprecate}(?:'|")( ` + endTag.source + ')', 'gm'), - andGreaterThanVersionToDeprecate2: new RegExp('(' + startTag.source + ` if )page.version ver_gte? (?:'|")${versionToDeprecate}(?:'|") and (.*? ` + endTag.source + ')', 'gm'), - notEqualsVersionToDeprecate: new RegExp('(' + startTag.source + ` if)(?:( page.version .*?) or)? page.version != (?:'|")${versionToDeprecate}(?:'|")( ` + endTag.source + ')', 'gm'), - andNotEqualsVersionToDeprecate: new RegExp('(' + startTag.source + ` if .*?) and page.version != (?:'|")${versionToDeprecate}(?:'|")( ` + endTag.source + ')', 'gm'), + greaterThanVersionToDeprecate: new RegExp(startTag.source + ` if ?(?: currentVersion == ('|")'?free-pro-team@latest'?('|") ?or)? currentVersion ver_gt ('|")${versionToDeprecate}('|") ` + endTag.source, 'gm'), + andGreaterThanVersionToDeprecate1: new RegExp('(' + startTag.source + ` if .*?) and currentVersion ver_gt (?:'|")${versionToDeprecate}(?:'|")( ` + endTag.source + ')', 'gm'), + andGreaterThanVersionToDeprecate2: new RegExp('(' + startTag.source + ` if )currentVersion ver_gt (?:'|")${versionToDeprecate}(?:'|") and (.*? ` + endTag.source + ')', 'gm'), + notEqualsVersionToDeprecate: new RegExp('(' + startTag.source + ` if)(?:( currentVersion .*?) or)? currentVersion != (?:'|")${versionToDeprecate}(?:'|")( ` + endTag.source + ')', 'gm'), + andNotEqualsVersionToDeprecate: new RegExp('(' + startTag.source + ` if .*?) and currentVersion != (?:'|")${versionToDeprecate}(?:'|")( ` + endTag.source + ')', 'gm'), // remove liquid and content lessThanNextOldestVersion: new RegExp(startTag.source + ` if .*?ver_lt ('|")${nextOldestVersion}('|") ?` + endTag.source, 'm'), equalsVersionToDeprecate: new RegExp(startTag.source + ` if .*?== ('|")${versionToDeprecate}('|") ?` + endTag.source, 'm') diff --git a/script/remove-deprecated-enterprise-version-markup.js b/script/remove-deprecated-enterprise-version-markup.js index d9c260b0d3..33133949d0 100755 --- a/script/remove-deprecated-enterprise-version-markup.js +++ b/script/remove-deprecated-enterprise-version-markup.js @@ -4,83 +4,92 @@ const fs = require('fs') const path = require('path') const walk = require('walk-sync') const matter = require('gray-matter') -const readlineSync = require('readline-sync') +const program = require('commander') +const { indexOf, nth } = require('lodash') const removeLiquidStatements = require('../lib/remove-liquid-statements') const removeDeprecatedFrontmatter = require('../lib/remove-deprecated-frontmatter') -const versionToDeprecate = require('../lib/enterprise-server-releases').deprecated[0] -const nextOldestVersion = require('../lib/enterprise-server-releases').oldestSupported -const devCheckout = process.argv[2] -const prompt = `This script will run in the current checkout of help.github.com. -Is that what you want? Press Y to continue, or enter any other key to cancel: ` +const enterpriseServerReleases = require('../lib/enterprise-server-releases') +const contentPath = path.join(__dirname, '../content') +const dataPath = path.join(__dirname, '../data') +const removeUnusedAssetsScript = 'script/remove-unused-assets' +const elseifRegex = /{-?% elsif/ // [start-readme] // // Run this script after an Enterprise deprecation to remove Liquid statements and frontmatter that contain the deprecated Enterprise version. // See the Enterprise deprecation issue template for instructions. // -// You can run this script on either the help docs or the developer docs. To run it on the help docs, enter: -// -// `script/remove-deprecated-enterprise-version-markup.js` -// -// To run it on the developer docs, provide a path to your developer docs checkout as an argument. You can use a tilde to represent your home directory. For example: -// -// `script/remove-deprecated-enterprise-version-markup.js ~/Desktop/internal-developer.github.com/` -// // [end-readme] -let contentDir = path.join(__dirname, '../content') -let dataDir = path.join(__dirname, '../data') +program + .description('Remove Liquid conditionals and update versions frontmatter for a given Enterprise Server release.') + .option('-r, --release ', 'Enterprise Server release number. Example: 2.19') + .parse(process.argv) -const elseifRegex = /{-?% elsif/ - -// determine whether to run the script on help docs or developer docs -if (devCheckout) { - try { - process.chdir(devCheckout) - console.log('OK, the script will run in ' + devCheckout) - contentDir = path.join(devCheckout, 'content') - dataDir = path.join(devCheckout, 'data') - } catch (err) { - console.log('No such directory! ' + devCheckout) - } -} else { - const answer = readlineSync.question(prompt) - - if (!answer.match(/^Y$/mi)) { - console.log('Exiting!') - process.exit() - } +// verify CLI options +if (!program.release) { + console.log(program.description() + '\n') + program.options.forEach(opt => { + console.log(opt.flags) + console.log(opt.description + '\n') + }) + process.exit(1) } +if (!enterpriseServerReleases.all.includes(program.release)) { + console.log(`You specified ${program.release}! Please specify a supported or deprecated release number from lib/enterprise-server-releases.js`) + process.exit(1) +} + +const versionToDeprecate = `enterprise-server@${program.release}` +const currentIndex = indexOf(enterpriseServerReleases.all, program.release) +const nextOldestRelease = nth(enterpriseServerReleases.all, currentIndex - 1) +const nextOldestVersion = `enterprise-server@${nextOldestRelease}` + +console.log(`Deprecating ${versionToDeprecate}!\n`) +console.log(`Next oldest version: ${nextOldestVersion}\n`) + // gather content and data files -const contentFiles = walk(contentDir, { includeBasePath: true }) - .filter(relativePath => relativePath.endsWith('.md') && !relativePath.match(/README/i)) +const contentFiles = walk(contentPath, { includeBasePath: true, directories: false }) + .filter(file => file.endsWith('.md')) + .filter(file => !(file.endsWith('README.md') || file === 'LICENSE')) -const dataFiles = walk(dataDir, { includeBasePath: true }) - .filter(relativePath => relativePath.endsWith('.yml') || relativePath.endsWith('.md')) - .filter(relativePath => !relativePath.includes('/graphql/')) +const dataFiles = walk(dataPath, { includeBasePath: true, directories: false }) + .filter(file => file.includes('data/reusables') || file.includes('data/variables')) + .filter(file => !file.endsWith('README.md')) -const files = contentFiles.concat(dataFiles) +const allFiles = contentFiles.concat(dataFiles) main() -console.log(`Removed ${versionToDeprecate} markup from content and data files! Review and run script/test.`) +console.log(`\nRunning ${removeUnusedAssetsScript}...`) +require(`../${removeUnusedAssetsScript}`) + +function printElseIfFoundWarning (location) { + console.log(`${location} has an 'elsif' condition! Resolve all elsifs by hand, then rerun the script.`) +} function main () { - files.forEach(file => { + allFiles.forEach(file => { const oldContents = fs.readFileSync(file, 'utf8') const { content, data } = matter(oldContents) - // can't safely handle elseifs programmatically, too many possible outcomes - // (only intro and title frontmatter are likely to contain elseif tags) - if (content.match(elseifRegex) || (data.intro && data.intro.match(elseifRegex)) || (data.title && data.title.match(elseifRegex))) { - console.log(`${file} has an 'elsif' condition! Resolve all elsifs by hand, then rerun the script.`) + // we can't safely handle elseifs programmatically, too many possible outcomes + if (elseifRegex.test(content)) { + printElseIfFoundWarning(`content in ${file}`) process.exit() } - // update frontmatter data (i.e., productVersions field) - const newData = removeDeprecatedFrontmatter(data, devCheckout, versionToDeprecate, nextOldestVersion) + Object.keys(data).forEach(key => { + if (elseifRegex.test(data[key])) { + printElseIfFoundWarning(`frontmatter '${key}' in ${file}`) + process.exit() + } + }) - // update liquid statements in body content + // update frontmatter versions prop + removeDeprecatedFrontmatter(file, data.versions, versionToDeprecate, nextOldestVersion) + + // update liquid statements in content and data const newContent = removeLiquidStatements(content, versionToDeprecate, nextOldestVersion) // make sure any intro fields that exist and are empty return an empty string, not null @@ -89,8 +98,10 @@ function main () { } // put it all back together - const newContents = matter.stringify(newContent, newData, { lineWidth: 10000 }) + const newContents = matter.stringify(newContent, data, { lineWidth: 10000 }) fs.writeFileSync(file, newContents) }) + + console.log(`Removed ${versionToDeprecate} markup from content and data files! Review and run script/test.`) } diff --git a/tests/content/remove-liquid-statements.js b/tests/content/remove-liquid-statements.js index 44f8057edf..80fd021669 100644 --- a/tests/content/remove-liquid-statements.js +++ b/tests/content/remove-liquid-statements.js @@ -7,8 +7,8 @@ const removeDeprecatedFrontmatter = require('../../lib/remove-deprecated-frontma const removeLiquidStatementsFixtures = path.join(__dirname, '../fixtures/remove-liquid-statements') // Hardcode values so tests don't go out of date -const versionToDeprecate = '2.13' -const nextOldestVersion = '2.14' +const versionToDeprecate = 'enterprise-server@2.13' +const nextOldestVersion = 'enterprise-server@2.14' // Remove liquid only const greaterThan = path.join(removeLiquidStatementsFixtures, 'greater-than.md') @@ -28,10 +28,10 @@ const frontmatter1 = path.join(removeLiquidStatementsFixtures, 'frontmatter1.md' const frontmatter2 = path.join(removeLiquidStatementsFixtures, 'frontmatter2.md') // process frontmatter -function processFrontmatter (contents) { +function processFrontmatter (contents, file) { const { content, data } = matter(contents) - const newData = removeDeprecatedFrontmatter(data, false, versionToDeprecate, nextOldestVersion) - return matter.stringify(content, newData, { lineWidth: 10000 }) + removeDeprecatedFrontmatter(file, data.versions, versionToDeprecate, nextOldestVersion) + return matter.stringify(content, data, { lineWidth: 10000 }) } describe('removing liquid statements only', () => { @@ -42,17 +42,17 @@ describe('removing liquid statements only', () => { expect($('.example1').text().trim()).toBe('Alpha') expect($('.example2').text().trim()).toBe('Alpha') expect($('.example3').text().trim()).toBe('Alpha') - expect($('.example4').text().trim()).toBe(`{% if page.version ver_gt "2.16" %}\n + expect($('.example4').text().trim()).toBe(`{% if currentVersion ver_gt "enterprise-server@2.16" %}\n Alpha\n\n{% else %}\n\nBravo\n\nCharlie\n\n{% endif %}`) - expect($('.example5').text().trim()).toBe(`{% if page.version ver_lt "2.16" %}\n + expect($('.example5').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n Alpha\n\nBravo\n\n{% else %}\n\nCharlie\n\n{% endif %}`) - expect($('.example6').text().trim()).toBe(`Alpha\n\n{% if page.version ver_lt "2.16" %}\n + expect($('.example6').text().trim()).toBe(`Alpha\n\n{% if currentVersion ver_lt "enterprise-server@2.16" %}\n Bravo\n\n{% endif %}`) - expect($('.example7').text().trim()).toBe(`Alpha\n\n{% if page.version ver_gt "2.16" %}\n + expect($('.example7').text().trim()).toBe(`Alpha\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n Bravo\n\n{% else %}\n\nCharlie\n\n{% endif %}`) expect($('.example8').text().trim()).toBe('Alpha') - expect($('.example9').text().trim()).toBe(`{% if page.version == 'dotcom' %}\n -Alpha\n\n{% else %}\n\nBravo\n\n{% if page.version ver_gt "2.16" %}\n\nCharlie\n + expect($('.example9').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n +Alpha\n\n{% else %}\n\nBravo\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n\nCharlie\n {% endif %}\n\nDelta\n\n{% endif %}`) expect($('.example10').text().trim()).toBe('Alpha') }) @@ -61,28 +61,28 @@ Alpha\n\n{% else %}\n\nBravo\n\n{% if page.version ver_gt "2.16" %}\n\nCharlie\n let contents = fs.readFileSync(andGreaterThan1, 'utf8') contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion) const $ = cheerio.load(contents) - expect($('.example1').text().trim()).toBe('{% if page.version != \'dotcom\' %}\n\nAlpha\n\n{% endif %}') - expect($('.example2').text().trim()).toBe('{% if page.version != \'dotcom\' %}\n\nAlpha\n\n{% endif %}') - expect($('.example3').text().trim()).toBe(`{% if page.version ver_gt "2.16" %}\n -Alpha\n\n{% else %}\n\nBravo\n\n{% if page.version != 'dotcom' %}\n\nCharlie\n\n{% endif %}\n{% endif %}`) - expect($('.example4').text().trim()).toBe(`{% if page.version ver_lt "2.16" %}\n -Alpha\n\n{% if page.version != 'dotcom' %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharlie\n\n{% endif %}`) - expect($('.example5').text().trim()).toBe(`{% if page.version != 'dotcom' %}\n -Alpha\n\n{% if page.version ver_gt "2.16" %}\n\nBravo\n\n{% endif %}\n\n{% endif %}`) + expect($('.example1').text().trim()).toBe('{% if currentVersion != "free-pro-team@latest" %}\n\nAlpha\n\n{% endif %}') + expect($('.example2').text().trim()).toBe('{% if currentVersion != "free-pro-team@latest" %}\n\nAlpha\n\n{% endif %}') + expect($('.example3').text().trim()).toBe(`{% if currentVersion ver_gt "enterprise-server@2.16" %}\n +Alpha\n\n{% else %}\n\nBravo\n\n{% if currentVersion != "free-pro-team@latest" %}\n\nCharlie\n\n{% endif %}\n{% endif %}`) + expect($('.example4').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n +Alpha\n\n{% if currentVersion != "free-pro-team@latest" %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharlie\n\n{% endif %}`) + expect($('.example5').text().trim()).toBe(`{% if currentVersion != "free-pro-team@latest" %}\n +Alpha\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n\nBravo\n\n{% endif %}\n\n{% endif %}`) }) test('removes liquid statements that specify "and greater than version to deprecate" (alternate format)', () => { let contents = fs.readFileSync(andGreaterThan2, 'utf8') contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion) const $ = cheerio.load(contents) - expect($('.example1').text().trim()).toBe('{% if page.version ver_lt "2.16" %}\n\nAlpha\n\n{% endif %}') - expect($('.example2').text().trim()).toBe('{% if page.version ver_lt "2.16" %}\n\nAlpha\n\n{% endif %}') - expect($('.example3').text().trim()).toBe(`{% if page.version == "dotcom" %}\n -Alpha\n\n{% else %}\n\nBravo\n\n{% if page.version ver_lt "2.16" %}\n\nCharlie\n\n{% endif %}\n{% endif %}`) - expect($('.example4').text().trim()).toBe(`{% if page.version != "dotcom" %}\n -Alpha\n\n{% if page.version ver_lt "2.16" %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharlie\n\n{% endif %}`) - expect($('.example5').text().trim()).toBe(`{% if page.version ver_lt "2.16" %}\n -Alpha\n\n{% if page.version != "dotcom" %}\n\nBravo\n\n{% endif %}\n\n{% endif %}`) + expect($('.example1').text().trim()).toBe('{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nAlpha\n\n{% endif %}') + expect($('.example2').text().trim()).toBe('{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nAlpha\n\n{% endif %}') + expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n +Alpha\n\n{% else %}\n\nBravo\n\n{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nCharlie\n\n{% endif %}\n{% endif %}`) + expect($('.example4').text().trim()).toBe(`{% if currentVersion != "free-pro-team@latest" %}\n +Alpha\n\n{% if currentVersion ver_lt "enterprise-server@2.16" %}\n\nBravo\n\n{% endif %}\n\n{% else %}\n\nCharlie\n\n{% endif %}`) + expect($('.example5').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n +Alpha\n\n{% if currentVersion != "free-pro-team@latest" %}\n\nBravo\n\n{% endif %}\n\n{% endif %}`) }) test('removes liquid statements that specify "not equals version to deprecate"', () => { @@ -90,14 +90,14 @@ Alpha\n\n{% if page.version != "dotcom" %}\n\nBravo\n\n{% endif %}\n\n{% endif % contents = removeLiquidStatements(contents, versionToDeprecate, nextOldestVersion) const $ = cheerio.load(contents) expect($('.example1').text().trim()).toBe('Alpha') - expect($('.example2').text().trim()).toBe('{% if page.version == \'dotcom\' %}\n\nAlpha\n\n{% endif %}') - expect($('.example3').text().trim()).toBe(`{% if page.version == "dotcom" %}\n + expect($('.example2').text().trim()).toBe('{% if currentVersion == "free-pro-team@latest" %}\n\nAlpha\n\n{% endif %}') + expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n Alpha\n\n{% else %}\n\nBravo\n\nCharlie\n\n{% endif %}`) - expect($('.example4').text().trim()).toBe(`{% if page.version == "dotcom" %}\n + expect($('.example4').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n Alpha\n\nBravo\n\n{% else %}\n\nCharlie\n\n{% endif %}`) - expect($('.example5').text().trim()).toBe(`Alpha\n\n{% if page.version == "dotcom" %}\n + expect($('.example5').text().trim()).toBe(`Alpha\n\n{% if currentVersion == "free-pro-team@latest" %}\n Bravo\n\n{% endif %}`) - expect($('.example6').text().trim()).toBe(`{% if page.version != 'dotcom' %}\n + expect($('.example6').text().trim()).toBe(`{% if currentVersion != "free-pro-team@latest" %}\n Alpha\n\n{% endif %}`) }) }) @@ -109,9 +109,9 @@ describe('removing liquid statements and content', () => { const $ = cheerio.load(contents) expect($('.example1').text().trim()).toBe('') expect($('.example2').text().trim()).toBe('') - expect($('.example3').text().trim()).toBe(`{% if page.version == "dotcom" %}\n + expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n Alpha\n\n{% else %}\n\nBravo\n\n{% endif %}`) - expect($('.example4').text().trim()).toBe(`{% if page.version == "dotcom" %}\n + expect($('.example4').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`) expect($('.example5').text().trim()).toBe('Charlie') expect($('.example6').text().trim()).toBe('Charlie\n\nBravo') @@ -123,34 +123,36 @@ Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`) const $ = cheerio.load(contents) expect($('.example1').text().trim()).toBe('Alpha') expect($('.example2').text().trim()).toBe('Alpha') - expect($('.example3').text().trim()).toBe(`{% if page.version == "dotcom" %}\n + expect($('.example3').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n Alpha\n\n{% else %}\n\nBravo\n\n{% endif %}`) - expect($('.example4').text().trim()).toBe(`{% if page.version == "dotcom" %}\n + expect($('.example4').text().trim()).toBe(`{% if currentVersion == "free-pro-team@latest" %}\n Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`) expect($('.example5').text().trim()).toBe('Charlie') - expect($('.example6').text().trim()).toBe(`{% if page.version ver_lt "2.16" %}\n + expect($('.example6').text().trim()).toBe(`{% if currentVersion ver_lt "enterprise-server@2.16" %}\n Alpha\n\n{% else %}\n\nCharlie\n\n{% endif %}`) expect($('.example7').text().trim()).toBe('') - expect($('.example8').text().trim()).toBe(`Bravo\n\n{% if page.version ver_gt "2.16" %}\n + expect($('.example8').text().trim()).toBe(`Bravo\n\n{% if currentVersion ver_gt "enterprise-server@2.16" %}\n Charlie\n\n{% else %}\n\nDelta\n\n{% endif %}\n\nEcho`) }) }) describe('updating frontmatter', () => { - test('updates productVersions Enterprise if set to greater-than-or-equal-to version to deprecate', () => { + test('updates frontmatter versions Enterprise if set to greater-than-or-equal-to version to deprecate', () => { let contents = fs.readFileSync(frontmatter1, 'utf8') - contents = processFrontmatter(contents) + contents = processFrontmatter(contents, frontmatter1) const $ = cheerio.load(contents) - expect($.text().includes('enterprise: \'*\'')).toBe(true) - expect($.text().includes('enterprise: \'>=2.13\'')).toBe(false) + // console.log('foo') + // console.log($.text()) + expect($.text().includes('enterprise-server: \'*\'')).toBe(true) + expect($.text().includes('enterprise-server: \'>=2.13\'')).toBe(false) }) - test('updates productVersions Enterprise if set to greater-than-or-equal-to next oldest version', () => { + test('updates frontmatter versions Enterprise if set to greater-than-or-equal-to next oldest version', () => { let contents = fs.readFileSync(frontmatter2, 'utf8') - contents = processFrontmatter(contents) + contents = processFrontmatter(contents, frontmatter2) const $ = cheerio.load(contents) - expect($.text().includes('enterprise: \'*\'')).toBe(true) - expect($.text().includes('enterprise: \'>=2.14\'')).toBe(false) + expect($.text().includes('enterprise-server: \'*\'')).toBe(true) + expect($.text().includes('enterprise-server: \'>=2.14\'')).toBe(false) }) }) diff --git a/tests/fixtures/remove-liquid-statements/and-greater-than1.md b/tests/fixtures/remove-liquid-statements/and-greater-than1.md index d5c3297016..087cf50a4c 100644 --- a/tests/fixtures/remove-liquid-statements/and-greater-than1.md +++ b/tests/fixtures/remove-liquid-statements/and-greater-than1.md @@ -6,7 +6,7 @@ intro: Remove liquid only ## 1
-{% if page.version != 'dotcom' and page.version ver_gt "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_gt "enterprise-server@2.13" %} Alpha @@ -17,7 +17,7 @@ Alpha ## 2
-{% if page.version != 'dotcom' and page.version ver_gt "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_gt "enterprise-server@2.13" %} Alpha @@ -32,7 +32,7 @@ Bravo ## 3
-{% if page.version ver_gt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.16" %} Alpha @@ -40,7 +40,7 @@ Alpha Bravo -{% if page.version != 'dotcom' and page.version ver_gt "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_gt "enterprise-server@2.13" %} Charlie @@ -52,11 +52,11 @@ Charlie ## 4
-{% if page.version ver_lt "2.16" %} +{% if currentVersion ver_lt "enterprise-server@2.16" %} Alpha -{% if page.version != 'dotcom' and page.version ver_gt "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_gt "enterprise-server@2.13" %} Bravo @@ -73,11 +73,11 @@ Charlie ## 5
-{% if page.version != 'dotcom' and page.version ver_gt "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_gt "enterprise-server@2.13" %} Alpha -{% if page.version ver_gt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.16" %} Bravo diff --git a/tests/fixtures/remove-liquid-statements/and-greater-than2.md b/tests/fixtures/remove-liquid-statements/and-greater-than2.md index 229b03b570..41400f478e 100644 --- a/tests/fixtures/remove-liquid-statements/and-greater-than2.md +++ b/tests/fixtures/remove-liquid-statements/and-greater-than2.md @@ -6,7 +6,7 @@ intro: Remove liquid only ## 1
-{% if page.version ver_gt "2.13" and page.version ver_lt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.13" and currentVersion ver_lt "enterprise-server@2.16" %} Alpha @@ -17,7 +17,7 @@ Alpha ## 2
-{% if page.version ver_gt "2.13" and page.version ver_lt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.13" and currentVersion ver_lt "enterprise-server@2.16" %} Alpha @@ -32,7 +32,7 @@ Bravo ## 3
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha @@ -40,7 +40,7 @@ Alpha Bravo -{% if page.version ver_gt "2.13" and page.version ver_lt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.13" and currentVersion ver_lt "enterprise-server@2.16" %} Charlie @@ -52,11 +52,11 @@ Charlie ## 4
-{% if page.version != "dotcom" %} +{% if currentVersion != "free-pro-team@latest" %} Alpha -{% if page.version ver_gt "2.13" and page.version ver_lt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.13" and currentVersion ver_lt "enterprise-server@2.16" %} Bravo @@ -73,11 +73,11 @@ Charlie ## 5
-{% if page.version ver_gt "2.13" and page.version ver_lt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.13" and currentVersion ver_lt "enterprise-server@2.16" %} Alpha -{% if page.version != "dotcom" %} +{% if currentVersion != "free-pro-team@latest" %} Bravo diff --git a/tests/fixtures/remove-liquid-statements/equals.md b/tests/fixtures/remove-liquid-statements/equals.md index 9d50828b07..7eae0e1c13 100644 --- a/tests/fixtures/remove-liquid-statements/equals.md +++ b/tests/fixtures/remove-liquid-statements/equals.md @@ -6,7 +6,7 @@ intro: Remove liquid and content ## 1
-{% if page.version == "2.13" %} +{% if currentVersion == "enterprise-server@2.13" %} Alpha @@ -17,7 +17,7 @@ Alpha ## 2
-{% if page.version != 'dotcom' and page.version == "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion == "enterprise-server@2.13" %} Alpha @@ -28,7 +28,7 @@ Alpha ## 3
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha @@ -36,7 +36,7 @@ Alpha Bravo -{% if page.version == "2.13" %} +{% if currentVersion == "enterprise-server@2.13" %} Charlie @@ -48,11 +48,11 @@ Charlie ## 4
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha -{% if page.version == "2.13" %} +{% if currentVersion == "enterprise-server@2.13" %} Bravo @@ -69,11 +69,11 @@ Charlie ## 5
-{% if page.version == "2.13" %} +{% if currentVersion == "enterprise-server@2.13" %} Alpha -{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Bravo @@ -90,7 +90,7 @@ Charlie ## 6
-{% if page.version == "2.13" %} +{% if currentVersion == "enterprise-server@2.13" %} Alpha @@ -98,7 +98,7 @@ Alpha Charlie -{% if page.version == "dotcom" or page.version ver_gt "2.13" %} +{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.13" %} Bravo diff --git a/tests/fixtures/remove-liquid-statements/frontmatter1.md b/tests/fixtures/remove-liquid-statements/frontmatter1.md index 688669fd0f..c3c6a06e1e 100644 --- a/tests/fixtures/remove-liquid-statements/frontmatter1.md +++ b/tests/fixtures/remove-liquid-statements/frontmatter1.md @@ -1,6 +1,6 @@ --- title: Frontmatter versions: - dotcom: '*' - enterprise: '>=2.13' + free-pro-team: '*' + enterprise-server: '>=2.13' --- diff --git a/tests/fixtures/remove-liquid-statements/frontmatter2.md b/tests/fixtures/remove-liquid-statements/frontmatter2.md index f6103b80bb..ad8814b0a7 100644 --- a/tests/fixtures/remove-liquid-statements/frontmatter2.md +++ b/tests/fixtures/remove-liquid-statements/frontmatter2.md @@ -1,6 +1,6 @@ --- title: Frontmatter versions: - dotcom: '*' - enterprise: '>=2.14' + free-pro-team: '*' + enterprise-server: '>=2.14' --- diff --git a/tests/fixtures/remove-liquid-statements/greater-than.md b/tests/fixtures/remove-liquid-statements/greater-than.md index 6b73e04494..3e2512c095 100644 --- a/tests/fixtures/remove-liquid-statements/greater-than.md +++ b/tests/fixtures/remove-liquid-statements/greater-than.md @@ -6,7 +6,7 @@ intro: Remove liquid only ## 1
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha @@ -17,7 +17,7 @@ Alpha ## 2
-{% if page.version == 'dotcom' or page.version ver_gt "2.13" %} +{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.13" %} Alpha @@ -28,7 +28,7 @@ Alpha ## 3
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha @@ -43,7 +43,7 @@ Bravo ## 4
-{% if page.version ver_gt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.16" %} Alpha @@ -51,7 +51,7 @@ Alpha Bravo -{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Charlie @@ -63,11 +63,11 @@ Charlie ## 5
-{% if page.version ver_lt "2.16" %} +{% if currentVersion ver_lt "enterprise-server@2.16" %} Alpha -{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Bravo @@ -84,11 +84,11 @@ Charlie ## 6
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha -{% if page.version ver_lt "2.16" %} +{% if currentVersion ver_lt "enterprise-server@2.16" %} Bravo @@ -105,11 +105,11 @@ Charlie ## 7
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha -{% if page.version ver_gt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.16" %} Bravo @@ -125,7 +125,7 @@ Charlie ## 8
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha @@ -133,7 +133,7 @@ Alpha Bravo -{% if page.version != "dotcom" %} +{% if currentVersion != "free-pro-team@latest" %} Charlie @@ -148,7 +148,7 @@ Delta ## 9
-{% if page.version == 'dotcom' %} +{% if currentVersion == "free-pro-team@latest" %} Alpha @@ -156,13 +156,13 @@ Alpha Bravo -{% if page.version ver_gt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.16" %} Charlie {% endif %} -{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Delta @@ -175,13 +175,13 @@ Delta ## 10
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha {% else %} -Security alerts for vulnerable dependencies are available in {% data variables.product.prodname_ghe_server %} 2.17+. For more information, see "[Enabling security alerts for vulnerable dependencies on {% data variables.product.prodname_ghe_server %}](/enterprise/admin/installation/enabling-security-alerts-for-vulnerable-dependencies-on-github-enterprise-server)." +Security alerts for vulnerable dependencies are available in {{ site.data.variables.product.prodname_ghe_server }} 2.17+. For more information, see "[Enabling security alerts for vulnerable dependencies on {{ site.data.variables.product.prodname_ghe_server }}](/enterprise/admin/installation/enabling-security-alerts-for-vulnerable-dependencies-on-github-enterprise-server)." {% endif %} diff --git a/tests/fixtures/remove-liquid-statements/less-than-next-oldest.md b/tests/fixtures/remove-liquid-statements/less-than-next-oldest.md index 6882a5b06e..16974b0add 100644 --- a/tests/fixtures/remove-liquid-statements/less-than-next-oldest.md +++ b/tests/fixtures/remove-liquid-statements/less-than-next-oldest.md @@ -8,7 +8,7 @@ intro: Remove liquid and content Alpha -{% if page.version ver_lt "2.14" %} +{% if currentVersion ver_lt "enterprise-server@2.14" %} Bravo @@ -21,7 +21,7 @@ Bravo Alpha -{% if page.version == 'dotcom' or page.version ver_lt "2.14" %} +{% if currentVersion == "free-pro-team@latest" or currentVersion ver_lt "enterprise-server@2.14" %} Bravo @@ -32,7 +32,7 @@ Bravo ## 3
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha @@ -40,7 +40,7 @@ Alpha Bravo -{% if page.version ver_lt "2.14" %} +{% if currentVersion ver_lt "enterprise-server@2.14" %} Charlie @@ -53,11 +53,11 @@ Charlie
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha -{% if page.version ver_lt "2.14" %} +{% if currentVersion ver_lt "enterprise-server@2.14" %} Bravo @@ -74,11 +74,11 @@ Charlie ## 5
-{% if page.version ver_lt "2.14" %} +{% if currentVersion ver_lt "enterprise-server@2.14" %} Alpha -{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Bravo @@ -95,7 +95,7 @@ Charlie ## 6
-{% if page.version ver_lt "2.16" %} +{% if currentVersion ver_lt "enterprise-server@2.16" %} Alpha @@ -103,7 +103,7 @@ Alpha Charlie -{% if page.version != "dotcom" and page.version ver_lt "2.14" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_lt "enterprise-server@2.14" %} Bravo @@ -116,11 +116,11 @@ Bravo ## 7
-{% if page.version != "dotcom" and page.version ver_lt "2.14" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion ver_lt "enterprise-server@2.14" %} Alpha -{% if page.version ver_lt "2.14" %} +{% if currentVersion ver_lt "enterprise-server@2.14" %} Bravo @@ -137,7 +137,7 @@ Charlie ## 8
-{% if page.version ver_lt "2.14" %} +{% if currentVersion ver_lt "enterprise-server@2.14" %} Alpha @@ -145,7 +145,7 @@ Alpha Bravo -{% if page.version ver_gt "2.16" %} +{% if currentVersion ver_gt "enterprise-server@2.16" %} Charlie diff --git a/tests/fixtures/remove-liquid-statements/not-equals.md b/tests/fixtures/remove-liquid-statements/not-equals.md index a4c987245d..0797bafd88 100644 --- a/tests/fixtures/remove-liquid-statements/not-equals.md +++ b/tests/fixtures/remove-liquid-statements/not-equals.md @@ -6,7 +6,7 @@ intro: Remove liquid only ## 1
-{% if page.version != "2.13" %} +{% if currentVersion != "enterprise-server@2.13" %} Alpha @@ -17,7 +17,7 @@ Alpha ## 2
-{% if page.version == 'dotcom' or page.version != "2.13" %} +{% if currentVersion == "free-pro-team@latest" or currentVersion != "enterprise-server@2.13" %} Alpha @@ -28,7 +28,7 @@ Alpha ## 3
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha @@ -36,7 +36,7 @@ Alpha Bravo -{% if page.version != "2.13" %} +{% if currentVersion != "enterprise-server@2.13" %} Charlie @@ -48,11 +48,11 @@ Charlie ## 4
-{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Alpha -{% if page.version != "2.13" %} +{% if currentVersion != "enterprise-server@2.13" %} Bravo @@ -69,11 +69,11 @@ Charlie ## 5
-{% if page.version != "2.13" %} +{% if currentVersion != "enterprise-server@2.13" %} Alpha -{% if page.version == "dotcom" %} +{% if currentVersion == "free-pro-team@latest" %} Bravo @@ -90,7 +90,7 @@ Charlie ## 6
-{% if page.version != 'dotcom' and page.version != "2.13" %} +{% if currentVersion != "free-pro-team@latest" and currentVersion != "enterprise-server@2.13" %} Alpha diff --git a/tests/fixtures/remove-liquid-statements/whitespace.md b/tests/fixtures/remove-liquid-statements/whitespace.md index 7d4cf265f9..39d058d552 100644 --- a/tests/fixtures/remove-liquid-statements/whitespace.md +++ b/tests/fixtures/remove-liquid-statements/whitespace.md @@ -4,35 +4,35 @@ title: Whitespace tests ## 1
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha {% endif %}
## 2
-{%- if page.version ver_gt "2.13" %} +{%- if currentVersion ver_gt "enterprise-server@2.13" %} Alpha {% endif %}
## 3
-{% if page.version == 'dotcom' or page.version ver_gt "2.13" %} +{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.13" %} Alpha {%- endif %}
## 4
-{%- if page.version == 'dotcom' or page.version ver_gt "2.13" %} +{%- if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.13" %} Alpha {%- endif %}
## 5
-{% if page.version ver_gt "2.13" %} +{% if currentVersion ver_gt "enterprise-server@2.13" %} Alpha {% endif %}
@@ -40,7 +40,7 @@ title: Whitespace tests ## 6
Alpha -{% if page.version == 'dotcom' or page.version ver_gt "2.13" %} +{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.13" %} Bravo {% endif %} Charlie @@ -48,6 +48,6 @@ title: Whitespace tests ## 7
-Alpha{% if page.version == 'dotcom' or page.version ver_gt "2.13" %} +Alpha{% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.13" %} Bravo{% endif %}