mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
refactor(build): improve building (#7048)
* fix: fetching contributors * refactor(build): improve building * fix: building * refactor: build constants * fix: lockfile * ci: remove token * ci: rename * refactor: improve docs constant
This commit is contained in:
parent
166acb23e3
commit
6a290ff85a
2
.github/workflows/pr-docs-start.yml
vendored
2
.github/workflows/pr-docs-start.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Preview Start
|
||||
name: PR Docs Start
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
|
@ -48,11 +48,15 @@ jobs:
|
||||
- name: Install latest Element Plus
|
||||
run: cd docs && pnpm i element-plus@latest
|
||||
|
||||
- name: Build Metadata
|
||||
run: cd internal/metadata && pnpm build
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build website
|
||||
run: pnpm docs:build
|
||||
env:
|
||||
DOC_ENV: production
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@v4.2.5
|
||||
|
6
.github/workflows/publish-docs-deploy.yml
vendored
6
.github/workflows/publish-docs-deploy.yml
vendored
@ -55,11 +55,15 @@ jobs:
|
||||
- name: Install latest Element Plus
|
||||
run: cd docs && pnpm i element-plus@latest
|
||||
|
||||
- name: Build Metadata
|
||||
run: cd internal/metadata && pnpm build
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build website
|
||||
run: pnpm docs:build
|
||||
env:
|
||||
DOC_ENV: production
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Deploy
|
||||
uses: JamesIves/github-pages-deploy-action@v4.2.5
|
||||
|
6
.github/workflows/staging-docs.yml
vendored
6
.github/workflows/staging-docs.yml
vendored
@ -56,12 +56,16 @@ jobs:
|
||||
- name: Generate common locale
|
||||
run: pnpm docs:gen-locale
|
||||
|
||||
- name: Build Metadata
|
||||
run: cd internal/metadata && pnpm build
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build website
|
||||
run: pnpm docs:build
|
||||
env:
|
||||
DOC_ENV: staging
|
||||
NODE_OPTIONS: --max-old-space-size=4096
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Deploy staging website
|
||||
uses: JamesIves/github-pages-deploy-action@v4.2.5
|
||||
|
@ -1,11 +1,12 @@
|
||||
import consola from 'consola'
|
||||
import { REPO_BRANCH, REPO_PATH } from '@element-plus/build-constants'
|
||||
import { docsDirName } from '@element-plus/build'
|
||||
import { languages } from './utils/lang'
|
||||
import { head } from './config/head'
|
||||
import { sidebars } from './config/sidebars'
|
||||
import { nav } from './config/nav'
|
||||
import { mdPlugin } from './config/plugins'
|
||||
import { features } from './config/features'
|
||||
import { branch, docsDir, repo } from './vitepress/constant'
|
||||
import type { UserConfig } from 'vitepress'
|
||||
|
||||
const buildTransformers = () => {
|
||||
@ -50,9 +51,9 @@ export const config: UserConfig = {
|
||||
lastUpdated: true,
|
||||
head,
|
||||
themeConfig: {
|
||||
repo,
|
||||
branch,
|
||||
docsDir,
|
||||
repo: REPO_PATH,
|
||||
docsBranch: REPO_BRANCH,
|
||||
docsDir: docsDirName,
|
||||
|
||||
editLinks: true,
|
||||
editLinkText: 'Edit this page on GitHub',
|
||||
|
@ -1,7 +1,7 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { docRoot, projRoot } from '@element-plus/build'
|
||||
import { branch, docsDir, repo } from '../vitepress/constant'
|
||||
import { docRoot, docsDirName, projRoot } from '@element-plus/build'
|
||||
import { REPO_BRANCH, REPO_PATH } from '@element-plus/build-constants'
|
||||
import { getLang } from '../utils/lang'
|
||||
import footerLocale from '../i18n/component/footer.json'
|
||||
import type { Plugin } from 'vite'
|
||||
@ -73,8 +73,8 @@ const transformVpScriptSetup = (code: string, append: Append) => {
|
||||
return code
|
||||
}
|
||||
|
||||
const GITHUB_BLOB_URL = `https://github.com/${repo}/blob/${branch}`
|
||||
const GITHUB_TREE_URL = `https://github.com/${repo}/tree/${branch}`
|
||||
const GITHUB_BLOB_URL = `https://github.com/${REPO_PATH}/blob/${REPO_BRANCH}`
|
||||
const GITHUB_TREE_URL = `https://github.com/${REPO_PATH}/tree/${REPO_BRANCH}`
|
||||
const transformComponentMarkdown = (
|
||||
id: string,
|
||||
componentId: string,
|
||||
@ -82,7 +82,7 @@ const transformComponentMarkdown = (
|
||||
append: Append
|
||||
) => {
|
||||
const lang = getLang(id)
|
||||
const docUrl = `${GITHUB_BLOB_URL}/${docsDir}/en-US/component/${componentId}.md`
|
||||
const docUrl = `${GITHUB_BLOB_URL}/${docsDirName}/en-US/component/${componentId}.md`
|
||||
const componentUrl = `${GITHUB_TREE_URL}/packages/components/${componentId}`
|
||||
const componentPath = path.resolve(
|
||||
projRoot,
|
||||
|
@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
// @ts-expect-error missing types
|
||||
import _contributors from '/virtual-contributors'
|
||||
import _contributors from '@element-plus/metadata/dist/contributors.json'
|
||||
import VpLink from '../common/vp-link.vue'
|
||||
|
||||
const props = defineProps<{ id: string }>()
|
||||
|
@ -9,9 +9,3 @@ export const breakpoints = {
|
||||
xlg: 1280,
|
||||
xxl: 1440,
|
||||
}
|
||||
|
||||
export const owner = 'element-plus'
|
||||
export const repoName = 'element-plus'
|
||||
export const repo = 'element-plus/element-plus'
|
||||
export const branch = 'dev'
|
||||
export const docsDir = 'docs'
|
||||
|
@ -11,6 +11,7 @@
|
||||
"dependencies": {
|
||||
"@docsearch/js": "^3.0.0",
|
||||
"@docsearch/react": "^3.0.0",
|
||||
"@element-plus/metadata": "latest",
|
||||
"@vueuse/core": "^8.2.4",
|
||||
"axios": "^0.26.1",
|
||||
"clipboard-copy": "^4.0.1",
|
||||
@ -22,6 +23,7 @@
|
||||
"devDependencies": {
|
||||
"@crowdin/cli": "^3.7.8",
|
||||
"@element-plus/build": "workspace:*",
|
||||
"@element-plus/build-constants": "workspace:*",
|
||||
"@iconify-json/ri": "^1.1.1",
|
||||
"@types/markdown-it": "^12.2.3",
|
||||
"cross-env": "^7.0.3",
|
||||
|
@ -14,7 +14,6 @@ import {
|
||||
getPackageDependencies,
|
||||
projRoot,
|
||||
} from '@element-plus/build'
|
||||
import { Contributors } from './.vitepress/plugins/contributors'
|
||||
import { MarkdownTransform } from './.vitepress/plugins/markdown-transform'
|
||||
import type { Alias } from 'vite'
|
||||
|
||||
@ -46,12 +45,10 @@ export default defineConfig(async ({ mode }) => {
|
||||
...dependencies,
|
||||
]
|
||||
optimizeDeps.push(
|
||||
...(
|
||||
await glob(['dayjs/plugin/*.js'], {
|
||||
cwd: path.resolve(projRoot, 'node_modules'),
|
||||
onlyFiles: true,
|
||||
})
|
||||
).map((file) => file.replace(/\.js$/, ''))
|
||||
...(await glob(['dayjs/plugin/*.js'], {
|
||||
cwd: path.resolve(projRoot, 'node_modules'),
|
||||
onlyFiles: true,
|
||||
}))
|
||||
)
|
||||
|
||||
return {
|
||||
@ -85,7 +82,6 @@ export default defineConfig(async ({ mode }) => {
|
||||
}),
|
||||
UnoCSS(),
|
||||
MarkdownTransform(),
|
||||
await Contributors(),
|
||||
Inspect(),
|
||||
mkcert(),
|
||||
],
|
||||
|
10
internal/build-constants/build.config.ts
Normal file
10
internal/build-constants/build.config.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { defineBuildConfig } from 'unbuild'
|
||||
|
||||
export default defineBuildConfig({
|
||||
entries: ['src/index'],
|
||||
clean: true,
|
||||
declaration: true,
|
||||
rollup: {
|
||||
emitCJS: true,
|
||||
},
|
||||
})
|
20
internal/build-constants/package.json
Normal file
20
internal/build-constants/package.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "@element-plus/build-constants",
|
||||
"version": "0.0.1",
|
||||
"description": "Build constants for Element Plus",
|
||||
"keywords": [
|
||||
"element-plus"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "pnpm run stub",
|
||||
"stub": "unbuild --stub"
|
||||
},
|
||||
"devDependencies": {
|
||||
"unbuild": "^0.7.2"
|
||||
}
|
||||
}
|
2
internal/build-constants/src/index.ts
Normal file
2
internal/build-constants/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './pkg'
|
||||
export * from './repo'
|
3
internal/build-constants/src/pkg.ts
Normal file
3
internal/build-constants/src/pkg.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const PKG_PREFIX = '@element-plus'
|
||||
export const PKG_NAME = 'element-plus'
|
||||
export const PKG_BRAND_NAME = 'Element Plus'
|
4
internal/build-constants/src/repo.ts
Normal file
4
internal/build-constants/src/repo.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export const REPO_OWNER = 'element-plus'
|
||||
export const REPO_NAME = 'element-plus'
|
||||
export const REPO_PATH = `${REPO_OWNER}/${REPO_NAME}`
|
||||
export const REPO_BRANCH = 'dev'
|
10
internal/build-utils/build.config.ts
Normal file
10
internal/build-utils/build.config.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { defineBuildConfig } from 'unbuild'
|
||||
|
||||
export default defineBuildConfig({
|
||||
entries: ['src/index'],
|
||||
clean: true,
|
||||
declaration: true,
|
||||
rollup: {
|
||||
emitCJS: true,
|
||||
},
|
||||
})
|
21
internal/build-utils/package.json
Normal file
21
internal/build-utils/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@element-plus/build-utils",
|
||||
"version": "0.0.1",
|
||||
"description": "Build utils for Element Plus",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
"element-plus"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.cjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "pnpm run stub",
|
||||
"stub": "unbuild --stub"
|
||||
},
|
||||
"devDependencies": {
|
||||
"unbuild": "^0.7.2"
|
||||
}
|
||||
}
|
9
internal/build-utils/src/fs.ts
Normal file
9
internal/build-utils/src/fs.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { existsSync } from 'fs'
|
||||
import { mkdir, writeFile } from 'fs/promises'
|
||||
|
||||
export const writeJson = (path: string, data: any, spaces = 0) =>
|
||||
writeFile(path, JSON.stringify(data, undefined, spaces), 'utf-8')
|
||||
|
||||
export const ensureDir = async (path: string) => {
|
||||
if (!existsSync(path)) await mkdir(path, { recursive: true })
|
||||
}
|
1
internal/build-utils/src/index.ts
Normal file
1
internal/build-utils/src/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './fs'
|
@ -12,6 +12,7 @@
|
||||
"stub": "unbuild --stub"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/build-constants": "^0.0.1",
|
||||
"@pnpm/find-workspace-packages": "^4.0.0",
|
||||
"@rollup/plugin-commonjs": "^21.0.3",
|
||||
"@rollup/plugin-node-resolve": "^13.1.3",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import path from 'path'
|
||||
import { PKG_NAME } from '@element-plus/build-constants'
|
||||
import { epOutput } from './utils'
|
||||
import { EP_PKG } from './constants'
|
||||
import type { ModuleFormat } from 'rollup'
|
||||
|
||||
export const modules = ['esm', 'cjs'] as const
|
||||
@ -32,7 +32,7 @@ export const buildConfig: Record<Module, BuildInfo> = {
|
||||
path: path.resolve(epOutput, 'es'),
|
||||
},
|
||||
bundle: {
|
||||
path: `${EP_PKG}/es`,
|
||||
path: `${PKG_NAME}/es`,
|
||||
},
|
||||
},
|
||||
cjs: {
|
||||
@ -44,7 +44,7 @@ export const buildConfig: Record<Module, BuildInfo> = {
|
||||
path: path.resolve(epOutput, 'lib'),
|
||||
},
|
||||
bundle: {
|
||||
path: `${EP_PKG}/lib`,
|
||||
path: `${PKG_NAME}/lib`,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
export const EP_PREFIX = '@element-plus'
|
||||
export const EP_PKG = 'element-plus'
|
||||
export const EP_BRAND_NAME = 'Element Plus'
|
@ -1,5 +1,4 @@
|
||||
export * from './tasks'
|
||||
export * from './utils'
|
||||
export * from './build-info'
|
||||
export * from './constants'
|
||||
export { default as typeSafe } from './type-safe.json'
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { EP_PKG, EP_PREFIX } from '../constants'
|
||||
import { PKG_NAME, PKG_PREFIX } from '@element-plus/build-constants'
|
||||
|
||||
import type { Plugin } from 'rollup'
|
||||
|
||||
export function ElementPlusAlias(): Plugin {
|
||||
const themeChalk = 'theme-chalk'
|
||||
const sourceThemeChalk = `${EP_PREFIX}/${themeChalk}` as const
|
||||
const bundleThemeChalk = `${EP_PKG}/${themeChalk}` as const
|
||||
const sourceThemeChalk = `${PKG_PREFIX}/${themeChalk}` as const
|
||||
const bundleThemeChalk = `${PKG_NAME}/${themeChalk}` as const
|
||||
|
||||
return {
|
||||
name: 'element-plus-alias-plugin',
|
||||
|
@ -9,6 +9,7 @@ import esbuild from 'rollup-plugin-esbuild'
|
||||
import { parallel } from 'gulp'
|
||||
import glob from 'fast-glob'
|
||||
import { camelCase, upperFirst } from 'lodash'
|
||||
import { PKG_BRAND_NAME } from '@element-plus/build-constants'
|
||||
import { version } from '../../../../packages/element-plus/version'
|
||||
import { ElementPlusAlias } from '../plugins/element-plus-alias'
|
||||
import {
|
||||
@ -20,10 +21,9 @@ import {
|
||||
withTaskName,
|
||||
writeBundles,
|
||||
} from '../utils'
|
||||
import { EP_BRAND_NAME } from '../constants'
|
||||
import { target } from '../build-info'
|
||||
|
||||
const banner = `/*! ${EP_BRAND_NAME} v${version} */\n`
|
||||
const banner = `/*! ${PKG_BRAND_NAME} v${version} */\n`
|
||||
|
||||
async function buildFullEntry(minify: boolean) {
|
||||
const bundle = await rollup({
|
||||
|
@ -12,7 +12,8 @@ export const utilRoot = resolve(pkgRoot, 'utils')
|
||||
export const buildRoot = resolve(projRoot, 'internal', 'build')
|
||||
|
||||
// Docs
|
||||
export const docRoot = resolve(projRoot, 'docs')
|
||||
export const docsDirName = 'docs'
|
||||
export const docRoot = resolve(projRoot, docsDirName)
|
||||
export const vpRoot = resolve(docRoot, '.vitepress')
|
||||
|
||||
/** `/dist` */
|
||||
|
@ -1,6 +1,6 @@
|
||||
import findWorkspacePackages from '@pnpm/find-workspace-packages'
|
||||
import { PKG_PREFIX } from '@element-plus/build-constants'
|
||||
import { buildConfig } from '../build-info'
|
||||
import { EP_PREFIX } from '../constants'
|
||||
import { projRoot } from './paths'
|
||||
|
||||
import type { Module } from '../build-info'
|
||||
@ -37,8 +37,8 @@ export const pathRewriter = (module: Module) => {
|
||||
const config = buildConfig[module]
|
||||
|
||||
return (id: string) => {
|
||||
id = id.replaceAll(`${EP_PREFIX}/theme-chalk`, 'element-plus/theme-chalk')
|
||||
id = id.replaceAll(`${EP_PREFIX}/`, `${config.bundle.path}/`)
|
||||
id = id.replaceAll(`${PKG_PREFIX}/theme-chalk`, 'element-plus/theme-chalk')
|
||||
id = id.replaceAll(`${PKG_PREFIX}/`, `${config.bundle.path}/`)
|
||||
return id
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
"index.js"
|
||||
],
|
||||
"main": "index.js",
|
||||
"scripts": {},
|
||||
"private": true,
|
||||
"peerDependencies": {
|
||||
"eslint": "^8.0.0"
|
||||
},
|
||||
|
32
internal/metadata/package.json
Normal file
32
internal/metadata/package.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@element-plus/metadata",
|
||||
"version": "0.0.1",
|
||||
"description": "Metadata for Element Plus",
|
||||
"keywords": [
|
||||
"element-plus"
|
||||
],
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "concurrently \"pnpm run build:contributor\" \"pnpm run build:components\"",
|
||||
"build:contributor": "esno src/contributor.ts",
|
||||
"build:components": "esno src/components.ts",
|
||||
"dev": "cross-env DEV=1 pnpm run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@element-plus/build": "^0.0.1",
|
||||
"@element-plus/build-constants": "^0.0.1",
|
||||
"@element-plus/build-utils": "^0.0.1",
|
||||
"@types/lodash-es": "^4.17.6",
|
||||
"concurrently": "^7.1.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"esno": "^0.14.1",
|
||||
"fast-glob": "^3.2.11",
|
||||
"lodash-es": "^4.17.21"
|
||||
}
|
||||
}
|
22
internal/metadata/src/components.ts
Normal file
22
internal/metadata/src/components.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import path from 'path'
|
||||
import glob from 'fast-glob'
|
||||
import chalk from 'chalk'
|
||||
import consola from 'consola'
|
||||
import { projRoot } from '@element-plus/build'
|
||||
import { ensureDir, writeJson } from '@element-plus/build-utils'
|
||||
|
||||
const pathOutput = path.resolve(__dirname, '..', 'dist')
|
||||
|
||||
async function main() {
|
||||
await ensureDir(pathOutput)
|
||||
|
||||
const components = await glob('*', {
|
||||
cwd: path.resolve(projRoot, 'packages/components'),
|
||||
onlyDirectories: true,
|
||||
})
|
||||
|
||||
await writeJson(path.resolve(pathOutput, 'components.json'), components)
|
||||
consola.success(chalk.green('Component list generated'))
|
||||
}
|
||||
|
||||
main()
|
@ -1,11 +1,20 @@
|
||||
import path from 'path'
|
||||
import { existsSync } from 'fs'
|
||||
import glob from 'fast-glob'
|
||||
import { Octokit } from 'octokit'
|
||||
import { projRoot } from '@element-plus/build'
|
||||
import { branch, owner, repoName } from '../vitepress/constant'
|
||||
import type { Plugin } from 'vite'
|
||||
import consola from 'consola'
|
||||
import chalk from 'chalk'
|
||||
import { chunk, mapValues } from 'lodash-es'
|
||||
import { errorAndExit, projRoot } from '@element-plus/build'
|
||||
import {
|
||||
REPO_BRANCH,
|
||||
REPO_NAME,
|
||||
REPO_OWNER,
|
||||
} from '@element-plus/build-constants'
|
||||
import { ensureDir, writeJson } from '@element-plus/build-utils'
|
||||
|
||||
interface FetchOption {
|
||||
key: string
|
||||
path: string
|
||||
after?: string
|
||||
}
|
||||
@ -42,16 +51,12 @@ interface ContributorInfo {
|
||||
count: number
|
||||
}
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
})
|
||||
|
||||
const fetchContributors = async (
|
||||
const fetchCommits = async (
|
||||
options: FetchOption[]
|
||||
): Promise<Record<string, ApiResult>> => {
|
||||
const query = `{
|
||||
repository(owner: "${owner}", name: "${repoName}") {
|
||||
object(expression: "${branch}") {
|
||||
repository(owner: "${REPO_OWNER}", name: "${REPO_NAME}") {
|
||||
object(expression: "${REPO_BRANCH}") {
|
||||
... on Commit {
|
||||
${options
|
||||
.map(({ path, after }, index) => {
|
||||
@ -110,16 +115,23 @@ const calcContributors = (commits: ApiResult['nodes']) => {
|
||||
return Object.values(contributors).sort((a, b) => b.count - a.count)
|
||||
}
|
||||
|
||||
const getContributorsAt = async (componentName: string) => {
|
||||
let options: FetchOption[] = [
|
||||
{ path: `packages/components/${componentName}` },
|
||||
{ path: `packages/theme-chalk/src/${componentName}.scss` },
|
||||
{ path: `docs/examples/${componentName}` },
|
||||
{ path: `docs/en-US/component/${componentName}.md` },
|
||||
]
|
||||
const commits: ApiResult['nodes'] = []
|
||||
const getContributorsByComponents = async (components: string[]) => {
|
||||
let options: FetchOption[] = components.flatMap((component) => [
|
||||
{ key: component, path: `packages/components/${component}` },
|
||||
{ key: component, path: `packages/theme-chalk/src/${component}.scss` },
|
||||
{ key: component, path: `docs/examples/${component}` },
|
||||
{ key: component, path: `docs/en-US/component/${component}.md` },
|
||||
])
|
||||
const commits: Record<string /* component name */, ApiResult['nodes']> = {}
|
||||
do {
|
||||
const results = await fetchContributors(options)
|
||||
const results = await fetchCommits(options)
|
||||
|
||||
for (const [i, result] of Object.values(results).entries()) {
|
||||
const component = options[i].key
|
||||
if (!commits[component]) commits[component] = []
|
||||
commits[component].push(...result.nodes)
|
||||
}
|
||||
|
||||
options = options
|
||||
.map((option, index) => {
|
||||
const pageInfo = results[index].pageInfo
|
||||
@ -127,43 +139,55 @@ const getContributorsAt = async (componentName: string) => {
|
||||
return { ...option, after }
|
||||
})
|
||||
.filter((option) => !!option.after)
|
||||
commits.push(...Object.values(results).flatMap((result) => result.nodes))
|
||||
} while (options.length > 0)
|
||||
|
||||
return calcContributors(commits)
|
||||
return mapValues(commits, (commits) => calcContributors(commits))
|
||||
}
|
||||
|
||||
export async function getContributors() {
|
||||
if (!process.env.GITHUB_TOKEN) return {}
|
||||
async function getContributors() {
|
||||
if (!process.env.GITHUB_TOKEN) throw new Error('GITHUB_TOKEN is empty')
|
||||
|
||||
const components = await glob('*', {
|
||||
cwd: path.resolve(projRoot, 'packages/components'),
|
||||
onlyDirectories: true,
|
||||
})
|
||||
const contributors = Object.fromEntries(
|
||||
await Promise.all(
|
||||
components.map((component) =>
|
||||
getContributorsAt(component).then((contributors) => [
|
||||
component,
|
||||
contributors,
|
||||
])
|
||||
)
|
||||
let contributors: Record<string, ContributorInfo[]> = {}
|
||||
|
||||
consola.info('Fetching contributors...')
|
||||
for (const chunkComponents of chunk(components, 10)) {
|
||||
contributors = {
|
||||
...contributors,
|
||||
...(await getContributorsByComponents(chunkComponents)),
|
||||
}
|
||||
consola.success(
|
||||
chalk.green(`Fetched contributors: ${chunkComponents.join(', ')}`)
|
||||
)
|
||||
)
|
||||
}
|
||||
return contributors
|
||||
}
|
||||
|
||||
const ID = '/virtual-contributors'
|
||||
const pathOutput = path.resolve(__dirname, '..', 'dist')
|
||||
const pathDest = path.resolve(pathOutput, 'contributors.json')
|
||||
|
||||
export async function Contributors(): Promise<Plugin> {
|
||||
const data = await getContributors()
|
||||
return {
|
||||
name: 'element-plus-contributors',
|
||||
resolveId(id) {
|
||||
return id === ID ? ID : null
|
||||
},
|
||||
load(id) {
|
||||
if (id !== ID) return null
|
||||
return `export default ${JSON.stringify(data)}`
|
||||
},
|
||||
const octokit = new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
})
|
||||
|
||||
async function main() {
|
||||
await ensureDir(pathOutput)
|
||||
|
||||
let contributors: Record<string, ContributorInfo[]>
|
||||
if (process.env.DEV) {
|
||||
if (existsSync(pathDest)) return
|
||||
contributors = {}
|
||||
} else {
|
||||
contributors = await getContributors().catch((err) => {
|
||||
errorAndExit(err)
|
||||
})
|
||||
}
|
||||
|
||||
await writeJson(pathDest, contributors)
|
||||
consola.success(chalk.green('Contributors generated'))
|
||||
}
|
||||
|
||||
main()
|
@ -34,9 +34,9 @@
|
||||
"docs:serve": "pnpm run -C docs serve",
|
||||
"docs:gen-locale": "pnpm run -C docs gen-locale",
|
||||
"docs:crowdin-credentials": "pnpm run -C docs crowdin-credentials",
|
||||
"stub": "pnpm run -C internal/build stub",
|
||||
"stub": "pnpm run -r --parallel stub",
|
||||
"prepare": "husky install",
|
||||
"postinstall": "pnpm gen:version && pnpm stub",
|
||||
"postinstall": "concurrently \"pnpm gen:version\" \"pnpm stub\" && pnpm run -C internal/metadata dev",
|
||||
"preinstall": "npx only-allow pnpm -y"
|
||||
},
|
||||
"config": {
|
||||
@ -105,6 +105,7 @@
|
||||
"babel-jest": "^26.6.3",
|
||||
"c8": "^7.11.0",
|
||||
"chalk": "^4.1.2",
|
||||
"concurrently": "^7.1.0",
|
||||
"consola": "^2.15.3",
|
||||
"csstype": "^2.6.20",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
|
118
pnpm-lock.yaml
118
pnpm-lock.yaml
@ -47,6 +47,7 @@ importers:
|
||||
babel-jest: ^26.6.3
|
||||
c8: ^7.11.0
|
||||
chalk: ^4.1.2
|
||||
concurrently: ^7.1.0
|
||||
consola: ^2.15.3
|
||||
csstype: ^2.6.20
|
||||
cz-conventional-changelog: ^3.3.0
|
||||
@ -131,6 +132,7 @@ importers:
|
||||
babel-jest: 26.6.3_@babel+core@7.17.8
|
||||
c8: 7.11.0
|
||||
chalk: 4.1.2
|
||||
concurrently: 7.1.0
|
||||
consola: 2.15.3
|
||||
csstype: 2.6.20
|
||||
cz-conventional-changelog: 3.3.0
|
||||
@ -166,6 +168,8 @@ importers:
|
||||
'@docsearch/js': ^3.0.0
|
||||
'@docsearch/react': ^3.0.0
|
||||
'@element-plus/build': workspace:*
|
||||
'@element-plus/build-constants': workspace:*
|
||||
'@element-plus/metadata': latest
|
||||
'@iconify-json/ri': ^1.1.1
|
||||
'@types/markdown-it': ^12.2.3
|
||||
'@vueuse/core': ^8.2.4
|
||||
@ -189,6 +193,7 @@ importers:
|
||||
dependencies:
|
||||
'@docsearch/js': 3.0.0
|
||||
'@docsearch/react': 3.0.0
|
||||
'@element-plus/metadata': link:../internal/metadata
|
||||
'@vueuse/core': 8.2.4_vue@3.2.31
|
||||
axios: 0.26.1
|
||||
clipboard-copy: 4.0.1
|
||||
@ -199,6 +204,7 @@ importers:
|
||||
devDependencies:
|
||||
'@crowdin/cli': 3.7.8
|
||||
'@element-plus/build': link:../internal/build
|
||||
'@element-plus/build-constants': link:../internal/build-constants
|
||||
'@iconify-json/ri': 1.1.1
|
||||
'@types/markdown-it': 12.2.3
|
||||
cross-env: 7.0.3
|
||||
@ -215,6 +221,7 @@ importers:
|
||||
|
||||
internal/build:
|
||||
specifiers:
|
||||
'@element-plus/build-constants': ^0.0.1
|
||||
'@pnpm/find-workspace-packages': ^4.0.0
|
||||
'@pnpm/types': ^8.0.0
|
||||
'@rollup/plugin-commonjs': ^21.0.3
|
||||
@ -236,6 +243,7 @@ importers:
|
||||
unplugin-vue-define-options: ^0.6.0
|
||||
vue: ^3.2.31
|
||||
dependencies:
|
||||
'@element-plus/build-constants': link:../build-constants
|
||||
'@pnpm/find-workspace-packages': 4.0.0_@pnpm+logger@4.0.0
|
||||
'@rollup/plugin-commonjs': 21.0.3_rollup@2.70.1
|
||||
'@rollup/plugin-node-resolve': 13.1.3_rollup@2.70.1
|
||||
@ -258,6 +266,18 @@ importers:
|
||||
'@pnpm/types': 8.0.0
|
||||
unbuild: 0.7.2
|
||||
|
||||
internal/build-constants:
|
||||
specifiers:
|
||||
unbuild: ^0.7.2
|
||||
devDependencies:
|
||||
unbuild: 0.7.2
|
||||
|
||||
internal/build-utils:
|
||||
specifiers:
|
||||
unbuild: ^0.7.2
|
||||
devDependencies:
|
||||
unbuild: 0.7.2
|
||||
|
||||
internal/eslint-config:
|
||||
specifiers:
|
||||
'@typescript-eslint/eslint-plugin': ^5.17.0
|
||||
@ -288,6 +308,28 @@ importers:
|
||||
jsonc-eslint-parser: 2.1.0
|
||||
yaml-eslint-parser: 0.5.0
|
||||
|
||||
internal/metadata:
|
||||
specifiers:
|
||||
'@element-plus/build': ^0.0.1
|
||||
'@element-plus/build-constants': ^0.0.1
|
||||
'@element-plus/build-utils': ^0.0.1
|
||||
'@types/lodash-es': ^4.17.6
|
||||
concurrently: ^7.1.0
|
||||
cross-env: ^7.0.3
|
||||
esno: ^0.14.1
|
||||
fast-glob: ^3.2.11
|
||||
lodash-es: ^4.17.21
|
||||
devDependencies:
|
||||
'@element-plus/build': link:../build
|
||||
'@element-plus/build-constants': link:../build-constants
|
||||
'@element-plus/build-utils': link:../build-utils
|
||||
'@types/lodash-es': 4.17.6
|
||||
concurrently: 7.1.0
|
||||
cross-env: 7.0.3
|
||||
esno: 0.14.1
|
||||
fast-glob: 3.2.11
|
||||
lodash-es: 4.17.21
|
||||
|
||||
packages/components:
|
||||
specifiers: {}
|
||||
|
||||
@ -2975,11 +3017,9 @@ packages:
|
||||
resolution: {integrity: sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==}
|
||||
dependencies:
|
||||
'@types/lodash': 4.14.181
|
||||
dev: false
|
||||
|
||||
/@types/lodash/4.14.181:
|
||||
resolution: {integrity: sha512-n3tyKthHJbkiWhDZs3DkhkCzt2MexYHXlX0td5iMplyfwketaOeKboEVBqzceH7juqvEg3q5oUoBFxSLu7zFag==}
|
||||
dev: false
|
||||
|
||||
/@types/lru-cache/5.1.1:
|
||||
resolution: {integrity: sha512-ssE3Vlrys7sdIzs5LOxCzTVMsU7i9oa/IaW92wF32JFb3CVczqOkru2xspuKczHEbG3nvmPY7IFqVmGGHdNbYw==}
|
||||
@ -4336,6 +4376,12 @@ packages:
|
||||
resolution: {integrity: sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
/builtins/4.1.0:
|
||||
resolution: {integrity: sha512-1bPRZQtmKaO6h7qV1YHXNtr6nCK28k0Zo95KM4dXfILcZZwoHJBN1m3lfLv9LPkcOZlrSr+J1bzMaZFO98Yq0w==}
|
||||
dependencies:
|
||||
semver: 7.3.5
|
||||
dev: true
|
||||
|
||||
/c8/7.11.0:
|
||||
resolution: {integrity: sha512-XqPyj1uvlHMr+Y1IeRndC2X5P7iJzJlEJwBpCdBbq2JocXOgJfr+JVfJkyNMGROke5LfKrhSFXGFXnwnRJAUJw==}
|
||||
engines: {node: '>=10.12.0'}
|
||||
@ -4815,6 +4861,21 @@ packages:
|
||||
typedarray: 0.0.6
|
||||
dev: false
|
||||
|
||||
/concurrently/7.1.0:
|
||||
resolution: {integrity: sha512-Bz0tMlYKZRUDqJlNiF/OImojMB9ruKUz6GCfmhFnSapXgPe+3xzY4byqoKG9tUZ7L2PGEUjfLPOLfIX3labnmw==}
|
||||
engines: {node: ^12.20.0 || ^14.13.0 || >=16.0.0}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
chalk: 4.1.2
|
||||
date-fns: 2.28.0
|
||||
lodash: 4.17.21
|
||||
rxjs: 6.6.7
|
||||
spawn-command: 0.0.2-1
|
||||
supports-color: 8.1.1
|
||||
tree-kill: 1.2.2
|
||||
yargs: 16.2.0
|
||||
dev: true
|
||||
|
||||
/config-chain/1.1.13:
|
||||
resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==}
|
||||
dependencies:
|
||||
@ -5059,6 +5120,11 @@ packages:
|
||||
whatwg-url: 8.7.0
|
||||
dev: true
|
||||
|
||||
/date-fns/2.28.0:
|
||||
resolution: {integrity: sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==}
|
||||
engines: {node: '>=0.11'}
|
||||
dev: true
|
||||
|
||||
/dayjs/1.11.0:
|
||||
resolution: {integrity: sha512-JLC809s6Y948/FuCZPm5IX8rRhQwOiyMb2TfVVQEixG7P8Lm/gt5S7yoQZmC8x1UehI9Pb7sksEt4xx14m+7Ug==}
|
||||
dev: false
|
||||
@ -5770,6 +5836,12 @@ packages:
|
||||
requiresBuild: true
|
||||
optional: true
|
||||
|
||||
/esbuild-node-loader/0.6.5:
|
||||
resolution: {integrity: sha512-uPP+dllWm38cFvDysdocutN3lfe5pTIbddAHp1ENyLzpHYqE2r+3Wo+pfg9X3p8DFWwzIisft5YkeBIthIcixw==}
|
||||
dependencies:
|
||||
esbuild: 0.14.31
|
||||
dev: true
|
||||
|
||||
/esbuild-openbsd-64/0.13.15:
|
||||
resolution: {integrity: sha512-wTfvtwYJYAFL1fSs8yHIdf5GEE4NkbtbXtjLWjM3Cw8mmQKqsg8kTiqJ9NJQe5NX/5Qlo7Xd9r1yKMMkHllp5g==}
|
||||
cpu: [x64]
|
||||
@ -5795,6 +5867,14 @@ packages:
|
||||
requiresBuild: true
|
||||
optional: true
|
||||
|
||||
/esbuild-register/3.3.2_esbuild@0.14.31:
|
||||
resolution: {integrity: sha512-jceAtTO6zxPmCfSD5cBb3rgIK1vmuqCKYwgylHiS1BF4pq0jJiJb4K2QMuqF4BEw7XDBRatYzip0upyTzfkgsQ==}
|
||||
peerDependencies:
|
||||
esbuild: '>=0.12 <1'
|
||||
dependencies:
|
||||
esbuild: 0.14.31
|
||||
dev: true
|
||||
|
||||
/esbuild-sunos-64/0.13.15:
|
||||
resolution: {integrity: sha512-lbivT9Bx3t1iWWrSnGyBP9ODriEvWDRiweAs69vI+miJoeKwHWOComSRukttbuzjZ8r1q0mQJ8Z7yUsDJ3hKdw==}
|
||||
cpu: [x64]
|
||||
@ -6224,6 +6304,17 @@ packages:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/esno/0.14.1:
|
||||
resolution: {integrity: sha512-yDFYw6dGUjCT1qKsdG7WOc/RzIh/qwxUEVZ+ohCltaxBxEFMNqeqbQL9xjRl6Yvdwrfc5OCjUA9JbFmuu/8BKg==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
cross-spawn: 7.0.3
|
||||
esbuild: 0.14.31
|
||||
esbuild-node-loader: 0.6.5
|
||||
esbuild-register: 3.3.2_esbuild@0.14.31
|
||||
import-meta-resolve: 1.1.1
|
||||
dev: true
|
||||
|
||||
/espree/9.3.1:
|
||||
resolution: {integrity: sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==}
|
||||
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
|
||||
@ -7263,6 +7354,12 @@ packages:
|
||||
resolve-cwd: 3.0.0
|
||||
dev: true
|
||||
|
||||
/import-meta-resolve/1.1.1:
|
||||
resolution: {integrity: sha512-JiTuIvVyPaUg11eTrNDx5bgQ/yMKMZffc7YSjvQeSMXy58DO2SQ8BtAf3xteZvmzvjYh14wnqNjL8XVeDy2o9A==}
|
||||
dependencies:
|
||||
builtins: 4.1.0
|
||||
dev: true
|
||||
|
||||
/imurmurhash/0.1.4:
|
||||
resolution: {integrity: sha1-khi5srkoojixPcT7a21XbyMUU+o=}
|
||||
engines: {node: '>=0.8.19'}
|
||||
@ -8573,7 +8670,6 @@ packages:
|
||||
|
||||
/lodash-es/4.17.21:
|
||||
resolution: {integrity: sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==}
|
||||
dev: false
|
||||
|
||||
/lodash-unified/1.0.2_da03a4540fbd16bbaafbb96724306afd:
|
||||
resolution: {integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g==}
|
||||
@ -10563,6 +10659,10 @@ packages:
|
||||
engines: {node: '>= 0.10'}
|
||||
dev: false
|
||||
|
||||
/spawn-command/0.0.2-1:
|
||||
resolution: {integrity: sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A=}
|
||||
dev: true
|
||||
|
||||
/spdx-correct/3.1.1:
|
||||
resolution: {integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==}
|
||||
dependencies:
|
||||
@ -10825,6 +10925,13 @@ packages:
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
|
||||
/supports-color/8.1.1:
|
||||
resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
dev: true
|
||||
|
||||
/supports-color/9.2.2:
|
||||
resolution: {integrity: sha512-XC6g/Kgux+rJXmwokjm9ECpD6k/smUoS5LKlUCcsYr4IY3rW0XyAympon2RmxGrlnZURMpg5T18gWDP9CsHXFA==}
|
||||
engines: {node: '>=12'}
|
||||
@ -11071,6 +11178,11 @@ packages:
|
||||
punycode: 2.1.1
|
||||
dev: true
|
||||
|
||||
/tree-kill/1.2.2:
|
||||
resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/trim-newlines/3.0.1:
|
||||
resolution: {integrity: sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==}
|
||||
engines: {node: '>=8'}
|
||||
|
Loading…
Reference in New Issue
Block a user