mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
refactor(cli): improve package.json generate (#250)
This commit is contained in:
parent
45b2a36798
commit
f0ea849072
@ -37,7 +37,10 @@
|
|||||||
"handlebars": "^4.7.8",
|
"handlebars": "^4.7.8",
|
||||||
"picocolors": "^1.1.0"
|
"picocolors": "^1.1.0"
|
||||||
},
|
},
|
||||||
"theme-plume": {
|
"plume-deps": {
|
||||||
"vuepress": "2.0.0-rc.15"
|
"vuepress": "2.0.0-rc.17",
|
||||||
|
"vue": "^3.5.10",
|
||||||
|
"sass-embedded": "^1.79.4",
|
||||||
|
"sass-loader": "^16.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type { File, ResolvedData } from './types.js'
|
|||||||
import { kebabCase } from '@pengzhanbo/utils'
|
import { kebabCase } from '@pengzhanbo/utils'
|
||||||
import { execaCommand } from 'execa'
|
import { execaCommand } from 'execa'
|
||||||
import { Mode } from './constants.js'
|
import { Mode } from './constants.js'
|
||||||
import { getDependenciesVersion, readJsonFile, resolve } from './utils/index.js'
|
import { readJsonFile, resolve } from './utils/index.js'
|
||||||
|
|
||||||
export async function createPackageJson(
|
export async function createPackageJson(
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
@ -53,26 +53,28 @@ export async function createPackageJson(
|
|||||||
|
|
||||||
pkg.devDependencies ??= {}
|
pkg.devDependencies ??= {}
|
||||||
|
|
||||||
|
const hasDep = (dep: string) => pkg.devDependencies?.[dep] || pkg.dependencies?.[dep]
|
||||||
|
|
||||||
const context = (await readJsonFile(resolve('package.json')))!
|
const context = (await readJsonFile(resolve('package.json')))!
|
||||||
const meta = context['theme-plume']
|
const meta = context['plume-deps']
|
||||||
|
|
||||||
|
pkg.devDependencies[`@vuepress/bundler-${bundler}`] = `${meta.vuepress}`
|
||||||
pkg.devDependencies.vuepress = `${meta.vuepress}`
|
pkg.devDependencies.vuepress = `${meta.vuepress}`
|
||||||
pkg.devDependencies['vuepress-theme-plume'] = `${context.version}`
|
pkg.devDependencies['vuepress-theme-plume'] = `${context.version}`
|
||||||
pkg.devDependencies[`@vuepress/bundler-${bundler}`] = `${meta.vuepress}`
|
|
||||||
pkg.devDependencies['http-server'] = '^14.1.1'
|
pkg.devDependencies['http-server'] = '^14.1.1'
|
||||||
|
|
||||||
const deps: string[] = []
|
const deps: string[] = []
|
||||||
if (!pkg.dependencies?.vue && !pkg.devDependencies.vue)
|
if (!hasDep('vue'))
|
||||||
deps.push('vue')
|
deps.push('vue')
|
||||||
if (bundler === 'webpack' && !pkg.dependencies?.['sass-loader'] && !pkg.devDependencies['sass-loader'])
|
|
||||||
|
if (bundler === 'webpack' && !hasDep('sass-loader'))
|
||||||
deps.push('sass-loader')
|
deps.push('sass-loader')
|
||||||
|
|
||||||
if (!pkg.dependencies?.['sass-embedded'] && !pkg.devDependencies['sass-embedded'])
|
if (!hasDep('sass-embedded'))
|
||||||
deps.push('sass-embedded')
|
deps.push('sass-embedded')
|
||||||
|
|
||||||
const dv = await getDependenciesVersion(deps)
|
for (const dep of deps)
|
||||||
|
pkg.devDependencies[dep] = meta[dep]
|
||||||
for (const [d, v] of Object.entries(dv))
|
|
||||||
pkg.devDependencies[d] = `^${v}`
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
filepath: 'package.json',
|
filepath: 'package.json',
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
export type DependencyVersion = 'latest' | 'next' | 'pre' | string
|
|
||||||
|
|
||||||
const api = 'https://api.pengzhanbo.cn/npm/dependencies/version'
|
|
||||||
|
|
||||||
export async function getDependenciesVersion(
|
|
||||||
dependencies: string[],
|
|
||||||
version: DependencyVersion = 'latest',
|
|
||||||
): Promise<Record<string, string>> {
|
|
||||||
const result = await fetch(api, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'content-type': 'application/json' },
|
|
||||||
body: JSON.stringify({ dependencies, version }),
|
|
||||||
}).then(res => res.json())
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
@ -7,6 +7,5 @@ export const resolve = (...args: string[]) => path.resolve(__dirname, '../', ...
|
|||||||
|
|
||||||
export const getTemplate = (dir: string) => resolve('templates', dir)
|
export const getTemplate = (dir: string) => resolve('templates', dir)
|
||||||
|
|
||||||
export * from './depsVersion.js'
|
|
||||||
export * from './fs.js'
|
export * from './fs.js'
|
||||||
export * from './getPackageManager.js'
|
export * from './getPackageManager.js'
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { defineUserConfig } from 'vuepress'
|
|
||||||
import { {{ bundler }}Bundler } from '@vuepress/bundler-{{ bundler }}'
|
import { {{ bundler }}Bundler } from '@vuepress/bundler-{{ bundler }}'
|
||||||
|
import { defineUserConfig } from 'vuepress'
|
||||||
import { plumeTheme } from 'vuepress-theme-plume'
|
import { plumeTheme } from 'vuepress-theme-plume'
|
||||||
|
|
||||||
export default defineUserConfig({
|
export default defineUserConfig({
|
||||||
@ -32,7 +32,7 @@ export default defineUserConfig({
|
|||||||
* @see https://theme-plume.vuejs.press/config/plugins/code-highlight/
|
* @see https://theme-plume.vuejs.press/config/plugins/code-highlight/
|
||||||
*/
|
*/
|
||||||
// shiki: {
|
// shiki: {
|
||||||
// // 强烈建议预设代码块高亮语言,插件默认加载所有语言会产生不必要的时间开销
|
// 强烈建议预设代码块高亮语言,插件默认加载所有语言会产生不必要的时间开销
|
||||||
// languages: ['shell', 'bash', 'typescript', 'javascript'],
|
// languages: ['shell', 'bash', 'typescript', 'javascript'],
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
|||||||
@ -50,8 +50,8 @@ npm run docs:preview
|
|||||||
npm run vp-update
|
npm run vp-update
|
||||||
```
|
```
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if (equal deploy "github")}}
|
|
||||||
|
|
||||||
|
{{#if (equal deploy "github")}}
|
||||||
## Deploy to GitHub Pages
|
## Deploy to GitHub Pages
|
||||||
|
|
||||||
The plume theme has been created with GitHub Actions: `.github/workflows/docs-deploy.yml`. You also need to make the following settings in the GitHub repository:
|
The plume theme has been created with GitHub Actions: `.github/workflows/docs-deploy.yml`. You also need to make the following settings in the GitHub repository:
|
||||||
|
|||||||
@ -50,8 +50,8 @@ npm run docs:preview
|
|||||||
npm run vp-update
|
npm run vp-update
|
||||||
```
|
```
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if (equal deploy "github")}}
|
|
||||||
|
|
||||||
|
{{#if (equal deploy "github")}}
|
||||||
## 部署到 GitHub Pages
|
## 部署到 GitHub Pages
|
||||||
|
|
||||||
主题已创建 github actions: `.github/workflows/docs-deploy.yml`,你还需要在 github 仓库中进行以下设置:
|
主题已创建 github actions: `.github/workflows/docs-deploy.yml`,你还需要在 github 仓库中进行以下设置:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user