Skip to content

Commit

Permalink
refactor: 重构
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed May 21, 2019
1 parent e8cf6ae commit bd51cf0
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/taro-cli/src/rn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,7 @@ class Compiler {
.on('end', () => {
this.initProjectFile()
if (!fs.existsSync(path.join(this.tempPath, 'node_modules'))) {
console.log()
console.log(chalk.yellow('开始安装依赖~'))
process.chdir(this.tempPath)
let command
if (Util.shouldUseYarn()) {
command = 'yarn'
} else if (Util.shouldUseCnpm()) {
command = 'cnpm install'
} else {
command = 'npm install'
}
exec(command, (err, stdout, stderr) => {
if (err) reject()
else {
console.log(stdout)
console.log(stderr)
}
resolve()
})
return installDep(this.tempPath)
} else {
resolve()
}
Expand Down Expand Up @@ -299,6 +281,30 @@ class Compiler {
}
}

function installDep (path:string) {
return new Promise((resolve, reject) => {
console.log()
console.log(chalk.yellow('开始安装依赖~'))
process.chdir(path)
let command
if (Util.shouldUseYarn()) {
command = 'yarn'
} else if (Util.shouldUseCnpm()) {
command = 'cnpm install'
} else {
command = 'npm install'
}
exec(command, (err, stdout, stderr) => {
if (err) reject()
else {
console.log(stdout)
console.log(stderr)
}
resolve()
})
})
}

export { Compiler }

export async function build (appPath: string, buildConfig: IBuildConfig) {
Expand All @@ -324,7 +330,7 @@ export async function build (appPath: string, buildConfig: IBuildConfig) {
* @description run packager server
* copy from react-native/local-cli/runAndroid/runAndroid.js
*/
function startServerInNewWindow ({port = 8081,tempPath}) {
function startServerInNewWindow ({port = 8081, tempPath}) {
// set up OS-specific filenames and commands
const isWindows = /^win/.test(process.platform)
const scriptFile = isWindows
Expand Down

0 comments on commit bd51cf0

Please sign in to comment.