Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build improve #167

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/configs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
/* Paths */
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@demos/*": ["../demos/*"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed everything which looks suspicious

"react": [""]
"@/*": ["./src/*"]
}
},
"include": ["src", "src/**/*.{ts,vue}"],
Expand Down
92 changes: 0 additions & 92 deletions packages/documentation/.vitepress/components/ThemeSwitcher.vue

This file was deleted.

3 changes: 0 additions & 3 deletions packages/documentation/.vitepress/configuration/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ export const vite = {
resolve: {
alias: {
'@': path.resolve(__dirname, '../../../ui/src'),
'components': path.join(__dirname, '../../components'),
'@demos': path.join(__dirname, '../../../examples/demos'),
leonid marked this conversation as resolved.
Show resolved Hide resolved
'@examples': path.join(__dirname, '../../../examples'),
}
},
css: {
Expand Down
3 changes: 0 additions & 3 deletions packages/examples/demos/button-group/ButtonGroupExample.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<script setup>
import { AcvButtonGroup } from '@acronis-platform/ui-component-library';
// or
import ButtonGroup from '@acronis-platform/ui-component-library/components/buttonGroup';
</script>

<template>
<AcvButtonGroup />
<ButtonGroup />
</template>
1 change: 0 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"@vitest/utils": "2.1.2",
"@vue/test-utils": "2.4.6",
"browserslist": "4.23.0",
"csstype": "3.1.3",
"cypress": "13.12.0",
"eslint": "9.12.0",
"eslint-plugin-cypress": "3.5.0",
Expand Down
13 changes: 3 additions & 10 deletions packages/ui/scripts/buildPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ export function buildPlugin(): Plugin[] {
sourceMap: false,
paths: {
'@/*': ['./src/*'],
'@demos/*': ['../../demos/*'],
'csstype': ['node_modules/csstype']
}
},
copyDtsFiles: true,
pathsToAliases: false,
aliasesExclude: [/^@ui-kit\/(services|hooks|config)/]
pathsToAliases: false
}),
];

Expand All @@ -50,10 +47,7 @@ export function buildPlugin(): Plugin[] {
sourcemap: true,
lib: {
entry: {
'index': 'src/index.ts',
// TODO add more entries
'button': 'src/components/button/public.ts',
'components/buttonGroup': 'src/components/button-group/public.ts',
index: 'src/index.ts',
},
formats: ['es'],
name: 'Acronis Ui Component Library',
Expand All @@ -74,8 +68,7 @@ export function buildPlugin(): Plugin[] {
},
chunkFileNames: '[name].[hash].js',
assetFileNames: 'assets/[name][extname]'
},
external: ['vue']
}
},
chunkSizeWarningLimit: 10000
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/theme-switcher/themeSwitcher.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import AcvButton from '@/components/button/button.vue';
import AcvDropdown from '@/components/dropdown/dropdown.vue';
import { AVAILABLE_COLOR_SCHEMES, useColorScheme } from '@/composables/useColorScheme.ts';
import { useColorScheme } from '@/composables/useColorScheme.ts';

const { setColorScheme, colorScheme: currentColorScheme } = useColorScheme();
</script>
Expand All @@ -18,9 +18,9 @@
<template #dropdown>
<ul>
<li
v-for="(colorScheme, key) in AVAILABLE_COLOR_SCHEMES"
:key="key"
:data-test="`color-scheme-item-${key}`"
v-for="(colorScheme) in ['light', 'dark'] as const"
:key="colorScheme"
:data-test="`color-scheme-item-${colorScheme}`"
class="color"
:class="{
selected: colorScheme === currentColorScheme }"
Expand Down
13 changes: 3 additions & 10 deletions packages/ui/src/composables/useColorScheme.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useColorScheme } from '@/composables/useColorScheme';
import { ACV_THEME_LC_KEY, useColorScheme } from '@/composables/useColorScheme';
import { describe, expect, it } from 'vitest';
import { nextTick } from 'vue';

Expand All @@ -9,7 +9,7 @@ describe('useColorScheme', () => {
});

it('returns dark mode status correctly', () => {
localStorage.setItem('acv-theme', 'dark');
localStorage.setItem(ACV_THEME_LC_KEY, 'dark');
const { isDark } = useColorScheme();
expect(isDark.value).toEqual(true);
});
Expand All @@ -19,14 +19,7 @@ describe('useColorScheme', () => {
setColorScheme('light');
expect(colorScheme.value).toEqual('light');
await nextTick();
expect(localStorage.getItem('acv-theme')).toEqual('light');
});

it('does not set invalid color scheme', () => {
const { setColorScheme, colorScheme } = useColorScheme();
setColorScheme('invalid');
expect(colorScheme.value).not.toEqual('invalid');
expect(localStorage.getItem('acv-theme')).not.toEqual('invalid');
expect(localStorage.getItem(ACV_THEME_LC_KEY)).toEqual('light');
});

it('does not change color scheme if the same is set', () => {
Expand Down
34 changes: 13 additions & 21 deletions packages/ui/src/composables/useColorScheme.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
import { useColorMode } from '@vueuse/core';
import { computed, ref } from 'vue';
import { computed } from 'vue';

export const AVAILABLE_COLOR_SCHEMES = {
light: 'light',
dark: 'dark',
acronis: 'acronis',
constructor: 'constructor',
virtuozzo: 'virtuozzo',
};
const ACV_THEME_LC_KEY = 'acv-theme';
export type ColorScheme = 'light' | 'dark';
export const ACV_THEME_LC_KEY = 'acv-color-scheme';

export function useColorScheme() {
const colorScheme = ref(localStorage.getItem(ACV_THEME_LC_KEY) || 'light');

const isDark = computed(() => colorScheme.value === 'dark');

const mode: any = useColorMode({
attribute: 'data-theme',
const mode = useColorMode({
attribute: 'class',
storageKey: ACV_THEME_LC_KEY,
modes: AVAILABLE_COLOR_SCHEMES,
modes: {
light: 'acv-color-scheme-light',
dark: 'acv-color-scheme-dark',
},
});
const colorScheme = computed(() => mode.value);
const isDark = computed(() => colorScheme.value === 'dark');

function setColorScheme(colorSchemeId: string) {
if (AVAILABLE_COLOR_SCHEMES[colorSchemeId]) {
mode.value = colorSchemeId;
colorScheme.value = colorSchemeId;
}
function setColorScheme(colorSchemeId: ColorScheme) {
mode.value = colorSchemeId;
}

return {
Expand Down
5 changes: 0 additions & 5 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ export default defineConfig(() => {
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@documentation': resolve(__dirname, '../../documentation'),
},
},
optimizeDeps: {
exclude: ['vitest/utils'],
include: ['@vitest/utils'],
},
plugins: [
vue(),
env.UI_BUILD && buildPlugin(),
Expand Down
21 changes: 11 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.