Skip to content

Commit

Permalink
fix: create-lib不再主动安装依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
xuasir committed Mar 6, 2021
1 parent 136420c commit 3fb09b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
3 changes: 1 addition & 2 deletions packages/create-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xus/create-lib",
"version": "0.1.2",
"version": "0.1.3",
"description": "xus cli cmd create",
"bin": {
"create-lib": "dist/cli.js",
Expand Down Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"chalk": "^4.1.0",
"enquirer": "^2.3.6",
"execa": "^5.0.0",
"log-symbols": "^4.0.0",
"ora": "^5.3.0",
"yargs-parser": "^20.2.6"
Expand Down
21 changes: 13 additions & 8 deletions packages/create-lib/src/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { prompt } from 'enquirer'
import { emptyDir, copy, getPkgManager, runCmd } from './utils'
import chalk from 'chalk'
import { emptyDir, copy, getPkgManager } from './utils'
import { Spinner } from './spinner'
import { join } from 'path'
import { join, relative } from 'path'
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs'

const BuiltInTemp = ['ts-lib', 'ts-lib-lerna']
Expand All @@ -14,6 +15,7 @@ const FileMap: Record<string, string> = {
const spinner = new Spinner()

export async function createTemp(args: { _: string[]; [key: string]: any }) {
const cwd = process.cwd()
let projectDir = args._.shift()
if (!projectDir) {
const { name } = await prompt<{ name: string }>({
Expand All @@ -25,7 +27,7 @@ export async function createTemp(args: { _: string[]; [key: string]: any }) {
projectDir = name
}

const root = join(process.cwd(), projectDir)
const root = join(cwd, projectDir)
if (!existsSync(root)) {
mkdirSync(root, { recursive: true })
} else {
Expand Down Expand Up @@ -85,9 +87,12 @@ export async function createTemp(args: { _: string[]; [key: string]: any }) {
spinner.succeed(`Create project succeed`)

const pkgManager = getPkgManager()
await runCmd(pkgManager, pkgManager === 'yarn' ? [] : ['install'], {
start: 'Install deps start',
succeed: 'Install deps succeed',
failed: 'Install deps failed'
})
console.log(`Done. ready to run:\n`)
if (cwd !== root) {
console.log(chalk.green(` cd ${relative(cwd, root)}`))
}
console.log(
chalk.green(` ${pkgManager === 'yarn' ? `yarn` : `npm install`}`)
)
console.log()
}
22 changes: 0 additions & 22 deletions packages/create-lib/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import execa from 'execa'
import {
mkdirSync,
readdirSync,
Expand Down Expand Up @@ -52,24 +51,3 @@ export type IRunCmdMessage = {
succeed: string
failed: string
}

export function runCmd(
cmd: string,
args: string[],
message: IRunCmdMessage,
options?: execa.Options
): Promise<boolean> {
spinner.start(message.start)
return new Promise((resolve, reject) => {
execa(cmd, args, options)
.then(() => {
spinner.succeed(message.succeed)
resolve(true)
})
.catch((err: any) => {
spinner.failed(message.failed)
error(err)
reject(false)
})
})
}
5 changes: 5 additions & 0 deletions xus.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
release: {
branch: 'main'
}
}

0 comments on commit 3fb09b8

Please sign in to comment.