0.1.0 move to gitea dist for downloads
This commit is contained in:
+31
-25
@@ -1,10 +1,23 @@
|
||||
"use strict";
|
||||
import { assert } from "bsert"
|
||||
import * as git from "simple-git/promise"
|
||||
import * as gyt from "git-describe"
|
||||
import { promises as fs, mkdirSync } from "fs"
|
||||
import * as rimraf from "rimraf"
|
||||
import * as path from "path"
|
||||
import * as Logger from 'log4js'
|
||||
Logger.configure({
|
||||
appenders:
|
||||
{
|
||||
"admin/gitupdater": { type: 'stdout' },
|
||||
//app: { type: 'file', filename: 'application.log' }
|
||||
},
|
||||
categories:
|
||||
{
|
||||
default: { appenders: [ 'admin/gitupdater' ], level: 'debug' }
|
||||
}
|
||||
})
|
||||
const logger = Logger.getLogger("admin/gitupdater")
|
||||
|
||||
|
||||
|
||||
const rmrf = (path:string, options = {}) => {
|
||||
@@ -17,6 +30,7 @@ export type RepoFolderStatus = {
|
||||
currentTag?: string
|
||||
tags?: string[]
|
||||
latestTag?: string
|
||||
remote?: string
|
||||
}
|
||||
|
||||
export class GitUpdater{
|
||||
@@ -41,6 +55,11 @@ export class GitUpdater{
|
||||
await this.repo.fetch("origin", "master", {
|
||||
"--tags": null
|
||||
});
|
||||
const remoteInfo = await this.repo.getRemotes(true)
|
||||
let remoteURL
|
||||
if(remoteInfo.length != 0){
|
||||
remoteURL = remoteInfo.find(i => i.name === "origin").refs.fetch
|
||||
}
|
||||
const remoteTags = await this.repo.tags();
|
||||
const desc = await gyt.gitDescribe(this.folderPath, { match: "*" });
|
||||
return {
|
||||
@@ -48,19 +67,22 @@ export class GitUpdater{
|
||||
empty: empty,
|
||||
currentTag: !desc.tag?null:desc.tag,
|
||||
tags: !remoteTags.all?[]:remoteTags.all,
|
||||
latestTag: remoteTags.latest
|
||||
latestTag: remoteTags.latest,
|
||||
remote: remoteURL
|
||||
};
|
||||
}
|
||||
|
||||
async cloneRepo(from:string, force:boolean = false):Promise<RepoFolderStatus> {
|
||||
if(this.folderPath === "." && force)
|
||||
throw new Error("refusing to `rm -rf .`: \ncloneRepo(from: "+from+", force: "+force+")")
|
||||
if(force){
|
||||
await rmrf(this.folderPath)
|
||||
await fs.mkdir(this.folderPath, { recursive: true });
|
||||
}
|
||||
const status = await this.getStatus()
|
||||
assert(status.exists && status.empty)
|
||||
if(!status.exists || !status.empty){
|
||||
logger.error("The folder "+this.folderPath+" doesn't exist or is not empty. Not cloning! Pass the force parameter to override this check")
|
||||
logger.error(status)
|
||||
return status
|
||||
}
|
||||
|
||||
await git(this.folderPath).clone(from, path.resolve(this.folderPath));
|
||||
return await this.getStatus();
|
||||
@@ -68,27 +90,11 @@ export class GitUpdater{
|
||||
|
||||
async checkoutTag(tag:string):Promise<RepoFolderStatus> {
|
||||
const status = await this.getStatus()
|
||||
assert(status.exists && status.tags && status.tags.length !== 0)
|
||||
if(!status.exists || !status.tags || status.tags.length === 0){
|
||||
logger.error("Unable to check out tag", tag, status)
|
||||
return status
|
||||
}
|
||||
await this.repo.checkout(tag);
|
||||
return await this.getStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
(async () => {
|
||||
const staticPath = path.join(__dirname, "..", "static")
|
||||
|
||||
const gl = new GitUpdater(staticPath)
|
||||
let status = await gl.getStatus()
|
||||
console.log(status)
|
||||
|
||||
if(status.empty){
|
||||
status = await gl.cloneRepo("https://gitea.frontblock.me/fb-dist/dashboard.git")
|
||||
console.log(status)
|
||||
}
|
||||
|
||||
status = await gl.checkoutTag(status.latestTag!)
|
||||
console.log(status)
|
||||
})()
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user