Skip to content

Commit

Permalink
fix(cli): fix generators files publish error
Browse files Browse the repository at this point in the history
affects: @varlet/cli
  • Loading branch information
haoziqaq committed Sep 9, 2021
1 parent 42905fe commit 29c014d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
7 changes: 0 additions & 7 deletions packages/varlet-cli/generators/sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
"Vue",
"UI"
],
"files": [
"es",
"umd",
"highlight",
"types",
"README.md"
],
"license": "MIT",
"scripts": {
"husky": "husky install",
Expand Down
7 changes: 0 additions & 7 deletions packages/varlet-cli/generators/tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
"Vue",
"UI"
],
"files": [
"es",
"umd",
"highlight",
"types",
"README.md"
],
"license": "MIT",
"scripts": {
"husky": "husky install",
Expand Down
10 changes: 9 additions & 1 deletion packages/varlet-cli/src/commands/gen.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import logger from '../shared/logger'
import inquirer from 'inquirer'
import { resolve } from 'path'
import { copy, pathExistsSync, readFileSync, writeFileSync } from 'fs-extra'
import { copy, pathExistsSync, readFileSync, writeFileSync, removeSync } from 'fs-extra'
import { CLI_PACKAGE_JSON, CWD, GENERATORS_DIR } from '../shared/constant'

function removeFiles(dest: string) {
const files = ['es', 'umd', 'highlight', 'types/index.d.ts', '.varlet', 'node_modules']

files.forEach((filename) => removeSync(resolve(dest, filename)))
}

function syncVersion(name: string) {
const file = resolve(CWD, name, 'package.json')
const pkg = JSON.parse(readFileSync(file, 'utf-8'))
const cliPkg = JSON.parse(readFileSync(CLI_PACKAGE_JSON, 'utf-8'))
pkg.devDependencies['@varlet/cli'] = `^${cliPkg.version}`
pkg.files = ['es', 'umd', 'highlight', 'types', 'README.md']
writeFileSync(file, JSON.stringify(pkg, null, 2))
}

Expand All @@ -30,6 +37,7 @@ export async function gen(name: string) {
const choice = ret['Please select your component library programming style']
const generator = resolve(GENERATORS_DIR, choice)
await copy(generator, dest)
removeFiles(dest)
syncVersion(name)

logger.success('Application generated successfully!')
Expand Down

0 comments on commit 29c014d

Please sign in to comment.