neverland 3dcc92a5c0
chore: bump prettier v3 and format all code (#12111)
* chore: bump prettier v3 and format all code

* chore: mjs config

* chore: revert

* chore: revert

* chore: update lock
2023-07-22 14:14:14 +08:00

54 lines
1.1 KiB
TypeScript

import { execa } from 'execa';
import { consola, createSpinner } from '../common/logger.js';
import { SCRIPT_EXTS } from '../common/constant.js';
type RunCommandMessages = {
start: string;
succeed: string;
failed: string;
};
function runCommand(
cmd: string,
options: string[],
messages: RunCommandMessages,
) {
const spinner = createSpinner(messages.start).start();
return new Promise((resolve) => {
execa(cmd, options, {
preferLocal: true,
env: { FORCE_COLOR: 'true' },
})
.then(() => {
spinner.success({ text: messages.succeed });
resolve(true);
})
.catch((err: any) => {
spinner.error({ text: messages.failed });
consola.error(err.stderr || err.stdout);
resolve(false);
});
});
}
function eslint() {
return runCommand(
'eslint',
['./src', '--fix', '--ext', SCRIPT_EXTS.join(',')],
{
start: 'Running eslint...',
succeed: 'ESLint Passed.',
failed: 'ESLint failed!',
},
);
}
export async function lint() {
const eslintPassed = await eslint();
if (!eslintPassed) {
process.exit(1);
}
}