typia 3.8.4-dev.20230502 → 4.0.0-dev.20230502

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/README.md +9 -1
  2. package/lib/factories/ProtocolFactory.d.ts +8 -0
  3. package/lib/factories/ProtocolFactory.js +112 -0
  4. package/lib/factories/ProtocolFactory.js.map +1 -0
  5. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +16 -0
  6. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +160 -0
  7. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  8. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  9. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  10. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  14. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  15. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  16. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +4 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_map.js +75 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +190 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_never.d.ts +1 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_never.js +6 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_never.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_object.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_object.js +157 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_object.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +5 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +25 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  41. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  42. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  43. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  44. package/lib/functional/$proto_bytes.d.ts +2 -0
  45. package/lib/functional/$proto_bytes.js +37 -0
  46. package/lib/functional/$proto_bytes.js.map +1 -0
  47. package/lib/functional/$proto_field.d.ts +10 -0
  48. package/lib/functional/$proto_field.js +42 -0
  49. package/lib/functional/$proto_field.js.map +1 -0
  50. package/lib/functional/$proto_float.d.ts +4 -0
  51. package/lib/functional/$proto_float.js +28 -0
  52. package/lib/functional/$proto_float.js.map +1 -0
  53. package/lib/functional/$proto_i32.d.ts +2 -0
  54. package/lib/functional/$proto_i32.js +23 -0
  55. package/lib/functional/$proto_i32.js.map +1 -0
  56. package/lib/functional/$proto_i64.d.ts +2 -0
  57. package/lib/functional/$proto_i64.js +31 -0
  58. package/lib/functional/$proto_i64.js.map +1 -0
  59. package/lib/functional/$proto_size.d.ts +6 -0
  60. package/lib/functional/$proto_size.js +76 -0
  61. package/lib/functional/$proto_size.js.map +1 -0
  62. package/lib/functional/$proto_string.d.ts +2 -0
  63. package/lib/functional/$proto_string.js +34 -0
  64. package/lib/functional/$proto_string.js.map +1 -0
  65. package/lib/functional/$varint.d.ts +6 -0
  66. package/lib/functional/$varint.js +99 -0
  67. package/lib/functional/$varint.js.map +1 -0
  68. package/lib/functional/$zigzag.d.ts +4 -0
  69. package/lib/functional/$zigzag.js +34 -0
  70. package/lib/functional/$zigzag.js.map +1 -0
  71. package/lib/messages/IProtocolMap.d.ts +5 -0
  72. package/lib/messages/IProtocolMap.js +3 -0
  73. package/lib/messages/IProtocolMap.js.map +1 -0
  74. package/lib/messages/IProtocolMessage.d.ts +5 -0
  75. package/lib/messages/IProtocolMessage.js +3 -0
  76. package/lib/messages/IProtocolMessage.js.map +1 -0
  77. package/lib/messages/IProtocolProperty.d.ts +12 -0
  78. package/lib/messages/IProtocolProperty.js +3 -0
  79. package/lib/messages/IProtocolProperty.js.map +1 -0
  80. package/lib/metadata/IMetadataTag.d.ts +3 -3
  81. package/lib/metadata/Metadata.js +1 -1
  82. package/lib/metadata/Metadata.js.map +1 -1
  83. package/lib/module.d.ts +2 -0
  84. package/lib/module.js +6 -1
  85. package/lib/module.js.map +1 -1
  86. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  87. package/lib/programmers/MessageProgrammer.js +141 -0
  88. package/lib/programmers/MessageProgrammer.js.map +1 -0
  89. package/lib/transformers/CallExpressionTransformer.js +5 -3
  90. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  91. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  92. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  93. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  94. package/lib/transformers/features/protocols/MessageTransformer.js +20 -0
  95. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  96. package/lib/utils/NameEncoder.d.ts +4 -0
  97. package/lib/utils/NameEncoder.js +89 -0
  98. package/lib/utils/NameEncoder.js.map +1 -0
  99. package/package.json +1 -1
  100. package/src/Primitive.ts +123 -123
  101. package/src/executable/TypiaGenerateWizard.ts +85 -85
  102. package/src/executable/TypiaSetupWizard.ts +133 -133
  103. package/src/executable/setup/CommandExecutor.ts +8 -8
  104. package/src/executable/setup/PackageManager.ts +71 -71
  105. package/src/executable/setup/PluginConfigurator.ts +70 -70
  106. package/src/executable/typia.ts +52 -52
  107. package/src/factories/CommentFactory.ts +14 -14
  108. package/src/factories/ExpressionFactory.ts +70 -70
  109. package/src/factories/IdentifierFactory.ts +63 -63
  110. package/src/factories/LiteralFactory.ts +39 -39
  111. package/src/factories/MetadataCollection.ts +121 -121
  112. package/src/factories/MetadataFactory.ts +62 -62
  113. package/src/factories/MetadataTagFactory.ts +297 -297
  114. package/src/factories/ProtocolFactory.ts +79 -0
  115. package/src/factories/StatementFactory.ts +24 -24
  116. package/src/factories/TemplateFactory.ts +58 -58
  117. package/src/factories/TypeFactory.ts +124 -124
  118. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  119. package/src/factories/internal/metadata/emplace_metadata_object.ts +143 -143
  120. package/src/factories/internal/metadata/iterate_metadata.ts +67 -67
  121. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  122. package/src/factories/internal/metadata/iterate_metadata_native.ts +219 -219
  123. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  124. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  125. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +48 -48
  126. package/src/factories/internal/metadata/iterate_metadata_union.ts +57 -57
  127. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +167 -0
  128. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  129. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  130. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  131. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  132. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  133. package/src/factories/internal/protocols/iterate_protocol_map.ts +58 -0
  134. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +96 -0
  135. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  136. package/src/factories/internal/protocols/iterate_protocol_never.ts +1 -0
  137. package/src/factories/internal/protocols/iterate_protocol_object.ts +110 -0
  138. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +34 -0
  139. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +29 -0
  140. package/src/functional/$any.ts +2 -2
  141. package/src/functional/$dictionary.ts +25 -25
  142. package/src/functional/$is_between.ts +2 -2
  143. package/src/functional/$is_custom.ts +14 -14
  144. package/src/functional/$is_date.ts +3 -3
  145. package/src/functional/$is_datetime.ts +2 -2
  146. package/src/functional/$is_email.ts +4 -4
  147. package/src/functional/$is_ipv4.ts +4 -4
  148. package/src/functional/$is_ipv6.ts +4 -4
  149. package/src/functional/$is_url.ts +4 -4
  150. package/src/functional/$is_uuid.ts +4 -4
  151. package/src/functional/$join.ts +46 -46
  152. package/src/functional/$number.ts +12 -12
  153. package/src/functional/$proto_bytes.ts +25 -0
  154. package/src/functional/$proto_field.ts +30 -0
  155. package/src/functional/$proto_float.ts +37 -0
  156. package/src/functional/$proto_i32.ts +29 -0
  157. package/src/functional/$proto_i64.ts +37 -0
  158. package/src/functional/$proto_size.ts +82 -0
  159. package/src/functional/$proto_string.ts +24 -0
  160. package/src/functional/$rest.ts +3 -3
  161. package/src/functional/$string.ts +37 -37
  162. package/src/functional/$tail.ts +5 -5
  163. package/src/functional/$varint.ts +130 -0
  164. package/src/functional/$zigzag.ts +39 -0
  165. package/src/messages/IProtocolMap.ts +5 -0
  166. package/src/messages/IProtocolMessage.ts +6 -0
  167. package/src/messages/IProtocolProperty.ts +13 -0
  168. package/src/metadata/IMetadata.ts +26 -26
  169. package/src/metadata/IMetadataTag.ts +11 -3
  170. package/src/metadata/Metadata.ts +543 -539
  171. package/src/metadata/MetadataConstant.ts +3 -3
  172. package/src/metadata/MetadataObject.ts +127 -127
  173. package/src/module.ts +2054 -2043
  174. package/src/programmers/ApplicationProgrammer.ts +62 -62
  175. package/src/programmers/AssertCloneProgrammer.ts +79 -79
  176. package/src/programmers/AssertParseProgrammer.ts +74 -74
  177. package/src/programmers/AssertProgrammer.ts +285 -285
  178. package/src/programmers/AssertPruneProgrammer.ts +76 -76
  179. package/src/programmers/AssertStringifyProgrammer.ts +74 -74
  180. package/src/programmers/CheckerProgrammer.ts +901 -901
  181. package/src/programmers/CloneProgrammer.ts +389 -389
  182. package/src/programmers/FeatureProgrammer.ts +500 -500
  183. package/src/programmers/IsCloneProgrammer.ts +86 -86
  184. package/src/programmers/IsParseProgrammer.ts +80 -80
  185. package/src/programmers/IsProgrammer.ts +212 -212
  186. package/src/programmers/IsPruneProgrammer.ts +81 -81
  187. package/src/programmers/IsStringifyProgrammer.ts +84 -84
  188. package/src/programmers/LiteralsProgrammer.ts +65 -65
  189. package/src/programmers/MessageProgrammer.ts +126 -0
  190. package/src/programmers/PruneProgrammer.ts +347 -347
  191. package/src/programmers/RandomProgrammer.ts +423 -423
  192. package/src/programmers/StringifyProgrammer.ts +798 -798
  193. package/src/programmers/TypiaProgrammer.ts +129 -129
  194. package/src/programmers/ValidateCloneProgrammer.ts +93 -93
  195. package/src/programmers/ValidateParseProgrammer.ts +78 -78
  196. package/src/programmers/ValidateProgrammer.ts +316 -316
  197. package/src/programmers/ValidatePruneProgrammer.ts +86 -86
  198. package/src/programmers/ValidateStringifyProgrammer.ts +92 -92
  199. package/src/programmers/helpers/CloneJoiner.ts +131 -131
  200. package/src/programmers/helpers/FunctionImporeter.ts +54 -54
  201. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  202. package/src/programmers/helpers/PruneJoiner.ts +144 -144
  203. package/src/programmers/helpers/StringifyJoinder.ts +113 -113
  204. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  205. package/src/programmers/helpers/UnionExplorer.ts +275 -275
  206. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  207. package/src/programmers/internal/application_array.ts +36 -36
  208. package/src/programmers/internal/application_boolean.ts +17 -17
  209. package/src/programmers/internal/application_constant.ts +30 -30
  210. package/src/programmers/internal/application_default_string.ts +33 -33
  211. package/src/programmers/internal/application_native.ts +32 -32
  212. package/src/programmers/internal/application_number.ts +73 -73
  213. package/src/programmers/internal/application_object.ts +155 -155
  214. package/src/programmers/internal/application_schema.ts +213 -213
  215. package/src/programmers/internal/application_string.ts +45 -45
  216. package/src/programmers/internal/application_templates.ts +26 -26
  217. package/src/programmers/internal/application_tuple.ts +31 -31
  218. package/src/programmers/internal/check_array.ts +30 -30
  219. package/src/programmers/internal/check_custom.ts +31 -31
  220. package/src/programmers/internal/check_dynamic_properties.ts +194 -194
  221. package/src/programmers/internal/check_everything.ts +28 -28
  222. package/src/programmers/internal/check_native.ts +21 -21
  223. package/src/programmers/internal/check_string_tags.ts +67 -67
  224. package/src/programmers/internal/check_union_array_like.ts +271 -271
  225. package/src/programmers/internal/check_union_tuple.ts +33 -33
  226. package/src/programmers/internal/random_custom.ts +29 -29
  227. package/src/programmers/internal/stringify_dynamic_properties.ts +167 -167
  228. package/src/programmers/internal/stringify_native.ts +7 -7
  229. package/src/programmers/internal/stringify_regular_properties.ts +83 -83
  230. package/src/schemas/IJsonSchema.ts +130 -130
  231. package/src/transform.ts +17 -17
  232. package/src/transformers/CallExpressionTransformer.ts +184 -177
  233. package/src/transformers/FileTransformer.ts +47 -47
  234. package/src/transformers/NodeTransformer.ts +13 -13
  235. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +112 -114
  236. package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
  237. package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
  238. package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
  239. package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
  240. package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
  241. package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
  242. package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
  243. package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
  244. package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
  245. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +39 -39
  246. package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
  247. package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
  248. package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
  249. package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
  250. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +28 -28
  251. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +52 -52
  252. package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
  253. package/src/transformers/features/miscellaneous/RandomTransformer.ts +42 -42
  254. package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
  255. package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
  256. package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
  257. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
  258. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
  259. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
  260. package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
  261. package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
  262. package/src/transformers/features/protocols/MessageTransformer.ts +31 -0
  263. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
  264. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
  265. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
  266. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
  267. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
  268. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
  269. package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
  270. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
  271. package/src/transformers/features/validators/AssertTransformer.ts +11 -11
  272. package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
  273. package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
  274. package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
  275. package/src/transformers/features/validators/IsTransformer.ts +11 -11
  276. package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
  277. package/src/transformers/internal/GenericTransformer.ts +97 -97
  278. package/src/utils/ArrayUtil.ts +44 -44
  279. package/src/utils/Escaper.ts +45 -45
  280. package/src/utils/MapUtil.ts +12 -12
  281. package/src/utils/NameEncoder.ts +32 -0
  282. package/src/utils/PatternUtil.ts +30 -30
  283. package/src/utils/RandomGenerator.ts +81 -81
