Skip to content

Commit

Permalink
tweak: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pei-pay committed Apr 13, 2024
1 parent 39e4e78 commit d20b226
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 75 deletions.
4 changes: 2 additions & 2 deletions meta/packages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PackageManifest } from '@vueyous/metadata';
import type { PackageManifest } from '@vueyous/metadata'

export const packages: PackageManifest[] = [
{
Expand Down Expand Up @@ -154,4 +154,4 @@ export const packages: PackageManifest[] = [
// ],
// iife: false,
// },
];
]
26 changes: 13 additions & 13 deletions packages/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { defineConfig } from 'vitepress';
import { defineConfig } from 'vitepress'

import { categoryNames, coreCategoryNames, metadata } from '../metadata/metadata';
import { categoryNames, coreCategoryNames, metadata } from '../metadata/metadata'

import viteConfig from './vite.config';
import viteConfig from './vite.config'

const Guide = [
{ text: 'はじめに', link: '/guide/' },
{ text: 'VueUseとは', link: '/guide/what-is-vueuse' },
{ text: '環境構築', link: '/guide/setup' },
];
]

const CoreCategories = coreCategoryNames.map(c => ({
text: c,
activeMatch: '___', // never active
link: `/functions#category=${c}`,
}));
}))

const DefaultSideBar = [
{ text: 'Guide', items: Guide },
{ text: 'Core Functions', items: CoreCategories },
];
]

const FunctionsSideBar = getFunctionsSideBar();
const FunctionsSideBar = getFunctionsSideBar()

// https://vitepress.dev/reference/site-config
export default defineConfig({
Expand Down Expand Up @@ -64,16 +64,16 @@ export default defineConfig({
},
// FIXME: any
vite: viteConfig as any,
});
})

function getFunctionsSideBar() {
const links: any = [];
const links: any = []

for (const name of categoryNames) {
if (name.startsWith('_'))
continue;
continue

const functions = metadata.functions.filter(i => i.category === name && !i.internal);
const functions = metadata.functions.filter(i => i.category === name && !i.internal)

links.push({
text: name,
Expand All @@ -84,8 +84,8 @@ function getFunctionsSideBar() {
link: name.startsWith('@')
? (functions[0].external || `/${functions[0].package}/README`)
: undefined,
});
})
}

return links;
return links
}
64 changes: 32 additions & 32 deletions packages/.vitepress/plugins/markdownTransform.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join, resolve } from 'node:path';
import type { Plugin } from 'vite';
import fs from 'fs-extra';
import { join, resolve } from 'node:path'
import type { Plugin } from 'vite'
import fs from 'fs-extra'
// import ts from 'typescript';
import { packages } from '../../../meta/packages';
import { functionNames, getFunction } from '../../../packages/metadata/metadata';
import { packages } from '../../../meta/packages'
import { functionNames, getFunction } from '../../../packages/metadata/metadata'
// import { getTypeDefinition, replacer } from '../../../scripts/utils';

