Skip to content

Commit

Permalink
feat(cli): add preview command that can preview document site for pro…
Browse files Browse the repository at this point in the history
…duction

affects: @varlet/cli, @varlet/ui
  • Loading branch information
haoziqaq committed Sep 26, 2021
1 parent 3ee3548 commit 3fea1f1
Show file tree
Hide file tree
Showing 7 changed files with 485 additions and 26 deletions.
2 changes: 2 additions & 0 deletions packages/varlet-cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ 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");
commander_1.version("varlet-cli " + require('../package.json').version).usage('<command> [options]');
commander_1.command('dev')
.option('-f --force', 'Force dep pre-optimization regardless of whether deps have changed')
.description('Run varlet development environment')
.action(dev_1.dev);
commander_1.command('build').description('Build varlet site for production').action(build_1.build);
commander_1.command('preview').description('Preview varlet site for production').action(preview_1.preview);
commander_1.command('compile')
.description('Compile varlet components library code')
.option('-nu, --noUmd', 'Do not compile umd target code')
Expand Down
3 changes: 2 additions & 1 deletion packages/varlet-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"vite": "^2.6.0-beta.2",
"@vitejs/plugin-vue": "1.9.2",
"@vitejs/plugin-vue-jsx": "1.1.8",
"@vue/compiler-sfc": "3.2.16"
"@vue/compiler-sfc": "3.2.16",
"live-server": "^1.2.1"
},
"devDependencies": {
"@types/babel__core": "^7.1.12",
Expand Down
17 changes: 17 additions & 0 deletions packages/varlet-cli/src/commands/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logger from '../shared/logger'
import execa from 'execa'
import { SITE_OUTPUT_PATH } from '../shared/constant'
import { pathExistsSync } from 'fs-extra'

export async function preview() {
if (!pathExistsSync(SITE_OUTPUT_PATH)) {
logger.warning('Cannot find the site folder, you must first run the build command to build the document site')
return
}

try {
execa.command('live-server --port=5500', { cwd: SITE_OUTPUT_PATH }).stdout?.pipe(process.stdout)
} catch (e) {
logger.error(e)
}
}
3 changes: 3 additions & 0 deletions packages/varlet-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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'

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

Expand All @@ -18,6 +19,8 @@ command('dev')

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

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

command('compile')
.description('Compile varlet components library code')
.option('-nu, --noUmd', 'Do not compile umd target code')
Expand Down
1 change: 1 addition & 0 deletions packages/varlet-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"scripts": {
"dev": "varlet-cli dev",
"build": "varlet-cli build",
"preview": "varlet-cli preview",
"compile": "varlet-cli compile",
"create": "varlet-cli create",
"test": "varlet-cli jest",
Expand Down
4 changes: 2 additions & 2 deletions packages/varlet-ui/src/table/example/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<var-table>
<thead>
<tr>
<th style="padding: 16px 8px">
<th>
<var-checkbox :model-value="isAllCheck" @change="handleAllCheckChange" />
</th>
<th>{{ pack.name }}</th>
Expand All @@ -46,7 +46,7 @@
</thead>
<tbody>
<tr v-for="item in data" :key="item.nameValue">
<td style="padding: 16px 8px">
<td>
<var-checkbox v-model="item.isCheck" />
</td>
<td>{{ item.name[item.nameValue] }}</td>
Expand Down
Loading

0 comments on commit 3fea1f1

Please sign in to comment.