Skip to content

Commit

Permalink
build: add configuration to build pre version (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm committed Nov 15, 2022
1 parent e9534bd commit b42a1c5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 19 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"scripts": {
"start": "gulp start --cwd ./packages/site --gulpfile ./scripts/gulp/gulpfile.ts",
"build": "npm-run-all -s build:clean -p build:lib build:declaration build:style build:site",
"build:pre-version": "npm-run-all -s build:clean -p build:lib build:declaration build:style build:site-pre-version",
"build:clean": "gulp build:clean --gulpfile ./scripts/gulp/gulpfile.ts",
"build:lib": "gulp build:lib --max-old-space-size=8192 --gulpfile ./scripts/gulp/gulpfile.ts",
"build:declaration": "gulp build:declaration --max-old-space-size=8192 --gulpfile ./scripts/gulp/gulpfile.ts",
"build:style": "gulp build:style --max-old-space-size=8192 --gulpfile ./scripts/gulp/gulpfile.ts",
"build:site": "gulp build:site --max-old-space-size=8192 --gulpfile ./scripts/gulp/gulpfile.ts",
"build:site-pre-version": "gulp build:site-pre-version --max-old-space-size=8192 --gulpfile ./scripts/gulp/gulpfile.ts",
"icons": "gulp icons --gulpfile ./scripts/gulp/gulpfile.ts",
"gen": "ts-node scripts/gen/generate.ts",
"lessvariable:update": "ts-node scripts/gen/style-variable/update.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"author": "IDuxFE<idux.feteam@gmail.com>",
"scripts": {
"start": "vite",
"build": "vite build"
"build": "vite build",
"build:pre-version": "vite build --mode pre-version"
},
"dependencies": {
"@idux/cdk": "^1.1.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/site/public/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preVersions": ["1.0.x"]
}
17 changes: 13 additions & 4 deletions packages/site/src/components/layout/header/HeaderVersion.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
import { version as currentVersion } from '@idux/components/version'
const versions = [currentVersion, '1.0.x']
const dataSource = versions.map(v => ({ key: v, label: v }))
const selectVersion = ref(currentVersion)
const versions = ref([currentVersion])
const dataSource = computed(() => versions.value.map(v => ({ key: v, label: v })))
watch(selectVersion, version => {
window.location.href = `${window.location.origin}/version/${version}`
})
onMounted(() => {
// eslint-disable-next-line no-undef
fetch(__BASE_URL__ + `config.json`)
.then(res => res.json())
.then(config => {
const { preVersions } = config
versions.value = [currentVersion, ...preVersions]
})
})
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/components/views/home/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const homeLocales = {
videoErr: '您的浏览器不支持 video 标签。',
bannerTitle: 'iDux',
bannerTitleDesc: '企业级设计规范 高效开发体验',
start: '开 始 使 用',
start: '开始使用',
github: 'GitHub',
compProperties: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/site/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const componentPath: Record<string, string> = {
IxLoadingBarProvider: '@idux/components/loading-bar',
}

export default defineConfig(({ command }) => {
export default defineConfig(({ command, mode }) => {
const isBuild = command === 'build'
const baseUrl = '/'
const baseUrl = mode === 'pre-version' ? `/version/${cdkPackage.version.slice(0, -1)}x/` : '/'

return {
plugins: [
Expand Down
4 changes: 3 additions & 1 deletion scripts/gulp/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
buildVersion,
} from './build'
import { iconsGenerate } from './icons'
import { siteBuild, siteStart } from './site'
import { siteBuild, siteBuildPreVersion, siteStart } from './site'

task('start', series(siteStart))

Expand All @@ -25,4 +25,6 @@ task('build:style', series(buildStyle))

task('build:site', series(siteBuild))

task('build:site-pre-version', series(siteBuildPreVersion))

task('icons', iconsGenerate)
4 changes: 4 additions & 0 deletions scripts/gulp/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ const start: TaskFunction = done => execNodeTask('vite', ['--host'])(done)

const build: TaskFunction = done => execNodeTask('lerna', ['run', 'build', '--scope', '@idux/site'])(done)

const buildPreVersion: TaskFunction = done =>
execNodeTask('lerna', ['run', 'build:pre-version', '--scope', '@idux/site'])(done)

export const siteStart = series(init, start)
export const siteBuild = series(init, build)
export const siteBuildPreVersion = series(init, buildPreVersion)
13 changes: 3 additions & 10 deletions scripts/gulp/site/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ interface DocsItem {
order: number
}

const componentsSortMap: Record<string, number> = {
const sortMap: Record<string, number> = {
General: 0,
通用: 0,
Layout: 1,
Expand All @@ -108,13 +108,6 @@ const componentsSortMap: Record<string, number> = {
其他: 7,
}

const proComponentsSortMap: Record<string, number> = {
General: 0,
通用: 0,
Layout: 1,
布局: 1,
}

const defaultRoutes = [`{path: '/', 'component': () => import('./components/views/home/Home.vue')},`]

type ComponentsMap = Record<string, { lang: string; children: Omit<DocsItem, 'lang'>[] }>
Expand Down Expand Up @@ -162,8 +155,8 @@ function handleDocsMeta(docsMeta: Record<string, Record<string, Meta>>) {
const proComponents = getComponentSort(proComponentsMap)

docs.sort((pre, next) => pre.order - next.order)
components.sort((pre, next) => componentsSortMap[pre.name] - componentsSortMap[next.name])
proComponents.sort((pre, next) => proComponentsSortMap[pre.name] - proComponentsSortMap[next.name])
components.sort((pre, next) => sortMap[pre.name] - sortMap[next.name])
proComponents.sort((pre, next) => sortMap[pre.name] - sortMap[next.name])
cdk.sort((pre, next) => pre.order - next.order)

return { docs, components, proComponents, cdk, routes }
Expand Down

0 comments on commit b42a1c5

Please sign in to comment.