Committed by cron-git from Yimian-PC

master
iotcat 4 years ago
parent d1d63a9cda
commit fbe85f1e17
  1. 98
      index.js
  2. 33
      node_modules/os/.npmignore
  3. 21
      node_modules/os/LICENSE
  4. 24
      node_modules/os/README.md
  5. 1
      node_modules/os/index.js
  6. 55
      node_modules/os/package.json
  7. 5
      package-lock.json
  8. 1
      package.json
  9. 3
      test.js

@ -1,18 +1,94 @@
const cron = require('node-schedule');
const git = require('simple-git')();
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-12-31 11:59:49
* @Last Modified by: IoTcat
* @Last Modified time: 2019-12-31 18:28:21
*/
module.exports = function(o_params){
/* factory mode */
var o = {
dir: './',
debug: false,
allowNotice: true,
pull: (params, callback) => pull(params, callback),
push: (params, callback) => push(params, callback),
sync: (callback, params_pull, params_push) => sync(callback, params_pull, params_push),
schedule: (time, callback, params_pull, params_push) => schedule(time, callback, params_pull, params_push)
}
/*
cron.scheduleJob('1-50 * * * * *', function(){
console.log('scheduleCronstyle:' + new Date());
});
*/
/* merge params */
Object.assign(o, o_params);
/* modules import */
const cron = require('node-schedule');
const git = require('simple-git')(o.dir);
/* Git pull action */
var pull = function(params_user, callback){
var params = {
remote: {
repo: 'origin',
branch: 'master'
},
pull_params: {}
}
Object.assign(params, params_user);
git.pull(params.remote.repo,
params.remote.branch,
params.pull_params,
function(){
if(o.allowNotice){
console.log(new Date() + ' - cron-git: git pull done.');
}
if(callback !== undefined){
callback();
}
});
}
/* Git push action */
var push = function(params_user, callback){
var params = {
add: {
path: './*'
},
commit: {
message: "Committed by cron-git from "+ require('os').hostname()
},
push_params: ['-u', 'origin', 'master']
}
Object.assign(params, params_user);
git.add(params.add.path)
.commit(params.commit.message)
.push(params.push_params, function(){
if(o.allowNotice){
console.log(new Date() + ' - cron-git: git push done.');
}
if(callback !== undefined){
callback();
}
});
}
git.pull('origin', 'master', {'--no-rebase': null}, ()=>{console.log(new Date() + ' - cron-git: git pull done.' + require('os').hostname())});
/* sync action */
var sync = function(callback, params_pull, params_push){
push(params_push);
pull(params_pull);
push(params_push, callback);
}
/* cron sync */
var schedule = function(time, callback, params_pull, params_push){
cron.scheduleJob(time, function(){
console.log(new Date() + ' - cron-git: Scheduled sync begin.');
sync(callback, params_pull, params_push);
});
}
git.add('./*')
.commit("Committed by cron-git auto")
.push(['-u', 'origin', 'master'], () => console.log(new Date() + ' - cron-git: git push done.'));
return o;
}

33
node_modules/os/.npmignore generated vendored

@ -0,0 +1,33 @@
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history

21
node_modules/os/LICENSE generated vendored

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Diego Rodríguez Baquero
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

24
node_modules/os/README.md generated vendored

@ -0,0 +1,24 @@
# node-os [![npm](https://img.shields.io/npm/v/os.svg)](https://www.npmjs.com/package/os) [![npm](https://img.shields.io/npm/dm/os.svg)](https://www.npmjs.com/package/os) [![npm](https://img.shields.io/npm/l/os.svg)](LICENSE)
#### NodeJS Core Module Extended
## Installation
```bash
npm i os --save
```
## Usage
In your node program:
```js
var os = require('os')
```
## API
https://nodejs.org/api/os.html
## License
MIT. Copyright (c) [Diego Rodríguez Baquero](https://diegorbaquero.com).

1
node_modules/os/index.js generated vendored

@ -0,0 +1 @@
module.exports = require('os')

55
node_modules/os/package.json generated vendored

@ -0,0 +1,55 @@
{
"_from": "os",
"_id": "os@0.1.1",
"_inBundle": false,
"_integrity": "sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M=",
"_location": "/os",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "os",
"name": "os",
"escapedName": "os",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/os/-/os-0.1.1.tgz",
"_shasum": "208845e89e193ad4d971474b93947736a56d13f3",
"_spec": "os",
"_where": "e:\\git\\cron-git",
"author": {
"name": "Diego Rodríguez Baquero",
"email": "diegorbaquero@gmail.com",
"url": "https://diegorbaquero.com"
},
"bugs": {
"url": "https://github.com/DiegoRBaquero/node-os/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "NodeJS Core Module Extended",
"homepage": "https://github.com/DiegoRBaquero/node-os#readme",
"keywords": [
"node",
"os",
"core",
"module"
],
"license": "MIT",
"main": "index.js",
"name": "os",
"repository": {
"type": "git",
"url": "git+https://github.com/DiegoRBaquero/node-os.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.1.1"
}

5
package-lock.json generated

@ -75,6 +75,11 @@
"resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz",
"integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA=="
},
"os": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/os/-/os-0.1.1.tgz",
"integrity": "sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M="
},
"simple-git": {
"version": "1.129.0",
"resolved": "https://registry.npmjs.org/simple-git/-/simple-git-1.129.0.tgz",

@ -22,6 +22,7 @@
"homepage": "https://github.com/IoTcat/cron-git#readme",
"dependencies": {
"node-schedule": "^1.3.2",
"os": "^0.1.1",
"simple-git": "^1.129.0"
}
}

@ -0,0 +1,3 @@
const crongit = require('./index.js')();
crongit.sync();
Loading…
Cancel
Save