git.schokokeks.org
Repositories
Help
Report an Issue
fs-draft.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
2809be5
Branches
Tags
master
midgard
vorlage
fs-draft.git
tools
koralle.js
minor changes; move to koralle-build-system
Christian Fraß
commited
2809be5
at 2016-08-09 01:17:44
koralle.js
Blame
History
Raw
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var _child_process = require("child_process"); var _fs = require("fs"); var configuration = {}; /** * @author fenris */ function indentation(depth, symbol) { if (symbol === void 0) { symbol = "\t"; } return ((depth == 0) ? "" : (symbol + indentation(depth - 1, symbol))); } /** * @author fenris */ var class_message = (function () { /** * @author fenris */ function class_message(content, parameters) { if (parameters === void 0) { parameters = {}; } /** * @author fenris */ this.depth = 0; if (parameters.prefix == undefined) parameters.prefix = null; if (parameters.type == undefined) parameters.type = null; if (parameters.depth == undefined) parameters.depth = 0; if (parameters.linebreak == undefined) parameters.linebreak = false; this.content = content; this.type = parameters.type; this.depth = parameters.depth; this.prefix = parameters.prefix; this.linebreak = parameters.linebreak; } /** * @author fenris */ class_message.prototype.generate = function (with_type) { if (with_type === void 0) { with_type = true; } var output = ""; output += indentation(this.depth); if (with_type) { if (this.type != null) { output += ("[" + this.type + "]" + " "); } } if (this.prefix != null) { output += ("<" + this.prefix + ">" + " "); } output += this.content; if (this.linebreak) { output += "\n"; } return output; }; /** * @author fenris */ class_message.prototype.stdout = function () { console.log(this.generate(true)); }; /** * @author fenris */ class_message.prototype.stderr = function () { console.error(this.generate(true)); }; /** * @author fenris */ class_message.prototype.console = function () { switch (this.type) { case "log": { console.log(this.generate(false)); break; } case "information": { console.info(this.generate(false)); break; } case "warning": { console.warn(this.generate(false)); break; } case "error": { console.error(this.generate(false)); break; } default: { throw (new Error("unhandled type '" + this.type + "'")); } } }; return class_message; }()); /** * @author fenris */ var class_cliout = (function () { function class_cliout() { } /** * @author fenris */ class_cliout.stdout = function (content, depth) { if (depth === void 0) { depth = 0; } console.log(indentation(depth) + content); }; /** * @author fenris */ class_cliout.stderr = function (content, depth) { if (depth === void 0) { depth = 0; } console.error(indentation(depth) + content); }; /** * @author fenris */ class_cliout.log = function (content, depth) { if (depth === void 0) { depth = 0; } this.stderr("-- " + content, depth); }; /** * @author fenris */ class_cliout.info = function (content, depth) { if (depth === void 0) { depth = 0; } this.stderr(">> " + content, depth); }; /** * @author fenris */ class_cliout.warn = function (content, depth) { if (depth === void 0) { depth = 0; } this.stderr(">> " + content, depth); }; /** * @author fenris */ class_cliout.error = function (content, depth) { if (depth === void 0) { depth = 0; } this.stderr(">> " + content, depth); }; return class_cliout; }()); /** * @author fenris */ var class_graph = (function () { /** * @author fenris */ function class_graph(nodes, edges) { if (nodes === void 0) { nodes = []; } if (edges === void 0) { edges = []; } this.nodes = nodes; this.edges = edges; } /** * @author fenris */ class_graph.prototype.without = function (pivot) { return (new class_graph(this.nodes.filter(function (node) { return (node != pivot); }), this.edges.filter(function (edge) { return ((edge.from != pivot) && (edge.to != pivot)); }))); }; return class_graph; }()); /** * @author fenris */ function topsort(graph) { if (graph.nodes.length == 0) { return []; } else { var pivot_1; var found = graph.nodes.some(function (node) { var count = graph.edges.filter(function (edge) { return (edge.to == node); }).length; if (count == 0) { pivot_1 = node; return true; } else { // console.info("'" + String(node) + "' has " + count.toString() + " incoming edges"); return false; } }); if (found) { return [pivot_1].concat(topsort(graph.without(pivot_1))); } else { throw (new Error("circular dependencies found")); } } } /** * @author fenris */ var lib_xml; (function (lib_xml) { /** * @author fenris */ var class_node = (function () { function class_node() { } return class_node; }()); lib_xml.class_node = class_node; /** * @author fenris */ var class_node_text = (function (_super) { __extends(class_node_text, _super); /** * @author fenris */ function class_node_text(content) { _super.call(this); this.content = content; } /** * @author fenris */ class_node_text.prototype.compile = function (depth) { if (depth === void 0) { depth = 0; } return (indentation(depth) + this.content + "\n"); }; return class_node_text; }(class_node)); lib_xml.class_node_text = class_node_text; /** * @author fenris */ var class_node_comment = (function (_super) { __extends(class_node_comment, _super); /** * @author fenris */ function class_node_comment(content) { _super.call(this); this.content = content; } /** * @author fenris */ class_node_comment.prototype.compile = function (depth) { if (depth === void 0) { depth = 0; } return (indentation(depth) + "<!-- " + this.content + " -->" + "\n"); }; return class_node_comment; }(class_node)); lib_xml.class_node_comment = class_node_comment; /** * @author fenris */ var class_node_complex = (function (_super) { __extends(class_node_complex, _super); /** * @author fenris */ function class_node_complex(name, attributes, children) { if (attributes === void 0) { attributes = {}; } if (children === void 0) { children = []; } _super.call(this); this.name = name; this.attributes = attributes; this.children = children; } /** * @author fenris */ class_node_complex.prototype.compile = function (depth) { var _this = this; if (depth === void 0) { depth = 0; } var output = ""; var attributes = Object.keys(this.attributes).map(function (key) { return (" " + key + "=" + ("\"" + _this.attributes[key] + "\"")); }).join(""); output += (indentation(depth) + "<" + this.name + attributes + ">" + "\n"); this.children.forEach(function (child) { return (output += child.compile(depth + 1)); }); output += (indentation(depth) + "</" + this.name + ">" + "\n"); return output; }; return class_node_complex; }(class_node)); lib_xml.class_node_complex = class_node_complex; })(lib_xml || (lib_xml = {})); /** * @author fenris */ var lib_gnumake; (function (lib_gnumake) { /** * @author fenris */ var class_rule = (function () { /** * @author fenris */ // public constructor(name : string, dependencies : Array<string>, actions : Array<string>, phony : boolean = false) { function class_rule(parameters) { if (parameters === void 0) { parameters = {}; } this.name = fetch(parameters, "name", null, 2); this.dependencies = fetch(parameters, "dependencies", [], 0); this.actions = fetch(parameters, "actions", [], 0); this.phony = fetch(parameters, "phony", false, 0); } /** * @author fenris */ class_rule.prototype.actions_get = function () { return this.actions; }; /** * @author fenris */ class_rule.prototype.compile = function (silent) { if (silent === void 0) { silent = false; } var output = ""; output += (this.name + ":" + this.dependencies.map(function (dependency) { return (" " + dependency); }).join("") + "\n"); this.actions.forEach(function (action) { return (output += "\t" + (silent ? "@ " : "") + action + "\n"); }); if (this.phony) output += (".PHONY: " + this.name + "\n"); return output; }; return class_rule; }()); lib_gnumake.class_rule = class_rule; /** * @author fenris */ var class_sheet = (function () { /** * @author fenris */ function class_sheet(rules, comments) { if (comments === void 0) { comments = []; } this.rules = rules; this.comments = comments; } /** * @author fenris */ class_sheet.prototype.compile = function (silent) { if (silent === void 0) { silent = false; } return ([] .concat(this.comments.map(function (comment) { return ("# " + comment); })) .concat([""]) .concat(this.rules.map(function (rule) { return rule.compile(silent); })) .join("\n")); }; return class_sheet; }()); lib_gnumake.class_sheet = class_sheet; })(lib_gnumake || (lib_gnumake = {})); /** * @author fenris */ var lib_ant; (function (lib_ant) { /** * @author fenris */ var class_comment = (function () { /** * @author fenris */ function class_comment(content) { this.content = content; } /** * @author fenris */ class_comment.prototype.compile = function () { return (new lib_xml.class_node_comment(this.content)); }; return class_comment; }()); lib_ant.class_comment = class_comment; /** * @author fenris */ var class_action = (function () { /** * @author fenris */ function class_action(representation) { this.representation = representation; } /** * @author fenris */ class_action.prototype.compile = function () { return this.representation; }; return class_action; }()); lib_ant.class_action = class_action; /** * @author fenris */ var class_target = (function () { /** * @author fenris */ function class_target(parameters) { if (parameters === void 0) { parameters = {}; } this.name = fetch(parameters, "name", null, 2); this.dependencies = fetch(parameters, "dependencies", [], 1); this.actions = fetch(parameters, "actions", [], 0); } /** * @author fenris */ class_target.prototype.actions_get = function () { return this.actions; }; /** * @author fenris */ class_target.prototype.compile = function () { return (new lib_xml.class_node_complex("target", { "name": this.name, "depends": this.dependencies.join(",") }, this.actions.map(function (action) { return action.compile(); }))); }; return class_target; }()); lib_ant.class_target = class_target; /** * @author fenris */ var class_project = (function () { /** * @author fenris */ function class_project(parameters) { if (parameters === void 0) { parameters = {}; } this.name = fetch(parameters, "name", null, 2); this.default_ = fetch(parameters, "default", null, 2); this.targets = fetch(parameters, "targets", [], 1); this.comments = fetch(parameters, "comments", [], 0); } /** * @author fenris */ class_project.prototype.compile = function () { return (new lib_xml.class_node_complex("project", { "name": this.name, "default": this.default_, }, ([] .concat(this.comments.map(function (comment) { return comment.compile(); })) .concat(this.targets.map(function (target) { return target.compile(); }))))); }; return class_project; }()); lib_ant.class_project = class_project; })(lib_ant || (lib_ant = {})); /** * @author fenris */ var __idcounter = 0; /** * @author fenris */ function genid(prefix) { if (prefix === void 0) { prefix = ""; } return (prefix + (__idcounter++).toString(16)); } /** * @author fenris */ function wait(dependencies, action) { if (dependencies.length > 0) { dependencies[0](function () { wait(dependencies.slice(1), action); }); } else { action(); } } /** * @author fenris */ function executor_chain(state, executors) { if (state === void 0) { state = null; } return (function (resolve, reject) { if (executors.length == 0) { resolve(state); } else { executors[0](state)(function resolve_(state_) { executor_chain(state_, executors.slice(1))(resolve, reject); }, function reject_(reason_) { reject(reason_); }); } }); } /** * @author fenris */ function fetch(structure, fieldname, fallback, escalation) { if (fallback === void 0) { fallback = undefined; } if (escalation === void 0) { escalation = 1; } if (fieldname in structure) { return structure[fieldname]; } else { var message = "field '" + fieldname + "' missing in structure"; switch (escalation) { case 0: { return fallback; break; } case 1: { message += ("; using fallback-value '" + String(fallback) + "'"); (new class_message(message, { "type": "warning", "prefix": "koralle" })).stderr(); return fallback; break; } case 2: { throw (new Error(message)); break; } default: { break; } } } } /** * @author fenris */ function read_json(path) { return (function (resolve, reject) { _fs.readFile(path, { "encoding": "utf-8", "flag": "r", }, function (error, content) { if (error != null) { reject(error); } else { try { var data = JSON.parse(content); resolve(data); } catch (exception) { reject((exception)); } } }); }); } /** * @author fenris */ var class_error = (function (_super) { __extends(class_error, _super); /** * @author fenris */ function class_error(text, sub) { if (sub === void 0) { sub = []; } _super.call(this, text); this.text = text; this.sub = sub; } /** * @author fenris */ class_error.prototype.toString = function () { return (this.text + " / " + this.sub.map(function (error) { return error.toString(); }).join(" ; ")); }; return class_error; }(Error)); /** * @author fenris */ var lib_path; (function (lib_path) { /** * @author fenris */ var class_step = (function () { function class_step() { } return class_step; }()); /** * @author fenris */ var class_step_stay = (function (_super) { __extends(class_step_stay, _super); function class_step_stay() { _super.apply(this, arguments); } /** * @author fenris */ class_step_stay.prototype.toString = function () { return "."; }; return class_step_stay; }(class_step)); /** * @author fenris */ var class_step_back = (function (_super) { __extends(class_step_back, _super); function class_step_back() { _super.apply(this, arguments); } /** * @author fenris */ class_step_back.prototype.toString = function () { return ".."; }; return class_step_back; }(class_step)); /** * @author fenris */ var class_step_regular = (function (_super) { __extends(class_step_regular, _super); /** * @author fenris */ function class_step_regular(name) { _super.call(this); this.name = name; } /** * @author fenris */ class_step_regular.prototype.toString = function () { return this.name; }; return class_step_regular; }(class_step)); /** * @author fenris */ function step_read(s) { switch (s) { case ".": { return (new class_step_stay()); } case "..": { return (new class_step_back()); } default: { return (new class_step_regular(s)); } } } /** * @author fenris */ var class_path = (function () { /** * @author fenris */ function class_path(steps) { if (steps === void 0) { steps = []; } this.steps = steps; } /** * @author fenris */ class_path.prototype.add = function (step) { return (new class_path(this.steps.concat([step]))).normalize(); }; /** * @author fenris */ class_path.prototype.extend = function (path) { return (new class_path(this.steps.concat(path.steps))).normalize(); }; /** * @author fenris */ class_path.prototype.normalize = function () { var steps = this.steps; // filter "stay" { steps = steps.filter(function (step) { return !(step instanceof class_step_stay); }); } // filter "regular-back" { var _loop_1 = function() { // console.info(new class_path(steps).toString()); if (steps.length < 1) { return "break"; } else { var last_1 = steps[0]; var found = steps.slice(1).some(function (step, index) { // console.info("--", step.toString()); if (step instanceof class_step_back) { if (last_1 instanceof class_step_regular) { steps.splice(index, 2); return true; } } last_1 = step; return false; }); if (!found) { return "break"; } } }; while (true) { var state_1 = _loop_1(); if (state_1 === "break") break; } } return (new class_path(steps)); }; /** * @author fenris */ class_path.prototype.toString = function () { return ((this.steps.length == 0) ? "./" : this.steps.map(function (step) { return (step.toString() + "/"); }).join("")); }; /** * @author fenris */ class_path.read = function (s) { var parts = s.split("/"); if (parts[parts.length - 1] == "") parts.pop(); return (new class_path(parts.map(step_read))); }; return class_path; }()); lib_path.class_path = class_path; /** * @author fenris */ function path_read(s) { return class_path.read(s); } lib_path.path_read = path_read; /** * @author fenris */ var class_location = (function () { /** * @author fenris */ function class_location(anchor, path) { this.anchor = anchor; this.path = path; } /** * @author fenris */ class_location.prototype.extend = function (path) { return (new class_location(this.anchor, this.path.extend(path))); }; /** * @author fenris */ class_location.prototype.go_thither = function () { process.chdir(this.toString()); }; /** * @author fenris */ class_location.prototype.expedition = function (core) { var that = this; var current = location_read(process.cwd()); function begin() { // (new class_message("changing directory to '" + that.toString() + "'")).stderr(); that.go_thither(); } function end() { // (new class_message("changing directory to '" + current.toString() + "'")).stderr(); current.go_thither(); } begin(); core(end); }; /** * @author fenris */ class_location.prototype.toString = function () { return (((this.anchor != null) ? this.anchor : "") + this.path.toString()); }; /** * @author fenris */ class_location.read = function (s) { if (s[0] == "/") { return (new class_location("/", path_read(s.slice(1)))); } else { return (new class_location(null, path_read(s))); } }; /** * @author fenris */ class_location.current = function () { return class_location.read(process.cwd()); }; return class_location; }()); lib_path.class_location = class_location; /** * @author fenris */ function location_read(s) { return class_location.read(s); } lib_path.location_read = location_read; /** * @author fenris */ var class_filepointer = (function () { /** * @author fenris */ function class_filepointer(location, filename) { this.location = location; this.filename = filename; } /** * @author fenris */ class_filepointer.prototype.foo = function (filepointer) { return (new class_filepointer(this.location.extend(filepointer.location.path), filepointer.filename)); }; /** * @author fenris */ class_filepointer.prototype.toString = function () { return (this.location.toString() /* + "/"*/ + ((this.filename == null) ? "" : this.filename)); }; /** * @author fenris */ class_filepointer.read = function (s) { var parts = s.split("/"); var last = parts[parts.length - 1]; if (last == "") { return (new class_filepointer(location_read(parts.join("/")), null)); } else { return (new class_filepointer(location_read(parts.slice(0, parts.length - 1).join("/")), last)); } }; return class_filepointer; }()); lib_path.class_filepointer = class_filepointer; /** * @author fenris */ function filepointer_read(s) { return class_filepointer.read(s); } lib_path.filepointer_read = filepointer_read; })(lib_path || (lib_path = {})); /** * @author fenris */ var class_action = (function () { /** * @author fenris */ function class_action() { } return class_action; }()); /** * @author fenris */ var class_action_adhoc = (function (_super) { __extends(class_action_adhoc, _super); /** * @author fenris */ function class_action_adhoc() { _super.call(this); } return class_action_adhoc; }(class_action)); /** * @author fenris */ var class_action_exec = (function (_super) { __extends(class_action_exec, _super); /** * @author fenris */ function class_action_exec(paths_input, paths_output, path_script, path_interpreter) { _super.call(this); this.paths_input = paths_input; this.paths_output = paths_output; this.path_script = path_script; this.path_interpreter = path_interpreter; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_exec.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; if (this.path_interpreter != null) parts.push(this.path_interpreter.toString()); parts.push(this.path_script.toString()); parts.push(this.paths_input.map(function (filepointer) { return filepointer.toString(); }).join(",")); parts.push(this.paths_output.map(function (filepointer) { return filepointer.toString(); }).join(",")); return parts.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { if (this.path_interpreter == null) { return (new lib_ant.class_action(new lib_xml.class_node_complex("exec", { "executable": this.path_script.toString() }, [ new lib_xml.class_node_complex("arg", { "value": "'" + this.paths_input.map(function (filepointer) { return filepointer.toString(); }).join(",") + "'" }), new lib_xml.class_node_complex("arg", { "value": "'" + this.paths_output.map(function (filepointer) { return filepointer.toString(); }).join(",") + "'" }), ]))); } else { return (new lib_ant.class_action(new lib_xml.class_node_complex("exec", { "executable": this.path_interpreter.toString() }, [ new lib_xml.class_node_complex("arg", { "value": this.path_script.toString() }), new lib_xml.class_node_complex("arg", { "value": "'" + this.paths_input.map(function (filepointer) { return filepointer.toString(); }).join(",") + "'" }), new lib_xml.class_node_complex("arg", { "value": "'" + this.paths_output.map(function (filepointer) { return filepointer.toString(); }).join(",") + "'" }), ]))); } break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_exec; }(class_action_adhoc)); /** * @author fenris */ var class_action_echo = (function (_super) { __extends(class_action_echo, _super); /** * @author fenris */ function class_action_echo(message) { _super.call(this); this.message = message; } /** * @desc for defining directly how the action is to be converted into a target-piece * @todo escape message * @author fenris */ class_action_echo.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; parts.push("echo"); parts.push("'" + this.message + "'"); return parts.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("echo", { "message": this.message }))); break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_echo; }(class_action_adhoc)); /** * @author fenris */ var class_action_koralle = (function (_super) { __extends(class_action_koralle, _super); /** * @author fenris */ function class_action_koralle(filepointer_in, filepointer_out, target, raw) { _super.call(this); this.filepointer_in = filepointer_in; this.filepointer_out = filepointer_out; this.target = target; this.raw = raw; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_koralle.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; parts.push("koralle"); parts.push("--target=" + this.target); if (this.raw) parts.push("--raw"); parts.push(this.filepointer_in.toString()); return (parts.join(" ") + " > " + this.filepointer_out.toString()); } default: { throw (new Error("not implemented")); } } break; } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("exec", { "executable": "koralle", "output": this.filepointer_out.toString(), }, ([] .concat([ new lib_xml.class_node_complex("arg", { "value": "--target=" + this.target }) ]) .concat(this.raw ? [ new lib_xml.class_node_complex("arg", { "value": "--raw" }), ] : []) .concat([ new lib_xml.class_node_complex("arg", { "value": this.filepointer_in.toString() }) ]))))); } default: { throw (new Error("unhandled target '" + target_identifier + "'")); } } }; return class_action_koralle; }(class_action_adhoc)); /** * @author fenris */ var class_action_build = (function (_super) { __extends(class_action_build, _super); /** * @author fenris */ function class_action_build(filepointer, workdir) { _super.call(this); this.filepointer = filepointer; this.workdir = workdir; } return class_action_build; }(class_action_adhoc)); /** * @author fenris */ var class_action_gnumake = (function (_super) { __extends(class_action_gnumake, _super); /** * @author fenris */ function class_action_gnumake(filepointer, workdir) { _super.call(this, filepointer, workdir); } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_gnumake.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { // cmd_cd1 var cmd_cd1 = void 0; { var parts = []; parts.push("cd"); parts.push(this.workdir.toString()); cmd_cd1 = parts.join(" "); } // cmd_cd2 var cmd_cd2 = void 0; { var parts = []; parts.push("cd"); parts.push("-"); cmd_cd2 = parts.join(" ") + " > /dev/null"; } // cmd_make var cmd_make = void 0; { var parts = []; parts.push("make"); parts.push("--no-print-directory"); parts.push("--file=" + this.filepointer.toString()); cmd_make = parts.join(" "); } return ((this.workdir == null) ? [cmd_make] : [cmd_cd1, cmd_make, cmd_cd2]).join(" && "); } default: { throw (new Error("not implemented")); } } break; } case "ant": { return (new lib_ant.class_action((this.workdir == null) ? new lib_xml.class_node_complex("exec", { "executable": "make", }, [ new lib_xml.class_node_complex("arg", { "value": "--no-print-directory" }), new lib_xml.class_node_complex("arg", { "value": "--file=" + this.filepointer.toString() }), ]) : new lib_xml.class_node_complex("exec", { "executable": "make", "dir": this.workdir.toString(), }, [ new lib_xml.class_node_complex("arg", { "value": "--no-print-directory" }), new lib_xml.class_node_complex("arg", { "value": "--file=" + this.filepointer.toString() }), ]))); } default: { throw (new Error("unhandled target '" + target_identifier + "'")); } } }; return class_action_gnumake; }(class_action_build)); /** * @author fenris */ var class_action_ant = (function (_super) { __extends(class_action_ant, _super); /** * @author fenris */ function class_action_ant(filepointer, workdir) { _super.call(this, filepointer, workdir); } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_ant.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { // cmd_cd1 var cmd_cd1 = void 0; { var parts = []; parts.push("cd"); parts.push(this.workdir.toString()); cmd_cd1 = parts.join(" "); } // cmd_cd2 var cmd_cd2 = void 0; { var parts = []; parts.push("cd"); parts.push("-"); cmd_cd2 = parts.join(" ") + " > /dev/null"; } // cmd_ant var cmd_ant = void 0; { var parts = []; parts.push("ant"); parts.push(this.filepointer.toString()); cmd_ant = parts.join(" "); } return ((this.workdir == null) ? [cmd_ant] : [cmd_cd1, cmd_ant, cmd_cd2]).join(" && "); } default: { throw (new Error("not implemented")); } } break; } case "ant": { return (new lib_ant.class_action((this.workdir == null) ? new lib_xml.class_node_complex("ant", { "antfile": this.filepointer.toString(), }) : new lib_xml.class_node_complex("ant", { "antfile": this.filepointer.toString(), "dir": this.workdir.toString(), }))); } default: { throw (new Error("unhandled target '" + target_identifier + "'")); } } }; return class_action_ant; }(class_action_build)); /** * @author fenris */ var class_action_mkdir = (function (_super) { __extends(class_action_mkdir, _super); /** * @author fenris */ function class_action_mkdir(location) { _super.call(this); this.location = location; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_mkdir.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; parts.push("mkdir"); parts.push("--parents"); parts.push(this.location.toString()); return parts.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("mkdir", { "dir": this.location.toString() }))); break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_mkdir; }(class_action_adhoc)); /** * @author fenris */ var class_action_touch = (function (_super) { __extends(class_action_touch, _super); /** * @author fenris */ function class_action_touch(filepointer) { _super.call(this); this.filepointer = filepointer; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_touch.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; parts.push("touch"); parts.push(this.filepointer.toString()); return parts.join(" "); } default: { throw (new Error("not implemented")); } } } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("touch", { "file": this.filepointer.toString() }))); } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_touch; }(class_action_adhoc)); /** * @author fenris */ var class_action_copy = (function (_super) { __extends(class_action_copy, _super); /** * @author fenris */ function class_action_copy(filepointer_from, filepointer_to, folder) { _super.call(this); this.filepointer_from = filepointer_from; this.filepointer_to = filepointer_to; this.folder = folder; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_copy.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; parts.push("cp"); if (this.folder) { parts.push("--recursive"); parts.push("--update"); parts.push("--verbose"); parts.push((new lib_path.class_filepointer(this.filepointer_from.location, "*")).toString()); } else { parts.push(this.filepointer_from.toString()); } parts.push(this.filepointer_to.toString()); return parts.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { if (!this.folder) { return (new lib_ant.class_action(new lib_xml.class_node_complex("copy", { "file": this.filepointer_from.toString(), "tofile": this.filepointer_to.toString(), }))); } else { return (new lib_ant.class_action(new lib_xml.class_node_complex("copy", { "todir": this.filepointer_to.toString(), }, [ new lib_xml.class_node_complex("fileset", { "dir": this.filepointer_from.toString(), }) ]))); } break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_copy; }(class_action_adhoc)); /** * @author fenris */ var class_action_concat = (function (_super) { __extends(class_action_concat, _super); /** * @author fenris */ function class_action_concat(filepointers_from, filepointer_to) { _super.call(this); this.filepointers_from = filepointers_from; this.filepointer_to = filepointer_to; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_concat.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts_1 = []; parts_1.push("cat"); this.filepointers_from.forEach(function (filepointer) { return parts_1.push(filepointer.toString()); }); parts_1.push(">"); parts_1.push(this.filepointer_to.toString()); return parts_1.join(" "); } default: { throw (new Error("not implemented")); } } } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("concat", { "destfile": this.filepointer_to.toString() }, [ new lib_xml.class_node_complex("filelist", { "dir": "." }, this.filepointers_from.map(function (filepointer) { return (new lib_xml.class_node_complex("file", { "name": filepointer.toString() })); })) ]))); } default: { throw (new Error("unhandled target '" + target_identifier + "'")); } } }; return class_action_concat; }(class_action_adhoc)); /** * @author fenris */ var class_action_lessc = (function (_super) { __extends(class_action_lessc, _super); /** * @author fenris */ function class_action_lessc(filepointer_from, filepointer_to) { _super.call(this); this.filepointer_from = filepointer_from; this.filepointer_to = filepointer_to; } /** * @author fenris */ class_action_lessc.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts = []; parts.push("lessc"); parts.push(this.filepointer_from.toString()); parts.push(this.filepointer_to.toString()); return parts.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("exec", { "executable": "lessc", "output": this.filepointer_to.toString(), }, [ new lib_xml.class_node_complex("arg", { "value": this.filepointer_from.toString() }), ]))); break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_lessc; }(class_action_adhoc)); /** * @author fenris */ var class_action_tsc = (function (_super) { __extends(class_action_tsc, _super); /** * @author fenris */ function class_action_tsc(paths_input, path_output, target, allowUnreachableCode, declaration) { _super.call(this); this.paths_input = paths_input; this.path_output = path_output; this.target = target; this.allowUnreachableCode = allowUnreachableCode; this.declaration = declaration; } /** * @author fenris */ class_action_tsc.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts_2 = []; parts_2.push("tsc"); if (this.allowUnreachableCode) parts_2.push("--allowUnreachableCode"); if (this.declaration) parts_2.push("--declaration"); if (this.target != null) parts_2.push("--target"); parts_2.push(this.target); this.paths_input.forEach(function (filepointer) { return parts_2.push(filepointer.toString()); }); parts_2.push("--outFile"); parts_2.push(this.path_output.toString()); return parts_2.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { return (new lib_ant.class_action(new lib_xml.class_node_complex("exec", { "executable": "tsc" }, ([] .concat(this.paths_input.map(function (filepointer) { return (new lib_xml.class_node_complex("arg", { "value": filepointer.toString() })); })) .concat(this.allowUnreachableCode ? [ new lib_xml.class_node_complex("arg", { "value": "--allowUnreachableCode" }), ] : []) .concat((this.target != null) ? [ new lib_xml.class_node_complex("arg", { "value": "--target" }), new lib_xml.class_node_complex("arg", { "value": this.target }), ] : []) .concat([ new lib_xml.class_node_complex("arg", { "value": "--outFile" }), new lib_xml.class_node_complex("arg", { "value": this.path_output.toString() }), ]))))); break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_tsc; }(class_action_adhoc)); /** * @author fenris */ var class_action_php = (function (_super) { __extends(class_action_php, _super); /** * @author fenris */ function class_action_php(filepointers_from, filepointer_to, only_first) { _super.call(this); this.filepointers_from = filepointers_from; this.filepointer_to = filepointer_to; this.only_first = only_first; } /** * @desc for defining directly how the action is to be converted into a target-piece * @author fenris */ class_action_php.prototype.compilation = function (target_identifier) { switch (target_identifier) { case "gnumake": { switch (configuration["system"]) { case "unix": { var parts_3 = []; parts_3.push("php"); if (this.only_first) { parts_3.push(this.filepointers_from[0].toString()); } else { this.filepointers_from.forEach(function (filepointer) { return parts_3.push(filepointer.toString()); }); } parts_3.push(">"); parts_3.push(this.filepointer_to.toString()); return parts_3.join(" "); break; } default: { throw (new Error("not implemented")); break; } } break; } case "ant": { throw (new Error("not implemented")); break; } default: { throw (new Error("unhandled target '" + target_identifier + "'")); break; } } }; return class_action_php; }(class_action_adhoc)); /** * @author fenris */ var class_task = (function () { /** * @author fenris */ function class_task(name, sub, active, parameters) { if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (parameters === void 0) { parameters = {}; } this.identifier = genid("task_"); this.name = (name != null) ? name : this.identifier; this.sub = sub; this.active = active; this.parameters = parameters; } /** * @author fenris */ class_task.prototype.identifier_get = function () { return this.identifier; }; /** * @author fenris */ class_task.prototype.name_get = function () { return this.name; }; /** * @author fenris */ class_task.prototype.sub_get = function () { return this.sub; }; /** * @author fenris */ class_task.prototype.active_get = function () { return this.active; }; /** * @returns the subgraph of all active tasks * @author fenris */ class_task.prototype.clean = function (root) { if (root === void 0) { root = true; } if (root && (!this.active)) { throw (new Error("cant't clean inactive root")); } else { this.sub = this.sub.filter(function (task_) { return task_.active; }); this.sub.forEach(function (task_) { return task_.clean(false); }); } }; /** * @author fenris */ class_task.register = function (id, factory) { this.pool[id] = factory; }; /** * @author fenris */ class_task.get = function (id) { return this.pool[id]; }; /** * @author fenris */ class_task.pool = {}; return class_task; }()); /** * @author fenris */ var class_task_group = (function (_super) { __extends(class_task_group, _super); function class_task_group() { _super.apply(this, arguments); } /** * @author fenris */ class_task_group.create = function (name, sub, active, parameters) { return (new class_task_group(name, sub, active)); }; /** * @override * @author fenris */ class_task_group.prototype.inputs = function () { return []; }; /** * @override * @author fenris */ class_task_group.prototype.outputs = function () { return []; }; /** * @override * @author fenris */ class_task_group.prototype.actions = function () { return []; }; return class_task_group; }(class_task)); class_task.register("group", /*(name, sub, active, parameters) => */ class_task_group.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_dependency = (function (_super) { __extends(class_task_dependency, _super); /** * @author fenris */ function class_task_dependency(name, sub, active, filepointer_project, target, raw, workdir // = null ) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (filepointer_project === void 0) { filepointer_project = null; } if (target === void 0) { target = configuration["target"]; } if (raw === void 0) { raw = true; } if (workdir === void 0) { workdir = filepointer_project.location; } _super.call(this, name, sub, active); this.filepointer_project = filepointer_project; this.target = target; this.raw = raw; this.workdir = workdir; } /** * @override * @author fenris */ class_task_dependency.prototype.inputs = function () { return [this.filepointer_project]; }; /** * @override * @author fenris */ class_task_dependency.prototype.outputs = function () { return []; }; /** * @author fenris */ class_task_dependency.prototype.actions = function () { switch (this.target) { case "gnumake": { var filepointer_buildfile = new lib_path.class_filepointer(configuration["tempfolder"], "makefile"); return [ new class_action_koralle(this.filepointer_project, filepointer_buildfile, this.target, this.raw), new class_action_gnumake(filepointer_buildfile, this.workdir), ]; } case "ant": { var filepointer_buildfile = new lib_path.class_filepointer(configuration["tempfolder"], "build.xml"); return [ new class_action_koralle(this.filepointer_project, filepointer_buildfile, this.target, this.raw), new class_action_ant(filepointer_buildfile, this.workdir), ]; } default: { throw (new Error("unhandled target '" + this.target + "'")); break; } } }; return class_task_dependency; }(class_task)); /** * @author fenris */ var class_task_script = (function (_super) { __extends(class_task_script, _super); /** * @author fenris */ function class_task_script(name, sub, active, inputs_, outputs_, path, interpreter) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (interpreter === void 0) { interpreter = null; } _super.call(this, name, sub, active); this.inputs_ = inputs_; this.outputs_ = outputs_; this.path = path; this.interpreter = interpreter; } /** * @author fenris */ class_task_script.create = function (name, sub, active, parameters) { var interpreter_raw = fetch(parameters, "interpreter", null, 1); var interpreter = ((interpreter_raw == null) ? null : lib_path.class_filepointer.read(interpreter_raw)); return (new class_task_script(name, sub, active, fetch(parameters, "inputs", [], 1).map(function (s) { return lib_path.class_filepointer.read(s); }), fetch(parameters, "outputs", [], 1).map(function (s) { return lib_path.class_filepointer.read(s); }), lib_path.class_filepointer.read(fetch(parameters, "path", null, 2)), interpreter)); }; /** * @override * @author fenris */ class_task_script.prototype.inputs = function () { return this.inputs_; }; /** * @override * @author fenris */ class_task_script.prototype.outputs = function () { return this.outputs_; }; /** * @author fenris */ class_task_script.prototype.actions = function () { return ([] .concat(this.outputs_.map(function (output) { return new class_action_mkdir(output.location); })) .concat([ new class_action_exec(this.inputs_, this.outputs_, this.path, this.interpreter), ])); }; return class_task_script; }(class_task)); class_task.register("script", /*(name, sub, active, parameters) => */ class_task_script.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_empty = (function (_super) { __extends(class_task_empty, _super); /** * @author fenris */ function class_task_empty(name, sub, active, output_) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (output_ === void 0) { output_ = null; } _super.call(this, name, sub, active); this.output_ = output_; } /** * @author fenris */ class_task_empty.create = function (name, sub, active, parameters) { return (new class_task_empty(name, sub, active, lib_path.class_filepointer.read(fetch(parameters, "output", null, 2)))); }; /** * @override * @author fenris */ class_task_empty.prototype.inputs = function () { return []; }; /** * @override * @author fenris */ class_task_empty.prototype.outputs = function () { return [this.output_]; }; /** * @override * @author fenris */ class_task_empty.prototype.actions = function () { return [ new class_action_mkdir(this.output_.location), new class_action_touch(this.output_), ]; }; return class_task_empty; }(class_task)); class_task.register("empty", /*(name, sub, active, parameters) => */ class_task_empty.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_copy = (function (_super) { __extends(class_task_copy, _super); /** * @author fenris */ function class_task_copy(name, sub, active, input_, output_, folder) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (input_ === void 0) { input_ = null; } if (output_ === void 0) { output_ = null; } if (folder === void 0) { folder = null; } _super.call(this, name, sub, active); this.input_ = input_; this.output_ = output_; this.folder = folder; } /** * @author fenris */ class_task_copy.create = function (name, sub, active, parameters) { return (new class_task_copy(name, sub, active, lib_path.class_filepointer.read(fetch(parameters, "input", null, 2)), lib_path.class_filepointer.read(fetch(parameters, "output", null, 2)), fetch(parameters, "folder", false, 0))); }; /** * @override * @author fenris */ class_task_copy.prototype.inputs = function () { return [this.input_]; }; /** * @override * @author fenris */ class_task_copy.prototype.outputs = function () { return [this.output_]; }; /** * @author fenris */ class_task_copy.prototype.actions = function () { return [ new class_action_mkdir(this.output_.location), new class_action_copy(this.input_, this.output_, this.folder), ]; }; return class_task_copy; }(class_task)); class_task.register("copy", /*(name, sub, active, parameters) => */ class_task_copy.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_concat = (function (_super) { __extends(class_task_concat, _super); /** * @author fenris */ function class_task_concat(name, sub, active, inputs_, output_) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (inputs_ === void 0) { inputs_ = null; } if (output_ === void 0) { output_ = null; } _super.call(this, name, sub, active); this.inputs_ = inputs_; this.output_ = output_; } /** * @author fenris */ class_task_concat.create = function (name, sub, active, parameters) { return (new class_task_concat(name, sub, active, fetch(parameters, "inputs", [], 2).map(function (s) { return lib_path.class_filepointer.read(s); }), lib_path.class_filepointer.read(fetch(parameters, "output", null, 2)))); }; /** * @override * @author fenris */ class_task_concat.prototype.inputs = function () { return this.inputs_; }; /** * @override * @author fenris */ class_task_concat.prototype.outputs = function () { return [this.output_]; }; /** * @override * @author fenris */ class_task_concat.prototype.actions = function () { return [ new class_action_mkdir(this.output_.location), new class_action_concat(this.inputs_, this.output_), ]; }; return class_task_concat; }(class_task)); class_task.register("concat", /*(name, sub, active, parameters) => */ class_task_concat.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_lesscss = (function (_super) { __extends(class_task_lesscss, _super); /** * @author fenris */ function class_task_lesscss(name, sub, active, inputs_, output_) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (inputs_ === void 0) { inputs_ = null; } if (output_ === void 0) { output_ = null; } _super.call(this, name, sub, active); this.inputs_ = inputs_; this.output_ = output_; } /** * @author fenris */ class_task_lesscss.create = function (name, sub, active, parameters) { return (new class_task_lesscss(name, sub, active, fetch(parameters, "inputs", null, 2).map(function (s) { return lib_path.class_filepointer.read(s); }), lib_path.class_filepointer.read(fetch(parameters, "output", null, 2)))); }; /** * @override * @author fenris */ class_task_lesscss.prototype.inputs = function () { return this.inputs_; }; /** * @override * @author fenris */ class_task_lesscss.prototype.outputs = function () { return [this.output_]; }; /** * @author fenris */ class_task_lesscss.prototype.actions = function () { var filepointer_temp = new lib_path.class_filepointer(lib_path.class_location.read(configuration["tempfolder"]), "_.less"); return [ new class_action_mkdir(this.output_.location), new class_action_concat(this.inputs_, filepointer_temp), new class_action_lessc(filepointer_temp, this.output_), ]; }; return class_task_lesscss; }(class_task)); class_task.register("lesscss", /*(name, sub, active, parameters) => */ class_task_lesscss.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_typescript = (function (_super) { __extends(class_task_typescript, _super); /** * @author fenris */ function class_task_typescript(name, sub, active, inputs_, output_, target, allowUnreachableCode, declaration) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (inputs_ === void 0) { inputs_ = null; } if (output_ === void 0) { output_ = null; } if (target === void 0) { target = null; } if (allowUnreachableCode === void 0) { allowUnreachableCode = null; } if (declaration === void 0) { declaration = null; } _super.call(this, name, sub, active); this.inputs_ = inputs_; this.output_ = output_; this.target = target; this.allowUnreachableCode = allowUnreachableCode; this.declaration = declaration; } /** * @author fenris */ class_task_typescript.create = function (name, sub, active, parameters) { return (new class_task_typescript(name, sub, active, fetch(parameters, "inputs", [], 1).map(function (s) { return lib_path.class_filepointer.read(s); }), lib_path.class_filepointer.read(fetch(parameters, "output", null, 2)), fetch(parameters, "target", null, 0), fetch(parameters, "allowUnreachableCode", false, 0), fetch(parameters, "declaration", false, 0))); }; /** * @override * @author fenris */ class_task_typescript.prototype.inputs = function () { return this.inputs_; }; /** * @override * @author fenris */ class_task_typescript.prototype.outputs = function () { return [this.output_]; }; /** * @author fenris */ class_task_typescript.prototype.actions = function () { return [ new class_action_mkdir(this.output_.location), new class_action_tsc(this.inputs_, this.output_, this.target, this.allowUnreachableCode, this.declaration), ]; }; return class_task_typescript; }(class_task)); class_task.register("typescript", /*(name, sub, active, parameters) => */ class_task_typescript.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_task_php = (function (_super) { __extends(class_task_php, _super); /** * @author fenris */ function class_task_php(name, sub, active, inputs_, output_, only_first) { if (name === void 0) { name = null; } if (sub === void 0) { sub = []; } if (active === void 0) { active = true; } if (inputs_ === void 0) { inputs_ = null; } if (output_ === void 0) { output_ = null; } if (only_first === void 0) { only_first = null; } _super.call(this, name, sub, active); this.inputs_ = inputs_; this.output_ = output_; this.only_first = only_first; } /** * @author fenris */ class_task_php.create = function (name, sub, active, parameters) { return (new class_task_php(name, sub, active, fetch(parameters, "inputs", [], 2).map(function (s) { return lib_path.class_filepointer.read(s); }), lib_path.class_filepointer.read(fetch(parameters, "output", null, 2)), fetch(parameters, "only_first", false, 0))); }; /** * @override * @author fenris */ class_task_php.prototype.inputs = function () { return this.inputs_; }; /** * @override * @author fenris */ class_task_php.prototype.outputs = function () { return [this.output_]; }; /** * @author fenris */ class_task_php.prototype.actions = function () { return [ new class_action_mkdir(this.output_.location), new class_action_php(this.inputs_, this.output_, this.only_first), ]; }; return class_task_php; }(class_task)); class_task.register("php", /*(name, sub, active, parameters) => */ class_task_php.create /*(name, sub, active, parameters)*/); /** * @author fenris */ var class_target = (function () { /** * @author fenris */ function class_target() { } return class_target; }()); /** * @author fenris */ var class_target_regular = (function (_super) { __extends(class_target_regular, _super); /** * @author fenris */ function class_target_regular(identifier) { _super.call(this); this.identifier = identifier; } /** * @author fenris */ class_target_regular.prototype.compile_action = function (action) { if (action instanceof class_action_adhoc) { var action_ = (action); return (action_.compilation(this.identifier)); } else { throw (new Error("no delegation for action '" + JSON.stringify(action) + "'")); } }; return class_target_regular; }(class_target)); /** * @author fenris */ var class_target_ant = (function (_super) { __extends(class_target_ant, _super); /** * @author fenris */ function class_target_ant() { _super.call(this, "ant"); } /** * @author fenris */ class_target_ant.prototype.compile_task = function (task, path) { var _this = this; if (path === void 0) { path = []; } var path_ = [task.name_get()]; var targets_core = [ new lib_ant.class_target({ "name": path_.join("-"), "dependencies": (task.sub_get() .filter(function (task_) { return task_.active_get(); }) .map(function (task_) { return [task_.name_get()] /*)*/.join("-"); })), "actions": ([] .concat([new class_action_echo(task.name_get())]) .concat(task.actions()) .map(function (action) { return _this.compile_action(action); })) }) ]; var targets_sub = task.sub_get() .map(function (task_) { return _this.compile_task(task_, path_); }) .reduce(function (x, y) { return x.concat(y); }, []); return [].concat(targets_core).concat(targets_sub); }; /** * @author fenris */ class_target_ant.prototype.compile_project = function (project, without_dependencies) { var _this = this; if (without_dependencies === void 0) { without_dependencies = false; } var that = this; var comments = [ // new lib_ant.class_comment("Project \"" + project.name_get() + "\""), new lib_ant.class_comment("This build script was generated by Koralle " + configuration["version"]), ]; var dependencies = project.dependencies_get().map(function (path, index) { return (new class_task_dependency("__dependency_" + index.toString(), [], true, lib_path.class_filepointer.read(path), that.identifier, true, undefined)); }); var targets = [] .concat([ new lib_ant.class_target({ "name": "__root", "dependencies": ["__dependencies", "__core"], }) ]) .concat([ new lib_ant.class_target({ "name": "__dependencies", "dependencies": without_dependencies ? [] : dependencies.map(function (dependency) { return dependency.name_get(); }), }) ]) .concat(dependencies.map(function (dependency) { return _this.compile_task(dependency); }).reduce(function (x, y) { return x.concat(y); }, [])) .concat([ new lib_ant.class_target({ "name": "__core", "dependencies": [project.roottask_get().name_get()], }) ]) .concat(this.compile_task(project.roottask_get())); return (new lib_ant.class_project({ "name": project.name_get(), "default": "__root", "comments": comments, "targets": targets, })); }; /** * @override * @author fenris */ class_target_ant.prototype.compile_project_string = function (project) { return this.compile_project(project).compile().compile(); }; /** * @override * @author fenris */ class_target_ant.prototype.execute = function (filepointer) { return (function (resolve, reject) { var command = [ "ant", "-file " + filepointer.toString(), ].join(" "); _child_process.exec(command, {}, function (stdout, stderr, error) { if (error != null) { reject(error); } else { resolve(undefined); } }); }); }; return class_target_ant; }(class_target_regular)); /** * @author fenris */ var class_target_gnumake = (function (_super) { __extends(class_target_gnumake, _super); /** * @author fenris */ function class_target_gnumake() { _super.call(this, "gnumake"); } /** * @author fenris */ class_target_gnumake.prototype.compile_task = function (task, path, depth, prefix) { var _this = this; if (path === void 0) { path = []; } if (depth === void 0) { depth = 0; } if (prefix === void 0) { prefix = null; } var path_ = [task.name_get()]; var logging_begin = new class_action_echo((new class_message("processing \"" + path_.join("-") + "\" ...", { "type": "log", "depth": depth, "prefix": prefix })).generate()); var logging_end = new class_action_echo((new class_message("... finished \"" + path_.join("-") + "\"", { "type": "log", "depth": depth, "prefix": prefix })).generate()); var rules_core = []; { // meta rule rules_core.push(new lib_gnumake.class_rule({ "name": path_.join("-"), "dependencies": ([] .concat(["__logging_" + path_.join("-")]) .concat(task.sub_get() .filter(function (task_) { return task_.active_get(); }) .map(function (task_) { return [task_.name_get()] /*)*/.join("-"); })) .concat(task.outputs().map(function (filepointer) { return filepointer.toString(); }))), "actions": ([] .concat((task.outputs().length == 0) ? task.actions() : []) .map(function (action) { return _this.compile_action(action); })), "phony": true, })); // logging rules_core.push(new lib_gnumake.class_rule({ "name": ("__logging_" + path_.join("-")), "actions": [logging_begin].map(function (action) { return _this.compile_action(action); }), "phony": true, })); // actual rule if (task.outputs().length > 0) { rules_core.push(new lib_gnumake.class_rule({ "name": task.outputs().map(function (filepointer) { return filepointer.toString(); }).join(" "), "dependencies": task.inputs().map(function (filepointer) { return filepointer.toString(); }), "actions": task.actions().map(function (action) { return _this.compile_action(action); }), "phony": false, })); } } var rules_sub = []; { rules_sub = task.sub_get() .map(function (task_) { return _this.compile_task(task_, path_, depth + 1, prefix); }) .reduce(function (x, y) { return x.concat(y); }, []); } return ([].concat(rules_core).concat(rules_sub)); }; /** * @author fenris */ class_target_gnumake.prototype.compile_project = function (project, without_dependencies) { var _this = this; if (without_dependencies === void 0) { without_dependencies = false; } var that = this; var comments = [ "Project \"" + project.name_get() + "\"", "This makefile was generated by Koralle " + configuration["version"], ]; var dependencies = project.dependencies_get().map(function (path, index) { return (new class_task_dependency("__dependency_" + index.toString(), [], true, lib_path.class_filepointer.read(path), that.identifier, true, undefined)); }); var rules = [] .concat([ new lib_gnumake.class_rule({ "name": "__default", "dependencies": ["__root"], "actions": [], "phony": true, }) ]) .concat([ new lib_gnumake.class_rule({ "name": "__root", "dependencies": ["__dependencies", "__core"], "phony": true, }) ]) .concat([ new lib_gnumake.class_rule({ "name": "__dependencies", "dependencies": without_dependencies ? [] : dependencies.map(function (dependency) { return dependency.name_get(); }), "phony": true, }) ]) .concat(dependencies.map(function (dependency) { return _this.compile_task(dependency); }).reduce(function (x, y) { return x.concat(y); }, [])) .concat([ new lib_gnumake.class_rule({ "name": "__core", "dependencies": [project.roottask_get().name_get()], "phony": true, }) ]) .concat(this.compile_task(project.roottask_get(), undefined, undefined, project.name_get())); return (new lib_gnumake.class_sheet(rules, comments)); }; /** * @override * @author fenris */ class_target_gnumake.prototype.compile_project_string = function (project, without_dependencies) { if (without_dependencies === void 0) { without_dependencies = false; } return (this.compile_project(project, without_dependencies).compile(true)); }; /** * @override * @author fenris */ class_target_gnumake.prototype.execute = function (filepointer) { return (function (resolve, reject) { var command = (["cd", filepointer.location].join(" ") + " && " + ["make", "--file=" + filepointer.filename].join(" ") + " ; " + ["cd", "-"].join(" ")); // (new class_message(command, {"prefix": "exec:command"})).stderr(); _child_process.exec(command, {}, function (stdout, stderr, error) { /* (new class_message(stdout, {"prefix": "exec:stdout"})).stderr(); (new class_message(stderr, {"prefix": "exec:stderr"})).stderr(); (new class_message(String(error), {"prefix": "exec:error"})).stderr(); */ if (error != null) { reject(error); } else { resolve(undefined); } }); }); }; return class_target_gnumake; }(class_target_regular)); /** * @author fenris */ var class_project = (function () { /** * @author fenris */ function class_project(name, version, dependencies_listed, roottask) { this.name = name; this.version = version; this.dependencies_listed = dependencies_listed; this.dependencies_all = null; this.roottask = roottask; } /** * @author fenris */ class_project.prototype.name_get = function () { return this.name; }; /** * @author fenris */ class_project.prototype.dependencies_set = function (dependencies_all) { this.dependencies_all = dependencies_all; }; /** * @author fenris */ class_project.prototype.dependencies_get = function () { return this.dependencies_all; }; /** * @author fenris */ class_project.prototype.roottask_get = function () { return this.roottask; }; /** * @author fenris */ class_project.create_task = function (raw) { var type = fetch(raw, "type", null, 2); return (class_task.get(type)(fetch(raw, "name", null, 1), fetch(raw, "sub", [], 0).map(function (raw) { return class_project.create_task(raw); }), fetch(raw, "active", true, 0), fetch(raw, "parameters", {}, 0))); }; /** * @author fenris */ class_project.create = function (project_raw) { var name = fetch(project_raw, "name", "(nameless project)", 1); var version = fetch(project_raw, "version", "0.0.0", 1); var dependencies = fetch(project_raw, "dependencies", [], 0); var roottask = class_project.create_task(fetch(project_raw, "roottask", null, 2)); // roottask.clean(); return (new class_project(name, version, dependencies, roottask)); }; return class_project; }()); /** * @author fenris */ function read(path) { return (function (resolve, reject) { _fs.access(path, _fs.R_OK | _fs.W_OK, function (error) { if (error != null) { reject(new Error("project.json at '" + path + "' couldn't be read")); } else { read_json(path)(resolve, reject); } }); }); } /** * @param path the path to the project.json relative to the current working directory * @param usage what to do with the result-graph * @author fenris */ function scan(filepointer, graph, depth) { if (graph === void 0) { graph = new class_graph(); } if (depth === void 0) { depth = 0; } if (graph.nodes.indexOf(filepointer.toString()) >= 0) { return (function (resolve, reject) { return resolve(graph); }); } else { return (function (resolve, reject) { executor_chain({ "graph": graph, "data": null, }, [ function (state_) { return function (resolve_, reject_) { state_.graph.nodes.push(filepointer.toString()); resolve_(state_); }; }, function (state_) { return function (resolve_, reject_) { read(filepointer.toString())(function (data) { state_.data = data; resolve_(state_); }, reject_); }; }, function (state_) { return executor_chain(state_, fetch(state_.data, "dependencies", [], 0).map(function (path) { return function (state__) { return function (resolve__, reject__) { // (new class_message("-- dep.-path is '" + path + "'", {"depth": depth})).stderr(); var filepointer_ = lib_path.filepointer_read(path); var filepointer__ = filepointer.foo(filepointer_); // (new class_message("-- combining " + ("'" + filepointer.toString() + "'") + " and " + ("'" + filepointer_.toString() + "'") + " to " + ("'" + filepointer__.toString() + "'"), {"depth": depth})).stderr(); var edge = { "from": filepointer__.toString(), "to": filepointer.toString() }; state__.graph.edges.push(edge); scan(filepointer__, state__.graph, depth + 1)(function (graph_) { state_.graph = graph_; resolve__(state__); }, reject__); }; }; })); }, ])(function (state) { return resolve(state.graph); }, reject); }); } } /** * @author fenris */ function main(args) { configuration = { "version": "0.0.4", "tempfolder": "/tmp/", "path_source": "source", "path_build": "build", "target": "gnumake", "system": "unix", "raw": false, "execute": false, "output": null, "path": "project.json", }; /* let argumentparser : lib_arguments.class_argumentparser = new lib_arguments.class_parser( [ new lib_arguments.class_argument_volatile<string>( { "type": "string", "ids_long": ["target"], "ids_short": ["t"], "default": "gnumake", "info": "the target build system; valid values are 'gnumake','ant'", } ), new lib_arguments.class_argument_volatile<string>( { "type": "string", "ids_long": ["system"], "ids_short": ["s"], "default": "unix", "info": "the target platform; valid values are 'unix', 'win'; default is 'unix'", } ), new lib_arguments.class_argument_volatile_boolean( { "type": "boolean", "ids_long": ["raw"], "ids_short": ["r"], "default": false, "info": "if set, depedencies are ignored/excluded from the output", } ), new lib_arguments.class_argument_volatile<boolean>( { "type": "boolean", "ids_long": ["execute"], "ids_short": ["x"], "default": false, "info": "if set, the build script will be executed instead of being printed to stdout", } ), ] ); */ var procede = args.every(function (arg) { if ((arg.indexOf("--") == 0) || (arg.indexOf("-") == 0)) { var parts = arg.split("="); switch (parts[0]) { case "--help": case "-h": { (new class_message("NAME")).stdout(); (new class_message("Koralle Build System Abstractor", { "depth": 1 })).stdout(); (new class_message("")).stdout(); { (new class_message("SYNOPSIS")).stdout(); (new class_message("koralle [--target=gnumake|ant] [--system=unix|win] <path-to-project.json>", { "depth": 1 })).stdout(); (new class_message("")).stdout(); } { (new class_message("DESCRIPTION")).stdout(); (new class_message("Koralle is not a build-system itself. Instead it generates scripts for existing build-systems (e.g. GNU Make, Apache Ant, …) on base of a common json-description-file (usually named 'project.json').", { "depth": 1 })).stdout(); (new class_message("", { "depth": 1 })).stdout(); (new class_message("Koralle is designed for reducing the amount of text needed to define the build-process.", { "depth": 1 })).stdout(); (new class_message("")).stdout(); } { (new class_message("OPTIONS")).stdout(); { (new class_message("--target | -t", { "depth": 1 })).stdout(); (new class_message("the target build system; valid values are 'gnumake','ant'; default is 'gnumake'", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } { (new class_message("--system | -s", { "depth": 1 })).stdout(); (new class_message("the target platform; valid values are 'unix', 'win'; default is 'unix'", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } { (new class_message("--raw | -r", { "depth": 1 })).stdout(); (new class_message("if set, depedencies are ignored/excluded from the output", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } { (new class_message("--execute | -x", { "depth": 1 })).stdout(); (new class_message("if set, the build script will be executed", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } { (new class_message("--output | -o", { "depth": 1 })).stdout(); (new class_message("the path of the output file", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } { (new class_message("--version | -v", { "depth": 1 })).stdout(); (new class_message("print the version and exit", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } { (new class_message("--help | -h", { "depth": 1 })).stdout(); (new class_message("show this help and exit", { "depth": 2 })).stdout(); (new class_message("")).stdout(); } } { (new class_message("AUTHOR")).stdout(); (new class_message("Christian Fraß <frass@greenscale.de>", { "depth": 1 })).stdout(); (new class_message("")).stdout(); } return false; break; } case "--version": case "-v": { (new class_message(configuration["version"].toString())).stdout(); return false; break; } case "--target": case "-t": { configuration["target"] = parts[1]; return true; break; } case "--system": case "-s": { configuration["system"] = parts[1]; return true; break; } case "--raw": case "-r": { configuration["raw"] = true; return true; break; } case "--output": case "-o": { configuration["output"] = parts[1]; return true; break; } case "--execute": case "-x": { configuration["execute"] = true; return true; break; } default: { return false; throw (new Error("unrecognized option '" + parts[0] + "'")); break; } } } else { configuration["path"] = arg; return true; } }); if (procede) { executor_chain({}, [ // environment function (state) { return function (resolve, reject) { var filepointer = lib_path.filepointer_read(configuration["path"]); filepointer.location.go_thither(); state.filepointer = filepointer; resolve(state); }; }, // scan dependencies function (state) { return function (resolve, reject) { if (configuration["raw"]) { state.order = []; resolve(state); } else { scan(state.filepointer)(function (graph) { try { var order = topsort(graph).filter(function (path) { return (path != state.filepointer.toString()); }); state.order = order; resolve(state); } catch (exception) { reject((exception)); } }, reject); } }; }, // setup project function (state) { return function (resolve, reject) { read(state.filepointer.toString())(function (data) { state.project = class_project.create(data); resolve(state); }, reject); }; }, // setup target function (state) { return function (resolve, reject) { var mapping = { "ant": new class_target_ant(), "gnumake": new class_target_gnumake(), "make": new class_target_gnumake(), }; var target = fetch(mapping, configuration["target"], null, 0); if (target == null) { reject(new Error("no implementation found for target '" + configuration["target"] + "'")); } else { state.target = target; resolve(state); } }; }, // generate function (state) { return function (resolve, reject) { state.project.dependencies_set(state.order); try { var script = state.target.compile_project_string(state.project, configuration["raw"]); state.script = script; resolve(state); } catch (exception) { reject((exception)); } }; }, // output function (state) { return function (resolve, reject) { var filepointer; if (configuration["output"] == null) { if (!configuration["execute"]) { filepointer = null; } else { filepointer = new lib_path.class_filepointer( // new lib_path.class_location(null, new lib_path.class_path(["."])), lib_path.class_location.read(configuration["tempfolder"]), "_koralle_"); } } else { filepointer = lib_path.class_filepointer.read(configuration["output"]); } if (filepointer == null) { (new class_message(state.script)).stdout(); } else { _fs.writeFile(filepointer.toString(), state.script); } state.output = filepointer; resolve(state); }; }, // execution function (state) { return function (resolve, reject) { if (!configuration["execute"]) { resolve(state); } else { state.target.execute(state.output)(function (result) { return resolve(state); }, reject); } }; }, ])(function (state) { // (new class_message("successfull", {"type": "information", "prefix": "koralle"})).stderr(); }, function (reason) { // throw reason; console.error(reason); (new class_message("an error occured: " + String(reason), { "type": "error", "prefix": "koralle" })).stderr(); }); } } main(process.argv.slice(2));