34 | function cleanModulesIfVersionChanged(bosco, repoPath, repo, next) { |
35 | NodeRunner.getVersion(bosco, { cwd: repoPath }, function (err, currentVersion) { |
36 | if (err) { return next(err); } |
37 | var nodeVersionKey = 'teams:' + bosco.getTeam() + ':nodes:' + repo; |
38 | var lastVersion = bosco.config.get(nodeVersionKey); |
39 | if (lastVersion && lastVersion !== currentVersion) { |
40 | bosco.prompt.start(); |
41 | var confirmationDescription = 'Node version in '.white + repo.cyan + ' has changed from '.white + lastVersion.green + ' to '.white + currentVersion.green + ', should I clear node_modules (y/N)?'.white; |
42 | bosco.prompt.get({ |
43 | properties: { |
44 | confirm: { |
45 | description: confirmationDescription |
46 | } |
47 | } |
48 | }, function (err, result) { |
49 | if (!result || (result.confirm !== 'Y' && result.confirm !== 'y')) { |
50 | return next(); |
51 | } |
52 | |
53 | exec('rm -rf ./node_modules', { cwd: repoPath }, function (err, stdout, stderr) { |
54 | if (err) { |
55 | bosco.error('Failed to clear node_modules for ' + repoPath.blue + ' >> ' + stderr); |
56 | } else { |
57 | bosco.log('Node version in ' + repo.green + ' updated to ' + currentVersion.green); |
58 | bosco.config.set(nodeVersionKey, currentVersion); |
59 | } |
60 | next(); |
61 | }); |
62 | }); |
63 | } else { |
64 | bosco.log('Node version in ' + repo.green + ' is OK at ' + currentVersion.green); |
65 | bosco.config.set(nodeVersionKey, currentVersion); |
66 | next(); |
67 | } |
68 | }); |
69 | } |