88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import gulp from "gulp";
|
|
import type { Task, TaskFunction } from "undertaker";
|
|
import { Config } from "../core/config";
|
|
import { BuildSystem, Platform } 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 class Project {
|
|
// TODO: compatibility
|
|
static Config = Config;
|
|
static BuildSystem = BuildSystem;
|
|
static Platform = Platform;
|
|
static Builder = Builder;
|
|
|
|
public buildSystem: string;
|
|
public platforms: string[];
|
|
public config: Config;
|
|
|
|
constructor(buildSystem: string, platforms: string[] | string, config: Config) {
|
|
this.buildSystem = buildSystem;
|
|
this.platforms = Array.isArray(platforms) ? platforms : [platforms];
|
|
this.config = config;
|
|
}
|
|
|
|
hasLib(name: string): boolean {
|
|
for (const lib of this.config.libs) {
|
|
if (lib.name === name) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
build(platform: string, debug: boolean = false): Task[] {
|
|
const builder = Builder.new(this.config, platform, this.buildSystem, debug);
|
|
const tasks: Task[] = [builder.prepare.bind(builder)];
|
|
tasks.push(builder.call.bind(builder));
|
|
return tasks;
|
|
}
|
|
|
|
run(platform: string, debug: boolean = false): Task[] {
|
|
const runner = Runner.new(this.config, platform, debug);
|
|
return [runner.prepare.bind(runner), runner.call.bind(runner)];
|
|
}
|
|
|
|
test(platform: string, debug: boolean = true): Task[] {
|
|
return this.build(platform, debug).concat(this.run(platform, debug));
|
|
}
|
|
|
|
pack(platform: string, 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.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);
|
|
}
|
|
}
|