@@ -1,133 +1,133 @@
1
- import fs from "fs";
2
-
3
- import { ArgumentParser } from "./setup/ArgumentParser";
4
- import { CommandExecutor } from "./setup/CommandExecutor";
5
- import { PackageManager } from "./setup/PackageManager";
6
- import { PluginConfigurator } from "./setup/PluginConfigurator";
7
-
8
- export namespace TypiaSetupWizard {
9
- export interface IArguments {
10
- manager: "npm" | "pnpm" | "yarn";
11
- project: string | null;
12
- }
13
-
14
- export async function setup(): Promise<void> {
15
- console.log("----------------------------------------");
16
- console.log(" Typia Setup Wizard");
17
- console.log("----------------------------------------");
18
-
19
- // PREPARE ASSETS
20
- const pack: PackageManager = await PackageManager.mount();
21
- const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
22
-
23
- // INSTALL TYPESCRIPT COMPILERS
24
- pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
25
- pack.install({ dev: true, modulo: "ts-node", version: "latest" });
26
- pack.install({
27
- dev: true,
28
- modulo: "typescript",
29
- version: (() => {
30
- const version: string = (() => {
31
- try {
32
- return require("ts-patch/package.json")?.version ?? "";
33
- } catch {
34
- return "";
35
- }
36
- })();
37
- return Number(version.split(".")[0] ?? "") >= 3
38
- ? "latest"
39
- : "4.9.5";
40
- })(),
41
- });
42
- args.project ??= (() => {
43
- CommandExecutor.run("npx tsc --init");
44
- return (args.project = "tsconfig.json");
45
- })();
46
-
47
- // SETUP TRANSFORMER
48
- await pack.save((data) => {
49
- data.scripts ??= {};
50
- if (
51
- typeof data.scripts.prepare === "string" &&
52
- data.scripts.prepare.length
53
- ) {
54
- if (data.scripts.prepare.indexOf("ts-patch install") === -1)
55
- data.scripts.prepare =
56
- "ts-patch install && " + data.scripts.prepare;
57
- } else data.scripts.prepare = "ts-patch install";
58
- });
59
- CommandExecutor.run("npm run prepare");
60
-
61
- // CONFIGURE TYPIA
62
- await PluginConfigurator.configure(args);
63
- }
64
-
65
- const inquiry: ArgumentParser.Inquiry<IArguments> = async (
66
- pack,
67
- command,
68
- prompt,
69
- action,
70
- ) => {
71
- // PREPARE ASSETS
72
- command.option("--manager [manager", "package manager");
73
- command.option("--project [project]", "tsconfig.json file location");
74
-
75
- // INTERNAL PROCEDURES
76
- const questioned = { value: false };
77
- const select =
78
- (name: string) =>
79
- (message: string) =>
80
- async <Choice extends string>(
81
- choices: Choice[],
82
- ): Promise<Choice> => {
83
- questioned.value = true;
84
- return (
85
- await prompt()({
86
- type: "list",
87
- name: name,
88
- message: message,
89
- choices: choices,
90
- })
91
- )[name];
92
- };
93
- const configure = async () => {
94
- const fileList: string[] = await (
95
- await fs.promises.readdir(process.cwd())
96
- )
97
- .filter(
98
- (str) =>
99
- str.substring(0, 8) === "tsconfig" &&
100
- str.substring(str.length - 5) === ".json",
101
- )
102
- .sort((x, y) =>
103
- x === "tsconfig.json"
104
- ? -1
105
- : y === "tsconfig.json"
106
- ? 1
107
- : x < y
108
- ? -1
109
- : 1,
110
- );
111
- if (fileList.length === 0) {
112
- if (process.cwd() !== pack.directory)
113
- throw new Error(`Unable to find "tsconfig.json" file.`);
114
- return null;
115
- } else if (fileList.length === 1) return fileList[0];
116
- return select("tsconfig")("TS Config File")(fileList);
117
- };
118
-
119
- // DO CONSTRUCT
120
- return action(async (options) => {
121
- options.manager ??= await select("manager")("Package Manager")([
122
- "npm" as const,
123
- "pnpm" as const,
124
- "yarn" as const,
125
- ]);
126
- pack.manager = options.manager;
127
- options.project ??= await configure();
128
-
129
- if (questioned.value) console.log("");
130
- return options as IArguments;
131
- });
132
- };
133
- }
1
+ import fs from "fs";
2
+
3
+ import { ArgumentParser } from "./setup/ArgumentParser";
4
+ import { CommandExecutor } from "./setup/CommandExecutor";
5
+ import { PackageManager } from "./setup/PackageManager";
6
+ import { PluginConfigurator } from "./setup/PluginConfigurator";
7
+
8
+ export namespace TypiaSetupWizard {
9
+ export interface IArguments {
10
+ manager: "npm" | "pnpm" | "yarn";
11
+ project: string | null;
12
+ }
13
+
14
+ export async function setup(): Promise<void> {
15
+ console.log("----------------------------------------");
16
+ console.log(" Typia Setup Wizard");
17
+ console.log("----------------------------------------");
18
+
19
+ // PREPARE ASSETS
20
+ const pack: PackageManager = await PackageManager.mount();
21
+ const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
22
+
23
+ // INSTALL TYPESCRIPT COMPILERS
24
+ pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
25
+ pack.install({ dev: true, modulo: "ts-node", version: "latest" });
26
+ pack.install({
27
+ dev: true,
28
+ modulo: "typescript",
29
+ version: (() => {
30
+ const version: string = (() => {
31
+ try {
32
+ return require("ts-patch/package.json")?.version ?? "";
33
+ } catch {
34
+ return "";
35
+ }
36
+ })();
37
+ return Number(version.split(".")[0] ?? "") >= 3
38
+ ? "latest"
39
+ : "4.9.5";
40
+ })(),
41
+ });
42
+ args.project ??= (() => {
43
+ CommandExecutor.run("npx tsc --init");
44
+ return (args.project = "tsconfig.json");
45
+ })();
46
+
47
+ // SETUP TRANSFORMER
48
+ await pack.save((data) => {
49
+ data.scripts ??= {};
50
+ if (
51
+ typeof data.scripts.prepare === "string" &&
52
+ data.scripts.prepare.length
53
+ ) {
54
+ if (data.scripts.prepare.indexOf("ts-patch install") === -1)
55
+ data.scripts.prepare =
56
+ "ts-patch install && " + data.scripts.prepare;
57
+ } else data.scripts.prepare = "ts-patch install";
58
+ });
59
+ CommandExecutor.run("npm run prepare");
60
+
61
+ // CONFIGURE TYPIA
62
+ await PluginConfigurator.configure(args);
63
+ }
64
+
65
+ const inquiry: ArgumentParser.Inquiry<IArguments> = async (
66
+ pack,
67
+ command,
68
+ prompt,
69
+ action,
70
+ ) => {
71
+ // PREPARE ASSETS
72
+ command.option("--manager [manager", "package manager");
73
+ command.option("--project [project]", "tsconfig.json file location");
74
+
75
+ // INTERNAL PROCEDURES
76
+ const questioned = { value: false };
77
+ const select =
78
+ (name: string) =>
79
+ (message: string) =>
80
+ async <Choice extends string>(
81
+ choices: Choice[],
82
+ ): Promise<Choice> => {
83
+ questioned.value = true;
84
+ return (
85
+ await prompt()({
86
+ type: "list",
87
+ name: name,
88
+ message: message,
89
+ choices: choices,
90
+ })
91
+ )[name];
92
+ };
93
+ const configure = async () => {
94
+ const fileList: string[] = await (
95
+ await fs.promises.readdir(process.cwd())
96
+ )
97
+ .filter(
98
+ (str) =>
99
+ str.substring(0, 8) === "tsconfig" &&
100
+ str.substring(str.length - 5) === ".json",
101
+ )
102
+ .sort((x, y) =>
103
+ x === "tsconfig.json"
104
+ ? -1
105
+ : y === "tsconfig.json"
106
+ ? 1
107
+ : x < y
108
+ ? -1
109
+ : 1,
110
+ );
111
+ if (fileList.length === 0) {
112
+ if (process.cwd() !== pack.directory)
113
+ throw new Error(`Unable to find "tsconfig.json" file.`);
114
+ return null;
115
+ } else if (fileList.length === 1) return fileList[0];
116
+ return select("tsconfig")("TS Config File")(fileList);
117
+ };
118
+
119
+ // DO CONSTRUCT
120
+ return action(async (options) => {
121
+ options.manager ??= await select("manager")("Package Manager")([
122
+ "npm" as const,
123
+ "pnpm" as const,
124
+ "yarn" as const,
125
+ ]);
126
+ pack.manager = options.manager;
127
+ options.project ??= await configure();
128
+
129
+ if (questioned.value) console.log("");
130
+ return options as IArguments;
131
+ });
132
+ };
133
+ }
@@ -1,8 +1,8 @@
1
- import cp from "child_process";
2
-
3
- export namespace CommandExecutor {
4
- export const run = (str: string): void => {
5
- console.log(str);
6
- cp.execSync(str, { stdio: "ignore" });
7
- };
8
- }
1
+ import cp from "child_process";
2
+
3
+ export namespace CommandExecutor {
4
+ export const run = (str: string): void => {
5
+ console.log(str);
6
+ cp.execSync(str, { stdio: "ignore" });
7
+ };
8
+ }
@@ -1,71 +1,71 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import { CommandExecutor } from "./CommandExecutor";
5
- import { FileRetriever } from "./FileRetriever";
6
-
7
- export class PackageManager {
8
- public manager: string = "npm";
9
- public get file(): string {
10
- return path.join(this.directory, "package.json");
11
- }
12
-
13
- public static async mount(): Promise<PackageManager> {
14
- const location: string | null = await FileRetriever.directory(
15
- "package.json",
16
- )(process.cwd());
17
- if (location === null)
18
- throw new Error(`Unable to find "package.json" file`);
19
-
20
- return new PackageManager(
21
- location,
22
- await this.load(path.join(location, "package.json")),
23
- );
24
- }
25
-
26
- public async save(modifier: (data: Package.Data) => void): Promise<void> {
27
- const content: string = await fs.promises.readFile(this.file, "utf8");
28
- this.data = JSON.parse(content);
29
- modifier(this.data);
30
-
31
- return fs.promises.writeFile(
32
- this.file,
33
- JSON.stringify(this.data, null, 2),
34
- "utf8",
35
- );
36
- }
37
-
38
- public install(props: {
39
- dev: boolean;
40
- modulo: string;
41
- version: string;
42
- }): boolean {
43
- const middle: string =
44
- this.manager === "yarn"
45
- ? `add${props.dev ? " -D" : ""}`
46
- : `install ${props.dev ? "--save-dev" : "--save"}`;
47
- CommandExecutor.run(
48
- `${this.manager} ${middle} ${props.modulo}${
49
- props.version ? `@${props.version}` : ""
50
- }`,
51
- );
52
- return true;
53
- }
54
-
55
- private constructor(
56
- public readonly directory: string,
57
- public data: Package.Data,
58
- ) {}
59
-
60
- private static async load(file: string): Promise<Package.Data> {
61
- const content: string = await fs.promises.readFile(file, "utf8");
62
- return JSON.parse(content);
63
- }
64
- }
65
- export namespace Package {
66
- export interface Data {
67
- scripts?: Record<string, string>;
68
- dependencies?: Record<string, string>;
69
- devDependencies?: Record<string, string>;
70
- }
71
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { CommandExecutor } from "./CommandExecutor";
5
+ import { FileRetriever } from "./FileRetriever";
6
+
7
+ export class PackageManager {
8
+ public manager: string = "npm";
9
+ public get file(): string {
10
+ return path.join(this.directory, "package.json");
11
+ }
12
+
13
+ public static async mount(): Promise<PackageManager> {
14
+ const location: string | null = await FileRetriever.directory(
15
+ "package.json",
16
+ )(process.cwd());
17
+ if (location === null)
18
+ throw new Error(`Unable to find "package.json" file`);
19
+
20
+ return new PackageManager(
21
+ location,
22
+ await this.load(path.join(location, "package.json")),
23
+ );
24
+ }
25
+
26
+ public async save(modifier: (data: Package.Data) => void): Promise<void> {
27
+ const content: string = await fs.promises.readFile(this.file, "utf8");
28
+ this.data = JSON.parse(content);
29
+ modifier(this.data);
30
+
31
+ return fs.promises.writeFile(
32
+ this.file,
33
+ JSON.stringify(this.data, null, 2),
34
+ "utf8",
35
+ );
36
+ }
37
+
38
+ public install(props: {
39
+ dev: boolean;
40
+ modulo: string;
41
+ version: string;
42
+ }): boolean {
43
+ const middle: string =
44
+ this.manager === "yarn"
45
+ ? `add${props.dev ? " -D" : ""}`
46
+ : `install ${props.dev ? "--save-dev" : "--save"}`;
47
+ CommandExecutor.run(
48
+ `${this.manager} ${middle} ${props.modulo}${
49
+ props.version ? `@${props.version}` : ""
50
+ }`,
51
+ );
52
+ return true;
53
+ }
54
+
55
+ private constructor(
56
+ public readonly directory: string,
57
+ public data: Package.Data,
58
+ ) {}
59
+
60
+ private static async load(file: string): Promise<Package.Data> {
61
+ const content: string = await fs.promises.readFile(file, "utf8");
62
+ return JSON.parse(content);
63
+ }
64
+ }
65
+ export namespace Package {
66
+ export interface Data {
67
+ scripts?: Record<string, string>;
68
+ dependencies?: Record<string, string>;
69
+ devDependencies?: Record<string, string>;
70
+ }
71
+ }
@@ -1,70 +1,70 @@
1
- import comments from "comment-json";
2
- import fs from "fs";
3
-
4
- import { TypiaSetupWizard } from "../TypiaSetupWizard";
5
-
6
- export namespace PluginConfigurator {
7
- export async function configure(
8
- args: TypiaSetupWizard.IArguments,
9
- ): Promise<void> {
10
- // GET COMPILER-OPTIONS
11
- const config: comments.CommentObject = comments.parse(
12
- await fs.promises.readFile(args.project!, "utf8"),
13
- ) as comments.CommentObject;
14
- const compilerOptions = config.compilerOptions as
15
- | comments.CommentObject
16
- | undefined;
17
- if (compilerOptions === undefined)
18
- throw new Error(
19
- `${args.project} file does not have "compilerOptions" property.`,
20
- );
21
-
22
- // PREPARE PLUGINS
23
- const plugins: comments.CommentArray<comments.CommentObject> = (() => {
24
- const plugins = compilerOptions.plugins as
25
- | comments.CommentArray<comments.CommentObject>
26
- | undefined;
27
- if (plugins === undefined)
28
- return (compilerOptions.plugins = [] as any);
29
- else if (!Array.isArray(plugins))
30
- throw new Error(
31
- `"plugins" property of ${args.project} must be array type.`,
32
- );
33
- return plugins;
34
- })();
35
-
36
- const strict: boolean | undefined = compilerOptions.strict as
37
- | boolean
38
- | undefined;
39
- const strictNullChecks: boolean | undefined =
40
- compilerOptions.strictNullChecks as boolean | undefined;
41
- const oldbie: comments.CommentObject | undefined = plugins.find(
42
- (p) =>
43
- typeof p === "object" &&
44
- p !== null &&
45
- p.transform === "typia/lib/transform",
46
- );
47
- if (
48
- strictNullChecks !== false &&
49
- (strict === true || strictNullChecks === true) &&
50
- oldbie !== undefined
51
- )
52
- return;
53
-
54
- // DO CONFIGURE
55
- compilerOptions.strictNullChecks = true;
56
- if (strict === undefined && strictNullChecks === undefined)
57
- compilerOptions.strict = true;
58
- if (oldbie === undefined)
59
- plugins.push(
60
- comments.parse(`
61
- {
62
- "transform": "typia/lib/transform"
63
- }`) as comments.CommentObject,
64
- );
65
- await fs.promises.writeFile(
66
- args.project!,
67
- comments.stringify(config, null, 2),
68
- );
69
- }
70
- }
1
+ import comments from "comment-json";
2
+ import fs from "fs";
3
+
4
+ import { TypiaSetupWizard } from "../TypiaSetupWizard";
5
+
6
+ export namespace PluginConfigurator {
7
+ export async function configure(
8
+ args: TypiaSetupWizard.IArguments,
9
+ ): Promise<void> {
10
+ // GET COMPILER-OPTIONS
11
+ const config: comments.CommentObject = comments.parse(
12
+ await fs.promises.readFile(args.project!, "utf8"),
13
+ ) as comments.CommentObject;
14
+ const compilerOptions = config.compilerOptions as
15
+ | comments.CommentObject
16
+ | undefined;
17
+ if (compilerOptions === undefined)
18
+ throw new Error(
19
+ `${args.project} file does not have "compilerOptions" property.`,
20
+ );
21
+
22
+ // PREPARE PLUGINS
23
+ const plugins: comments.CommentArray<comments.CommentObject> = (() => {
24
+ const plugins = compilerOptions.plugins as
25
+ | comments.CommentArray<comments.CommentObject>
26
+ | undefined;
27
+ if (plugins === undefined)
28
+ return (compilerOptions.plugins = [] as any);
29
+ else if (!Array.isArray(plugins))
30
+ throw new Error(
31
+ `"plugins" property of ${args.project} must be array type.`,
32
+ );
33
+ return plugins;
34
+ })();
35
+
36
+ const strict: boolean | undefined = compilerOptions.strict as
37
+ | boolean
38
+ | undefined;
39
+ const strictNullChecks: boolean | undefined =
40
+ compilerOptions.strictNullChecks as boolean | undefined;
41
+ const oldbie: comments.CommentObject | undefined = plugins.find(
42
+ (p) =>
43
+ typeof p === "object" &&
44
+ p !== null &&
45
+ p.transform === "typia/lib/transform",
46
+ );
47
+ if (
48
+ strictNullChecks !== false &&
49
+ (strict === true || strictNullChecks === true) &&
50
+ oldbie !== undefined
51
+ )
52
+ return;
53
+
54
+ // DO CONFIGURE
55
+ compilerOptions.strictNullChecks = true;
56
+ if (strict === undefined && strictNullChecks === undefined)
57
+ compilerOptions.strict = true;
58
+ if (oldbie === undefined)
59
+ plugins.push(
60
+ comments.parse(`
61
+ {
62
+ "transform": "typia/lib/transform"
63
+ }`) as comments.CommentObject,
64
+ );
65
+ await fs.promises.writeFile(
66
+ args.project!,
67
+ comments.stringify(config, null, 2),
68
+ );
69
+ }
70
+ }