Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import type { IApi } from 'father';
import { exec, execSync } from 'child_process';

// 检查是否已安装 npm 包
function checkNpmPackageInstalled(packageName: string) {
return new Promise((resolve) => {
exec(`npm list --depth=0 ${packageName}`, (error: Error) => {
resolve(!error);
});
});
}

export default (api: IApi) => {
// Compile break if export type without consistent
api.onStart(() => {
api.onStart(async () => {
if (api.name !== 'build') {
return;
}

const inputFolder =
api?.config?.esm?.input || api?.config?.esm?.input || 'src/';

const { execSync } = require('child_process');
try {
const isInstalled = await checkNpmPackageInstalled('eslint');
if (isInstalled) {
execSync(
`npx eslint ${inputFolder} --ext .tsx,.ts --rule '@typescript-eslint/consistent-type-exports: error'`,
{
Expand All @@ -21,7 +31,7 @@ export default (api: IApi) => {
encoding: 'utf-8',
},
);
} catch (error) {
} else {
console.log('ESLint is not installed, skip.');
}
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"strict": true,
"lib": ["ES2015"],
"skipLibCheck": true,
"esModuleInterop": true,
"baseUrl": "./"
Expand Down