Skip to content

Commit

Permalink
feat(cli): add defineConfig for type helper (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz authored Oct 13, 2022
1 parent d99cef8 commit 84579f4
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 207 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ packages/varlet-cli/site/pc/*.routes.ts
packages/varlet-cli/site/pc/routes.ts
packages/varlet-cli/site/site.config.json
packages/varlet-cli/site/*.site.config.json
packages/varlet-cli/lib/bin.d.ts

packages/varlet-ui/site
packages/varlet-ui/lib
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-cli/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Also refer to `@varlet/ui` [varlet.config.js](https://github.com/varletjs/varlet
| -- | -------------- | -------- | ---------- |
| `name` | The full name of the component library, which will be used as the package name | _string_ | `Varlet` |
| `namespace` | Component library namespace, which will be used as a component prefix | _string_ | `var` |
| `host` | Development server host | _number_ | `localhost` |
| `host` | Development server host | _string_ | `localhost` |
| `port` | Development server port | _number_ | `8080` |
| `title` | The title of the component library in the documentation | _string_ | `VARLET` |
| `logo` | The logo of the component library in the documentation | _string_ | `-` |
Expand Down
2 changes: 1 addition & 1 deletion packages/varlet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ varlet-cli gen
| ----- | -------------- | -------- | ---------- |
| `name` | 组件库全名,会作为包名 | _string_ | `Varlet` |
| `namespace` | 组件库命名空间, 会作为组件前缀 | _string_ | `var` |
| `host` | 开发服务器主机 | _number_ | `localhost` |
| `host` | 开发服务器主机 | _string_ | `localhost` |
| `port` | 开发服务器端口 | _number_ | `8080` |
| `title` | 文档中组件库的标题 | _string_ | `VARLET` |
| `logo` | 文档中组件库的logo | _string_ | `-` |
Expand Down
102 changes: 102 additions & 0 deletions packages/varlet-cli/lib/bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = __importDefault(require("./shared/logger"));
var commander_1 = require("commander");
var dev_1 = require("./commands/dev");
var build_1 = require("./commands/build");
var vite_1 = require("./commands/vite");
var compile_1 = require("./commands/compile");
var create_1 = require("./commands/create");
var jest_1 = require("./commands/jest");
var lint_1 = require("./commands/lint");
var gen_1 = require("./commands/gen");
var preview_1 = require("./commands/preview");
var changelog_1 = require("./commands/changelog");
var release_1 = require("./commands/release");
var commitLint_1 = require("./commands/commitLint");
var program = new commander_1.Command();
program.version("varlet-cli ".concat(require('../package.json').version)).usage('<command> [options]');
program
.command('dev')
.option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
.description('Run varlet development environment')
.action(dev_1.dev);
program.command('build').description('Build varlet site for production').action(build_1.build);
program
.command('build:vite')
.description('Use vite build app for production')
.action(function () { return (0, vite_1.vite)('build'); });
program
.command('dev:vite')
.description('Use vite start server for development')
.action(function () { return (0, vite_1.vite)('dev'); });
program.command('preview').description('Preview varlet site for production').action(preview_1.preview);
program
.command('compile')
.description('Compile varlet components library code')
.option('-nu, --noUmd', 'Do not compile umd target code')
.action(compile_1.compile);
program.command('lint').description('Lint code').action(lint_1.lint);
program
.command('create')
.description('Create a component directory')
.option('-n, --name <componentName>', 'Component name')
.option('-s, --sfc', 'Generate files in sfc format')
.option('-t, --tsx', 'Generate files in tsx format')
.option('-l, --locale', 'Generator internationalized files')
.action(create_1.create);
program
.command('jest')
.description('Run Jest in work directory')
.option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
.option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
.option('-c, --component <componentName>', 'Test a specific component')
.option('-cc --clearCache', 'Clear test cache')
.action(jest_1.jest);
program
.command('gen')
.description('Generate cli application')
.option('-n, --name <applicationName>', 'Application name')
.option('-s, --sfc', 'Generate files in sfc format')
.option('-t, --tsx', 'Generate files in tsx format')
.option('-l, --locale', 'Generator internationalized files')
.action(gen_1.gen);
program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(changelog_1.changelog);
program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(release_1.release);
program.command('commit-lint <gitParams>').description('Lint commit message').action(commitLint_1.commitLint);
program.on('command:*', function (_a) {
var _b = __read(_a, 1), cmd = _b[0];
program.outputHelp();
logger_1.default.error("\nUnknown command ".concat(cmd, ".\n"));
process.exitCode = 1;
});
program.parse();
103 changes: 3 additions & 100 deletions packages/varlet-cli/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,5 @@
#!/usr/bin/env node
"use strict";
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var logger_1 = __importDefault(require("./shared/logger"));
var commander_1 = require("commander");
var dev_1 = require("./commands/dev");
var build_1 = require("./commands/build");
var vite_1 = require("./commands/vite");
var compile_1 = require("./commands/compile");
var create_1 = require("./commands/create");
var jest_1 = require("./commands/jest");
var lint_1 = require("./commands/lint");
var gen_1 = require("./commands/gen");
var preview_1 = require("./commands/preview");
var changelog_1 = require("./commands/changelog");
var release_1 = require("./commands/release");
var commitLint_1 = require("./commands/commitLint");
var program = new commander_1.Command();
program.version("varlet-cli ".concat(require('../package.json').version)).usage('<command> [options]');
program
.command('dev')
.option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
.description('Run varlet development environment')
.action(dev_1.dev);
program.command('build').description('Build varlet site for production').action(build_1.build);
program
.command('build:vite')
.description('Use vite build app for production')
.action(function () { return (0, vite_1.vite)('build'); });
program
.command('dev:vite')
.description('Use vite start server for development')
.action(function () { return (0, vite_1.vite)('dev'); });
program.command('preview').description('Preview varlet site for production').action(preview_1.preview);
program
.command('compile')
.description('Compile varlet components library code')
.option('-nu, --noUmd', 'Do not compile umd target code')
.action(compile_1.compile);
program.command('lint').description('Lint code').action(lint_1.lint);
program
.command('create')
.description('Create a component directory')
.option('-n, --name <componentName>', 'Component name')
.option('-s, --sfc', 'Generate files in sfc format')
.option('-t, --tsx', 'Generate files in tsx format')
.option('-l, --locale', 'Generator internationalized files')
.action(create_1.create);
program
.command('jest')
.description('Run Jest in work directory')
.option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
.option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
.option('-c, --component <componentName>', 'Test a specific component')
.option('-cc --clearCache', 'Clear test cache')
.action(jest_1.jest);
program
.command('gen')
.description('Generate cli application')
.option('-n, --name <applicationName>', 'Application name')
.option('-s, --sfc', 'Generate files in sfc format')
.option('-t, --tsx', 'Generate files in tsx format')
.option('-l, --locale', 'Generator internationalized files')
.action(gen_1.gen);
program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(changelog_1.changelog);
program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(release_1.release);
program.command('commit-lint <gitParams>').description('Lint commit message').action(commitLint_1.commitLint);
program.on('command:*', function (_a) {
var _b = __read(_a, 1), cmd = _b[0];
program.outputHelp();
logger_1.default.error("\nUnknown command ".concat(cmd, ".\n"));
process.exitCode = 1;
});
program.parse();
exports.defineConfig = void 0;
var varlet_config_1 = require("./config/varlet.config");
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return varlet_config_1.defineConfig; } });
6 changes: 4 additions & 2 deletions packages/varlet-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "2.0.0",
"description": "cli of varlet",
"bin": {
"varlet-cli": "./lib/index.js"
"varlet-cli": "./lib/bin.js"
},
"main": "./lib/index.js",
"module": "./lib/index.js",
"keywords": [
"cli",
"varlet"
Expand Down Expand Up @@ -93,4 +95,4 @@
"vue": "3.2.25",
"vue-router": "4.0.12"
}
}
}
97 changes: 97 additions & 0 deletions packages/varlet-cli/src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env node
import logger from './shared/logger'
import { Command } from 'commander'
import { dev } from './commands/dev'
import { build } from './commands/build'
import { vite } from './commands/vite'
import { compile } from './commands/compile'
import { create } from './commands/create'
import { jest } from './commands/jest'
import { lint } from './commands/lint'
import { gen } from './commands/gen'
import { preview } from './commands/preview'
import { changelog } from './commands/changelog'
import { release } from './commands/release'
import { commitLint } from './commands/commitLint'

const program = new Command()

program.version(`varlet-cli ${require('../package.json').version}`).usage('<command> [options]')

program
.command('dev')
.option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
.description('Run varlet development environment')
.action(dev)

program.command('build').description('Build varlet site for production').action(build)

program
.command('build:vite')
.description('Use vite build app for production')
.action(() => vite('build'))

program
.command('dev:vite')
.description('Use vite start server for development')
.action(() => vite('dev'))

program.command('preview').description('Preview varlet site for production').action(preview)

program
.command('compile')
.description('Compile varlet components library code')
.option('-nu, --noUmd', 'Do not compile umd target code')
.action(compile)

program.command('lint').description('Lint code').action(lint)

program
.command('create')
.description('Create a component directory')
.option('-n, --name <componentName>', 'Component name')
.option('-s, --sfc', 'Generate files in sfc format')
.option('-t, --tsx', 'Generate files in tsx format')
.option('-l, --locale', 'Generator internationalized files')
.action(create)

program
.command('jest')
.description('Run Jest in work directory')
.option('-w, --watch', 'Watch files for changes and rerun tests related to changed files')
.option('-wa, --watchAll', 'Watch files for changes and rerun all tests when something changes')
.option('-c, --component <componentName>', 'Test a specific component')
.option('-cc --clearCache', 'Clear test cache')
.action(jest)

program
.command('gen')
.description('Generate cli application')
.option('-n, --name <applicationName>', 'Application name')
.option('-s, --sfc', 'Generate files in sfc format')
.option('-t, --tsx', 'Generate files in tsx format')
.option('-l, --locale', 'Generator internationalized files')
.action(gen)

program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(changelog)

program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(release)

program.command('commit-lint <gitParams>').description('Lint commit message').action(commitLint)

program.on('command:*', ([cmd]) => {
program.outputHelp()
logger.error(`\nUnknown command ${cmd}.\n`)
process.exitCode = 1
})

program.parse()
Loading

0 comments on commit 84579f4

Please sign in to comment.