Skip to content

Commit

Permalink
tweak: delete unnecessary codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pei-pay committed Apr 13, 2024
1 parent d20b226 commit beef172
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 333 deletions.
140 changes: 2 additions & 138 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';

Check failure on line 1 in meta/packages.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

export const packages: PackageManifest[] = [
{
Expand All @@ -18,140 +18,4 @@ export const packages: PackageManifest[] = [
display: 'VueYous',
description: 'Collection of essential Vue Composition Utilities',
},
// {
// name: 'components',
// display: 'Components',
// description: 'Renderless components for VueUse',
// author: 'Jacob Clevenger<https://github.com/wheatjs>',
// external: [
// '@vueuse/core',
// '@vueuse/shared',
// ],
// },
// {
// name: 'math',
// display: 'Math',
// description: 'Math functions for VueUse',
// external: [
// '@vueuse/shared',
// ],
// },
// {
// name: 'nuxt',
// display: 'Nuxt',
// description: 'VueUse Nuxt Module',
// manualImport: true,
// addon: true,
// iife: false,
// cjs: false,
// utils: true,
// target: 'node14',
// external: [
// '@vueuse/core',
// '@vueuse/shared',
// '@nuxt/kit',
// 'local-pkg',
// 'fs',
// 'path',
// 'url',
// 'node:fs',
// 'node:path',
// 'node:url',
// ],
// },
// {
// name: 'router',
// display: 'Router',
// description: 'Utilities for vue-router',
// addon: true,
// external: [
// 'vue-router',
// ],
// globals: {
// 'vue-router': 'VueRouter',
// },
// },
// {
// name: 'integrations',
// display: 'Integrations',
// description: 'Integration wrappers for utility libraries',
// addon: true,
// submodules: true,
// external: [
// 'axios',
// 'universal-cookie',
// 'qrcode',
// 'http',
// 'nprogress',
// 'jwt-decode',
// 'focus-trap',
// 'change-case',
// 'drauu',
// '@vueuse/core',
// '@vueuse/shared',
// 'fuse.js',
// 'async-validator',
// 'idb-keyval',
// 'sortablejs',
// 'node:http',
// ],
// globals: {
// 'axios': 'axios',
// 'universal-cookie': 'UniversalCookie',
// 'qrcode': 'QRCode',
// 'nprogress': 'nprogress',
// 'jwt-decode': 'jwt_decode',
// 'focus-trap': 'focusTrap',
// 'drauu': 'Drauu',
// 'fuse.js': 'Fuse',
// 'change-case': 'changeCase',
// 'async-validator': 'AsyncValidator',
// 'idb-keyval': 'idbKeyval',
// 'sortablejs': 'Sortable',
// },
// },
// {
// name: 'rxjs',
// display: 'RxJS',
// description: 'Enables RxJS reactive functions in Vue',
// addon: true,
// external: [
// 'rxjs',
// 'rxjs/operators',
// ],
// globals: {
// 'rxjs': 'rxjs',
// 'rxjs/operators': 'rxjs.operator',
// },
// },
// {
// name: 'firebase',
// display: 'Firebase',
// description: 'Enables realtime bindings for Firebase',
// addon: true,
// submodules: true,
// external: [
// 'firebase',
// 'firebase/app',
// 'firebase/database',
// 'firebase/firestore',
// ],
// globals: {
// 'firebase': 'firebase',
// 'firebase/app': 'firebase',
// 'firebase/database': 'firebase',
// 'firebase/firestore': 'firebase',
// },
// },
// {
// name: 'electron',
// display: 'Electron',
// description: 'Electron renderer process modules for VueUse',
// author: 'Archer Gu<https://github.com/ArcherGu>',
// addon: true,
// external: [
// 'electron',
// ],
// iife: false,
// },
]
];

Check failure on line 21 in meta/packages.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
66 changes: 32 additions & 34 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';

Check failure on line 1 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
import type { Plugin } from 'vite';

Check failure on line 2 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
import fs from 'fs-extra';

