+8
-26
@@ -1,34 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import Ajv from "ajv";
|
||||
import fs from "fs";
|
||||
import gulp from "gulp";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { Preset, type ProjectPreset } from ".";
|
||||
import { name, version } from "../package.json" with { type: "json" };
|
||||
import compiler from "./preset/compiler";
|
||||
import loader from "./preset/loader";
|
||||
import register from "./preset/register";
|
||||
import validator from "./preset/validator";
|
||||
|
||||
console.log(`[${name} ${version}]`);
|
||||
|
||||
const loadPreset = (): Preset => {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const presetData: Record<string, ProjectPreset> = JSON.parse(fs.readFileSync("haxetool.json", "utf8"));
|
||||
const ajv = new Ajv();
|
||||
const presetSchema = ajv.compile(
|
||||
JSON.parse(fs.readFileSync(path.join(__dirname, "..", "haxetool.schema.json"), "utf-8")),
|
||||
);
|
||||
const valid = presetSchema(presetData);
|
||||
if (!valid) {
|
||||
throw presetSchema.errors;
|
||||
}
|
||||
|
||||
const packageInfo = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
||||
const configData = fs.existsSync("config.json") ? JSON.parse(fs.readFileSync("config.json", "utf8")) : null;
|
||||
return new Preset(presetData, configData, packageInfo);
|
||||
};
|
||||
|
||||
const showTasks = () => {
|
||||
const tree = gulp.tree({ deep: true });
|
||||
console.log(tree.nodes.map((node) => node.label).join("\n"));
|
||||
@@ -47,8 +27,10 @@ const runTask = async (name: string) => {
|
||||
};
|
||||
|
||||
export const main = async () => {
|
||||
const preset = loadPreset();
|
||||
preset.register(gulp);
|
||||
const preset = loader();
|
||||
validator(preset);
|
||||
const projects = compiler(preset);
|
||||
register(projects);
|
||||
|
||||
if (process.argv.length > 2) {
|
||||
await runTask(process.argv[2]);
|
||||
|
||||
Reference in New Issue
Block a user