backend/source/main.ts

171 lines
3.7 KiB
TypeScript
Raw Normal View History

2024-09-08 21:31:17 +02:00
/**
*/
2024-09-09 12:13:10 +02:00
async function main(
args_raw : Array<string>
) : Promise<void>
{
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": null,
"name": "data-path",
}),
"timezone_shift": lib_plankton.args.class_argument.volatile({
"indicators_long": ["timezone_shift"],
"indicators_short": ["t"],
"type": lib_plankton.args.enum_type.string,
"mode": lib_plankton.args.enum_mode.replace,
"default": 0,
// "info": null,
"name": "timezone-shift",
}),
"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": null,
"name": "help",
}),
});
const args : Record<string, any> = arg_handler.read(lib_plankton.args.enum_environment.cli, args_raw.join(" "));
2024-09-08 21:31:17 +02:00
2024-09-09 12:13:10 +02:00
// exec
if (args["help"]) {
process.stdout.write(
arg_handler.generate_help(
2024-09-08 21:31:17 +02:00
{
2024-09-09 12:13:10 +02:00
"programname": "kalender",
"description": "Kalender",
"executable": "kalender",
2024-09-08 21:31:17 +02:00
}
2024-09-09 12:13:10 +02:00
)
2024-09-08 21:31:17 +02:00
+
2024-09-09 12:13:10 +02:00
"\n"
);
}
else {
const data : type_datamodel = lib_plankton.call.convey(
await lib_plankton.file.read(args["data_path"]),
[
lib_plankton.json.decode,
(data_raw : any) => (
({
"users": data_raw["users"],
"calendars": (
data_raw["calendars"]
2024-09-08 21:31:17 +02:00
.map(
2024-09-09 12:13:10 +02:00
(calendar_entry_raw : any) => ({
"id": calendar_entry_raw["id"],
"object": (
((calendar_object_raw) => {
switch (calendar_object_raw["kind"]) {
case "concrete": {
return {
"kind": "concrete",
"data": {
"name": calendar_object_raw["data"]["name"],
"users": calendar_object_raw["data"]["users"],
"events": (
calendar_object_raw["data"]["events"]
.map(
(event_raw : any) => ({
"name": event_raw["name"],
"begin": event_raw["begin"],
"end": (
(event_raw["end"] === null)
?
null
:
event_raw["end"]
),
"description": event_raw["description"],
})
)
),
},
};
break;
}
case "collection": {
return calendar_object_raw;
break;
}
}
}) (calendar_entry_raw["object"])
),
})
2024-09-08 21:31:17 +02:00
)
2024-09-09 12:13:10 +02:00
),
}) as type_datamodel
),
]
);
const output : string = calendar_view_table_html(
data,
4,
2024-09-08 21:31:17 +02:00
{
2024-09-09 12:13:10 +02:00
"year": 2024,
2024-09-09 21:01:02 +02:00
"week": 35
2024-09-08 21:31:17 +02:00
},
{
2024-09-09 12:13:10 +02:00
"year": 2024,
2024-09-09 21:01:02 +02:00
"week": 41
2024-09-08 21:31:17 +02:00
},
{
2024-09-09 12:13:10 +02:00
"timezone_shift": parseInt(args["timezone_shift"]),
}
);
process.stdout.write(output);
}
return Promise.resolve<void>(undefined);
}
/*
process.stderr.write(
JSON.stringify(
{
"x1": datetime_from_date_object(
new Date(Date.now()),
{
"timezone_shift": 2,
2024-09-08 21:31:17 +02:00
}
2024-09-09 12:13:10 +02:00
),
"x2": datetime_from_date_object(
new Date(Date.now()),
{
"timezone_shift": 0,
2024-09-08 21:31:17 +02:00
}
2024-09-09 12:13:10 +02:00
),
"x3": pit_from_year_and_week(
2024,
37,
{
"timezone_shift": 0,
2024-09-08 21:31:17 +02:00
}
2024-09-09 12:13:10 +02:00
),
2024-09-08 21:31:17 +02:00
},
2024-09-09 12:13:10 +02:00
undefined,
"\t"
)
+
"\n"
);
*/
(
main(process.argv.slice(2))
.then(
() => {}
)
.catch(
(error) => {process.stderr.write(String(error) + "\n");}
)
);