cron-git-updater
Version:
Cronjob to Git Pull Repository
104 lines (72 loc) • 2.38 kB
Markdown
Git clone a repo into a folder and schedule a cron job to pull updates from the remote origin.
```bash
npm install cron-git-updater
```
```js
const CGU = require('cron-git-updater')
// const CGU_Config = {
// repository: 'github or gitlab link',
// branch: 'main',
// fromReleases: false,
// token: 'for private repository',
// tempLocation: '../history',
// ignoreFiles: [''],
// keepAllBackup: true,
// testing_dir: 'testing',
// executeOnComplete: './run-on-update.sh',
// exitOnComplete: false,
// }
const newUpdater = new CGU({
repository: 'https://gitlab.com/mikesaraus/expsql_rtapi.git',
branch: 'development',
tempLocation: '../history',
})
// Schedule a task to update the repository
// It uses .update() function
// Check is performed and won't update if same version
newUpdater.schedule('0 0 * * *', 'Asia/Manila')
// Call the updater manually
// It first check for internect connection
// Then check if local version does not match
// from remote version
newUpdater.update()
// Call the updater manually and force update
// No check is done it will force to use
// the remote version of the app
newUpdater.forceUpdate()
```
Task scheduler based on timezone
- `cron_syntax` - Schedule when the task should run. e.g. `'0 0 * * *'` (schedule every 12am)
```bash
```
- `timezone` - The timezone that is used for job scheduling. Default is `Asia/Manila`
Update the repository
Some check is performed to insure success
- Check if machine has active internet connection
- call .compareVersions() if update is needed
Compare check `local` version and `remote` version
Read local app `package.json`
Read remote repository `package.json`
Download remote repository
Force update the local project from remote repository