Skip to content

Commit

Permalink
[chore] Clear lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mantou132 committed Jan 3, 2024
1 parent 4d9152a commit ca27049
Show file tree
Hide file tree
Showing 29 changed files with 252 additions and 109 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,19 @@ module.exports = {
},
],
},
overrides: [
{
files: [
'**/*.js',
'**/*.test.ts',
'packages/gem-port/src/**/*.ts',
'packages/gem-examples/src/**/*.ts',
'packages/gem-devtools/src/scripts/*.ts',
'packages/gem/src/helper/logger.ts',
],
rules: {
'no-console': 'off',
},
},
],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "root",
"version": "1.6.5",
"scripts": {
"lint": "lerna exec -- tsc --noEmit && eslint . --ext .ts,.js",
"lint": "lerna exec --ignore @gemjs/config -- tsc --noEmit && eslint . --ext .ts,.js",
"test": "lerna exec --concurrency=1 --scope '{@mantou/gem,gem-book,duoyun-ui}' -- yarn test",
"release": "lerna version",
"prepare:build": "yarn --cwd packages/gem build && lerna exec --scope '{gem-analyzer,duoyun-ui,gem-book,gem-port}' -- yarn build",
Expand Down
1 change: 0 additions & 1 deletion packages/config/index.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/duoyun-ui/src/elements/base/wake-lock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**只要元素显示在屏幕内,屏幕就不会自动熄灭 */

import { GemElementOptions } from '@mantou/gem/lib/element';
import { logger } from '@mantou/gem/helper/logger';

import { DuoyunVisibleBaseElement } from './visible';

Expand All @@ -13,11 +14,9 @@ export function wakeLock(ele: DuoyunWakeLockBaseElement) {

// log
wakeLockPromise?.then((wakeLock) => {
// eslint-disable-next-line no-console
console.info('wake lock created!');
logger.info('wake lock created!');
wakeLock.addEventListener('release', () => {
// eslint-disable-next-line no-console
console.info('wake lock released!');
logger.info('wake lock released!');
});
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/elements/keyboard-access.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GemElement, html } from '@mantou/gem/lib/element';
import { adoptedStyle, customElement, attribute, part } from '@mantou/gem/lib/decorators';
import { createCSSSheet, css, styleMap } from '@mantou/gem/lib/utils';
import { logger } from '@mantou/gem/helper/logger';

import { hotkeys, HotKeyHandles, unlock } from '../lib/hotkeys';
import { isNotNullish } from '../lib/types';
Expand Down Expand Up @@ -115,8 +116,7 @@ export class DuoyunKeyboardAccessElement extends GemElement<State> {
const keydownHandles: HotKeyHandles = {
onLock: () => this.setState({ waiting: true }),
onUnlock: () => this.setState({ waiting: false }),
// eslint-disable-next-line no-console
onUncapture: () => console.warn('Un Capture!'),
onUncapture: () => logger.warn('Un Capture!'),
};

this.setState({
Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/elements/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@mantou/gem/lib/decorators';
import { GemElement, html, TemplateResult } from '@mantou/gem/lib/element';
import { createCSSSheet, css, LinkedList, LinkedListItem, styled, styleMap } from '@mantou/gem/lib/utils';
import { logger } from '@mantou/gem/helper/logger';

import { theme } from '../lib/theme';
import { blockContainer } from '../lib/styles';
Expand Down Expand Up @@ -129,8 +130,7 @@ export class DuoyunListElement extends GemElement<State> {
};

#log = (...args: any) => {
// eslint-disable-next-line no-console
this.debug && console.log(...args);
this.debug && logger.info(...args);
};

#isEnd = (direction: 0 | -1) => {
Expand Down
1 change: 0 additions & 1 deletion packages/duoyun-ui/src/lib/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ export function adjustRange([min, max]: number[], stepCount: number, units?: num
let u = unit;
for (let i = 0; ; i++) {
if (i > 100) {
// console.warn([min, max]);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/duoyun-ui/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Store, connect, updateStore, useStore } from '@mantou/gem/lib/store';
import { render, TemplateResult } from '@mantou/gem/lib/element';
import { NonPrimitive, cleanObject } from '@mantou/gem/lib/utils';
import { logger } from '@mantou/gem/helper/logger';

import { isNullish } from '../lib/types';

Expand Down Expand Up @@ -117,8 +118,7 @@ export async function forever<T>(callback: () => Promise<T>, interval = 1000): P
try {
return await callback();
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
logger.error(err);
await sleep(interval);
return forever(callback, interval);
}
Expand Down
1 change: 1 addition & 0 deletions packages/gem-book/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"jsdom": "^16.5.3",
"lodash": "^4.17.21",
"marked": "^10.0.0",
"chalk": "^2.4.2",
"mkdirp": "^1.0.4",
"parse-github-url": "^1.0.2",
"ts-loader": "^9.5.1",
Expand Down
1 change: 0 additions & 1 deletion packages/gem-book/public/custom-ws-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class WebSocketClient {
constructor(url) {
this.client = new WebSocket(url);
this.client.onerror = (error) => {
// eslint-disable-next-line no-console
console.error(error);
};
}
Expand Down
13 changes: 7 additions & 6 deletions packages/gem-book/src/bin/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import WebpackDevServer from 'webpack-dev-server';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import { GenerateSW } from 'workbox-webpack-plugin';
import chalk from 'chalk';

Check warning on line 10 in packages/gem-book/src/bin/builder.ts

View workflow job for this annotation

GitHub Actions / lint

'chalk' is defined but never used. Allowed unused vars must match /^_/u

import { BookConfig, CliUniqueConfig } from '../common/config';
import { STATS_FILE } from '../common/constant';

import { resolveLocalPlugin, resolveTheme, isURL, importObject } from './utils';
import { resolveLocalPlugin, resolveTheme, isURL, importObject, print } from './utils';

const publicDir = path.resolve(__dirname, '../public');
const entryDir = path.resolve(__dirname, process.env.GEM_BOOK_DEV ? '../src/website' : '../website');
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function startBuilder(dir: string, options: Required<CliUniqueConfi
const themePath = resolveTheme(theme);

const compiler = webpack({
stats: build ? 'normal' : 'errors-warnings',
mode: build ? 'production' : 'development',
entry: [entryDir],
module: {
Expand Down Expand Up @@ -122,7 +124,7 @@ export async function startBuilder(dir: string, options: Required<CliUniqueConfi
if (build) {
compiler.run((err, stats) => {
if (err) {
console.error(err.stack || err);
print(err);
return;
}

Expand All @@ -131,12 +133,12 @@ export async function startBuilder(dir: string, options: Required<CliUniqueConfi
const info = stats.toJson();

if (stats.hasErrors()) {
console.error(info.errors);
info.errors?.forEach((error) => print(Object.assign(new Error(error.message), { stack: error.stack })));
process.exit(1);
}

if (stats.hasWarnings()) {
console.warn(info.warnings);
info.errors?.forEach((warning) => print(warning.message));
}

if (debug) {
Expand Down Expand Up @@ -171,8 +173,7 @@ export async function startBuilder(dir: string, options: Required<CliUniqueConfi
);
server.startCallback((err) => {
if (err) {
// eslint-disable-next-line no-console
console.error(err);
print(err);
}
});

Expand Down
86 changes: 37 additions & 49 deletions packages/gem-book/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import path from 'path';
import fs from 'fs';

import program from 'commander';
import mkdirp from 'mkdirp';
import { sync } from 'mkdirp';
import getRepoInfo from 'git-repo-info';
import { throttle } from 'lodash';
import chalk from 'chalk';

import { version } from '../../package.json';
import { BookConfig, CliConfig, CliUniqueConfig, NavItem, SidebarConfig } from '../common/config';
Expand All @@ -27,7 +28,7 @@ import {
getMetadata,
isMdFile,
isSomeContent,
inspectObject,
print,
getRepoTitle,
checkRelativeLink,
readDirConfig,
Expand Down Expand Up @@ -79,7 +80,7 @@ async function syncConfig(fullPath?: string) {
}
});

if (cliConfig.debug) inspectObject(cliConfig);
if (cliConfig.debug) print(cliConfig);

obj.nav = obj.nav?.filter((e) => {
if (e.title?.toLowerCase() === 'github') {
Expand Down Expand Up @@ -229,15 +230,14 @@ async function generateBookConfig(dir: string) {
const configPath = path.resolve(cliConfig.output || dir, cliConfig.output.endsWith('.json') ? '' : DEFAULT_FILE);
const configStr = JSON.stringify(bookConfig, null, 2) + '\n';
if (!isSomeContent(configPath, configStr)) {
mkdirp.sync(path.dirname(configPath));
sync(path.dirname(configPath));
// Trigger rename event
fs.writeFileSync(configPath, configStr);
}
}

if (cliConfig.debug) inspectObject(bookConfig, 2);
// eslint-disable-next-line no-console
console.log(`${new Date().toISOString()} book config updated! ${Date.now() - t}ms`);
if (cliConfig.debug) print(bookConfig);
print(chalk.green(`[${new Date().toISOString()}]: book config updated! ${Date.now() - t}ms`));
}

program
Expand Down Expand Up @@ -337,35 +337,27 @@ program
await syncConfig(configPath);
await generateBookConfig(dir);

const updateBookConfig = throttle(
async () => {
await generateBookConfig(dir);
devServerEventTarget.dispatchEvent(
Object.assign(new Event(UPDATE_EVENT), {
detail: { config: bookConfig },
}),
);
},
100,
{ trailing: true },
);
const updateBookConfig = throttle(async () => {
await generateBookConfig(dir);
devServerEventTarget.dispatchEvent(
Object.assign(new Event(UPDATE_EVENT), {
detail: { config: bookConfig },
}),
);
}, 100);

const watchTheme = () => {
const themePath = resolveTheme(cliConfig.theme);
if (themePath) {
return fs.watch(
themePath,
throttle(
async () => {
devServerEventTarget.dispatchEvent(
Object.assign(new Event(UPDATE_EVENT), {
detail: { theme: await importObject(themePath) },
}),
);
},
100,
{ trailing: true },
),
throttle(async () => {
devServerEventTarget.dispatchEvent(
Object.assign(new Event(UPDATE_EVENT), {
detail: { theme: await importObject(themePath) },
}),
);
}, 100),
);
}
};
Expand All @@ -381,25 +373,21 @@ program
if (configPath) {
fs.watch(
configPath,
throttle(
async () => {
cliConfig = structuredClone(initCliOptions);
bookConfig = structuredClone(initBookConfig);
await syncConfig(configPath);
await generateBookConfig(dir);
await server?.stop();
server = await startBuilder(dir, cliConfig, bookConfig);
devServerEventTarget.dispatchEvent(
Object.assign(new Event(UPDATE_EVENT), {
detail: { config: bookConfig },
}),
);
themeWatcher?.close();
themeWatcher = watchTheme();
},
300,
{ trailing: true },
),
throttle(async () => {
cliConfig = structuredClone(initCliOptions);
bookConfig = structuredClone(initBookConfig);
await syncConfig(configPath);
await generateBookConfig(dir);
await server?.stop();
server = await startBuilder(dir, cliConfig, bookConfig);
devServerEventTarget.dispatchEvent(
Object.assign(new Event(UPDATE_EVENT), {
detail: { config: bookConfig },
}),
);
themeWatcher?.close();
themeWatcher = watchTheme();
}, 100),
);
}

Expand Down
Loading

0 comments on commit ca27049

Please sign in to comment.