Skip to content

Commit

Permalink
build: sync version
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm committed Oct 22, 2022
1 parent c98f2ac commit 096d39d
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/cdk/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

export const version = '0.0.0-NOT-USED'
export const version = __VERSION_CDK__
2 changes: 1 addition & 1 deletion packages/components/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

export const version = '0.0.0-NOT-USED'
export const version = __VERSION_COMPONENTS__
2 changes: 1 addition & 1 deletion packages/pro/form/demo/Register.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<IxProForm class="demo-form" autoId="register" :fields="fields" @submit="onSubmit">
<template #password="props">
<template #captcha="props">
<IxRow gutter="8">
<IxCol span="12">
<IxInput v-bind="props"> </IxInput>
Expand Down
2 changes: 1 addition & 1 deletion packages/pro/version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

export const version = '0.0.0-NOT-USED'
export const version = __VERSION_PRO__
6 changes: 3 additions & 3 deletions packages/site/src/components/views/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default defineComponent({
gap: 16px;
.ix-button {
border-radius: 40px;
width: 120px;
min-width: 120px;
border: none;
box-shadow: none;
}
Expand All @@ -117,7 +117,7 @@ export default defineComponent({
.ix-button-group {
.ix-button {
border-radius: 32px;
width: 96px;
min-width: 96px;
}
}
}
Expand All @@ -140,7 +140,7 @@ export default defineComponent({
gap: 12px;
.ix-button {
border-radius: 32px;
width: 88px;
min-width: 88px;
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/site/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'

import cdkPackage from '@idux/cdk/package.json'
import componentsPackage from '@idux/components/package.json'
import proPackage from '@idux/pro/package.json'

import { mdPlugin } from './plugins/mdPlugin'
import { themePlugin } from './plugins/themePlugin'
import { transformIndexPlugin } from './plugins/transformIndexPlugin'
Expand Down Expand Up @@ -49,6 +53,9 @@ export default defineConfig(({ command }) => {
},
define: {
__DEV__: !isBuild,
__VERSION_CDK__: `'${cdkPackage.version}'`,
__VERSION_COMPONENTS__: `'${componentsPackage.version}'`,
__VERSION_PRO__: `'${proPackage.version}'`,
},
css: {
preprocessorOptions: {
Expand Down
7 changes: 1 addition & 6 deletions scripts/gulp/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
complete,
copyPackageFiles,
moveDeclaration,
syncVersion,
} from './utils'

const { packageRoot, projectRoot, icon } = gulpConfig
Expand Down Expand Up @@ -81,11 +80,7 @@ export const buildStyle = series(
complete('Style'),
)

export const buildVersion = series(
copyPackageFiles(distDirname, packageRoot, projectRoot),
syncVersion(distDirname),
complete('Version'),
)
export const buildVersion = series(copyPackageFiles(distDirname, packageRoot, projectRoot), complete('Version'))

export const buildFullIndex = series(
_buildFullIndex(cdkOptions),
Expand Down
16 changes: 13 additions & 3 deletions scripts/gulp/build/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { upperFirst } from 'lodash'
import { Plugin, RollupOptions } from 'rollup'
import typescript from 'rollup-plugin-typescript2'

import cdkPackage from '../../../packages/cdk/package.json'
import componentsPackage from '../../../packages/components/package.json'
import proPackage from '../../../packages/pro/package.json'
import { esbuildPlugin } from './esbuild'

interface Options {
Expand All @@ -23,6 +26,13 @@ interface Options {
}

const externalDeps = ['vue', '@vue', '@idux', '@floating-ui/dom', 'date-fns', 'lodash-es', 'ajv']
const replaceOptions = {
__DEV__: "process.env.NODE_ENV !== 'production'",
__VERSION_CDK__: `'${cdkPackage.version}'`,
__VERSION_COMPONENTS__: `'${componentsPackage.version}'`,
__VERSION_PRO__: `'${proPackage.version}'`,
preventAssignment: true,
}

export const getRollupSingleOptions = (options: Options): RollupOptions => {
const { targetDirname, distDirname, compName = '', minify = false } = options
Expand All @@ -32,7 +42,7 @@ export const getRollupSingleOptions = (options: Options): RollupOptions => {

const plugins = [
nodeResolve(),
replace({ __DEV__: "process.env.NODE_ENV !== 'production'", preventAssignment: true }),
replace(replaceOptions),
vuePlugin(),
vueJsxPlugin({ enableObjectSlots: false }),
esbuildPlugin({ minify }),
Expand Down Expand Up @@ -67,7 +77,7 @@ export const getRollupFullOptions = (options: Options): RollupOptions => {
],
}),
nodeResolve(),
replace({ __DEV__: true, preventAssignment: true }),
replace(replaceOptions),
vuePlugin(),
vueJsxPlugin({ enableObjectSlots: false }),
esbuildPlugin({
Expand Down Expand Up @@ -123,7 +133,7 @@ export const getRollupDeclarationOptions = (options: Options): RollupOptions =>

const plugins = [
nodeResolve(),
replace({ __DEV__: "process.env.NODE_ENV !== 'production'", preventAssignment: true }),
replace(replaceOptions),
vuePlugin(),
vueJsxPlugin({ enableObjectSlots: false }),
typescript({
Expand Down
20 changes: 1 addition & 19 deletions scripts/gulp/build/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path'

// import { Extractor, ExtractorConfig } from '@microsoft/api-extractor'
import { copy, copyFile, readJSON, readdir, statSync, writeFile, writeJson } from 'fs-extra'
import { copy, copyFile, readdir, statSync, writeFile, writeJson } from 'fs-extra'
import { TaskFunction } from 'gulp'
import { OutputOptions, rollup } from 'rollup'

Expand Down Expand Up @@ -201,24 +201,6 @@ export const copyPackageFiles = (distDirname: string, projectRoot: string, packa
return copyPackageFiles
}

export const syncVersion = (distDirname: string): TaskFunction => {
const syncVersion: TaskFunction = async done => {
const filterPackages = ['site', 'packages']
const packages = await readdir(distDirname)
packages
.filter(packageName => !filterPackages.includes(packageName))
.map(async packageName => {
const { version } = await readJSON(join(distDirname, packageName, 'package.json'))
const versionString = `export const version = '${version}'`
await writeFile(join(distDirname, packageName, 'version/index.js'), versionString)
const versionDeclarationString = `export declare const version = '${version}'`
await writeFile(join(distDirname, packageName, 'version/index.d.ts'), versionDeclarationString)
})
done()
}
return syncVersion
}

export const buildStyle = (targetDirname: string, distDirname: string, packageName: string): TaskFunction => {
const buildStyle: TaskFunction = async done => {
await compileLess(targetDirname, distDirname, packageName)
Expand Down
3 changes: 3 additions & 0 deletions typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export {}

declare global {
const __DEV__: boolean
const __VERSION_CDK__: string
const __VERSION_COMPONENTS__: string
const __VERSION_PRO__: string
function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number
function clearInterval(handle?: number): void
Expand Down

0 comments on commit 096d39d

Please sign in to comment.