Skip to content

Commit

Permalink
feat(client): add declaration files for component
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Feb 22, 2025
1 parent 4db8e79 commit 081c40e
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 89 deletions.
2 changes: 0 additions & 2 deletions docs/src/.vuepress/components/MigrationTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ const click = (event: FormDataEvent) => {
if (typeof act === 'function') {
let text = act(source.value);
console.log(text);
if (typeof text !== 'string') {
text = JSON.stringify(text, null, '\t');
}
Expand Down
63 changes: 14 additions & 49 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { globals, hope, tsParser } from 'eslint-config-mister-hope';
import {
defaultNamingConventionRules,
globals,
hope,
} from 'eslint-config-mister-hope';
import { vue } from 'eslint-config-mister-hope/vue';
import reactRecommended from 'eslint-plugin-react/configs/recommended.js';

Expand All @@ -12,47 +16,18 @@ export default hope(
'**/.vuepress/utils/csv.js',
'example/**',
],
js: {
'no-console': 'off',
},
ts: {
rules: {
'no-console': 'off',
},
},
},
{
languageOptions: {
parserOptions: {
parser: tsParser,
tsconfigDirName: import.meta.dirname,
project: ['./tsconfig.eslint.json'],
extraFileExtensions: ['.vue'],
},
},
},
...vue(
{

...vue({
all: {
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allow',
},
{
selector: ['variable'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allowSingleOrDouble',
trailingUnderscore: 'allowSingleOrDouble',
},
{
selector: ['parameter'],
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: ['property'],
format: null,
Expand All @@ -62,36 +37,25 @@ export default hope(
},
filter: '(^\\/$|^/.*/$|^@|^[a-z]+(?:-[a-z]+)*?$)',
},
{
selector: ['property'],
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'import',
format: ['PascalCase', 'camelCase'],
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
...defaultNamingConventionRules,
],
},
{
sfc: {
'vue/block-lang': [
'error',
{
script: { lang: 'ts' },
},
],
},
),
}),

// @ts-expect-error: react plugin types
{
files: ['packages/admin/src/**/*.{js,jsx}'],

...reactRecommended,

languageOptions: {
...reactRecommended.languageOptions,
globals: {
Expand Down Expand Up @@ -140,6 +104,7 @@ export default hope(
rules: {
'@typescript-eslint/class-literal-property-style': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-console': 'off',
},
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"cross-env": "7.0.3",
"cz-conventional-changelog": "3.3.0",
"eslint": "9.20.1",
"eslint-config-mister-hope": "0.6.5",
"eslint-config-mister-hope": "0.7.5",
"eslint-plugin-react": "7.37.4",
"eslint-plugin-vue": "9.32.0",
"husky": "9.1.7",
Expand Down
11 changes: 6 additions & 5 deletions packages/admin/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ async function run() {
}
}),
]).then((token) => {
if (!token) {
return;
}
if (!token) return;

window.TOKEN = token;
sessionStorage.setItem('TOKEN', token);
});

await Promise.all([store.dispatch({ type: 'user/loadUserInfo' })]).catch(
(e) => {
console.error(e);
(err) => {
// eslint-disable-next-line no-console
console.error(err);
},
);

Expand All @@ -52,6 +52,7 @@ async function run() {
);
}

// eslint-disable-next-line no-console
console.log(
'%c @waline/admin %c v' + VERSION + ' ',
'color: white; background: #0078E7; padding:5px 0;',
Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/pages/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default function () {
? query.get('redirect')
: defaultRedirect;

console.log(redirect);
navigate(redirect.replace(/\/+/g, '/'));
}, [user]);

Expand Down
9 changes: 5 additions & 4 deletions packages/admin/src/pages/migration/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ export default function () {

alert(t('import success'));
location.reload();
} catch (e) {
console.log(e);
alert(e.message);
throw e;
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
alert(err.message);
throw err;
} finally {
setImportLoading(false);
e.target.value = null;
Expand Down
1 change: 1 addition & 0 deletions packages/admin/src/pages/profile/twoFactorAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function () {
setUpdating(true);
await updateProfile({ ['2fa']: '' }).catch((reason) => {
alert(reason);
// eslint-disable-next-line no-console
console.error(reason);
});
setUpdating(false);
Expand Down
1 change: 0 additions & 1 deletion packages/admin/src/pages/user/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function () {

useEffect(() => {
getUserList({ page: list.page }).then((data) => {
console.log(data);
setList({ ...list, ...data });
});
}, [list.page]);
Expand Down
6 changes: 5 additions & 1 deletion packages/client/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ export default [
},

// components declaration files
// TODO: Generate declaration files
{
input: './src/components/WalineComment.d.ts',
output: [{ file: './dist/components.d.ts', format: 'esm' }],
plugins: [dts({ compilerOptions: { preserveSymlinks: false } })],
},

// comment
{
Expand Down
33 changes: 19 additions & 14 deletions packages/client/src/components/ArticleReaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,31 @@ const votingIndex = ref(-1);
const voteNumbers = ref<number[]>([]);
const locale = computed(() => config.value.locale);
const isReactionEnabled = computed(() => config.value.reaction.length > 0);
const reaction = computed(() => {
const { reaction } = config.value;
const reactionsInfo = computed<ReactionItem[] | null>(() => {
const { reaction, path } = config.value;
if (!reaction.length) return null;
return reaction?.length ? reaction : null;
});
return reaction.map((icon, index) => ({
icon,
desc: locale.value[`reaction${index}` as keyof WalineReactionLocale],
active: reactionStorage.value[path] === index,
}));
const reactionsInfo = computed<ReactionItem[] | null>(() => {
const { path } = config.value;
return (
reaction.value?.map((icon, index) => ({
icon,
desc: locale.value[`reaction${index}` as keyof WalineReactionLocale],
active: reactionStorage.value[path] === index,
})) ?? null
);
});
let abort: (() => void) | undefined;
const fetchReaction = async (): Promise<void> => {
if (!isReactionEnabled.value) return;
const { serverURL, lang, path } = config.value;
if (!reaction.value) return;
const { serverURL, lang, path, reaction } = config.value;
const controller = new AbortController();
abort = controller.abort.bind(controller);
Expand All @@ -50,11 +55,11 @@ const fetchReaction = async (): Promise<void> => {
serverURL,
lang,
paths: [path],
type: reaction.map((_, index) => `reaction${index}`),
type: reaction.value.map((_, index) => `reaction${index}`),
signal: controller.signal,
})) as Record<string, number>[];
voteNumbers.value = reaction.map(
voteNumbers.value = reaction.value.map(
(_, index) => reactionData[`reaction${index}`],
);
};
Expand Down
33 changes: 33 additions & 0 deletions packages/client/src/components/WalineComment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-disable @typescript-eslint/no-empty-object-type */
import type {
ComponentOptionsMixin,
ComponentProvideOptions,
DefineComponent,
PublicProps,
} from 'vue';

import type { WalineProps } from '../typings/index.js';

declare const _default: DefineComponent<
WalineProps,
{},
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<WalineProps> & Readonly<{}>,
{},
{},
{},
{},
string,
ComponentProvideOptions,
false,
{},
HTMLDivElement
>;
export default _default;
1 change: 1 addition & 0 deletions packages/client/src/components/WalineComment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const getCommentData = (pageNumber: number): void => {
})
.catch((err: unknown) => {
if ((err as Error).name !== 'AbortError') {
// eslint-disable-next-line no-console
console.error((err as Error).message);
status.value = 'error';
}
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export const init = ({
let app: App<Element> | null = null;

if (root) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Some props design are bad
app = createApp(() => h(Waline, { path: state.path, ...props }));

app.mount(root);
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/utils/error.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const errorHandler = (err: Error): void => {
// eslint-disable-next-line no-console
if (err.name !== 'AbortError') console.error(err.message);
};
4 changes: 2 additions & 2 deletions packages/server/src/controller/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ module.exports = class extends BaseRest {
think.logger.debug(`Comment initial status is ${data.status}`);

if (data.status === 'approved') {
const spam = await akismet(data, this.ctx.serverURL).catch((e) =>
console.log(e),
const spam = await akismet(data, this.ctx.serverURL).catch((err) =>
console.log(err),
); // ignore akismet error

if (spam === true) {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ module.exports = class extends BaseRest {
{ url: apiUrl },
),
});
} catch (e) {
console.log(e);
} catch (err) {
console.log(err);

return this.fail(
this.locale(
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/extend/think.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ module.exports = {
);

return address.slice(0, depth).join(' ');
} catch (e) {
console.log(e);
} catch (err) {
console.log(err);

return '';
}
Expand Down
Loading

0 comments on commit 081c40e

Please sign in to comment.