-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4bbfef
commit 21babd6
Showing
12 changed files
with
2,766 additions
and
1,713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { InitOptions } from '../type' | ||
import { PROJECT_TYPES } from '../utils/constants' | ||
import inquirer from 'inquirer' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import { execSync } from 'child_process' | ||
import getNpmType from '../utils/npmType' | ||
|
||
/** | ||
* 是否添加cui commitlit | ||
*/ | ||
const chooseEslintType = async () => { | ||
const { type } = await inquirer.prompt({ | ||
type: 'list', | ||
name: 'type', | ||
message: 'cui' as any, | ||
choices: PROJECT_TYPES, | ||
}) | ||
|
||
return type | ||
} | ||
|
||
const init = async (options: InitOptions) => { | ||
const npmType = await getNpmType | ||
|
||
const cwd = options?.cwd || process.cwd() | ||
const { cui } = options | ||
const config: Record<string, any> = {} | ||
|
||
// 初始化 commitlint | ||
config.cui = await chooseEslintType() | ||
const pkgPath = path.resolve(cwd, 'package.json') | ||
let pkg = JSON.parse(fs.readFileSync(pkgPath, { encoding: 'utf-8' })) | ||
pkg['scripts']['commit:lint'] = 'commitlint --edit' | ||
// 配置husky | ||
console.log('-------------开始安装husky') | ||
execSync(`${npmType} add husky -D`) | ||
console.log('------------------开始初始化husky') | ||
execSync('npx husky init') | ||
console.log('----------------开始配置hooks') | ||
execSync(`echo "${npmType} run commit:lint" > .husky/pre-commit`) | ||
console.log('---------------开始写入package') | ||
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)) | ||
console.log('完成') | ||
} | ||
|
||
export default init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PKG_NAME, PKG_VERSION } from '../utils/constants' | ||
import { execSync } from 'child_process' | ||
import getNpmType from '../utils/npmType' | ||
|
||
const checkLatestVersion = async () => { | ||
const npmType = await getNpmType | ||
const latestVersion = execSync(`${npmType} view ${PKG_NAME} version`) | ||
.toString('utf-8') | ||
.trim() | ||
return latestVersion | ||
} | ||
const update = async () => { | ||
try { | ||
const latestVersion = await checkLatestVersion() | ||
console.log('当前为最新版' + latestVersion) | ||
} catch (error) {} | ||
} | ||
|
||
export default update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 比较当前版本 | ||
// 获取当前版本 | ||
import { program } from 'commander' | ||
import { PKG_NAME, PKG_VERSION } from './utils/constants' | ||
import init from './actions/init' | ||
const cwd = process.cwd() | ||
program | ||
.version(PKG_VERSION) | ||
.description( | ||
`${PKG_NAME} 是 印客学院前端编码规范工程化 的配套 Lint 工具,提供简单的 CLI 和 Node.js API,让项目能够一键接入、一键扫描、一键修复、一键升级,并为项目配置 git commit 卡点,降低项目实施规范的成本` | ||
) | ||
|
||
program | ||
.command('init') | ||
.description( | ||
'一键接入:为项目初始化规范工具和配置,可以根据项目类型和需求进行定制' | ||
) | ||
.option('--vscode', '写入.vscode/setting.json配置') | ||
.action(async (cmd) => { | ||
await init({ | ||
cwd, | ||
}) | ||
}) | ||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
extends: ['@c1007568349/commitlint'], | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "yunxiang-cli", | ||
"version": "1.0.0", | ||
"description": "", | ||
"bin": "index.ts", | ||
"scripts": { | ||
"test": "ts-node cli.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/command-exists": "^1.2.3", | ||
"@types/node": "^22.1.0" | ||
}, | ||
"dependencies": { | ||
"@inquirer/type": "^1.5.1", | ||
"command-exists": "^1.2.9", | ||
"commander": "^12.1.0", | ||
"inquirer": "^10.1.6", | ||
"ora": "^8.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Visit https://aka.ms/tsconfig to read more about this file */ | ||
|
||
/* Language and Environment */ | ||
"target": "ES5" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, | ||
|
||
/* Modules */ | ||
"module": "commonjs" /* Specify what module code is generated. */, | ||
|
||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, | ||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ | ||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, | ||
|
||
/* Type Checking */ | ||
"strict": true /* Enable all strict type-checking options. */, | ||
|
||
"skipLibCheck": true /* Skip type checking all .d.ts files. */, | ||
"types": ["node"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export interface InitOptions { | ||
cwd?: string | ||
// // 是否检查并升级 encode-fe-lint 的版本 | ||
// checkVersionUpdate: boolean | ||
// // 是否需要自动重写 lint 配置 | ||
// rewriteConfig?: boolean | ||
// // eslint 类型 | ||
// eslintType?: string | ||
// // 是否启用 ESLint | ||
// enableESLint?: boolean | ||
// // 是否启用 stylelint | ||
// enableStylelint?: boolean | ||
// // 是否启用 markdownlint | ||
// enableMarkdownlint?: boolean | ||
// // 是否启用 prettier | ||
// enablePrettier?: boolean | ||
// // 是否禁用自动在初始化完成后安装依赖 | ||
// disableNpmInstall?: boolean | ||
// 是否使用cui | ||
cui?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
export const pkg = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8') | ||
) | ||
|
||
/** | ||
* 包名 | ||
*/ | ||
export const PKG_NAME: string = pkg.name | ||
|
||
/** | ||
* 包版本号 | ||
*/ | ||
export const PKG_VERSION: string = pkg.version | ||
|
||
/** | ||
* 项目类型 | ||
*/ | ||
export const PROJECT_TYPES: Array<{ name: string; value: string }> = [ | ||
{ | ||
name: '不使用cui', | ||
value: '1', | ||
}, | ||
{ | ||
name: '使用cui', | ||
value: '2', | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { sync as commandExistsSync } from 'command-exists' | ||
// pnpm 类型 | ||
const getNpmType: Promise<'npm' | 'pnpm'> = new Promise((resolve) => { | ||
if (!commandExistsSync('pnpm')) { | ||
return resolve('npm') | ||
} | ||
resolve('pnpm') | ||
}) | ||
export default getNpmType |
Oops, something went wrong.