Skip to content

Commit

Permalink
feat: support cli
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jun 3, 2021
1 parent 579c0a7 commit af87343
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
50 changes: 50 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

const yParser = require('yargs-parser');
const semver = require('semver');
const { existsSync } = require('fs');
const { join } = require('path');
const chalk = require('chalk');

// print version and @local
const args = yParser(process.argv.slice(2));

if (args.v || args.version) {
// eslint-disable-next-line global-require
console.log(require('./package').version);
if (existsSync(join(__dirname, '.local'))) {
console.log(chalk.cyan('@local'));
}
process.exit(0);
}

if (!semver.satisfies(process.version, '>= 8.0.0')) {
console.error(chalk.red('✘ The generator will only work with Node v8.0.0 and up!'));
process.exit(1);
}
const cwd = process.cwd();

const option = args._[0];

switch (option) {
case 'verify-commit':
// eslint-disable-next-line global-require
require('./dist/verifyCommit')({ cwd, ...args });
break;

default:
if (args.h || args.help) {
const details = `
Commands:
${chalk.cyan('verify-commit')} 检查 commit 提交的信息
Examples:
${chalk.gray('fabric')}
pro -h
${chalk.gray('verify-commit ')}
pro verify-commit
`.trim();
console.log(details);
}
break;
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"design",
"pro"
],
"bin": {
"fabric": "./cli.js"
},
"homepage": "https://github.com/umijs/fabric#readme",
"bugs": {
"url": "https://github.com/umijs/fabric/issues"
Expand All @@ -22,7 +25,8 @@
"author": "qixian.cs@outlook.com",
"main": "dist/index.js",
"files": [
"dist"
"dist",
"cli.js"
],
"scripts": {
"build": "tsc --build tsconfig.json",
Expand Down
2 changes: 2 additions & 0 deletions src/verifyCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ if (!commitRE.test(msg)) {
process.exit(1);
});
}

export default () => {};

0 comments on commit af87343

Please sign in to comment.