1 | const {template} = require('lodash');
|
2 | const AggregateError = require('aggregate-error');
|
3 | const {isGitRepo, verifyTagName} = require('./git');
|
4 | const getError = require('./get-error');
|
5 |
|
6 | module.exports = async ({cwd, env, options: {repositoryUrl, tagFormat}}) => {
|
7 | const errors = [];
|
8 |
|
9 | if (!(await isGitRepo({cwd, env}))) {
|
10 | errors.push(getError('ENOGITREPO', {cwd}));
|
11 | } else if (!repositoryUrl) {
|
12 | errors.push(getError('ENOREPOURL'));
|
13 | }
|
14 |
|
15 |
|
16 | if (!(await verifyTagName(template(tagFormat)({version: '0.0.0'})))) {
|
17 | errors.push(getError('EINVALIDTAGFORMAT', {tagFormat}));
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | if ((template(tagFormat)({version: ' '}).match(/ /g) || []).length !== 1) {
|
24 | errors.push(getError('ETAGNOVERSION', {tagFormat}));
|
25 | }
|
26 |
|
27 | if (errors.length > 0) {
|
28 | throw new AggregateError(errors);
|
29 | }
|
30 | };
|