typia 3.6.4 → 3.6.6
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/lib/functional/$is_uuid.js +1 -1
- package/lib/functional/$is_uuid.js.map +1 -1
- package/lib/module.d.ts +1 -1
- package/lib/programmers/internal/application_number.js +1 -1
- package/package.json +1 -1
- package/src/executable/setup/ArgumentParser.ts +91 -91
- package/src/executable/setup/FileRetriever.ts +33 -33
- package/src/executable/setup/PackageManager.ts +92 -92
- package/src/executable/setup/PluginConfigurator.ts +99 -99
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
- package/src/functional/$is_uuid.ts +2 -1
- package/src/module.ts +1946 -1946
- package/src/programmers/AssertCloneProgrammer.ts +70 -70
- package/src/programmers/AssertParseProgrammer.ts +65 -65
- package/src/programmers/AssertProgrammer.ts +232 -232
- package/src/programmers/AssertPruneProgrammer.ts +67 -67
- package/src/programmers/AssertStringifyProgrammer.ts +71 -71
- package/src/programmers/CheckerProgrammer.ts +893 -893
- package/src/programmers/CloneProgrammer.ts +386 -386
- package/src/programmers/FeatureProgrammer.ts +505 -505
- package/src/programmers/IsCloneProgrammer.ts +80 -80
- package/src/programmers/IsParseProgrammer.ts +74 -74
- package/src/programmers/IsPruneProgrammer.ts +75 -75
- package/src/programmers/IsStringifyProgrammer.ts +81 -81
- package/src/programmers/PruneProgrammer.ts +341 -341
- package/src/programmers/RandomProgrammer.ts +391 -391
- package/src/programmers/StringifyProgrammer.ts +795 -795
- package/src/programmers/ValidateCloneProgrammer.ts +90 -90
- package/src/programmers/ValidateParseProgrammer.ts +69 -69
- package/src/programmers/ValidateProgrammer.ts +266 -266
- package/src/programmers/ValidatePruneProgrammer.ts +83 -83
- package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
- package/src/programmers/internal/application_number.ts +1 -1
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomGenerator.ts +42 -42
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +48 -48
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
- package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
- package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
- package/src/transformers/features/validators/IsTransformer.ts +10 -10
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +99 -99
|
@@ -5,5 +5,5 @@ function $is_uuid(str) {
|
|
|
5
5
|
return REGEX.test(str);
|
|
6
6
|
}
|
|
7
7
|
exports.$is_uuid = $is_uuid;
|
|
8
|
-
var REGEX = /^[0-
|
|
8
|
+
var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
9
9
|
//# sourceMappingURL=$is_uuid.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"$is_uuid.js","sourceRoot":"","sources":["../../src/functional/$is_uuid.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,GAAW;IAChC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAFD,4BAEC;AACD,IAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"$is_uuid.js","sourceRoot":"","sources":["../../src/functional/$is_uuid.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,GAAW;IAChC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAFD,4BAEC;AACD,IAAM,KAAK,GACP,qHAAqH,CAAC"}
|
package/lib/module.d.ts
CHANGED
|
@@ -1071,7 +1071,7 @@ export declare function createValidateEquals(): never;
|
|
|
1071
1071
|
*
|
|
1072
1072
|
* @author Jeongho Nam - https://github.com/samchon
|
|
1073
1073
|
*/
|
|
1074
|
-
export declare function createValidateEquals<T>(): (input: unknown) => IValidation
|
|
1074
|
+
export declare function createValidateEquals<T>(): (input: unknown) => IValidation<T>;
|
|
1075
1075
|
/**
|
|
1076
1076
|
* Creates a reusable {@link isParse} function.
|
|
1077
1077
|
*
|
|
@@ -56,7 +56,7 @@ var application_number = function (nullable, attribute) {
|
|
|
56
56
|
(attribute["x-typia-metaTags"] || []).find(function (tag) { return tag.kind === "type" && tag.value === "uint"; }))
|
|
57
57
|
if (output.minimum === undefined || output.minimum < 0)
|
|
58
58
|
output.minimum = 0;
|
|
59
|
-
else if (output.exclusiveMinimum
|
|
59
|
+
else if (output.exclusiveMinimum !== undefined &&
|
|
60
60
|
output.exclusiveMinimum < 0) {
|
|
61
61
|
delete output.exclusiveMinimum;
|
|
62
62
|
output.maximum = 0;
|
package/package.json
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import type CommanderModule from "commander";
|
|
2
|
-
import type * as InquirerModule from "inquirer";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
import { FileRetriever } from "./FileRetriever";
|
|
6
|
-
import { PackageManager } from "./PackageManager";
|
|
7
|
-
|
|
8
|
-
export namespace ArgumentParser {
|
|
9
|
-
export type Inquiry<T> = (
|
|
10
|
-
pack: PackageManager,
|
|
11
|
-
command: CommanderModule.Command,
|
|
12
|
-
prompt: (
|
|
13
|
-
opt?: InquirerModule.StreamOptions,
|
|
14
|
-
) => InquirerModule.PromptModule,
|
|
15
|
-
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
16
|
-
) => Promise<T>;
|
|
17
|
-
|
|
18
|
-
export const parse =
|
|
19
|
-
(pack: PackageManager) =>
|
|
20
|
-
(erase: boolean) =>
|
|
21
|
-
async <T>(
|
|
22
|
-
inquiry: (
|
|
23
|
-
pack: PackageManager,
|
|
24
|
-
command: CommanderModule.Command,
|
|
25
|
-
prompt: (
|
|
26
|
-
opt?: InquirerModule.StreamOptions,
|
|
27
|
-
) => InquirerModule.PromptModule,
|
|
28
|
-
action: (
|
|
29
|
-
closure: (options: Partial<T>) => Promise<T>,
|
|
30
|
-
) => Promise<T>,
|
|
31
|
-
) => Promise<T>,
|
|
32
|
-
): Promise<T> => {
|
|
33
|
-
// INSTALL TEMPORARY PACKAGES
|
|
34
|
-
const newbie = {
|
|
35
|
-
commander: pack.install({
|
|
36
|
-
dev: true,
|
|
37
|
-
modulo: "commander",
|
|
38
|
-
version: "10.0.0",
|
|
39
|
-
silent: true,
|
|
40
|
-
}),
|
|
41
|
-
inquirer: pack.install({
|
|
42
|
-
dev: true,
|
|
43
|
-
modulo: "inquirer",
|
|
44
|
-
version: "8.2.5",
|
|
45
|
-
silent: true,
|
|
46
|
-
}),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// LOAD INSTALLED MODULES
|
|
50
|
-
const { program: command }: typeof CommanderModule =
|
|
51
|
-
await FileRetriever.require(
|
|
52
|
-
path.join("node_modules", "commander"),
|
|
53
|
-
)(pack.directory);
|
|
54
|
-
const { createPromptModule: prompt }: typeof InquirerModule =
|
|
55
|
-
await FileRetriever.require(
|
|
56
|
-
path.join("node_modules", "inquirer"),
|
|
57
|
-
)(pack.directory);
|
|
58
|
-
|
|
59
|
-
// TAKE OPTIONS
|
|
60
|
-
const action = (closure: (options: Partial<T>) => Promise<T>) =>
|
|
61
|
-
new Promise<T>((resolve, reject) => {
|
|
62
|
-
command.action(async (options) => {
|
|
63
|
-
try {
|
|
64
|
-
resolve(await closure(options));
|
|
65
|
-
} catch (exp) {
|
|
66
|
-
reject(exp);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
command.parseAsync().catch(reject);
|
|
70
|
-
});
|
|
71
|
-
const output: T | Error = await (async () => {
|
|
72
|
-
try {
|
|
73
|
-
return await inquiry(pack, command, prompt, action);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
return error as Error;
|
|
76
|
-
}
|
|
77
|
-
})();
|
|
78
|
-
|
|
79
|
-
// REMOVE TEMPORARY PACKAGES
|
|
80
|
-
if (erase === true) {
|
|
81
|
-
if (newbie.commander)
|
|
82
|
-
pack.erase({ modulo: "commander", silent: true });
|
|
83
|
-
if (newbie.inquirer)
|
|
84
|
-
pack.erase({ modulo: "inquirer", silent: true });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// RETURNS
|
|
88
|
-
if (output instanceof Error) throw output;
|
|
89
|
-
return output;
|
|
90
|
-
};
|
|
91
|
-
}
|
|
1
|
+
import type CommanderModule from "commander";
|
|
2
|
+
import type * as InquirerModule from "inquirer";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
import { FileRetriever } from "./FileRetriever";
|
|
6
|
+
import { PackageManager } from "./PackageManager";
|
|
7
|
+
|
|
8
|
+
export namespace ArgumentParser {
|
|
9
|
+
export type Inquiry<T> = (
|
|
10
|
+
pack: PackageManager,
|
|
11
|
+
command: CommanderModule.Command,
|
|
12
|
+
prompt: (
|
|
13
|
+
opt?: InquirerModule.StreamOptions,
|
|
14
|
+
) => InquirerModule.PromptModule,
|
|
15
|
+
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
|
|
16
|
+
) => Promise<T>;
|
|
17
|
+
|
|
18
|
+
export const parse =
|
|
19
|
+
(pack: PackageManager) =>
|
|
20
|
+
(erase: boolean) =>
|
|
21
|
+
async <T>(
|
|
22
|
+
inquiry: (
|
|
23
|
+
pack: PackageManager,
|
|
24
|
+
command: CommanderModule.Command,
|
|
25
|
+
prompt: (
|
|
26
|
+
opt?: InquirerModule.StreamOptions,
|
|
27
|
+
) => InquirerModule.PromptModule,
|
|
28
|
+
action: (
|
|
29
|
+
closure: (options: Partial<T>) => Promise<T>,
|
|
30
|
+
) => Promise<T>,
|
|
31
|
+
) => Promise<T>,
|
|
32
|
+
): Promise<T> => {
|
|
33
|
+
// INSTALL TEMPORARY PACKAGES
|
|
34
|
+
const newbie = {
|
|
35
|
+
commander: pack.install({
|
|
36
|
+
dev: true,
|
|
37
|
+
modulo: "commander",
|
|
38
|
+
version: "10.0.0",
|
|
39
|
+
silent: true,
|
|
40
|
+
}),
|
|
41
|
+
inquirer: pack.install({
|
|
42
|
+
dev: true,
|
|
43
|
+
modulo: "inquirer",
|
|
44
|
+
version: "8.2.5",
|
|
45
|
+
silent: true,
|
|
46
|
+
}),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// LOAD INSTALLED MODULES
|
|
50
|
+
const { program: command }: typeof CommanderModule =
|
|
51
|
+
await FileRetriever.require(
|
|
52
|
+
path.join("node_modules", "commander"),
|
|
53
|
+
)(pack.directory);
|
|
54
|
+
const { createPromptModule: prompt }: typeof InquirerModule =
|
|
55
|
+
await FileRetriever.require(
|
|
56
|
+
path.join("node_modules", "inquirer"),
|
|
57
|
+
)(pack.directory);
|
|
58
|
+
|
|
59
|
+
// TAKE OPTIONS
|
|
60
|
+
const action = (closure: (options: Partial<T>) => Promise<T>) =>
|
|
61
|
+
new Promise<T>((resolve, reject) => {
|
|
62
|
+
command.action(async (options) => {
|
|
63
|
+
try {
|
|
64
|
+
resolve(await closure(options));
|
|
65
|
+
} catch (exp) {
|
|
66
|
+
reject(exp);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
command.parseAsync().catch(reject);
|
|
70
|
+
});
|
|
71
|
+
const output: T | Error = await (async () => {
|
|
72
|
+
try {
|
|
73
|
+
return await inquiry(pack, command, prompt, action);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return error as Error;
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
// REMOVE TEMPORARY PACKAGES
|
|
80
|
+
if (erase === true) {
|
|
81
|
+
if (newbie.commander)
|
|
82
|
+
pack.erase({ modulo: "commander", silent: true });
|
|
83
|
+
if (newbie.inquirer)
|
|
84
|
+
pack.erase({ modulo: "inquirer", silent: true });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// RETURNS
|
|
88
|
+
if (output instanceof Error) throw output;
|
|
89
|
+
return output;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
export namespace FileRetriever {
|
|
5
|
-
export const directory =
|
|
6
|
-
(name: string) =>
|
|
7
|
-
(dir: string, depth: number = 0): string | null => {
|
|
8
|
-
const location: string = path.join(dir, name);
|
|
9
|
-
if (fs.existsSync(location)) return dir;
|
|
10
|
-
else if (depth > 2) return null;
|
|
11
|
-
return directory(name)(path.join(dir, ".."), depth + 1);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const file =
|
|
15
|
-
(name: string) =>
|
|
16
|
-
(directory: string, depth: number = 0): string | null => {
|
|
17
|
-
const location: string = path.join(directory, name);
|
|
18
|
-
if (fs.existsSync(location)) return location;
|
|
19
|
-
else if (depth > 2) return null;
|
|
20
|
-
return file(name)(path.join(directory, ".."), depth + 1);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const require =
|
|
24
|
-
(name: string) =>
|
|
25
|
-
async (directory: string, depth: number = 0) => {
|
|
26
|
-
const location: string | null = file(name)(directory, depth);
|
|
27
|
-
if (location === null)
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Unable to find installed module. Please report to the nestia - https://github.com/samchon/nestia/issues`,
|
|
30
|
-
);
|
|
31
|
-
return import(location);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export namespace FileRetriever {
|
|
5
|
+
export const directory =
|
|
6
|
+
(name: string) =>
|
|
7
|
+
(dir: string, depth: number = 0): string | null => {
|
|
8
|
+
const location: string = path.join(dir, name);
|
|
9
|
+
if (fs.existsSync(location)) return dir;
|
|
10
|
+
else if (depth > 2) return null;
|
|
11
|
+
return directory(name)(path.join(dir, ".."), depth + 1);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const file =
|
|
15
|
+
(name: string) =>
|
|
16
|
+
(directory: string, depth: number = 0): string | null => {
|
|
17
|
+
const location: string = path.join(directory, name);
|
|
18
|
+
if (fs.existsSync(location)) return location;
|
|
19
|
+
else if (depth > 2) return null;
|
|
20
|
+
return file(name)(path.join(directory, ".."), depth + 1);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const require =
|
|
24
|
+
(name: string) =>
|
|
25
|
+
async (directory: string, depth: number = 0) => {
|
|
26
|
+
const location: string | null = file(name)(directory, depth);
|
|
27
|
+
if (location === null)
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Unable to find installed module. Please report to the nestia - https://github.com/samchon/nestia/issues`,
|
|
30
|
+
);
|
|
31
|
+
return import(location);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,92 +1,92 @@
|
|
|
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
|
-
silent?: boolean;
|
|
41
|
-
modulo: string;
|
|
42
|
-
version?: string;
|
|
43
|
-
}): boolean {
|
|
44
|
-
const container = props.dev
|
|
45
|
-
? this.data.devDependencies
|
|
46
|
-
: this.data.dependencies;
|
|
47
|
-
if (
|
|
48
|
-
!!container?.[props.modulo] &&
|
|
49
|
-
FileRetriever.file(path.join("node_modules", props.modulo))(
|
|
50
|
-
this.directory,
|
|
51
|
-
) !== null
|
|
52
|
-
)
|
|
53
|
-
return false;
|
|
54
|
-
|
|
55
|
-
const middle: string =
|
|
56
|
-
this.manager === "yarn"
|
|
57
|
-
? `add${props.dev ? " -D" : ""}`
|
|
58
|
-
: `install ${props.dev ? "--save-dev" : "--save"}`;
|
|
59
|
-
CommandExecutor.run(
|
|
60
|
-
`${this.manager} ${middle} ${props.modulo}${
|
|
61
|
-
props.version ? `@${props.version}` : ""
|
|
62
|
-
}`,
|
|
63
|
-
!!props.silent,
|
|
64
|
-
);
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public erase(props: { modulo: string; silent?: boolean }): void {
|
|
69
|
-
const middle: string = this.manager === "yarn" ? "remove" : "uninstall";
|
|
70
|
-
CommandExecutor.run(
|
|
71
|
-
`${this.manager} ${middle} ${props.modulo}`,
|
|
72
|
-
!!props.silent,
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private constructor(
|
|
77
|
-
public readonly directory: string,
|
|
78
|
-
public data: Package.Data,
|
|
79
|
-
) {}
|
|
80
|
-
|
|
81
|
-
private static async load(file: string): Promise<Package.Data> {
|
|
82
|
-
const content: string = await fs.promises.readFile(file, "utf8");
|
|
83
|
-
return JSON.parse(content);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export namespace Package {
|
|
87
|
-
export interface Data {
|
|
88
|
-
scripts?: Record<string, string>;
|
|
89
|
-
dependencies?: Record<string, string>;
|
|
90
|
-
devDependencies?: Record<string, string>;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
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
|
+
silent?: boolean;
|
|
41
|
+
modulo: string;
|
|
42
|
+
version?: string;
|
|
43
|
+
}): boolean {
|
|
44
|
+
const container = props.dev
|
|
45
|
+
? this.data.devDependencies
|
|
46
|
+
: this.data.dependencies;
|
|
47
|
+
if (
|
|
48
|
+
!!container?.[props.modulo] &&
|
|
49
|
+
FileRetriever.file(path.join("node_modules", props.modulo))(
|
|
50
|
+
this.directory,
|
|
51
|
+
) !== null
|
|
52
|
+
)
|
|
53
|
+
return false;
|
|
54
|
+
|
|
55
|
+
const middle: string =
|
|
56
|
+
this.manager === "yarn"
|
|
57
|
+
? `add${props.dev ? " -D" : ""}`
|
|
58
|
+
: `install ${props.dev ? "--save-dev" : "--save"}`;
|
|
59
|
+
CommandExecutor.run(
|
|
60
|
+
`${this.manager} ${middle} ${props.modulo}${
|
|
61
|
+
props.version ? `@${props.version}` : ""
|
|
62
|
+
}`,
|
|
63
|
+
!!props.silent,
|
|
64
|
+
);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public erase(props: { modulo: string; silent?: boolean }): void {
|
|
69
|
+
const middle: string = this.manager === "yarn" ? "remove" : "uninstall";
|
|
70
|
+
CommandExecutor.run(
|
|
71
|
+
`${this.manager} ${middle} ${props.modulo}`,
|
|
72
|
+
!!props.silent,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private constructor(
|
|
77
|
+
public readonly directory: string,
|
|
78
|
+
public data: Package.Data,
|
|
79
|
+
) {}
|
|
80
|
+
|
|
81
|
+
private static async load(file: string): Promise<Package.Data> {
|
|
82
|
+
const content: string = await fs.promises.readFile(file, "utf8");
|
|
83
|
+
return JSON.parse(content);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export namespace Package {
|
|
87
|
+
export interface Data {
|
|
88
|
+
scripts?: Record<string, string>;
|
|
89
|
+
dependencies?: Record<string, string>;
|
|
90
|
+
devDependencies?: Record<string, string>;
|
|
91
|
+
}
|
|
92
|
+
}
|