-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit.js
42 lines (34 loc) · 1.25 KB
/
commit.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
#!/usr/bin/env node
require('dotenv').config();
const jsonfile = require("jsonfile");
const moment = require("moment");
const sgit = require("simple-git");
const git = sgit({ config: [ `http.extraHeader=Authorization: Basic ${btoa(process.env.TOKEN)}` ] });
const _s = require("scramb");
const { setIntervalAsync, clearIntervalAsync } = require('set-interval-async');
const prompts = require('prompts');
prompts.override(require('yargs').argv);
const filepath = "./data.json";
async function main() {
const res = await prompts([
{ type: 'number', name: 'days', message: 'days to subtract?', initial: 0 },
{ type: 'number', name: 'totalCommit', message: 'how many commits?', initial: 7 },
{ type: 'confirm', name: 'confirm', message: 'proceed?', initial: true }
]);
if(!res.confirm) return;
const DATE = moment().subtract(res.days, 'd').format();
let i = 0;
let interval = setIntervalAsync(async() => {
if(i === res.totalCommit) {
await git.push();
return clearIntervalAsync(interval);
}
let data = { data: DATE, r: _s.passGen(8).result };
jsonfile.writeFile(filepath, data, async function () {
console.log(data, i);
await git.add('./*').commit(DATE, { "--date": DATE });
});
i++
}, 100)
}
main();