-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
154 lines (132 loc) · 3.65 KB
/
index.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use babel';
import concatStream from 'concat-stream';
import conventionalChangelog from 'conventional-changelog';
import conventionalCommitsDetector from 'conventional-commits-detector';
import conventionalGithubReleaser from 'conventional-github-releaser';
import gitRawCommits from 'git-raw-commits';
import loophole from 'loophole';
import path from 'path';
import through from 'through2';
function chdirToRepo() {
const editor = atom.workspace.getActiveTextEditor();
if (!editor) {
return;
}
const file = editor.getURI();
// hack
process.chdir(path.dirname(file));
}
function getConfigs(done) {
let preset = atom.config.get('conventional-changelog.preset').toLowerCase();
let append = atom.config.get('conventional-changelog.append');
let releaseCount = atom.config.get('conventional-changelog.releaseCount');
if (preset === 'auto') {
loophole.allowUnsafeNewFunctionAsync((unsafeDone) => {
let commits = [];
gitRawCommits()
.on('error', (err) => {
err.message = 'Error in git-raw-commits: ' + err.message;
done(err);
unsafeDone();
})
.pipe(through((data, enc, cb) => {
commits.push(data.toString());
cb();
}, () => {
preset = conventionalCommitsDetector(commits);
done(null, [{
preset,
append,
releaseCount
}]);
unsafeDone();
}));
})
return;
}
done(null, [{
preset,
append,
releaseCount
}]);
}
function changelog() {
chdirToRepo();
const editor = atom.workspace.getActiveTextEditor();
let text = editor.getText();
getConfigs((err, data) => {
if (err) {
console.error(err);
atom.beep();
return;
}
let configs = data;
let opts = configs[0];
loophole.allowUnsafeNewFunctionAsync((unsafeDone) => {
return conventionalChangelog(...configs)
.on('error', function(err) {
err.message = 'Error in conventional-changelog: ' + err.message;
console.error(err);
atom.beep();
unsafeDone();
})
.pipe(concatStream((data) => {
data = data.toString();
if (opts.releaseCount === 0) {
text = data;
} else if (opts.append) {
text = text + data;
} else if (!opts.append) {
text = data + text;
}
editor.setText(text);
unsafeDone();
}));
});
});
}
function githubRelease() {
chdirToRepo();
getConfigs((err, data) => {
if (err) {
console.error(err);
atom.beep();
return;
}
let configs = data;
loophole.allowUnsafeNewFunctionAsync((unsafeDone) => {
return conventionalGithubReleaser({
type: 'token'
}, ...configs, (err, data) => {
if (err) {
err.message = 'Error in conventional-github-releaser: ' + err.message;
console.error(err);
atom.beep();
unsafeDone();
}
unsafeDone();
});
});
});
}
export let config = {
preset: {
type: 'string',
description: 'auto, angular, atom, ember, eslint, express, jquery, jscs, jshint or codemirror.',
default: 'auto'
},
append: {
type: 'boolean',
description: 'Should the log be appended to existing data.',
default: false
},
releaseCount: {
type: 'number',
description: 'How many releases of changelog you want to generate.',
default: 1
}
};
export let activate = () => {
atom.commands.add('atom-workspace', 'conventional-changelog:changelog', changelog);
atom.commands.add('atom-workspace', 'conventional-changelog:githubRelease', githubRelease);
};