-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
74 lines (71 loc) · 2.27 KB
/
test.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
#! /usr/bin/env node
const simpleGit = require('simple-git');
const git = simpleGit();
const filePath = './package.json';
const packageJson = require(filePath);
const fs = require('fs').promises;
const commander = require('commander');
const program = new commander.Command();
const inquirer = require('inquirer');
const npmPublish = require("@jsdevtools/npm-publish");
program
.command('publish')
.description('create a new release')
.action(() => {
inquirer
.prompt([
{
type: 'list',
name: 'releaseType',
message: 'Choose a release type:',
choices: [
'major',
'minor',
'patch'
],
},
{
type: 'input',
name: 'commit',
message: 'Enter commit description:',
default: ''
},
])
.then((answers) => {
console.log('doing release...');
test(answers);
})
});
program.parse(process.argv);
async function test(answers) {
try {
const versionNumbers = packageJson.version.split('.');
let major = versionNumbers[0];
let minor = versionNumbers[1];
let patch = versionNumbers[2];
if (answers.releaseType === "major") {
major = Number(major) + 1;
}
else if (answers.releaseType === "minor") {
minor = Number(minor) + 1;
}
else if (answers.releaseType === "patch") {
patch = Number(patch) + 1;
}
const newVersionNumber = `${major}.${minor}.${patch}`;
packageJson.version = newVersionNumber;
console.log(1)
await fs.writeFile(filePath, JSON.stringify(packageJson, null, 4));
console.log(2)
await git.add('*').commit(answers.commit).push().addTag(packageJson.version);
console.log(3)
await npmPublish({
token: process.env.INPUT_TOKEN
});
console.log(4);
// await git.pull();
}
catch (e) {
console.log(e);
}
}