leitfaden-digitalisierung/source/main.ts
2025-05-19 21:18:37 +00:00

212 lines
4.7 KiB
TypeScript

namespace leitfaden
{
/**
*/
type type_realization_entry = {
title : string;
text : Array<string>;
tldr : Array<string>;
example : Array<string>;
};
/**
*/
type type_data = {
problems : {
title : string;
list : Array<string>;
};
goals : {
title : string;
list : Array<string>;
explanation : string;
};
realization : {
pool : Record<string, type_realization_entry>;
order : Array<string>;
};
};
/**
*/
export async function main(
args_raw : Array<string>
) : Promise<void>
{
// args
const arg_handler : lib_plankton.args.class_handler = new lib_plankton.args.class_handler(
{
"data_path": lib_plankton.args.class_argument.volatile({
"indicators_long": ["data-path"],
"indicators_short": ["d"],
"type": lib_plankton.args.enum_type.string,
"mode": lib_plankton.args.enum_mode.replace,
"default": "data.json",
"info": "path to data file",
"name": "data-path",
}),
"verbosity": lib_plankton.args.class_argument.volatile({
"indicators_long": ["verbosity"],
"indicators_short": ["v"],
"type": lib_plankton.args.enum_type.string,
"mode": lib_plankton.args.enum_mode.replace,
"default": "notice",
"info": "error | warning | notice | info | debug",
"name": "verbosity",
}),
"help": lib_plankton.args.class_argument.volatile({
"indicators_long": ["help"],
"indicators_short": ["h"],
"type": lib_plankton.args.enum_type.boolean,
"mode": lib_plankton.args.enum_mode.replace,
"default": false,
"info": "alias for action 'help'",
"name": "help",
}),
}
);
const args : Record<string, any> = arg_handler.read(
lib_plankton.args.enum_environment.cli,
args_raw.join(" ")
);
// init
lib_plankton.log.set_main_logger(
[
{
"kind": "filtered",
"data": {
"core": {
"kind": "std",
"data": {
"target": "stderr",
"format": {
"kind": "human_readable",
"data": {
}
}
}
},
"predicate": [
[
{
"item": {
"kind": "level",
"data": {
"threshold": args.verbosity,
}
},
},
]
],
}
},
]
);
await leitfaden.templates_init();
const data : type_data = lib_plankton.json.decode(
await lib_plankton.file.read(args.data_path)
);
const style : string = await lib_plankton.file.read("style.css");
// exec
const output : string = await leitfaden.render(
"main",
{
"style": style,
"problems": await leitfaden.render(
"problems",
{
"title": data.problems.title,
"list": data.problems.list.map(
entry => lib_plankton.string.coin(
"<li>{{entry}}</li>",
{
"entry": entry,
}
)
).join("\n"),
}
),
"goals": await leitfaden.render(
"goals",
{
"title": data.goals.title,
"list": data.goals.list.map(
entry => lib_plankton.string.coin(
"<li>{{entry}}</li>",
{
"entry": entry,
}
)
).join("\n"),
"explanation": data.goals.explanation,
}
),
"realization": await leitfaden.render(
"realization",
{
"title": "Umsetzung",
"entries": await leitfaden.tabs(
(await leitfaden.promise_all_stable(
data.realization.order
.map(
async (name) => {
const realization : type_realization_entry = data.realization.pool[name];
return Promise.resolve({
"name": name,
"title": realization.title,
"content": await leitfaden.render(
"realization-entry",
{
"title": realization.title,
"text": realization.text.map(
x => lib_plankton.string.coin(
"<p>{{content}}</p>",
{
"content": x,
}
)
).join("\n"),
"tldr": realization.tldr.map(
x => lib_plankton.string.coin(
"<li>{{content}}</li>",
{
"content": x,
}
)
).join("\n"),
"example": realization.example.map(
x => lib_plankton.string.coin(
"<p>{{content}}</p>",
{
"content": x,
}
)
).join("\n"),
}
)
});
}
)
))
),
}
),
}
);
process.stdout.write(output);
}
}
(
leitfaden.main(process.argv.slice(2))
.then(() => {})
.catch((error) => {process.stderr.write(String(error)); process.exit(1);})
);