1b85fc9a1308f1305a4525dd93427f7f597ee55c
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

1) #!/usr/bin/env node
2) 
3) /*
4) import {repositories.language} from './repository-language';
5) import {repositories.type} from './repository-type';
6) import {repositories.tag} from './repository-tag';
7) import {repositories.concept} from './repository-concept';
8)  */
9) 
10) 
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

11) function syntaxerror() : void
12) {
13) 	console.error("-- wrong syntax");
14) 	process.exit(1);
15) }
16) 
17) 
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

18) /**
19)  */
20) async function main(args : Array<string>) : Promise<void>
21) {
22) 	const command : string = args.shift();
23) 	switch (command)
24) 	{
25) 		case "setup":
26) 		{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

27) 			await repositories.language.setup();
28) 			await repositories.type.setup();
29) 			await repositories.tag.setup();
30) 			await repositories.expression.setup();
31) 			await repositories.concept.setup();
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

32) 			process.exit(0);
33) 			break;
34) 		}
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

35) 		case "show":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

36) 		{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

37) 			const concept_id = parseInt(args.shift());
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

38) 			const exposal : services.concept.type_exposal = await services.concept.expose(concept_id);
39) 			console.info(JSON.stringify(exposal, undefined, "\t"));
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

40) 			process.exit(0);
41) 			break;
42) 		}
43) 		case "translate":
44) 		{
45) 			const language_from : string = args.shift();
46) 			const language_to : string = args.shift();
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

47) 			const part : string = args.join(" "); args = [];
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

48) 			const result = await services.concept.get_translations
49) 			(
50) 				language_from,
51) 				language_to,
52) 				part
53) 			);
54) 			result.forEach
55) 			(
56) 				(entry) =>
57) 				{
58) 					console.info
59) 					(
60) 						helpers.string.coin
61) 						(
62) 							"[{{language_from}}] {{value_from}} ~ [{{language_to}}] {{value_to}}",
63) 							{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

64) 								"language_from": entry["language_from"],
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

65) 								"value_from": entry["value_from"],
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

66) 								"language_to": entry["language_to"],
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

67) 								"value_to": entry["value_to"],
68) 							}
69) 						)
70) 					);
71) 				}
72) 			);
73) 			process.exit(0);
74) 			break;
75) 		}
76) 		case "export":
77) 		{
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

78) 			const directory : string = ((args.length >= 1) ? args.shift() : "/tmp");
79) 			const result : Array<services.concept.type_exposal> = await services.concept.export_();
80) 			for await (const exposal of result)
81) 			{
82) 				const path : string = helpers.string.coin
83) 				(
84) 					"{{directory}}/concept_{{id}}.json",
85) 					{
86) 						"directory": directory,
87) 						"id": helpers.string.pad_left(exposal.id.toFixed(0), 5, "0"),
88) 					}
89) 				);
90) 				const content : string = JSON.stringify(result, undefined, "\t");
91) 				await helpers.file.write(path, content);
92) 			}
93) 			console.info(directory);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

94) 			process.exit(0);
95) 			break;
96) 		}
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

97) 		case "search":
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

98) 		{
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

99) 			const part : string = args.join(" "); args = [];
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

100) 			const result : Array<services.concept.type_exposal> = await services.concept.search(part);
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

101) 			result.forEach
102) 			(
103) 				(entry) =>
104) 				{
105) 					console.info
106) 					(
107) 						helpers.string.coin
108) 						(
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

109) 							"{{id}} | {{type}} | {{description}} | {{tags}} | {{expressions}}",
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

110) 							{
111) 								"id": entry["id"].toFixed(),
112) 								"type": entry["type"],
113) 								"description": (entry["description"] ?? '-'),
114) 								"tags": entry["tags"].join(","),
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

115) 								"expressions": (
116) 									() =>
117) 									{
118) 										let parts : Array<string> = [];
119) 										for (const [key, value] of Object.entries(entry["expressions"]))
120) 										{
121) 											parts.push(key + ":" + value.join("/"));
122) 										}
123) 										return parts.join(",");
124) 									}
125) 								) (),
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

126) 							}
127) 						)
128) 					);
129) 				}
130) 			);
131) 			process.exit(0);
132) 			break;
133) 		}
134) 		case "feed":
135) 		{
136) 			const content : string = await helpers.misc.stdin();
137) 			const data : any = JSON.parse(content);
138) 			const concept_thing : any = data;
139) 			const concept_id : int = await services.concept.suck(concept_thing);
140) 			console.info(concept_id);
141) 			process.exit(0);
Christian Fraß [add] typescript logic

Christian Fraß authored 3 years ago

142) 			break;
143) 		}
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

144) 		case "new":
145) 		{
146) 			if (args.length < 1)
147) 			{
148) 				syntaxerror();
149) 			}
150) 			else
151) 			{
152) 				const type : string = args.shift();
153) 				const tags : Array<string> = (
154) 					(args.length >= 1)
155) 					? args.shift().split(",")
156) 					: []
157) 				);
158) 				const description : string = (
159) 					(args.length >= 1)
160) 					? args.shift()
161) 					: null
162) 				);
163) 				const concept_thing : any =
164) 				{
165) 					"type": type,
166) 					"description": description,
167) 					"tags": tags,
Christian Fraß [mod] makefile

Christian Fraß authored 3 years ago

168) 					"expressions": [],
Christian Fraß [mod] logic

Christian Fraß authored 3 years ago

169) 				};
170) 				const concept_id : int = await services.concept.suck(concept_thing);
171) 				console.info(concept_id);
172) 				process.exit(0);
173) 			}
174) 			break;
175) 		}
176) 		case "set":
177) 		{
178) 			if (args.length < 1)
179) 			{
180) 				syntaxerror();
181) 			}
182) 			else
183) 			{
184) 				const concept_id : int = parseInt(args.shift());
185) 			}
186) 		}