update build
This commit is contained in:
@@ -7,8 +7,9 @@ import express = require('express');
|
||||
import http = require('http');
|
||||
import bsock = require('bsock');
|
||||
import { FrontblockCherryPicker } from "git-cherrypicker"
|
||||
import { basename } from "path"
|
||||
import { promises as fs } from "fs"
|
||||
import { GitUpdater } from "./GitUpdater";
|
||||
import * as git from "simple-git/promise"
|
||||
|
||||
const kfs = require("key-file-storage").default('kfs')
|
||||
|
||||
@@ -81,10 +82,23 @@ export class FrontblockAdmin extends ConfigLoader<AdminConf>{
|
||||
return {httpPort: 8080}
|
||||
}
|
||||
|
||||
private async updateDashboard(){
|
||||
const dashboard = new GitUpdater("./static")
|
||||
const status = await dashboard.cloneRepo("https://gitea.frontblock.me/fb-dist/dashboard.git", true)
|
||||
console.log(status)
|
||||
}
|
||||
|
||||
private async updatePluginmanager(){
|
||||
const dashboard = new GitUpdater("./plugins/PluginManager")
|
||||
const status = await dashboard.cloneRepo("https://gitea.frontblock.me/fb-dist/pluginmanager.git", true)
|
||||
console.log(status)
|
||||
}
|
||||
|
||||
private async initialize(){
|
||||
await fs.mkdir("plugins/PluginManager", {recursive: true})
|
||||
await (new FrontblockCherryPicker("fb-dist/pluginmanager", "master", "Plugin.js")).write("plugins/PluginManager/Plugin.js")
|
||||
await (new FrontblockCherryPicker("fb-dist/pluginmanager", "master", "FrontendPlugin.js")).write("plugins/PluginManager/FrontendPlugin.js")
|
||||
await this.updateDashboard()
|
||||
|
||||
await this.updatePluginmanager()
|
||||
|
||||
let str = "../plugins/PluginManager/Plugin"
|
||||
const PM = await import(str)
|
||||
this.pm = new PM.default()
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"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"
|
||||
|
||||
|
||||
const rmrf = (path:string, options = {}) => {
|
||||
return new Promise((acc, _) => rimraf(path, options, acc))
|
||||
}
|
||||
|
||||
type RepoFolderStatus = {
|
||||
exists: boolean
|
||||
empty: boolean
|
||||
currentTag?: string
|
||||
tags?: string[]
|
||||
latestTag?: string
|
||||
}
|
||||
|
||||
export class GitUpdater{
|
||||
private readonly repo
|
||||
constructor(private readonly folderPath:string){
|
||||
this.folderPath = folderPath;
|
||||
mkdirSync(this.folderPath, { recursive: true });
|
||||
this.repo = git(this.folderPath)
|
||||
}
|
||||
|
||||
async getStatus():Promise<RepoFolderStatus>{
|
||||
try {
|
||||
await fs.access(this.folderPath);
|
||||
}
|
||||
catch (e) {
|
||||
return { exists: false, empty: true };
|
||||
}
|
||||
|
||||
const files = await fs.readdir(this.folderPath)
|
||||
const empty:boolean = files.length === 0
|
||||
|
||||
await this.repo.fetch("origin", "master", {
|
||||
"--tags": null
|
||||
});
|
||||
const remoteTags = await this.repo.tags();
|
||||
const desc = await gyt.gitDescribe(this.folderPath, { match: "*" });
|
||||
return {
|
||||
exists: true,
|
||||
empty: empty,
|
||||
currentTag: !desc.tag?null:desc.tag,
|
||||
tags: !remoteTags.all?[]:remoteTags.all,
|
||||
latestTag: remoteTags.latest
|
||||
};
|
||||
}
|
||||
|
||||
async cloneRepo(from:string, force:boolean = false):Promise<RepoFolderStatus> {
|
||||
if(force){
|
||||
await rmrf(this.folderPath)
|
||||
await fs.mkdir(this.folderPath, { recursive: true });
|
||||
}
|
||||
const status = await this.getStatus()
|
||||
assert(status.exists && status.empty)
|
||||
|
||||
await git(this.folderPath).clone(from, path.resolve(this.folderPath));
|
||||
return await this.getStatus();
|
||||
}
|
||||
|
||||
async checkoutTag(tag:string):Promise<RepoFolderStatus> {
|
||||
const status = await this.getStatus()
|
||||
assert(status.exists && status.tags && status.tags.length !== 0)
|
||||
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