diff --git a/bin/mvb.js b/bin/mvb.js index 7cbe97c6..e7dd3f28 100755 --- a/bin/mvb.js +++ b/bin/mvb.js @@ -1,5 +1,6 @@ #!/usr/bin/env node import crypto from 'node:crypto'; +import os from 'node:os'; import path from 'node:path'; import {format, inspect} from 'node:util'; @@ -19,10 +20,6 @@ import Debug from 'debug'; // debugger const debug = Debug('@lando/mvb'); // eslint-disable-line -// helper to get remote git clone url -const getCloneUrl = () => getStdOut('git config --get remote.origin.url', {trim: true}); -// env -const onNetlify = process.env?.NETLIFY === 'true'; // enable debug if applicable if (process.argv.includes('--debug') || process.env.RUNNER_DEBUG === '1') { @@ -89,21 +86,17 @@ debug('received argv %o', argv); debug('default options %o', defaults); log('found site %s at %s', magenta(site.title), magenta(osource)); -// determine cachebase -const cacheBase = onNetlify ? '/opt/build/cache' : siteConfig.cacheDir; - // resolve options with argv input const options = { ...defaults, ...argv, - cacheDir: path.resolve(cacheBase, '@lando', 'mvb'), - tmpDir: path.resolve(siteConfig.tempDir, nanoid()), + cacheDir: path.resolve(process.env?.NETLIFY === 'true' ? '/opt/build/cache' : siteConfig.cacheDir, '@lando', 'mvb'), + tmpDir: path.resolve(os.tmpdir(), nanoid()), }; debug('multiversion build from %o using resolved build options: %O', srcDir, options); // determine gitdir -// @TODO: throw error if no git dir? -const gitDir = traverseUp(['.git'], osource).find(dir => fs.existsSync(dir)); +const gitDir = path.resolve(traverseUp(['.git'], osource).find(dir => fs.existsSync(dir)), '..'); debug('determined git-dir: %o', gitDir); // do the initial setup @@ -115,32 +108,19 @@ const oexec = createExec({cwd: process.cwd(), debug}); const exec = createExec({cwd: options.tmpDir, debug}); // start it up -log('collecting version information from %s...', magenta(gitDir)); +log('setting up mvb build environment using %s...', magenta(gitDir)); // lets make sure the source repo at least has all the tag information it needs const updateArgs = ['fetch', 'origin', '--tags', '--no-filter']; // if shallow then add to update refs if (getStdOut('git rev-parse --is-shallow-repository', {trim: true}) === 'true') updateArgs.push('--unshallow'); -// update all refs +// update original await oexec('git', updateArgs); +// checkout branch +await oexec('git', ['checkout', getBranch()]); -await oexec('git', ['status']); -console.log(getStdOut('git rev-parse --abbrev-ref HEAD', {trim: true})); -await oexec('git', ['diff']); - -// if we are in detached head state then checkout best branch -if (getStdOut('git rev-parse --abbrev-ref HEAD', {trim: true}) === 'HEAD') await oexec('git', ['checkout', getBranch()]); - -process.exit(1) - -// build clone args -const cloneArgs = ['clone', '--origin', 'origin', '--no-single-branch']; -// netlicf clone -if (onNetlify) cloneArgs.push('--depth', '2147483647', '--branch', getBranch(), getCloneUrl(), './'); -// generic clone -else cloneArgs.push('--no-local', '--no-hardlinks', gitDir, './'); -// do the vampire -await exec('git', cloneArgs); +// and then copy the repo in tmpdir so we can operate on it +fs.copySync(gitDir, options.tmpDir); // get extended version information const {extended} = await getTags(options.tmpDir, options); diff --git a/components/VPLLink.vue b/components/VPLLink.vue index db4a6d30..472f20df 100644 --- a/components/VPLLink.vue +++ b/components/VPLLink.vue @@ -4,12 +4,13 @@ class="VPLink" :class="{ link: href, + 'lando': true, 'vp-external-link-icon': isExternal, 'no-icon': noIcon }" - :href="href ? normalizeLink(href) : undefined" + :href="link" :target="target ?? (isExternal ? '_blank' : isFauxInternal ? '_self' : undefined)" - :rel="rel ?? (isExternal ? 'noreferrer' : undefined)" + :rel="relation ?? (isExternal ? 'noreferrer' : undefined)" > @@ -26,6 +27,10 @@ const {theme} = useData(); const {internalDomains} = theme.value; const props = defineProps({ + absolute: { + type: Boolean, + default: false, + }, tag: { type: String, default: undefined, @@ -48,13 +53,14 @@ const props = defineProps({ }, }); +const relation = computed(() => props.rel === 'mvb' ? 'alternate' : props.rel); const tag = computed(() => props.tag ?? (props.href ? 'a' : 'span')); -const isFauxInternal = computed(() => { - return props.href && internalDomains.find(domain => props.href.startsWith(domain)) !== undefined; -}); - +const isFauxInternal = computed(() => props.href && internalDomains.find(domain => props.href.startsWith(domain)) !== undefined); const isExternal = computed(() => !isFauxInternal.value && props.href && EXTERNAL_URL_RE.test(props.href)); - - +const link = computed(() => { + if (props.rel === 'mvb' && props.href) return props.href; + return props.href ? normalizeLink(props.href) : undefined; +}); + diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index 6426066d..aca924ee 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -19,9 +19,9 @@ const sidebarEnder = { { text: 'Other Doc Versions', items: [ - {text: 'stable', target: '_blank', link: '/v/stable/'}, - {text: 'edge', target: '_blank', link: '/v/edge/'}, - {text: 'see all versions', link: '/v/'}, + {rel: 'mvb', text: 'stable', target: '_blank', link: '/v/stable/'}, + {rel: 'mvb', text: 'edge', target: '_blank', link: '/v/edge/'}, + {rel: 'mvb', text: 'see all versions', link: '/v/'}, ], }, {text: 'Other Releases', link: 'https://github.com/lando/vitepress-theme-default-plus/releases'}, diff --git a/netlify.toml b/netlify.toml index fc3b7c9c..12f77ad0 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,7 @@ [build] base = "./" publish = "docs/.vitepress/dist/" - command = "npx mvb docs --no-cache --debug" + command = "npx mvb docs --no-cache" # Sets our asset optimization [build.processing.css] diff --git a/utils/get-tags.js b/utils/get-tags.js index 244cc2d3..3cc2d82f 100644 --- a/utils/get-tags.js +++ b/utils/get-tags.js @@ -38,7 +38,7 @@ export default function async( if (versions.length > 0) { aliases.edge = versions[0]; aliases.stable = versions.filter(version => semver.prerelease(version) === null)[0]; - aliases.dev = getStdOut(`git describe --tags --always --abbrev=1 --match="${match}" ${getBranch(cwd)}`, {trim: true}); + aliases.dev = getStdOut(`git describe --tags --always --abbrev=1 --match="${match}" ${getBranch(cwd)}`, opts); } debug('generated aliases %o', aliases);