2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -43,11 +43,13 @@ jobs:
|
||||
{ name: 'automated-pipelines', path: 'src/automated-pipelines/tests', },
|
||||
{ name: 'content', path: 'tests/content', },
|
||||
// { name: 'content-linter', path: 'src/content-linter/tests', },
|
||||
{ name: 'content-render', path: 'src/content-render/tests', },
|
||||
{ name: 'events', path: 'src/events/tests', },
|
||||
{ name: 'ghes-releases', path: 'src/ghes-releases/tests', },
|
||||
{ name: 'github-apps', path: 'src/github-apps/tests', },
|
||||
{ name: 'graphql', path: 'src/graphql/tests', },
|
||||
{ name: 'landings', path: 'src/landings/tests', },
|
||||
// { name: 'learning-track', path: 'src/learning-track/tests', },
|
||||
{ name: 'linting', path: 'src/content-linter/tests', },
|
||||
{ name: 'observability', path: 'src/observability/tests' },
|
||||
{ name: 'pageinfo', path: 'src/pageinfo/tests', },
|
||||
|
||||
125
package-lock.json
generated
125
package-lock.json
generated
@@ -146,7 +146,7 @@
|
||||
"markdownlint": "^0.28.2",
|
||||
"markdownlint-rule-helpers": "^0.19.0",
|
||||
"mdast-util-gfm-table": "^1.0.7",
|
||||
"micromark-extension-gfm-table": "^1.0.5",
|
||||
"micromark-extension-gfm-table": "^2.0.0",
|
||||
"mkdirp": "^3.0.0",
|
||||
"mockdate": "^3.0.5",
|
||||
"nock": "^13.2.7",
|
||||
@@ -169,8 +169,7 @@
|
||||
"node": "^16 || ^18"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"esm": "^3.2.25",
|
||||
"website-scraper": "^5.3.1"
|
||||
"esm": "^3.2.25"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/core": {
|
||||
@@ -7401,6 +7400,19 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/devlop": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/devlop/-/devlop-1.0.0.tgz",
|
||||
"integrity": "sha512-DNY7Ok32YUNiFjTw9sNVqUET5c2/cqbOdDxnsI6MkfQOvMcAULqPVqABm/An9IGVRP4ulHEvpo3/w2Potw3cfQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"dequal": "^2.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
}
|
||||
},
|
||||
"node_modules/diff": {
|
||||
"version": "5.0.0",
|
||||
"license": "BSD-3-Clause",
|
||||
@@ -13828,20 +13840,94 @@
|
||||
}
|
||||
},
|
||||
"node_modules/micromark-extension-gfm-table": {
|
||||
"version": "1.0.5",
|
||||
"license": "MIT",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/micromark-extension-gfm-table/-/micromark-extension-gfm-table-2.0.0.tgz",
|
||||
"integrity": "sha512-PoHlhypg1ItIucOaHmKE8fbin3vTLpDOUg8KAr8gRCF1MOZI9Nquq2i/44wFvviM4WuxJzc3demT8Y3dkfvYrw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"micromark-factory-space": "^1.0.0",
|
||||
"micromark-util-character": "^1.0.0",
|
||||
"micromark-util-symbol": "^1.0.0",
|
||||
"micromark-util-types": "^1.0.0",
|
||||
"uvu": "^0.5.0"
|
||||
"devlop": "^1.0.0",
|
||||
"micromark-factory-space": "^2.0.0",
|
||||
"micromark-util-character": "^2.0.0",
|
||||
"micromark-util-symbol": "^2.0.0",
|
||||
"micromark-util-types": "^2.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/micromark-extension-gfm-table/node_modules/micromark-factory-space": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/micromark-factory-space/-/micromark-factory-space-2.0.0.tgz",
|
||||
"integrity": "sha512-TKr+LIDX2pkBJXFLzpyPyljzYK3MtmllMUMODTQJIUfDGncESaqB90db9IAUcz4AZAJFdd8U9zOp9ty1458rxg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "GitHub Sponsors",
|
||||
"url": "https://github.com/sponsors/unifiedjs"
|
||||
},
|
||||
{
|
||||
"type": "OpenCollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"micromark-util-character": "^2.0.0",
|
||||
"micromark-util-types": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/micromark-extension-gfm-table/node_modules/micromark-util-character": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/micromark-util-character/-/micromark-util-character-2.0.1.tgz",
|
||||
"integrity": "sha512-3wgnrmEAJ4T+mGXAUfMvMAbxU9RDG43XmGce4j6CwPtVxB3vfwXSZ6KhFwDzZ3mZHhmPimMAXg71veiBGzeAZw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "GitHub Sponsors",
|
||||
"url": "https://github.com/sponsors/unifiedjs"
|
||||
},
|
||||
{
|
||||
"type": "OpenCollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"micromark-util-symbol": "^2.0.0",
|
||||
"micromark-util-types": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/micromark-extension-gfm-table/node_modules/micromark-util-symbol": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/micromark-util-symbol/-/micromark-util-symbol-2.0.0.tgz",
|
||||
"integrity": "sha512-8JZt9ElZ5kyTnO94muPxIGS8oyElRJaiJO8EzV6ZSyGQ1Is8xwl4Q45qU5UOg+bGH4AikWziz0iN4sFLWs8PGw==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "GitHub Sponsors",
|
||||
"url": "https://github.com/sponsors/unifiedjs"
|
||||
},
|
||||
{
|
||||
"type": "OpenCollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/micromark-extension-gfm-table/node_modules/micromark-util-types": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/micromark-util-types/-/micromark-util-types-2.0.0.tgz",
|
||||
"integrity": "sha512-oNh6S2WMHWRZrmutsRmDDfkzKtxF+bc2VxLC9dvtrDIRFln627VsFP6fLMgTryGDljgLPjkrzQSDcPrjPyDJ5w==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "GitHub Sponsors",
|
||||
"url": "https://github.com/sponsors/unifiedjs"
|
||||
},
|
||||
{
|
||||
"type": "OpenCollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/micromark-extension-gfm-tagfilter": {
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
@@ -13868,6 +13954,22 @@
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/micromark-extension-gfm/node_modules/micromark-extension-gfm-table": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/micromark-extension-gfm-table/-/micromark-extension-gfm-table-1.0.7.tgz",
|
||||
"integrity": "sha512-3ZORTHtcSnMQEKtAOsBQ9/oHp9096pI/UvdPtN7ehKvrmZZ2+bbWhi0ln+I9drmwXMt5boocn6OlwQzNXeVeqw==",
|
||||
"dependencies": {
|
||||
"micromark-factory-space": "^1.0.0",
|
||||
"micromark-util-character": "^1.0.0",
|
||||
"micromark-util-symbol": "^1.0.0",
|
||||
"micromark-util-types": "^1.0.0",
|
||||
"uvu": "^0.5.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/micromark-factory-destination": {
|
||||
"version": "1.0.0",
|
||||
"funding": [
|
||||
@@ -18472,8 +18574,9 @@
|
||||
},
|
||||
"node_modules/website-scraper": {
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npmjs.org/website-scraper/-/website-scraper-5.3.1.tgz",
|
||||
"integrity": "sha512-gogqPXD2gVsxoyd2yRiympw3rA5GuEpD1CaDEJ/J8zzanx7hkbTtneoO1SGs436PpLbWVcUge+6APGLhzsuZPA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cheerio": "1.0.0-rc.12",
|
||||
"css-url-parser": "^1.0.0",
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
"markdownlint": "^0.28.2",
|
||||
"markdownlint-rule-helpers": "^0.19.0",
|
||||
"mdast-util-gfm-table": "^1.0.7",
|
||||
"micromark-extension-gfm-table": "^1.0.5",
|
||||
"micromark-extension-gfm-table": "^2.0.0",
|
||||
"mkdirp": "^3.0.0",
|
||||
"mockdate": "^3.0.5",
|
||||
"nock": "^13.2.7",
|
||||
@@ -213,8 +213,7 @@
|
||||
"website-scraper": "^5.3.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"esm": "^3.2.25",
|
||||
"website-scraper": "^5.3.1"
|
||||
"esm": "^3.2.25"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16 || ^18"
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { fileURLToPath } from 'url'
|
||||
import path from 'path'
|
||||
|
||||
import { afterAll, beforeAll, expect, describe, it } from '@jest/globals'
|
||||
|
||||
import Page from '../../../lib/page.js'
|
||||
@@ -8,8 +5,6 @@ import languages from '../../../lib/languages.js'
|
||||
import nonEnterpriseDefaultVersion from '../../../lib/non-enterprise-default-version.js'
|
||||
import { DataDirectory } from '../../../tests/helpers/data-directory.js'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
describe('data tag', () => {
|
||||
let dd
|
||||
const enDirBefore = languages.en.dir
|
||||
@@ -35,7 +30,7 @@ describe('data tag', () => {
|
||||
it('should render fine if data is found', async () => {
|
||||
const page = await Page.init({
|
||||
relativePath: 'liquid-tags/good-data-variable.md',
|
||||
basePath: path.join(__dirname, '../../fixtures'),
|
||||
basePath: './tests/fixtures',
|
||||
languageCode: 'en',
|
||||
})
|
||||
const context = {
|
||||
@@ -52,7 +47,7 @@ describe('data tag', () => {
|
||||
it('should throw if the data tag is used with something unrecognized', async () => {
|
||||
const page = await Page.init({
|
||||
relativePath: 'liquid-tags/bad-data-variable.md',
|
||||
basePath: path.join(__dirname, '../../fixtures'),
|
||||
basePath: './tests/fixtures',
|
||||
languageCode: 'en',
|
||||
})
|
||||
const context = {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import { execSync } from 'child_process'
|
||||
import scrape from 'website-scraper'
|
||||
import { program } from 'commander'
|
||||
import { rimraf } from 'rimraf'
|
||||
@@ -35,6 +34,7 @@ program
|
||||
'-o, --output <PATH>',
|
||||
`output directory to place scraped HTML files and redirects. By default, this temp directory is named 'tmpArchivalDir_<VERSION_TO_DEPRECATE>'`
|
||||
)
|
||||
.option('-l, --local-dev', 'Do not rewrite asset paths to enable testing scraped content locally')
|
||||
.option('-d, --dry-run', 'only scrape the first 10 pages for testing purposes')
|
||||
.option(
|
||||
'-p, --page <PATH>',
|
||||
@@ -45,6 +45,7 @@ program
|
||||
const output = program.opts().output
|
||||
const dryRun = program.opts().dryRun
|
||||
const singlePage = program.opts().page
|
||||
const localDev = program.opts().localDev
|
||||
const tmpArchivalDirectory = output
|
||||
? path.join(process.cwd(), output)
|
||||
: path.join(process.cwd(), `tmpArchivalDir_${version}`)
|
||||
@@ -67,19 +68,30 @@ class RewriteAssetPathsPlugin {
|
||||
|
||||
// Get the text contents of the resource
|
||||
const text = resource.getText()
|
||||
let newBody = ''
|
||||
let newBody = text
|
||||
|
||||
// Rewrite HTML asset paths. Example:
|
||||
// ../assets/images/foo/bar.png ->
|
||||
// https://githubdocs.azureedge.net/github-images/enterprise/2.17/assets/images/foo/bar.png
|
||||
|
||||
if (resource.isHtml()) {
|
||||
newBody = text.replace(
|
||||
/(?<attribute>src|href)="(?:\.\.\/|\/)*(?<basepath>_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g,
|
||||
(match, attribute, basepath) => {
|
||||
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
|
||||
return `${attribute}="${replaced}`
|
||||
}
|
||||
// Remove nextjs scripts and manifest.json link
|
||||
newBody = newBody.replace(
|
||||
/<script\ssrc="(\.\.\/)*_next\/static\/[\w]+\/(_buildManifest|_ssgManifest).js?".*?><\/script>/g,
|
||||
''
|
||||
)
|
||||
newBody = newBody.replace(/<link href=".*manifest.json".*?>/g, '')
|
||||
|
||||
if (!localDev) {
|
||||
// Rewrite asset paths
|
||||
newBody = newBody.replace(
|
||||
/(?<attribute>src|href)="(?:\.\.\/|\/)*(?<basepath>_next\/static|javascripts|stylesheets|assets\/fonts|assets\/cb-\d+\/images|node_modules)/g,
|
||||
(match, attribute, basepath) => {
|
||||
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
|
||||
return `${attribute}="${replaced}`
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite CSS asset paths. Example
|
||||
@@ -88,25 +100,25 @@ class RewriteAssetPathsPlugin {
|
||||
// url(../../../assets/cb-303/images/octicons/search-24.svg) ->
|
||||
// url(https://githubdocs.azureedge.net/github-images/enterprise/2.20/assets/cb-303/images/octicons/search-24.svg)
|
||||
if (resource.isCss()) {
|
||||
newBody = text.replace(
|
||||
/(?<attribute>url)(?<paren>\("|\()(?:\.\.\/)*(?<basepath>_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g,
|
||||
(match, attribute, paren, basepath) => {
|
||||
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
|
||||
return `${attribute}${paren}${replaced}`
|
||||
}
|
||||
)
|
||||
if (!localDev) {
|
||||
newBody = newBody.replace(
|
||||
/(?<attribute>url)(?<paren>\("|\()(?:\.\.\/)*(?<basepath>_next\/static|assets\/fonts|assets\/images|assets\/cb-\d+\/images)/g,
|
||||
(match, attribute, paren, basepath) => {
|
||||
const replaced = `${REMOTE_ENTERPRISE_STORAGE_URL}/${this.version}/${basepath}`
|
||||
return `${attribute}${paren}${replaced}`
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const filePath = path.join(this.tempDirectory, resource.getFilename())
|
||||
await fs.promises.writeFile(filePath, newBody, 'binary')
|
||||
await fs.promises.writeFile(filePath, newBody, resource.encoding)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// Build the production assets, to simulate a production deployment
|
||||
console.log('Running `npm run build` for production assets')
|
||||
execSync('npm run build', { stdio: 'inherit' })
|
||||
console.log('Finish building production assets')
|
||||
if (dryRun) {
|
||||
console.log(
|
||||
|
||||
Reference in New Issue
Block a user