export function MarkdownTransform(): Plugin {
Expand All @@ -18,31 +18,31 @@ export function MarkdownTransform(): Plugin {
enforce: 'pre',
async transform(code, id) {
if (!id.match(/\.md\b/))
return null;
return null

// linkify function names
code = code.replace(
new RegExp(`\`({${functionNames.join('|')}})\`(.)`, 'g'),
(_, name, ending) => {
if (ending === ']') // already a link
return _;
const fn = getFunction(name)!;
return `[\`${fn.name}\`](${fn.docs}) `;
return _
const fn = getFunction(name)!
return `[\`${fn.name}\`](${fn.docs}) `
},
);
)

// TODO: set link after deployed
// convert links to relative
// code = code.replace(/https?:\/\/vueuse\.org\//g, '/');

const [pkg, _name, i] = id.split('/').slice(-3);
const [pkg, _name, i] = id.split('/').slice(-3)

const name = functionNames.find(n => n.toLowerCase() === _name.toLowerCase()) || _name;
const name = functionNames.find(n => n.toLowerCase() === _name.toLowerCase()) || _name

if (functionNames.includes(name) && i === 'index.md') {
const frontmatterEnds = code.indexOf('---\n\n');
const firstHeader = code.search(/\n#{2,6}\s.+/);
const sliceIndex = firstHeader < 0 ? frontmatterEnds < 0 ? 0 : frontmatterEnds + 4 : firstHeader;
const frontmatterEnds = code.indexOf('---\n\n')
const firstHeader = code.search(/\n#{2,6}\s.+/)
const sliceIndex = firstHeader < 0 ? frontmatterEnds < 0 ? 0 : frontmatterEnds + 4 : firstHeader

// Insert JS/TS code blocks
// code = await replaceAsync(code, /\n```ts( [^\n]+)?\n(.+?)\n```\n/gs, async (_, meta = '', snippet = '') => {
Expand Down Expand Up @@ -73,32 +73,32 @@ export function MarkdownTransform(): Plugin {
// </CodeToggle>\n`;
// });

const { header } = await getFunctionMarkdown(pkg, name);
const { header } = await getFunctionMarkdown(pkg, name)

// if (hasTypes)
// code = replacer(code, footer, 'FOOTER', 'tail');
if (header)
code = code.slice(0, sliceIndex) + header + code.slice(sliceIndex);
code = code.slice(0, sliceIndex) + header + code.slice(sliceIndex)

code = code
.replace(/(# \w+?)\n/, `$1\n\n<FunctionInfo fn="${name}"/>\n`);
.replace(/(# \w+?)\n/, `$1\n\n<FunctionInfo fn="${name}"/>\n`)
// .replace(/## (Components?(?:\sUsage)?)/i, '## $1\n<LearnMoreComponents />\n\n')
// .replace(/## (Directives?(?:\sUsage)?)/i, '## $1\n<LearnMoreDirectives />\n\n');
}

return code;
return code
},
};
}
}

const DIR_SRC = resolve(__dirname, '../..');
const GITHUB_BLOB_URL = 'https://github.com/pei-pay/VueYous/blob/main/packages';
const DIR_SRC = resolve(__dirname, '../..')
const GITHUB_BLOB_URL = 'https://github.com/pei-pay/VueYous/blob/main/packages'

export async function getFunctionMarkdown(pkg: string, name: string) {
const URL = `${GITHUB_BLOB_URL}/${pkg}/${name}`;
const URL = `${GITHUB_BLOB_URL}/${pkg}/${name}`

const dirname = join(DIR_SRC, pkg, name);
const demoPath = ['demo.vue'].find(i => fs.existsSync(join(dirname, i)));
const dirname = join(DIR_SRC, pkg, name)
const demoPath = ['demo.vue'].find(i => fs.existsSync(join(dirname, i)))
// const types = await getTypeDefinition(pkg, name);

// if (!types)
Expand Down Expand Up @@ -128,9 +128,9 @@ export async function getFunctionMarkdown(pkg: string, name: string) {
['Docs', `${URL}/index.md`],
])
.filter(i => i)
.map(i => `[${i![0]}](${i![1]})`).join(' • ');
.map(i => `[${i![0]}](${i![1]})`).join(' • ')

const sourceSection = `## Source\n\n${links}\n`;
const sourceSection = `## Source\n\n${links}\n`
// const ContributorsSection = `
// ## Contributors

Expand All @@ -155,21 +155,21 @@ import Demo from \'./${demoPath}\'
<Demo/>
</DemoContainer>
`
: '';
: ''

const packageNote = packages.find(p => p.name === pkg)!.addon
? `Available in the <a href="/${pkg}/README">@vueyous/${pkg}</a> add-on.\n`
: '';
: ''

// const footer = `${typingSection}\n\n${sourceSection}\n${ContributorsSection}\n${changelogSection}\n`;
const footer = `${sourceSection}`;
const footer = `${sourceSection}`

const header = demoSection + packageNote;
const header = demoSection + packageNote

return {
footer,
header,
};
}
}

// function replaceAsync(str: string, match: RegExp, replacer: (substring: string, ...args: any[]) => Promise<string>) {
Expand Down
8 changes: 4 additions & 4 deletions packages/.vitepress/theme/components/DemoContainer.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { onErrorCaptured, ref } from 'vue';
import { onErrorCaptured, ref } from 'vue'
const error = ref<Error | null>(null);
const error = ref<Error | null>(null)
onErrorCaptured((err) => {
error.value = err;
});
error.value = err
})
</script>

<template>
Expand Down
18 changes: 9 additions & 9 deletions packages/.vitepress/theme/components/FunctionInfo.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<script setup lang="ts">
import { useTimeAgo } from '@vueuse/core';
import { computed } from 'vue';
import { functions } from '@vueyous/metadata';
import { useTimeAgo } from '@vueuse/core'
import { computed } from 'vue'
import { functions } from '@vueyous/metadata'
const props = defineProps<{ fn: string; }>();
const info = computed(() => functions.find(i => i.name === props.fn)!);
const lastUpdated = useTimeAgo(new Date(info.value?.lastUpdated || 0));
const link = computed(() => `/functions\#category=${encodeURIComponent(info.value!.category!)}`);
const props = defineProps<{ fn: string }>()
const info = computed(() => functions.find(i => i.name === props.fn)!)
const lastUpdated = useTimeAgo(new Date(info.value?.lastUpdated || 0))
const link = computed(() => `/functions\#category=${encodeURIComponent(info.value!.category!)}`)
// const exportSize = exportSizes[info.value!.name as keyof typeof exportSizes];
function getFunctionLink(fn: string) {
const info = functions.find(i => i.name === fn);
const info = functions.find(i => i.name === fn)
// TODO: set link after deploy
return info?.docs?.replace(/https?:\/\/vueuse\.org\//g, '/');
return info?.docs?.replace(/https?:\/\/vueuse\.org\//g, '/')
}
</script>

Expand Down
10 changes: 5 additions & 5 deletions packages/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DefaultTheme from 'vitepress/theme';
import DefaultTheme from 'vitepress/theme'

import './styles/main.css';
import './styles/demo.css';
import 'uno.css';
import './styles/main.css'
import './styles/demo.css'
import 'uno.css'

export default DefaultTheme;
export default DefaultTheme
12 changes: 6 additions & 6 deletions packages/.vitepress/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
import Components from 'unplugin-vue-components/vite';
import UnoCSS from 'unocss/vite';
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
import UnoCSS from 'unocss/vite'

import { MarkdownTransform } from './plugins/markdownTransform';
import { MarkdownTransform } from './plugins/markdownTransform'

export default defineConfig({
server: {
Expand Down Expand Up @@ -33,4 +33,4 @@ export default defineConfig({
},
dedupe: ['vue'],
},
});
})
2 changes: 1 addition & 1 deletion packages/core/useManualRefHistory/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ related: useRefHistory

Manually track the change history of a ref when the using calls `commit()`, also provides undo and redo functionality

## How to make
## How to make
2 changes: 1 addition & 1 deletion packages/shared/watchIgnorable/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ category: Watch
alias: ignorableWatch
---

# watchIgnorable
# watchIgnorable
4 changes: 2 additions & 2 deletions unocss.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
presetUno,
transformerDirectives,
transformerVariantGroup,
} from 'unocss';
} from 'unocss'

export default defineConfig({
shortcuts: {
Expand Down Expand Up @@ -33,4 +33,4 @@ export default defineConfig({
transformerDirectives(),
transformerVariantGroup(),
],
});
})

0 comments on commit d20b226

Please sign in to comment.