typia 3.4.6 → 3.4.8
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.
- package/README.md +12 -2
- package/lib/executable/internal/CommandParser.d.ts +3 -0
- package/lib/executable/internal/CommandParser.js +21 -0
- package/lib/executable/internal/CommandParser.js.map +1 -0
- package/lib/executable/internal/TypiaSetupWizard.d.ts +2 -2
- package/lib/executable/internal/TypiaSetupWizard.js +57 -35
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/typia.js +22 -21
- package/lib/executable/typia.js.map +1 -1
- package/lib/factories/internal/iterate_metadata.js +1 -1
- package/lib/factories/internal/iterate_metadata.js.map +1 -1
- package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
- package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
- package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -0
- package/src/executable/internal/TypiaSetupWizard.ts +108 -87
- package/src/executable/typia.ts +25 -14
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +52 -52
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/MetadataHelper.ts +12 -12
- package/src/factories/internal/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/explore_metadata.ts +91 -91
- package/src/factories/internal/iterate_metadata.ts +1 -2
- package/src/factories/internal/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/iterate_metadata_object.ts +45 -45
- package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
- package/src/factories/internal/iterate_metadata_union.ts +59 -59
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +122 -122
- package/src/metadata/Metadata.ts +477 -477
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/AssertParseProgrammer.ts +45 -45
- package/src/programmers/AssertProgrammer.ts +444 -444
- package/src/programmers/AssertStringifyProgrammer.ts +45 -45
- package/src/programmers/CheckerProgrammer.ts +798 -798
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +51 -51
- package/src/programmers/IsProgrammer.ts +169 -169
- package/src/programmers/IsStringifyProgrammer.ts +49 -49
- package/src/programmers/ValidateParseProgrammer.ts +49 -49
- package/src/programmers/ValidateProgrammer.ts +236 -236
- package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +18 -18
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_schema.ts +221 -221
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_number.ts +181 -181
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +4 -4
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
package/src/Primitive.ts
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Primitive type.
|
|
3
|
-
*
|
|
4
|
-
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
-
* primitive type.
|
|
6
|
-
*
|
|
7
|
-
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
-
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
-
* `string` or `number`.
|
|
10
|
-
*
|
|
11
|
-
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
-
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
-
* type of the TMP type finally be the primitive object.
|
|
14
|
-
*
|
|
15
|
-
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
-
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
-
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
-
*
|
|
19
|
-
* Before | After
|
|
20
|
-
* ------------------------|----------------------------------------
|
|
21
|
-
* `Boolean` | `boolean`
|
|
22
|
-
* `Number` | `number`
|
|
23
|
-
* `String` | `string`
|
|
24
|
-
* `Class` | `object`
|
|
25
|
-
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
-
* Others | No change
|
|
27
|
-
*
|
|
28
|
-
* @template Instance Target argument type.
|
|
29
|
-
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
-
*/
|
|
31
|
-
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
-
? T
|
|
33
|
-
: _Primitive<T>;
|
|
34
|
-
|
|
35
|
-
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
-
|
|
37
|
-
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
-
? Instance extends object
|
|
39
|
-
? Instance extends IJsonable<infer Raw>
|
|
40
|
-
? _ValueOf<Raw> extends object
|
|
41
|
-
? Raw extends object
|
|
42
|
-
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
-
: never // cannot be
|
|
44
|
-
: _ValueOf<Raw> // atomic value
|
|
45
|
-
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
-
: never // cannot be
|
|
47
|
-
: _ValueOf<Instance>;
|
|
48
|
-
|
|
49
|
-
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
-
? _Primitive<T>[]
|
|
51
|
-
: {
|
|
52
|
-
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
-
? never
|
|
54
|
-
: _Primitive<Instance[P]>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
-
? boolean
|
|
59
|
-
: _IsValueOf<Instance, Number> extends true
|
|
60
|
-
? number
|
|
61
|
-
: _IsValueOf<Instance, String> extends true
|
|
62
|
-
? string
|
|
63
|
-
: Instance;
|
|
64
|
-
|
|
65
|
-
type _IsValueOf<
|
|
66
|
-
Instance,
|
|
67
|
-
Object extends IValueOf<any>,
|
|
68
|
-
> = Instance extends Object
|
|
69
|
-
? Object extends IValueOf<infer Primitive>
|
|
70
|
-
? Instance extends Primitive
|
|
71
|
-
? false
|
|
72
|
-
: true // not Primitive, but Object
|
|
73
|
-
: false // cannot be
|
|
74
|
-
: false;
|
|
75
|
-
|
|
76
|
-
interface IValueOf<T> {
|
|
77
|
-
valueOf(): T;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface IJsonable<T> {
|
|
81
|
-
toJSON(): T;
|
|
82
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Primitive type.
|
|
3
|
+
*
|
|
4
|
+
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
+
* primitive type.
|
|
6
|
+
*
|
|
7
|
+
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
+
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
+
* `string` or `number`.
|
|
10
|
+
*
|
|
11
|
+
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
+
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
+
* type of the TMP type finally be the primitive object.
|
|
14
|
+
*
|
|
15
|
+
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
+
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
+
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
+
*
|
|
19
|
+
* Before | After
|
|
20
|
+
* ------------------------|----------------------------------------
|
|
21
|
+
* `Boolean` | `boolean`
|
|
22
|
+
* `Number` | `number`
|
|
23
|
+
* `String` | `string`
|
|
24
|
+
* `Class` | `object`
|
|
25
|
+
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
+
* Others | No change
|
|
27
|
+
*
|
|
28
|
+
* @template Instance Target argument type.
|
|
29
|
+
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
+
? T
|
|
33
|
+
: _Primitive<T>;
|
|
34
|
+
|
|
35
|
+
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
+
|
|
37
|
+
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
+
? Instance extends object
|
|
39
|
+
? Instance extends IJsonable<infer Raw>
|
|
40
|
+
? _ValueOf<Raw> extends object
|
|
41
|
+
? Raw extends object
|
|
42
|
+
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
+
: never // cannot be
|
|
44
|
+
: _ValueOf<Raw> // atomic value
|
|
45
|
+
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
+
: never // cannot be
|
|
47
|
+
: _ValueOf<Instance>;
|
|
48
|
+
|
|
49
|
+
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
+
? _Primitive<T>[]
|
|
51
|
+
: {
|
|
52
|
+
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
+
? never
|
|
54
|
+
: _Primitive<Instance[P]>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
+
? boolean
|
|
59
|
+
: _IsValueOf<Instance, Number> extends true
|
|
60
|
+
? number
|
|
61
|
+
: _IsValueOf<Instance, String> extends true
|
|
62
|
+
? string
|
|
63
|
+
: Instance;
|
|
64
|
+
|
|
65
|
+
type _IsValueOf<
|
|
66
|
+
Instance,
|
|
67
|
+
Object extends IValueOf<any>,
|
|
68
|
+
> = Instance extends Object
|
|
69
|
+
? Object extends IValueOf<infer Primitive>
|
|
70
|
+
? Instance extends Primitive
|
|
71
|
+
? false
|
|
72
|
+
: true // not Primitive, but Object
|
|
73
|
+
: false // cannot be
|
|
74
|
+
: false;
|
|
75
|
+
|
|
76
|
+
interface IValueOf<T> {
|
|
77
|
+
valueOf(): T;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface IJsonable<T> {
|
|
81
|
+
toJSON(): T;
|
|
82
|
+
}
|
package/src/TypeGuardError.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export class TypeGuardError extends Error {
|
|
2
|
-
public readonly method: string;
|
|
3
|
-
public readonly path: string | undefined;
|
|
4
|
-
public readonly expected: string;
|
|
5
|
-
public readonly value: any;
|
|
6
|
-
|
|
7
|
-
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
-
// MESSAGE CONSTRUCTION
|
|
9
|
-
super(
|
|
10
|
-
props.message ||
|
|
11
|
-
`Error on ${props.method}(): invalid type${
|
|
12
|
-
props.path ? ` on ${props.path}` : ""
|
|
13
|
-
}, expect to be ${props.expected}`,
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// INHERITANCE POLYFILL
|
|
17
|
-
const proto = new.target.prototype;
|
|
18
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
-
else (this as any).__proto__ = proto;
|
|
20
|
-
|
|
21
|
-
// ASSIGN MEMBERS
|
|
22
|
-
this.method = props.method;
|
|
23
|
-
this.path = props.path;
|
|
24
|
-
this.expected = props.expected;
|
|
25
|
-
this.value = props.value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export namespace TypeGuardError {
|
|
29
|
-
export interface IProps {
|
|
30
|
-
method: string;
|
|
31
|
-
path?: string;
|
|
32
|
-
expected: string;
|
|
33
|
-
value: any;
|
|
34
|
-
message?: string;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
export class TypeGuardError extends Error {
|
|
2
|
+
public readonly method: string;
|
|
3
|
+
public readonly path: string | undefined;
|
|
4
|
+
public readonly expected: string;
|
|
5
|
+
public readonly value: any;
|
|
6
|
+
|
|
7
|
+
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
+
// MESSAGE CONSTRUCTION
|
|
9
|
+
super(
|
|
10
|
+
props.message ||
|
|
11
|
+
`Error on ${props.method}(): invalid type${
|
|
12
|
+
props.path ? ` on ${props.path}` : ""
|
|
13
|
+
}, expect to be ${props.expected}`,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// INHERITANCE POLYFILL
|
|
17
|
+
const proto = new.target.prototype;
|
|
18
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
+
else (this as any).__proto__ = proto;
|
|
20
|
+
|
|
21
|
+
// ASSIGN MEMBERS
|
|
22
|
+
this.method = props.method;
|
|
23
|
+
this.path = props.path;
|
|
24
|
+
this.expected = props.expected;
|
|
25
|
+
this.value = props.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export namespace TypeGuardError {
|
|
29
|
+
export interface IProps {
|
|
30
|
+
method: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
expected: string;
|
|
33
|
+
value: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -3,23 +3,25 @@ import type Comment from "comment-json";
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
|
|
5
5
|
export namespace TypiaSetupWizard {
|
|
6
|
-
export async function ttypescript(): Promise<void> {
|
|
6
|
+
export async function ttypescript(manager: string): Promise<void> {
|
|
7
7
|
// INSTALL
|
|
8
|
-
const pack: any = await prepare();
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const pack: any = await prepare(manager);
|
|
9
|
+
add(manager)(pack)("ttypescript", true);
|
|
10
|
+
add(manager)(pack)("ts-node", true);
|
|
11
11
|
|
|
12
12
|
// TSCONFIG.JSON
|
|
13
|
-
await configure();
|
|
13
|
+
await configure(manager);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export async function tsPatch(): Promise<void> {
|
|
16
|
+
export async function tsPatch(manager: string): Promise<void> {
|
|
17
17
|
// INSTALL
|
|
18
|
-
|
|
19
|
-
install(pack, "ts-patch", "--save-dev");
|
|
18
|
+
add(manager)(await prepare(manager))("ts-patch", true);
|
|
20
19
|
execute("npx ts-patch install");
|
|
21
20
|
|
|
22
21
|
// PACKAGE.JSON
|
|
22
|
+
const pack: any = JSON.parse(
|
|
23
|
+
await fs.promises.readFile("package.json", "utf8"),
|
|
24
|
+
);
|
|
23
25
|
if (!pack.scripts || typeof pack.scripts !== "object")
|
|
24
26
|
pack.scripts = {};
|
|
25
27
|
if (typeof pack.scripts.prepare === "string") {
|
|
@@ -35,105 +37,124 @@ export namespace TypiaSetupWizard {
|
|
|
35
37
|
);
|
|
36
38
|
|
|
37
39
|
// TSCONFIG.JSON
|
|
38
|
-
await configure();
|
|
40
|
+
await configure(manager);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
async function prepare(): Promise<any> {
|
|
43
|
+
async function prepare(manager: string): Promise<any> {
|
|
42
44
|
if (fs.existsSync("package.json") === false)
|
|
43
45
|
halt(() => {})("make package.json file or move to it.");
|
|
46
|
+
|
|
44
47
|
const pack: any = JSON.parse(
|
|
45
48
|
await fs.promises.readFile("package.json", "utf8"),
|
|
46
49
|
);
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
const wizard = add(manager)(pack);
|
|
51
|
+
|
|
52
|
+
wizard("typia", false);
|
|
53
|
+
wizard("typescript", true);
|
|
49
54
|
return pack;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (fs.existsSync("tsconfig.json") === false)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const halter: (msg: string) => never = halt(() => {
|
|
65
|
-
if (temporary === true)
|
|
66
|
-
cp.execSync("npm uninstall --save-dev comment-json");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// READ TSCONFIG FILE
|
|
70
|
-
const Comment: typeof import("comment-json") = await import(
|
|
71
|
-
process.cwd() + "/node_modules/comment-json"
|
|
72
|
-
);
|
|
73
|
-
const config: Comment.CommentObject = Comment.parse(
|
|
74
|
-
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
75
|
-
) as Comment.CommentObject;
|
|
76
|
-
const options = config.compilerOptions as
|
|
77
|
-
| Comment.CommentObject
|
|
78
|
-
| undefined;
|
|
79
|
-
if (options === undefined)
|
|
80
|
-
halter(
|
|
81
|
-
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
57
|
+
const configure =
|
|
58
|
+
(manager: string) =>
|
|
59
|
+
async (pack: any): Promise<void> => {
|
|
60
|
+
// VALIDATE PRERATATION
|
|
61
|
+
if (fs.existsSync("tsconfig.json") === false) {
|
|
62
|
+
execute("npx tsc --init");
|
|
63
|
+
if (fs.existsSync("tsconfig.json") === false)
|
|
64
|
+
halt(() => {})("tsconfig.json file does not exist.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const temporary: boolean = !fs.existsSync(
|
|
68
|
+
"node_modules/comment-json",
|
|
82
69
|
);
|
|
70
|
+
if (temporary === true) add(manager)(pack)("comment-json", true);
|
|
71
|
+
|
|
72
|
+
const halter: (msg: string) => never = halt(() => {
|
|
73
|
+
if (temporary === true) remove(manager)("comment-json", true);
|
|
74
|
+
});
|
|
83
75
|
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
76
|
+
// READ TSCONFIG FILE
|
|
77
|
+
const Comment: typeof import("comment-json") = await import(
|
|
78
|
+
process.cwd() + "/node_modules/comment-json"
|
|
79
|
+
);
|
|
80
|
+
const config: Comment.CommentObject = Comment.parse(
|
|
81
|
+
await fs.promises.readFile("tsconfig.json", "utf8"),
|
|
82
|
+
) as Comment.CommentObject;
|
|
83
|
+
const options = config.compilerOptions as
|
|
84
|
+
| Comment.CommentObject
|
|
87
85
|
| undefined;
|
|
88
|
-
if (
|
|
89
|
-
else if (!Array.isArray(plugins))
|
|
86
|
+
if (options === undefined)
|
|
90
87
|
halter(
|
|
91
|
-
`
|
|
88
|
+
`tsconfig.json file does not have "compilerOptions" property.`,
|
|
92
89
|
);
|
|
93
|
-
return plugins;
|
|
94
|
-
})();
|
|
95
|
-
|
|
96
|
-
// CHECK WHETHER CONFIGURED
|
|
97
|
-
const strict: boolean = options.strict === true;
|
|
98
|
-
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
99
|
-
(p) =>
|
|
100
|
-
typeof p === "object" &&
|
|
101
|
-
p !== null &&
|
|
102
|
-
p.transform === "typia/lib/transform",
|
|
103
|
-
);
|
|
104
90
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
92
|
+
(() => {
|
|
93
|
+
const plugins = options.plugins as
|
|
94
|
+
| Comment.CommentArray<Comment.CommentObject>
|
|
95
|
+
| undefined;
|
|
96
|
+
if (plugins === undefined)
|
|
97
|
+
return (options.plugins = [] as any);
|
|
98
|
+
else if (!Array.isArray(plugins))
|
|
99
|
+
halter(
|
|
100
|
+
`"plugins" property of tsconfig.json must be array type.`,
|
|
101
|
+
);
|
|
102
|
+
return plugins;
|
|
103
|
+
})();
|
|
104
|
+
|
|
105
|
+
// CHECK WHETHER CONFIGURED
|
|
106
|
+
const strict: boolean = options.strict === true;
|
|
107
|
+
const oldbie: Comment.CommentObject | undefined = plugins.find(
|
|
108
|
+
(p) =>
|
|
109
|
+
typeof p === "object" &&
|
|
110
|
+
p !== null &&
|
|
111
|
+
p.transform === "typia/lib/transform",
|
|
108
112
|
);
|
|
109
|
-
} else {
|
|
110
|
-
// DO CONFIGURE
|
|
111
|
-
options.strict = true;
|
|
112
|
-
plugins.push({ transform: "typia/lib/transform" } as any);
|
|
113
|
-
|
|
114
|
-
await fs.promises.writeFile(
|
|
115
|
-
"tsconfig.json",
|
|
116
|
-
Comment.stringify(config, null, 2),
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
if (temporary === true)
|
|
120
|
-
cp.execSync("npm uninstall --save-dev comment-json");
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
113
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
114
|
+
if (strict === true && oldbie !== undefined) {
|
|
115
|
+
console.log(
|
|
116
|
+
"you've been already configured the tsconfig.json file.",
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
// DO CONFIGURE
|
|
120
|
+
options.strict = true;
|
|
121
|
+
plugins.push({ transform: "typia/lib/transform" } as any);
|
|
122
|
+
|
|
123
|
+
await fs.promises.writeFile(
|
|
124
|
+
"tsconfig.json",
|
|
125
|
+
Comment.stringify(config, null, 2),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (temporary === true) remove(manager)("comment-json", false);
|
|
129
|
+
};
|
|
135
130
|
}
|
|
136
131
|
|
|
132
|
+
const add =
|
|
133
|
+
(manager: string) =>
|
|
134
|
+
(pack: any) =>
|
|
135
|
+
(modulo: string, devOnly: boolean): void => {
|
|
136
|
+
const exists: boolean =
|
|
137
|
+
(devOnly === false
|
|
138
|
+
? !!pack.dependencies && !!pack.dependencies[modulo]
|
|
139
|
+
: !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
|
|
140
|
+
fs.existsSync("node_modules/" + modulo);
|
|
141
|
+
const middle: string =
|
|
142
|
+
manager === "yarn"
|
|
143
|
+
? `add${devOnly ? " -D" : ""}`
|
|
144
|
+
: `install ${devOnly ? "--save-dev" : "--save"}`;
|
|
145
|
+
if (exists === false) execute(`${manager} ${middle} ${modulo}`);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const remove =
|
|
149
|
+
(manager: string) =>
|
|
150
|
+
(modulo: string, devOnly: boolean): void => {
|
|
151
|
+
const middle: string =
|
|
152
|
+
manager === "yarn"
|
|
153
|
+
? `remove${devOnly ? " -D" : ""}`
|
|
154
|
+
: `uninstall ${devOnly ? "--save-dev" : "--save"}`;
|
|
155
|
+
execute(`${manager} ${middle} ${modulo}`);
|
|
156
|
+
};
|
|
157
|
+
|
|
137
158
|
const halt =
|
|
138
159
|
(closer: () => any) =>
|
|
139
160
|
(desc: string): never => {
|
package/src/executable/typia.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { CommandParser } from "./internal/CommandParser";
|
|
2
3
|
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
3
4
|
|
|
4
|
-
const USAGE = `
|
|
5
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
6
|
+
|
|
7
|
+
npx typia setup \\
|
|
8
|
+
--compiler (ttypescript|ts-patch) \\
|
|
9
|
+
--manager (npm|pnpm|yarn)
|
|
5
10
|
|
|
6
11
|
- npx typia setup
|
|
7
|
-
- npx typia setup ttypescript
|
|
8
|
-
- npx typia setup ts-patch
|
|
12
|
+
- npx typia setup --compiler ttypescript
|
|
13
|
+
- npx typia setup --compiler ts-patch
|
|
14
|
+
- npx typia setup --manager pnpm`;
|
|
9
15
|
|
|
10
16
|
function halt(desc: string): never {
|
|
11
17
|
console.error(desc);
|
|
@@ -13,21 +19,26 @@ function halt(desc: string): never {
|
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
async function setup(): Promise<void> {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const options: Record<string, string> = CommandParser.parse(
|
|
23
|
+
process.argv.slice(3),
|
|
24
|
+
);
|
|
25
|
+
const manager: string = options.manager ?? "npm";
|
|
26
|
+
const compiler: string = options.compiler ?? "ttypescript";
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
(compiler !== "ttypescript" && compiler !== "ts-patch") ||
|
|
30
|
+
(manager !== "npm" && manager !== "pnpm" && manager !== "yarn")
|
|
31
|
+
)
|
|
32
|
+
halt(USAGE);
|
|
33
|
+
else if (compiler === "ttypescript")
|
|
34
|
+
await TypiaSetupWizard.ttypescript(manager);
|
|
35
|
+
else await TypiaSetupWizard.tsPatch(manager);
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
async function main(): Promise<void> {
|
|
28
39
|
const type: string | undefined = process.argv[2];
|
|
29
|
-
if (type ===
|
|
30
|
-
else
|
|
40
|
+
if (type === "setup") await setup();
|
|
41
|
+
else halt(USAGE);
|
|
31
42
|
}
|
|
32
43
|
main().catch((exp) => {
|
|
33
44
|
console.error(exp);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
-
return comments
|
|
6
|
-
.map((part) => part.text)
|
|
7
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
-
.join("");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
+
return comments
|
|
6
|
+
.map((part) => part.text)
|
|
7
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
+
.join("");
|
|
9
|
+
}
|
|
10
|
+
}
|