forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-init.js
68 lines (62 loc) · 2.02 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
var Promise = require('ember-cli/lib/ext/promise');
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 Task = require('ember-cli/lib/models/task');
var gitEnvironmentVariables = {
GIT_AUTHOR_NAME: 'angular-cli',
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 () {
// check if we're inside a git repo
return exec('git rev-parse --is-inside-work-tree')
.then(function () {
return true;
})
.catch(function() {
return false;
})
})
.then(function (insideGitRepo) {
if (insideGitRepo) {
return ui.writeLine('Directory is already under version control. Skipping initialization of git.');
}
return exec('git init')
.then(function () {
return exec('git add .');
})
.then(function () {
var commitTemplate = fs.readFileSync(
path.join(__dirname, '../utilities/INITIAL_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 git is not found or an error was thrown during the `git`
// init process just swallow any errors here
});
}
});
module.exports.overrideCore = true;