docus 3.0.1-20250617-092222-935cbfe → 3.0.1-20250617-093112-f14f67b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/app/utils/git.ts +108 -0
- package/app/app/utils/meta.ts +29 -0
- package/app/modules/default-configs.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import { readGitConfig } from 'pkg-types'
|
|
3
|
+
import gitUrlParse from 'git-url-parse'
|
|
4
|
+
|
|
5
|
+
export interface GitInfo {
|
|
6
|
+
// Repository name
|
|
7
|
+
name: string
|
|
8
|
+
// Repository owner/organization
|
|
9
|
+
owner: string
|
|
10
|
+
// Repository URL
|
|
11
|
+
url: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getGitBranch() {
|
|
15
|
+
const envName
|
|
16
|
+
= process.env.CF_PAGES_BRANCH
|
|
17
|
+
|| process.env.CI_COMMIT_BRANCH
|
|
18
|
+
|| process.env.VERCEL_GIT_COMMIT_REF
|
|
19
|
+
|| process.env.BRANCH
|
|
20
|
+
|| process.env.GITHUB_REF_NAME
|
|
21
|
+
|
|
22
|
+
if (envName && envName !== 'HEAD') {
|
|
23
|
+
return envName
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
|
|
27
|
+
if (branch && branch !== 'HEAD') {
|
|
28
|
+
return branch
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return 'main'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function getLocalGitInfo(rootDir: string): Promise<GitInfo | undefined> {
|
|
37
|
+
const remote = await getLocalGitRemote(rootDir)
|
|
38
|
+
if (!remote) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// https://www.npmjs.com/package/git-url-parse#clipboard-example
|
|
43
|
+
const { name, owner, source } = gitUrlParse(remote)
|
|
44
|
+
const url = `https://${source}/${owner}/${name}`
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
owner,
|
|
49
|
+
url,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function getLocalGitRemote(dir: string): Promise<string | undefined> {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = await readGitConfig(dir)
|
|
56
|
+
if (!parsed) {
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
return parsed.remote?.['origin']?.url
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Ignore error
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getGitEnv(): GitInfo | undefined {
|
|
67
|
+
// https://github.com/unjs/std-env/issues/59
|
|
68
|
+
const envInfo = {
|
|
69
|
+
// Provider
|
|
70
|
+
provider: process.env.VERCEL_GIT_PROVIDER // vercel
|
|
71
|
+
|| (process.env.GITHUB_SERVER_URL ? 'github' : undefined) // github
|
|
72
|
+
|| '',
|
|
73
|
+
// Owner
|
|
74
|
+
owner: process.env.VERCEL_GIT_REPO_OWNER // vercel
|
|
75
|
+
|| process.env.GITHUB_REPOSITORY_OWNER // github
|
|
76
|
+
|| process.env.CI_PROJECT_PATH?.split('/').shift() // gitlab
|
|
77
|
+
|| '',
|
|
78
|
+
// Name
|
|
79
|
+
name: process.env.VERCEL_GIT_REPO_SLUG
|
|
80
|
+
|| process.env.GITHUB_REPOSITORY?.split('/').pop() // github
|
|
81
|
+
|| process.env.CI_PROJECT_PATH?.split('/').splice(1).join('/') // gitlab
|
|
82
|
+
|| '',
|
|
83
|
+
// Url
|
|
84
|
+
url: process.env.REPOSITORY_URL || '', // netlify
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!envInfo.url && envInfo.provider && envInfo.owner && envInfo.name) {
|
|
88
|
+
envInfo.url = `https://${envInfo.provider}.com/${envInfo.owner}/${envInfo.name}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// If only url available (ex: Netlify)
|
|
92
|
+
if (!envInfo.name && !envInfo.owner && envInfo.url) {
|
|
93
|
+
try {
|
|
94
|
+
const { name, owner } = gitUrlParse(envInfo.url)
|
|
95
|
+
envInfo.name = name
|
|
96
|
+
envInfo.owner = owner
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Ignore error
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
name: envInfo.name,
|
|
105
|
+
owner: envInfo.owner,
|
|
106
|
+
url: envInfo.url,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export function inferSiteURL() {
|
|
5
|
+
// https://github.com/unjs/std-env/issues/59
|
|
6
|
+
return (
|
|
7
|
+
process.env.NUXT_SITE_URL
|
|
8
|
+
|| (process.env.NEXT_PUBLIC_VERCEL_URL && `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`) // Vercel
|
|
9
|
+
|| process.env.URL // Netlify
|
|
10
|
+
|| process.env.CI_PAGES_URL // Gitlab Pages
|
|
11
|
+
|| process.env.CF_PAGES_URL // Cloudflare Pages
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function getPackageJsonMetadata(dir: string) {
|
|
16
|
+
try {
|
|
17
|
+
const packageJson = await readFile(resolve(dir, 'package.json'), 'utf-8')
|
|
18
|
+
const parsed = JSON.parse(packageJson)
|
|
19
|
+
return {
|
|
20
|
+
name: parsed.name,
|
|
21
|
+
description: parsed.description,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return {
|
|
26
|
+
name: 'docs',
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineNuxtModule } from 'nuxt/kit'
|
|
2
2
|
import { defu } from 'defu'
|
|
3
|
-
import { inferSiteURL, getPackageJsonMetadata } from '
|
|
4
|
-
import { getGitBranch, getGitEnv, getLocalGitInfo } from '
|
|
3
|
+
import { inferSiteURL, getPackageJsonMetadata } from '../app/utils/meta'
|
|
4
|
+
import { getGitBranch, getGitEnv, getLocalGitInfo } from '../app/utils/git'
|
|
5
5
|
|
|
6
6
|
export default defineNuxtModule({
|
|
7
7
|
meta: {
|