Check failure on line 3 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
// import ts from 'typescript';
import { packages } from '../../../meta/packages'
import { functionNames, getFunction } from '../../../packages/metadata/metadata'
import { packages } from '../../../meta/packages';

Check failure on line 5 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
import { functionNames, getFunction } from '../../../packages/metadata/metadata';

Check failure on line 6 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
// 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;

Check failure on line 21 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon

// 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 _;

Check failure on line 28 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
const fn = getFunction(name)!;

Check failure on line 29 in packages/.vitepress/plugins/markdownTransform.ts

View workflow job for this annotation

GitHub Actions / lint

Extra semicolon
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,30 @@ 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(/## (Components?(?:\sUsage)?)/i, '## $1\n<LearnMoreComponents />\n\n')
// .replace(/## (Directives?(?:\sUsage)?)/i, '## $1\n<LearnMoreDirectives />\n\n');
.replace(/(# \w+?)\n/, `$1\n\n<FunctionInfo fn="${name}"/>\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 +126,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 +153,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
29 changes: 9 additions & 20 deletions packages/.vitepress/theme/components/FunctionInfo.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
<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 exportSize = exportSizes[info.value!.name as keyof typeof exportSizes];
function getFunctionLink(fn: string) {
const info = functions.find(i => i.name === fn)
// TODO: set link after deploy
return info?.docs?.replace(/https?:\/\/vueuse\.org\//g, '/')
}
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!)}`);
</script>

<template>
Expand All @@ -23,10 +15,6 @@ function getFunctionLink(fn: string) {
Category
</div>
<div><a :href="link">{{ info.category }}</a></div>
<!-- <div opacity="50">
Export Size
</div>
<div> {{ exportSize }}</div> -->
<template v-if="info.package !== 'core' && info.package !== 'shared'">
<div opacity="50">
Package
Expand All @@ -52,7 +40,8 @@ function getFunctionLink(fn: string) {
Related
</div>
<div flex="~ gap-1 wrap">
<a v-for="(name, idx) of info.related" :key="idx" class="!py-0" :href="getFunctionLink(name)">
<!-- TODO: add link -->
<a v-for="(name, idx) of info.related" :key="idx" class="!py-0" href="">
<code>{{ name }}</code>
</a>
</div>
Expand Down
24 changes: 11 additions & 13 deletions packages/metadata/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PackageIndexes } from './types'
import _metadata, { categories as _categories, functions as _functions, packages as _packages } from './index.json'
import type { PackageIndexes } from './types';
import _metadata, { categories as _categories, functions as _functions, packages as _packages } from './index.json';

const categoriesOrder = [
'State',
Expand All @@ -14,22 +14,20 @@ const categoriesOrder = [
'Array',
'Time',
'Utilities',
]
];

export const metadata = _metadata as PackageIndexes
export const functions = _functions as PackageIndexes['functions']
export const packages = _packages as PackageIndexes['packages']
export const categories = _categories as PackageIndexes['categories']
export const metadata = _metadata as PackageIndexes;
export const functions = _functions as PackageIndexes['functions'];
export const packages = _packages as PackageIndexes['packages'];
export const categories = _categories as PackageIndexes['categories'];

export const functionNames = functions.map(f => f.name)
export const functionNames = functions.map(f => f.name);
export const categoryNames = Array.from(categories)
.sort((a, b) => categoriesOrder.indexOf(a) - categoriesOrder.indexOf(b))
.sort((a, b) => a.startsWith('@') ? 1 : b.startsWith('@') ? -1 : 0)
.sort((a, b) => a.startsWith('@') ? 1 : b.startsWith('@') ? -1 : 0);
export const coreCategoryNames = categoryNames
.filter(f => !f.startsWith('@'))
// export const addonCategoryNames = categoryNames
// .filter(f => f.startsWith('@'));
.filter(f => !f.startsWith('@'));

export function getFunction(name: string) {
return metadata.functions.find(f => f.name === name)
return metadata.functions.find(f => f.name === name);
}
Loading

0 comments on commit beef172

Please sign in to comment.