fy-convertor
Version:
Convert excel/xml/json/bin/protocl/ts/as ...
81 lines • 2.62 kB
JavaScript
import fs from 'fs-extra';
import { SVNClient } from '@taiyosen/easy-svn';
import { toolchain } from '../tools/toolchain.js';
import { GitHelper } from './GitHelper.js';
export class RepoHolder {
svnClient = new SVNClient();
static ins;
static get Instance() {
if (!RepoHolder.ins)
RepoHolder.ins = new RepoHolder();
return RepoHolder.ins;
}
type = 'svn';
commitOutput = '';
constructor() {
const env = process.env;
if (env.SVN_USERNAME && env.SVN_PASSWORD) {
this.svnClient.setConfig({
username: env.SVN_USERNAME,
password: env.SVN_PASSWORD,
globalParams: ['--non-interactive', '--trust-server-cert', '--no-auth-cache']
});
}
}
setAsType(type) {
this.type = type;
}
async checkOutSubDir(revert, localPath, repo, subDir, branch) {
if (this.type == 'svn') {
await this.checkSVN(revert, localPath, repo + subDir);
}
else {
await GitHelper.Instance.partialCloneDirectory({
gitUrl: repo,
sparsePath: subDir,
localPath,
branch
});
}
}
async checkSVN(revert, localPath, svnPath) {
if (this.type != 'svn') {
throw new Error('RepoHolder is not svn type');
}
if (fs.existsSync(localPath)) {
await this.svnClient.cleanup(true, localPath);
if (revert) {
await this.svnClient.revert(localPath);
}
await this.svnClient.update(localPath);
}
else {
await fs.mkdirp(localPath);
await this.svnClient.checkout(svnPath, localPath);
}
}
async commit(msg, ...paths) {
if (this.type == 'svn') {
await this.svnClient.addUnversioned(...paths);
this.commitOutput = await this.svnClient.commit(msg, ...paths);
}
else {
this.commitOutput = await GitHelper.Instance.commitAndPush(msg, ...paths);
}
}
getLastCommitFiles() {
const files = [];
const mchs = this.commitOutput.matchAll(/(?:Adding|Sending)\s+(\S+)/g);
for (const mch of mchs) {
files.push(mch[1]);
}
return files;
}
}
export function adjustSVN(raw) {
if (toolchain.options.publish) {
raw = raw.replace('trunk', 'branches/publish');
}
return raw;
}
//# sourceMappingURL=RepoHolder.js.map