Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awe here we go again with this bullshit #52

Merged
merged 15 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions bin/mvb.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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') {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions components/VPLLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
>
<slot />
</component>
Expand All @@ -26,6 +27,10 @@ const {theme} = useData();
const {internalDomains} = theme.value;

const props = defineProps({
absolute: {
type: Boolean,
default: false,
},
tag: {
type: String,
default: undefined,
Expand All @@ -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));
</script>


const link = computed(() => {
if (props.rel === 'mvb' && props.href) return props.href;
return props.href ? normalizeLink(props.href) : undefined;
});
</script>
6 changes: 3 additions & 3 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<strong>see all versions</strong>', link: '/v/'},
{rel: 'mvb', text: 'stable', target: '_blank', link: '/v/stable/'},
{rel: 'mvb', text: 'edge', target: '_blank', link: '/v/edge/'},
{rel: 'mvb', text: '<strong>see all versions</strong>', link: '/v/'},
],
},
{text: 'Other Releases', link: 'https://github.com/lando/vitepress-theme-default-plus/releases'},
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion utils/get-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading