Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): compiler standardization #839

Merged
merged 22 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Varlet is a Material design mobile component library developed based on `Vue3`,

```html
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/vue@next"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/@varlet/ui/umd/varlet.js"></script>
<script>
const app = Vue.createApp({
Expand Down Expand Up @@ -76,7 +76,7 @@ pnpm add @varlet/ui
import App from './App.vue'
import Varlet from '@varlet/ui'
import { createApp } from 'vue'
import '@varlet/ui/es/style.js'
import '@varlet/ui/es/style'

createApp(App).use(Varlet).mount('#app')
```
Expand Down
4 changes: 2 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Varlet 是一个基于 `Vue3` 开发的 Material 风格移动端组件库,全

```html
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/vue@next"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.jsdelivr.net/npm/@varlet/ui/umd/varlet.js"></script>
<script>
const app = Vue.createApp({
Expand Down Expand Up @@ -75,7 +75,7 @@ pnpm add @varlet/ui
import App from './App.vue'
import Varlet from '@varlet/ui'
import { createApp } from 'vue'
import '@varlet/ui/es/style.js'
import '@varlet/ui/es/style'

createApp(App).use(Varlet).mount('#app')
```
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"bootstrap": "pnpm install && node scripts/bootstrap.mjs",
"lint": "varlet-cli lint",
"changelog": "varlet-cli changelog",
"release": "node scripts/publish.mjs && varlet-cli release"
"release": "node scripts/release.mjs"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --allow-empty --concurrent false",
Expand Down Expand Up @@ -89,4 +89,4 @@
"engines": {
"pnpm": ">=7.9"
}
}
}
30 changes: 1 addition & 29 deletions packages/varlet-cli/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varle
If you want to insert other pages into the component library, you can create a `pages` folder in the project root directory to write a vue component to generate other pages.
The directory structure is as follows:

```js
```text
|-- varlet-ui
|-- src
|-- docs
Expand All @@ -77,7 +77,6 @@ The directory structure is as follows:
|-- zh-CN.ts
|-- en-US.ts
|-- index.vue

```

The resulting route is as follows:
Expand Down Expand Up @@ -197,30 +196,3 @@ varlet-cli create

- 1.`npm` repository registry must set to `npm` official mirror
- 2.Execute `npm login` to log in

### Module Compatible

Some external dependencies may need to be compatible with module syntax to achieve the purpose of compiling correctly to `commonjs` and `esmodule`. For example, the wording of `esmodule` of `dayjs` is

```js
import dayjs from 'dayjs/esm'
```

In order to build `commonjs`, the writing method is

```js
import * as dayjs from 'dayjs'
```

In the project, we embrace the first way of writing the `esmodule` module, and make the following configuration for adaptation

```js
// varlet.config.mjs
import { defineConfig } from '@varlet/cli'

export default defineConfig({
moduleCompatible: {
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
}
})
```
32 changes: 2 additions & 30 deletions packages/varlet-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ varlet-cli gen
如果想在组件库中插入其他页面,可以在项目根目录下的创建 `pages` 文件夹编写 vue 组件, 用来生成其他的页面。
目录结构如下:

```js
```text
|-- varlet-ui
|-- src
|-- docs
Expand All @@ -75,7 +75,6 @@ varlet-cli gen
|-- zh-CN.ts
|-- en-US.ts
|-- index.vue

```

生成的路由如下:
Expand Down Expand Up @@ -194,31 +193,4 @@ varlet-cli create
### 发布前注意

1. `npm` 的仓库源必须指向 `npm` 官方镜像
2. 执行 `npm login` 进行登录

### 模块适配对象

一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到 `commonjs` 和 `esmodule` 的目的,例如 `dayjs` 的 `esmodule` 写法是

```js
import dayjs from 'dayjs/esm'
```

而为了构建 `commonjs` 时的写法是

```js
import * as dayjs from 'dayjs'
```

在项目中我们拥抱 `esmodule` 模块使用第一种写法,并做如下配置进行适配

