Skip to content

Commit

Permalink
Merge branch 'main' into gavin/v4-dev-customrouter
Browse files Browse the repository at this point in the history
* main: (48 commits)
  fix(LockModal): Cannot unlock (vbenjs#3143)
  Pr/code editor boardered (vbenjs#3142)
  chore: fix type:check error (vbenjs#3139)
  fix(customExport): Failure to export (vbenjs#3137)
  fix(full-screen): dom fullscreen status text (vbenjs#3130)
  fix(BasicForm): type instantiation is excessively deep and possibly infinite. (vbenjs#3128)
  chore: fix type:check error (vbenjs#3126)
  fix: #2744tabs选项卡渲染问题,以及完善路由中affix=true时处理逻辑。 (vbenjs#3127)
  chore: update `unplugin-config` (vbenjs#3120)
  chore(demo): 修正表单增删示例类型错误
  fix(demo): useForm中DatePicker,RangePicker 日期控件位置不对
  fix(Editor): ts类型错误
  chore(MenuItem): watch回调参数类型不一致
  fix(SimpleMenuTag): SimpleMenuTag的引用都改为动态组件引用,以消除打包警告.close vbenjs#3121
  chore(demo): 消除ts类型错误
  fix: ScrollContainer的一个问题 vbenjs#3046 (vbenjs#3119)
  fix(StrengthMeter): change事件应随handleChange一起抛出。close vbenjs#3118
  Revert "chore: update `unplugin-config` (vbenjs#3116)" (vbenjs#3117)
  chore: update `unplugin-config` (vbenjs#3116)
  fix(EditCellTable): 表格编辑行在使用Switch,checkedValue为数字时无法切换开关.close vbenjs#2560
  ...

# Conflicts:
#	pnpm-lock.yaml
#	src/components/Form/src/BasicForm.vue
#	src/components/Form/src/components/ApiSelect.vue
#	src/components/Form/src/hooks/useForm.ts
#	src/layouts/default/header/MultipleHeader.vue
#	src/views/demo/form/UseForm.vue
  • Loading branch information
gavinZhang001 committed Oct 17, 2023
2 parents 5f15341 + cdac147 commit 80e273f
Show file tree
Hide file tree
Showing 97 changed files with 2,289 additions and 6,231 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lokalise.i18n-ally",
"antfu.iconify",
"mikestead.dotenv",
"heybourn.headwind"
"heybourn.headwind",
"vue.vscode-typescript-vue-plugin"
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
}
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"i18n-ally.localesPaths": ["src/locales/lang"],
"i18n-ally.keystyle": "nested",
Expand Down
3 changes: 2 additions & 1 deletion internal/vite-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@vitejs/plugin-vue": "^4.2.3",
"@gz/eslint-config": "workspace:*",
"@vitejs/plugin-vue-jsx": "^3.0.1",
"ant-design-vue": "^3.2.20",
"ant-design-vue": "^4.0.3",
"dayjs": "^1.11.9",
"dotenv": "^16.3.1",
"fs-extra": "^11.1.1",
Expand All @@ -40,6 +40,7 @@
"rollup-plugin-visualizer": "^5.9.2",
"sass": "^1.63.6",
"unocss": "^0.53.4",
"unplugin-config": "^0.1.3",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-dts": "^3.1.0",
"vite-plugin-html": "^3.2.0",
Expand Down
117 changes: 22 additions & 95 deletions internal/vite-config/src/plugins/appConfig.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,31 @@
import colors from 'picocolors';
import { readPackageJSON } from 'pkg-types';
import GenerateConfig from 'unplugin-config/vite';
import { type PluginOption } from 'vite';

import { getEnvConfig } from '../utils/env';
import { createContentHash } from '../utils/hash';
import { strToHex } from '../utils/hash';

const GLOBAL_CONFIG_FILE_NAME = '_app.config.js';
const PLUGIN_NAME = 'app-config';

async function createAppConfigPlugin({
root,
isBuild,
}: {
root: string;
isBuild: boolean;
}): Promise<PluginOption> {
let publicPath: string;
let source: string;
if (!isBuild) {
return {
name: PLUGIN_NAME,
};
}
const { version = '' } = await readPackageJSON(root);

return {
name: PLUGIN_NAME,
async configResolved(_config) {
const appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? '';
// appTitle = appTitle.replace(/\s/g, '_').replace(/-/g, '_');
publicPath = _config.base;
source = await getConfigSource(appTitle);
// This constant sets the output directory for the Vite package
const OUTPUT_DIR = 'dist';
export async function createConfigPluginConfig(
shouldGenerateConfig: boolean,
): Promise<PluginOption> {
const config = await getEnvConfig();
// LINK /src/utils/env.ts -> getVariableName
const APP_NAME = strToHex(config?.VITE_GLOB_APP_TITLE ?? '__APP');
// https://github.com/kirklin/unplugin-config
return GenerateConfig({
appName: APP_NAME,
envVariables: {
prefix: 'VITE_GLOB_',
},
async transformIndexHtml(html) {
publicPath = publicPath.endsWith('/') ? publicPath : `${publicPath}/`;

const appConfigSrc = `${
publicPath || '/'
}${GLOBAL_CONFIG_FILE_NAME}?v=${version}-${createContentHash(source)}`;

return {
html,
tags: [
{
tag: 'script',
attrs: {
src: appConfigSrc,
},
},
],
};
configFile: {
generate: shouldGenerateConfig,
fileName: GLOBAL_CONFIG_FILE_NAME,
outputDir: OUTPUT_DIR,
},
async generateBundle() {
try {
this.emitFile({
type: 'asset',
fileName: GLOBAL_CONFIG_FILE_NAME,
source,
});

console.log(colors.cyan(`✨configuration file is build successfully!`));
} catch (error) {
console.log(
colors.red('configuration file configuration file failed to package:\n' + error),
);
}
htmlInjection: {
decodeEntities: true,
},
};
});
}

/**
* Get the configuration file variable name
* @param env
*/
const getVariableName = (title: string) => {
function strToHex(str: string) {
const result: string[] = [];
for (let i = 0; i < str.length; ++i) {
const hex = str.charCodeAt(i).toString(16);
result.push(('000' + hex).slice(-4));
}
return result.join('').toUpperCase();
}
return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '');
};

async function getConfigSource(appTitle: string) {
const config = await getEnvConfig();
const variableName = getVariableName(appTitle);
const windowVariable = `window.${variableName}`;
// Ensure that the variable will not be modified
let source = `${windowVariable}=${JSON.stringify(config)};`;
source += `
Object.freeze(${windowVariable});
Object.defineProperty(window, "${variableName}", {
configurable: false,
writable: false,
});
`.replace(/\s/g, '');
return source;
}

export { createAppConfigPlugin };
6 changes: 3 additions & 3 deletions internal/vite-config/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import vueJsx from '@vitejs/plugin-vue-jsx';
import { type PluginOption } from 'vite';
import purgeIcons from 'vite-plugin-purge-icons';

import { createAppConfigPlugin } from './appConfig';
import { createConfigPluginConfig } from './appConfig';
import { configCompressPlugin } from './compress';
import { configHtmlPlugin } from './html';
import { configMockPlugin } from './mock';
Expand All @@ -18,10 +18,10 @@ interface Options {
enableAnalyze?: boolean;
}

async function createPlugins({ isBuild, root, enableMock, compress, enableAnalyze }: Options) {
async function createPlugins({ isBuild, enableMock, compress, enableAnalyze }: Options) {
const vitePlugins: (PluginOption | PluginOption[])[] = [vue(), vueJsx()];

const appConfigPlugin = await createAppConfigPlugin({ root, isBuild });
const appConfigPlugin = await createConfigPluginConfig(isBuild);
vitePlugins.push(appConfigPlugin);

// vite-plugin-html
Expand Down
7 changes: 6 additions & 1 deletion internal/vite-config/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ function getConfFiles() {
* @param match prefix
* @param confFiles ext
*/
export async function getEnvConfig(match = 'VITE_GLOB_', confFiles = getConfFiles()) {
export async function getEnvConfig(
match = 'VITE_GLOB_',
confFiles = getConfFiles(),
): Promise<{
[key: string]: string;
}> {
let envConfig = {};

for (const confFile of confFiles) {
Expand Down
10 changes: 9 additions & 1 deletion internal/vite-config/src/utils/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ function createContentHash(content: string, hashLSize = 12) {
const hash = createHash('sha256').update(content);
return hash.digest('hex').slice(0, hashLSize);
}
function strToHex(str: string) {
const result: string[] = [];
for (let i = 0; i < str.length; ++i) {
const hex = str.charCodeAt(i).toString(16);
result.push(('000' + hex).slice(-4));
}
return result.join('').toUpperCase();
}

export { createContentHash };
export { createContentHash, strToHex };
15 changes: 11 additions & 4 deletions internal/vite-config/src/utils/modifyVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { resolve } from 'node:path';

import { generate } from '@ant-design/colors';
// @ts-ignore: typo
import { getThemeVariables } from 'ant-design-vue/dist/theme';
/* import { getThemeVariables } from 'ant-design-vue/dist/theme'; */
import { theme } from 'ant-design-vue/lib';
import convertLegacyToken from 'ant-design-vue/lib/theme/convertLegacyToken';

const { defaultAlgorithm, defaultSeed } = theme;

const primaryColor = '#0960bd';

Expand All @@ -25,11 +29,14 @@ export function generateModifyVars() {
primaryColorObj[`primary-${index + 1}`] = palettes[index];
}

const modifyVars = getThemeVariables();
// const modifyVars = getThemeVariables();
const mapToken = defaultAlgorithm(defaultSeed);
const v3Token = convertLegacyToken(mapToken);

return {
...modifyVars,
...v3Token,
// reference: Avoid repeated references
hack: `${modifyVars.hack} @import (reference) "${resolve('src/design/config.less')}";`,
hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
'primary-color': primary,
...primaryColorObj,
'info-color': primary,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=8192 pnpm vite build",
"build:analyze": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm vite build --mode analyze",
"build:docker": "vite build --mode docker",
"build:no-cache": "pnpm clean:cache && npm run build",
"build:no-cache": "pnpm store prune && npm run build",
"build:test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm vite build --mode test",
"commit": "czg",
"dev": "pnpm vite",
Expand Down Expand Up @@ -64,7 +64,7 @@
"@vueuse/core": "^10.2.1",
"@vueuse/shared": "^10.2.1",
"@zxcvbn-ts/core": "^3.0.2",
"ant-design-vue": "^4.0.2",
"ant-design-vue": "^4.0.3",
"axios": "^1.4.0",
"codemirror": "^5.65.12",
"cropperjs": "^1.5.13",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type NonNullable<T> = T extends null | undefined ? never : T;
/**
* 字符串类型对象
*/
type Recordable<T> = Record<string, T>;
type Recordable<T = any> = Record<string, T>;

/**
* 字符串类型对象(只读)
Expand Down
Loading

0 comments on commit 80e273f

Please sign in to comment.