78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
import gulp from "gulp";
|
|
import type { Task, TaskFunction } from "undertaker";
|
|
import { Platform, type Config } from "../core/type";
|
|
import { Builder } from "./core/builder";
|
|
import { Packer } from "./core/packer";
|
|
import { Runner } from "./core/runner";
|
|
import { RuffleRunner } from "./impl/runner/ruffle";
|
|
export * from "./core";
|
|
export * from "./impl";
|
|
|
|
export class Project {
|
|
public config: Config;
|
|
|
|
constructor(config: Config) {
|
|
this.config = config;
|
|
}
|
|
|
|
hasLib(name: string): boolean {
|
|
for (const lib of this.config.libs) {
|
|
if (lib.name === name) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
build(platform: Platform, debug: boolean = false): Task[] {
|
|
const builder = Builder.new(this.config, platform, this.config.buildSystem, debug);
|
|
const tasks: Task[] = [builder.prepare.bind(builder)];
|
|
tasks.push(builder.call.bind(builder));
|
|
return tasks;
|
|
}
|
|
|
|
run(platform: Platform, debug: boolean = false): Task[] {
|
|
const runner = Runner.new(this.config, platform, debug);
|
|
return [runner.prepare.bind(runner), runner.call.bind(runner)];
|
|
}
|
|
|
|
test(platform: Platform, debug: boolean = true): Task[] {
|
|
return this.build(platform, debug).concat(this.run(platform, debug));
|
|
}
|
|
|
|
pack(platform: Platform, name: string) {
|
|
const packer = Packer.new(this.config, platform, name);
|
|
return [packer.prepare.bind(packer), packer.call.bind(packer)];
|
|
}
|
|
|
|
compile(external_gulp?: gulp.Gulp): Record<string, TaskFunction> {
|
|
const result: Record<string, TaskFunction> = {};
|
|
const _gulp = external_gulp || gulp;
|
|
for (const platform of this.config.platforms) {
|
|
result[`${this.config.name}:${platform}:build`] = _gulp.series(this.build(platform));
|
|
if (Runner.factory[platform]) {
|
|
result[`${this.config.name}:${platform}:run`] = _gulp.series(this.run(platform));
|
|
result[`${this.config.name}:${platform}:test`] = _gulp.series(this.test(platform));
|
|
}
|
|
if (Packer.factory[platform]) {
|
|
for (const name of Object.keys(Packer.factory[platform])) {
|
|
result[`${this.config.name}:${platform}:${name}`] = _gulp.series(this.pack(platform, name));
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
register(external_gulp?: gulp.Gulp) {
|
|
const _gulp = external_gulp || gulp;
|
|
for (const [k, v] of Object.entries(this.compile(_gulp))) {
|
|
_gulp.task(k, v);
|
|
}
|
|
}
|
|
|
|
// TODO:
|
|
static useRuffle() {
|
|
Runner.register(Platform.FLASH, RuffleRunner);
|
|
}
|
|
}
|