feat(projects): 1.0 beta

This commit is contained in:
Soybean
2023-11-17 08:45:00 +08:00
parent 1ea4817f6a
commit e918a2c0f5
499 changed files with 15918 additions and 24708 deletions

View File

@ -0,0 +1,5 @@
import { rimraf } from 'rimraf';
export async function cleanup(paths: string[]) {
await rimraf(paths, { glob: true });
}

View File

@ -0,0 +1,75 @@
import path from 'node:path';
import { readFileSync } from 'node:fs';
import enquirer from 'enquirer';
import { bgRed, red, green } from 'kolorist';
import { execCommand } from '../shared';
import type { CliOption } from '../types';
interface PromptObject {
types: string;
scopes: string;
description: string;
}
export async function gitCommit(
gitCommitTypes: CliOption['gitCommitTypes'],
gitCommitScopes: CliOption['gitCommitScopes']
) {
const typesChoices = gitCommitTypes.map(([name, title]) => {
const nameWithSuffix = `${name}:`;
const message = `${nameWithSuffix.padEnd(12)}${title}`;
return {
name,
message
};
});
const scopesChoices = gitCommitScopes.map(([name, title]) => ({
name,
message: `${name.padEnd(30)} (${title})`
}));
const result = await enquirer.prompt<PromptObject>([
{
name: 'types',
type: 'select',
message: 'Please select a type',
choices: typesChoices
},
{
name: 'scopes',
type: 'select',
message: 'Please select a scope',
choices: scopesChoices
},
{
name: 'description',
type: 'text',
message: 'Please enter a description'
}
]);
const commitMsg = `${result.types}(${result.scopes}): ${result.description}`;
await execCommand('git', ['commit', '-m', commitMsg], { stdio: 'inherit' });
}
export async function gitCommitVerify() {
const gitPath = await execCommand('git', ['rev-parse', '--show-toplevel']);
const gitMsgPath = path.join(gitPath, '.git', 'COMMIT_EDITMSG');
const commitMsg = readFileSync(gitMsgPath, 'utf8').trim();
const REG_EXP = /(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
if (!REG_EXP.test(commitMsg)) {
throw new Error(
`${bgRed(' ERROR ')} ${red('git commit message must match the Conventional Commits standard!')}\n\n${green(
'Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org'
)}`
);
}
}

View File

@ -0,0 +1,5 @@
export * from './git-commit';
export * from './cleanup';
export * from './update-pkg';
export * from './prettier';
export * from './lint-staged';

View File

@ -0,0 +1,5 @@
export async function execLintStaged(config: Record<string, string | string[]>) {
const lintStaged = (await import('lint-staged')).default;
return lintStaged({ config, allowEmpty: true });
}

View File

@ -0,0 +1,7 @@
import { execCommand } from '../shared';
export async function prettierWrite(writeGlob: string[]) {
await execCommand('npx', ['prettier', '--write', '.', ...writeGlob], {
stdio: 'inherit'
});
}

View File

@ -0,0 +1,5 @@
import { execCommand } from '../shared';
export async function updatePkg(args: string[] = ['--deep', '-u']) {
execCommand('npx', ['ncu', ...args], { stdio: 'inherit' });
}