-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
init-dev-env.js
executable file
·119 lines (86 loc) · 2.92 KB
/
init-dev-env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var exec = require('child_process').exec;
var path = require('path');
// We have a copy of rimraf (v2.2.2), so that people can run this script without `npm install`.
var rimraf = require('./rimraf');
var isWin = !!process.platform.match(/^win/);
var pathTo = function(p) {
return path.resolve(__dirname + '/../' + p);
};
var scriptPath = pathTo('node_modules/grunt-conventional-changelog/lib/validate-commit-msg.js');
var gitHookPath = pathTo('.git/hooks/commit-msg');
var gitHookSetup = function() {
if (fs.existsSync(gitHookPath)) {
fs.unlinkSync(gitHookPath);
console.log('Existing link removed:', gitHookPath);
}
console.log('Adding symbolic link: %s linked to %s', scriptPath, gitHookPath);
fs.symlinkSync(scriptPath, gitHookPath, 'file');
};
var installGruntCli = function(callback) {
console.log('Installing grunt-cli...');
var gcli = exec('npm install -g grunt-cli', function (error) {
if (error !== null) {
console.error('error installing grunt-cli: ' + error);
} else {
callback();
}
});
gcli.stdout.pipe(process.stdout);
gcli.stderr.pipe(process.stderr);
};
var checkForGruntCli = function(callback) {
console.log('Checking for grunt-cli...');
exec('grunt --version', function (error, stdout) {
if (error) {
installGruntCli(callback);
} else {
console.log('grunt-cli is already installed:');
console.log(stdout);
callback();
}
});
};
var installDependencies = function() {
console.log('Installing dependencies...');
var install = exec('npm install', function (error) {
if (error !== null) {
console.error('Error installing karma dependencies: ' + error);
}
// Remove the extra karma in node_modules/karma.
// This is Karma from NPM, installed because plugins have Karma as a peer dependency and
// at the same time, Karma uses a local instance if present and therefore running `karma`
// in the working directory would cause using the Karma from NPM, rather than the Karma from
// the working space.
rimraf(pathTo('node_modules/karma'), function(err) {
if (err) {
console.error('Can not remove "' + pathTo('node_modules/karma') + '".\n' +
'Please remove it manually.');
} else {
console.log('YAY, YOUR WORKSPACE IS READY!');
}
});
});
install.stdout.pipe(process.stdout);
install.stderr.pipe(process.stderr);
};
var runInit = function() {
gitHookSetup();
checkForGruntCli(function cb() {
installDependencies();
});
};
if (isWin) {
exec('whoami /priv', function(err, o) {
if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') === -1) {
console.log('You do not appear to have symlink privileges. Exiting init script.');
console.log('Windows requires admin privileges to create symlinks.');
} else {
runInit();
}
});
} else {
runInit();
}