```js
// varlet.config.mjs
import { defineConfig } from '@varlet/cli'

export default defineConfig({
moduleCompatible: {
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
}
})
```
2. 执行 `npm login` 进行登录
241 changes: 119 additions & 122 deletions packages/varlet-cli/lib/node/bin.js
Original file line number Diff line number Diff line change
@@ -1,122 +1,119 @@
#!/usr/bin/env node
import fse from 'fs-extra';
import { Command } from 'commander';
import { CLI_PACKAGE_JSON } from './shared/constant.js';
const { readJSONSync } = fse;
const program = new Command();
program.version(`varlet-cli ${readJSONSync(CLI_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(async (options) => {
const { dev } = await import('./commands/dev.js');
return dev(options);
});
program
.command('build')
.description('Build varlet site for production')
.action(async () => {
const { build } = await import('./commands/build.js');
return build();
});
program
.command('build:vite')
.description('Use vite build app for production')
.action(async () => {
const { vite } = await import('./commands/vite.js');
return vite('build');
});
program
.command('dev:vite')
.description('Use vite start server for development')
.action(async () => {
const { vite } = await import('./commands/vite.js');
return vite('dev');
});
program
.command('preview')
.description('Preview varlet site for production')
.action(async () => {
const { preview } = await import('./commands/preview.js');
return preview();
});
program
.command('compile')
.description('Compile varlet components library code')
.option('-nu, --noUmd', 'Do not compile umd target code')
.action(async (options) => {
const { compile } = await import('./commands/compile.js');
return compile(options);
});
program
.command('lint')
.description('Lint code')
.action(async () => {
const { lint } = await import('./commands/lint.js');
return 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(async (options) => {
const { create } = await import('./commands/create.js');
return create(options);
});
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(async (option) => {
const { jest } = await import('./commands/jest.js');
return jest(option);
});
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(async (option) => {
const { gen } = await import('./commands/gen.js');
return gen(option);
});
program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(async (option) => {
const { changelog } = await import('./commands/changelog.js');
return changelog(option);
});
program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(async (option) => {
const { release } = await import('./commands/release.js');
return release(option);
});
program
.command('commit-lint <gitParams>')
.description('Lint commit message')
.action(async (option) => {
const { commitLint } = await import('./commands/commitLint.js');
return commitLint(option);
});
program.on('command:*', async ([cmd]) => {
const { default: logger } = await import('./shared/logger.js');
program.outputHelp();
logger.error(`\nUnknown command ${cmd}.\n`);
process.exitCode = 1;
});
program.parse();
#!/usr/bin/env node
import { Command } from 'commander';
import { getCliVersion } from './shared/fsUtils.js';
const program = new Command();
program.version(`varlet-cli ${getCliVersion()}`).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(async (options) => {
const { dev } = await import('./commands/dev.js');
return dev(options);
});
program
.command('build')
.description('Build varlet site for production')
.action(async () => {
const { build } = await import('./commands/build.js');
return build();
});
program
.command('build:vite')
.description('Use vite build app for production')
.action(async () => {
const { vite } = await import('./commands/vite.js');
return vite('build');
});
program
.command('dev:vite')
.description('Use vite start server for development')
.action(async () => {
const { vite } = await import('./commands/vite.js');
return vite('dev');
});
program
.command('preview')
.description('Preview varlet site for production')
.action(async () => {
const { preview } = await import('./commands/preview.js');
return preview();
});
program
.command('compile')
.description('Compile varlet components library code')
.action(async () => {
const { compile } = await import('./commands/compile.js');
return compile();
});
program
.command('lint')
.description('Lint code')
.action(async () => {
const { lint } = await import('./commands/lint.js');
return 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(async (options) => {
const { create } = await import('./commands/create.js');
return create(options);
});
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(async (option) => {
const { jest } = await import('./commands/jest.js');
return jest(option);
});
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(async (option) => {
const { gen } = await import('./commands/gen.js');
return gen(option);
});
program
.command('changelog')
.option('-rc --releaseCount <releaseCount>', 'Release count')
.option('-f --file <file>', 'Changelog filename')
.description('Generate changelog')
.action(async (option) => {
const { changelog } = await import('./commands/changelog.js');
return changelog(option);
});
program
.command('release')
.option('-r --remote <remote>', 'Remote name')
.description('Release all packages and generate changelogs')
.action(async (option) => {
const { release } = await import('./commands/release.js');
return release(option);
});
program
.command('commit-lint <gitParams>')
.description('Lint commit message')
.action(async (option) => {
const { commitLint } = await import('./commands/commitLint.js');
return commitLint(option);
});
program.on('command:*', async ([cmd]) => {
const { default: logger } = await import('./shared/logger.js');
program.outputHelp();
logger.error(`\nUnknown command ${cmd}.\n`);
process.exitCode = 1;
});
program.parse();
Loading