Skip to content

Commit

Permalink
feat(projects): add unocss
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Mar 2, 2024
1 parent e5beae8 commit 86891d3
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 3 deletions.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default defineConfig(
solid: { files: ['**/*solid.tsx'] },
svelte: true,
astro: true,
unocss: true,
formatter: {
html: true,
css: true,
Expand Down
2 changes: 1 addition & 1 deletion example/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defineOptions({
</script>

<template>
<div></div>
<div class="text-12px text-#fff font-bold"></div>
</template>

<style scoped></style>
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"update-pkg": "soy ncu"
},
"peerDependencies": {
"@unocss/eslint-config": ">=0.58.0",
"eslint": ">=8.40.0",
"eslint-plugin-astro": ">=0.30.0",
"eslint-plugin-react": ">=7.0.0",
Expand All @@ -74,6 +75,9 @@
"@toml-tools/parser": {
"optional": true
},
"@unocss/eslint-config": {
"optional": true
},
"eslint-plugin-astro": {
"optional": true
},
Expand Down Expand Up @@ -141,6 +145,7 @@
"@types/prompts": "2.4.9",
"@types/react": "18.2.61",
"@types/react-dom": "18.2.19",
"@unocss/eslint-config": "0.58.5",
"astro": "4.4.9",
"eslint": "8.57.0",
"eslint-plugin-astro": "0.31.4",
Expand Down
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export * from './react';
export * from './solid';
export * from './svelte';
export * from './astro';
export * from './unocss';
export * from './prettier';
export * from './formatter';
12 changes: 12 additions & 0 deletions src/configs/unocss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ensurePackages, interopDefault } from '../shared';
import type { FlatConfigItem } from '../types';

export async function createUnocssConfig(enable?: boolean) {
if (!enable) return [];

await ensurePackages(['@unocss/eslint-config']);

const unocss = await interopDefault(import('@unocss/eslint-config'));

return [unocss as FlatConfigItem];
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
createSvelteConfig,
createTsConfig,
createUnicornConfig,
createUnocssConfig,
createVueConfig
} from './configs';
import { createOptions } from './options';
Expand All @@ -34,6 +35,7 @@ export async function defineConfig(options: Partial<Options> = {}, ...userConfig
const reactNative = await createReactNativeConfig(opts['react-native']);
const svelte = await createSvelteConfig(opts.svelte, opts.prettierRules);
const astro = await createAstroConfig(opts.astro);
const unocss = await createUnocssConfig(opts.unocss);
const prettier = await createPrettierConfig(opts.prettierRules);
const formatter = await createFormatterConfig(opts.formatter, opts.prettierRules);

Expand All @@ -52,6 +54,7 @@ export async function defineConfig(options: Partial<Options> = {}, ...userConfig
...solid,
...astro,
...svelte,
...unocss,
...userResolved,
...prettier,
...formatter
Expand Down
8 changes: 6 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ export interface BaseOptions {

export type Options = Partial<BaseOptions> & {
vue?: VueOptions | boolean;
} & OnDemandRuleOptions;
} & OnDemandRuleOptions & {
unocss?: boolean;
};

export type ParsedOptions = BaseOptions & {
vue?: RequiredVueOptions;
} & Partial<RequiredOnDemandRuleOptions>;
} & Partial<RequiredOnDemandRuleOptions> & {
unocss?: boolean;
};

export type {
FlatConfigItem,
Expand Down

0 comments on commit 86891d3

Please sign in to comment.