forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-init.js
50 lines (45 loc) · 1.58 KB
/
git-init.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
'use strict';
var Promise = require('../../lib/ext/promise');
var Task = require('../models/task');
var exec = Promise.denodeify(require('child_process').exec);
var path = require('path');
var pkg = require('../../../package.json');
var fs = require('fs');
var template = require('lodash/template');
var gitEnvironmentVariables = {
GIT_AUTHOR_NAME: 'Tomster',
GIT_AUTHOR_EMAIL: '[email protected]',
get GIT_COMMITTER_NAME() { return this.GIT_AUTHOR_NAME; },
get GIT_COMMITTER_EMAIL() { return this.GIT_AUTHOR_EMAIL; }
};
module.exports = Task.extend({
run: function(commandOptions) {
var chalk = require('chalk');
var ui = this.ui;
if (commandOptions.skipGit) {
return Promise.resolve();
}
return exec('git --version')
.then(function() {
return exec('git init')
.then(function() {
return exec('git add .');
})
.then(function() {
var commitTemplate = fs.readFileSync(path.join(__dirname, '../utilities/COMMIT_MESSAGE.txt'));
var commitMessage = template(commitTemplate)(pkg);
return exec('git commit -m "' + commitMessage + '"', {env: gitEnvironmentVariables});
})
.then(function() {
ui.writeLine(chalk.green('Successfully initialized git.'));
});
})
.catch(function(error) {
if (commandOptions.logErrors) {
ui.writeError(error);
}
// if git is not found or an error was thrown during the `git`
// init process just swallow any errors here
});
}
});