Skip to content

Commit 8ae909e

Browse files
committed
feat: install template dependencies
1 parent 28028ed commit 8ae909e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/getTemplate/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const { isAbsolute } = require('path')
22
const semver = require('semver')
33
const git = require('simple-git/promise')
44

5+
56
const throwError = require('../throwError')
67
const log = require('../log')
78
const { isRepo } = require('../utils')
9+
const installDeps = require('./installDeps')
810

911
const copy = require('./copy')
1012
const clone = require('./clone')
@@ -18,6 +20,8 @@ module.exports = async (path, storage, version) => {
1820
if (isAbsolute(path)) await copy(path, storage)
1921
else await clone(path, storage)
2022

23+
let revert = () => {}
24+
2125
if (await isRepo(storage)) {
2226
const gitT = git(storage)
2327
let tags = await gitT.tags()
@@ -46,6 +50,10 @@ module.exports = async (path, storage, version) => {
4650
log.info(`template version: ${tags[0]}`)
4751
}
4852

49-
return createRevert(storage, currentBranch)
53+
revert = createRevert(storage, currentBranch)
5054
}
55+
56+
await installDeps(storage)
57+
58+
return revert
5159
}

src/getTemplate/installDeps.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require('fs-extra')
2+
const { exec } = require('child_process')
3+
const { join } = require('path')
4+
const log = require('../log')
5+
6+
7+
const install = path => new Promise((resolve, reject) => {
8+
log.info('install template dependencies...')
9+
10+
exec('npm install --production', { cwd: path }, (error, stdout, stderr) => {
11+
if (error) {
12+
log.error('Unable install template dependencies');
13+
return reject(error)
14+
}
15+
16+
// process.stdout.write(stdout)
17+
process.stderr.write(stderr)
18+
resolve()
19+
})
20+
})
21+
22+
module.exports = async path => {
23+
if (!await fs.pathExists(join(path, 'package.json'))) return
24+
await install(path)
25+
}
26+

0 commit comments

Comments
 (0)