-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7887aa
commit 4395f27
Showing
24 changed files
with
1,188 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"name": "@vuepress/helper", | ||
"version": "2.0.0-rc.2", | ||
"description": "VuePress helper", | ||
"keywords": [ | ||
"vuepress", | ||
"helper", | ||
"bundler-helper", | ||
"excerpt" | ||
], | ||
"homepage": "https://github.com/vuepress", | ||
"bugs": { | ||
"url": "https://github.com/vuepress/ecosystem/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/vuepress/ecosystem.git", | ||
"directory": "tools/helper" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "Mr.Hope", | ||
"email": "[email protected]", | ||
"url": "https://mister-hope.com" | ||
}, | ||
"type": "module", | ||
"exports": { | ||
".": "./lib/node/index.js", | ||
"./client": "./lib/client/index.js", | ||
"./client/*": "./lib/client/*", | ||
"./node": "./lib/node/index.js", | ||
"./noopComponent": "./lib/client/noopComponent.js", | ||
"./noopModule": "./lib/client/noopModule.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "./lib/node/index.js", | ||
"types": "./lib/node/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"build": "tsc -b tsconfig.build.json", | ||
"clean": "rimraf lib *.tsbuildinfo" | ||
}, | ||
"dependencies": { | ||
"@vue/shared": "^3.4.15", | ||
"cheerio": "1.0.0-rc.12", | ||
"fflate": "^0.8.1", | ||
"gray-matter": "^4.0.3", | ||
"vue": "^3.4.15" | ||
}, | ||
"devDependencies": { | ||
"@types/connect": "3.4.38", | ||
"@vuepress/bundler-vite": "2.0.0-rc.2", | ||
"@vuepress/bundler-webpack": "2.0.0-rc.2", | ||
"@vuepress/plugin-git": "2.0.0-rc.1", | ||
"vite": "5.0.12" | ||
}, | ||
"peerDependencies": { | ||
"vuepress": "2.0.0-rc.2" | ||
}, | ||
"engines": { | ||
"node": ">=18.16.0", | ||
"npm": ">=8", | ||
"pnpm": ">=7", | ||
"yarn": ">=2" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useLocaleConfig.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { computed } from 'vue' | ||
import type { ComputedRef } from 'vue' | ||
import { useRouteLocale } from 'vuepress/client' | ||
import type { LocaleConfig, LocaleData } from 'vuepress/shared' | ||
|
||
/** | ||
* Get current locale config | ||
* | ||
* @param localesConfig client locale Config | ||
* @returns current locale config | ||
*/ | ||
export const useLocaleConfig = <T extends LocaleData>( | ||
localesConfig: LocaleConfig<T>, | ||
): ComputedRef<Partial<T>> => { | ||
const routeLocale = useRouteLocale() | ||
|
||
return computed(() => localesConfig[routeLocale.value] ?? {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './composables/index.js' | ||
export * from '../shared/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { FunctionalComponent } from 'vue' | ||
|
||
const noopComponent: FunctionalComponent = () => null | ||
|
||
export default noopComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { ViteBundlerOptions } from '@vuepress/bundler-vite' | ||
import type { WebpackBundlerOptions } from '@vuepress/bundler-webpack' | ||
import type { App } from 'vuepress/core' | ||
import { isString } from '../../shared/index.js' | ||
import { getBundlerName } from './getBundlerName.js' | ||
|
||
/** | ||
* Add tags as customElement | ||
* | ||
* @param bundlerOptions VuePress Bundler config | ||
* @param app VuePress Node App | ||
* @param customElements tags recognized as custom element | ||
*/ | ||
export const addCustomElement = ( | ||
bundlerOptions: unknown, | ||
app: App, | ||
customElement: string[] | string | RegExp, | ||
): void => { | ||
const customElements = isString(customElement) | ||
? [customElement] | ||
: customElement | ||
const bundlerName = getBundlerName(app) | ||
|
||
// for vite | ||
if (bundlerName === 'vite') { | ||
const viteBundlerConfig = bundlerOptions as ViteBundlerOptions | ||
|
||
const { isCustomElement } = (((viteBundlerConfig.vuePluginOptions ??= | ||
{}).template ??= {}).compilerOptions ??= {}) | ||
|
||
viteBundlerConfig.vuePluginOptions.template.compilerOptions.isCustomElement = | ||
(tag: string): boolean | void => { | ||
if ( | ||
customElements instanceof RegExp | ||
? customElements.test(tag) | ||
: customElements.includes(tag) | ||
) | ||
return true | ||
|
||
return isCustomElement?.(tag) | ||
} | ||
} | ||
|
||
// for webpack | ||
else if (bundlerName === 'webpack') { | ||
const webpackBundlerConfig = bundlerOptions as WebpackBundlerOptions | ||
|
||
const { isCustomElement } = ((webpackBundlerConfig.vue ??= | ||
{}).compilerOptions ??= {}) | ||
|
||
webpackBundlerConfig.vue.compilerOptions.isCustomElement = ( | ||
tag: string, | ||
): boolean | void => { | ||
if ( | ||
customElements instanceof RegExp | ||
? customElements.test(tag) | ||
: customElements.includes(tag) | ||
) | ||
return true | ||
|
||
return isCustomElement?.(tag) | ||
} | ||
} | ||
} |
Oops, something went wrong.