Skip to content

Commit

Permalink
feat: add chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
yosion-p authored and ygj6 committed Jul 2, 2021
1 parent 03fffd1 commit e777da0
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 32 deletions.
222 changes: 201 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"dependencies": {
"@originjs/vue-sfc-ast-parser": "^1.0.0-beta0",
"chalk": "^4.1.1",
"commander": "^7.2.0",
"ejs": "^3.1.6",
"jscodeshift": "^0.12.0",
Expand Down
19 changes: 10 additions & 9 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path'
import fs from 'fs'
import chalk from 'chalk'
import { geneIndexHtml } from '../generate/geneIndexHtml'
import { genePackageJson } from '../generate/genePackageJson'
import { geneViteConfig } from '../generate/geneViteConfig'
Expand Down Expand Up @@ -30,11 +31,11 @@ export function run (): void {
}

export async function start (config : Config): Promise<void> {
console.log('******************* Webpack to Vite *******************')
console.log(`Project path: ${config.rootDir}`)
console.log(chalk.green('******************* Webpack to Vite:chalk *******************'))
console.log(chalk.green(`Project path: ${config.rootDir}`))

if (!fs.existsSync(config.rootDir)) {
console.error(`Project path is not correct : ${config.rootDir}`)
console.log(chalk.red(`Project path is not correct : ${config.rootDir}`))
return
}

Expand All @@ -49,19 +50,19 @@ export async function start (config : Config): Promise<void> {
// generate index.html must be after generate vite.config.js
geneIndexHtml(rootDir, config)

console.log('************************ Done ! ************************')
console.log(chalk.green('************************ Done ! ************************'))
const pkgManager = fs.existsSync(path.resolve(rootDir, 'yarn.lock'))
? 'yarn'
: 'npm'

console.log('Now please run:\n')
console.log(chalk.green('Now please run:\n'))
if (rootDir !== cwd) {
console.log(`cd ${path.relative(cwd, rootDir)}`)
console.log(chalk.green(`cd ${path.relative(cwd, rootDir)}`))
}

console.log(`${pkgManager === 'yarn' ? 'yarn' : 'npm install'}`)
console.log(
console.log(chalk.green(`${pkgManager === 'yarn' ? 'yarn' : 'npm install'}`))
console.log(chalk.green(
`${pkgManager === 'yarn' ? 'yarn serve-vite' : 'npm run serve-vite'}`
)
))
console.log()
}
5 changes: 3 additions & 2 deletions src/generate/genePackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { readSync, writeSync } from '../utils/file'
import { getVueVersion } from '../utils/version'
import path from 'path'
import chalk from 'chalk'
import * as constants from '../constants/constants'

// TODO: compatible with vue2 and vue3
export function genePackageJson (packageJsonPath: string): void {
const rootDir = path.dirname(packageJsonPath)
const source = readSync(packageJsonPath)
if (source === '') {
console.log(`read package.json error, path: ${rootDir}`)
console.log(chalk.red(`read package.json error, path: ${rootDir}`))
}

const packageJson = JSON.parse(source)
if (packageJson === '') {
console.log(`parse json error, path: ${rootDir}`)
console.log(chalk.red(`parse json error, path: ${rootDir}`))
}

const vueVersion = getVueVersion(rootDir)
Expand Down

0 comments on commit e777da0

Please sign in to comment.