59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { Resolver, ResolveResult } from './resolver'
|
|
import { Publisher } from './publisher'
|
|
|
|
export interface Project {
|
|
name: string
|
|
scm: ScmInfo
|
|
resolver: Record<string, Resolver<any>>
|
|
publisher?: Record<string, Publisher<any>>
|
|
}
|
|
|
|
export type ScmType = 'git'
|
|
|
|
export interface ScmInfo {
|
|
type?: ScmType
|
|
url: string
|
|
}
|
|
|
|
const validateScmInfo = (scm?: ScmInfo) => {
|
|
if(!scm) {
|
|
throw Error('Missing scm info')
|
|
}
|
|
if(!scm.url) {
|
|
throw Error('Missing scm url')
|
|
}
|
|
}
|
|
|
|
export class ProjectRunner {
|
|
|
|
readonly project: Project
|
|
|
|
constructor(project: Project) {
|
|
this.project = project
|
|
}
|
|
|
|
public async resolve(limit?: string[]): Promise<Record<string, ResolveResult[]>> {
|
|
const results: Record<string, ResolveResult[]> = {}
|
|
const promises = Object.entries(this.project.resolver)
|
|
.filter(([name,]) => !limit || limit.includes(name))
|
|
.map(async ([name, resolver]) => {
|
|
results[name] = await resolver.resolve()
|
|
})
|
|
await Promise.all(promises)
|
|
return results
|
|
}
|
|
|
|
public static loadProject(path: string) {
|
|
const project = require(path) as Project
|
|
ProjectRunner.validateProject(project)
|
|
return project as Project
|
|
}
|
|
|
|
public static validateProject(project: Project) {
|
|
if(!project.name) {
|
|
throw Error('Missing project name')
|
|
}
|
|
validateScmInfo(project.scm)
|
|
}
|
|
}
|