nestia 2.0.6 → 2.0.7-dev.20220414
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/{src/IConfiguration.ts → bin/IConfiguration.d.ts} +5 -8
- package/bin/IConfiguration.d.ts.map +1 -0
- package/bin/IConfiguration.js +3 -0
- package/bin/NestiaApplication.d.ts +10 -0
- package/bin/NestiaApplication.d.ts.map +1 -0
- package/bin/NestiaApplication.js +281 -0
- package/bin/analyses/ControllerAnalyzer.d.ts +7 -0
- package/bin/analyses/ControllerAnalyzer.d.ts.map +1 -0
- package/bin/analyses/ControllerAnalyzer.js +186 -0
- package/bin/analyses/GenericAnalyzer.d.ts +6 -0
- package/bin/analyses/GenericAnalyzer.d.ts.map +1 -0
- package/bin/analyses/GenericAnalyzer.js +100 -0
- package/bin/analyses/ImportAnalyzer.d.ts +13 -0
- package/bin/analyses/ImportAnalyzer.d.ts.map +1 -0
- package/bin/analyses/ImportAnalyzer.js +82 -0
- package/bin/analyses/ReflectAnalyzer.d.ts +5 -0
- package/bin/analyses/ReflectAnalyzer.d.ts.map +1 -0
- package/bin/analyses/ReflectAnalyzer.js +307 -0
- package/bin/analyses/SourceFinder.d.ts +5 -0
- package/bin/analyses/SourceFinder.d.ts.map +1 -0
- package/bin/analyses/SourceFinder.js +260 -0
- package/bin/bundle/HttpError.d.ts +2 -0
- package/bin/bundle/HttpError.d.ts.map +1 -0
- package/bin/bundle/HttpError.js +6 -0
- package/bin/bundle/IConnection.d.ts +2 -0
- package/bin/bundle/IConnection.d.ts.map +1 -0
- package/bin/bundle/IConnection.js +3 -0
- package/bin/bundle/Primitive.d.ts +2 -0
- package/bin/bundle/Primitive.d.ts.map +1 -0
- package/bin/bundle/Primitive.js +6 -0
- package/bin/bundle/__internal/AesPkcs5.d.ts +2 -0
- package/bin/bundle/__internal/AesPkcs5.d.ts.map +1 -0
- package/bin/bundle/__internal/AesPkcs5.js +6 -0
- package/bin/bundle/__internal/Fetcher.d.ts +2 -0
- package/bin/bundle/__internal/Fetcher.d.ts.map +1 -0
- package/bin/bundle/__internal/Fetcher.js +6 -0
- package/bin/executable/internal/CompilerOptions.d.ts +13 -0
- package/bin/executable/internal/CompilerOptions.d.ts.map +1 -0
- package/bin/executable/internal/CompilerOptions.js +132 -0
- package/bin/executable/internal/NestiaConfig.d.ts +5 -0
- package/bin/executable/internal/NestiaConfig.d.ts.map +1 -0
- package/bin/executable/internal/NestiaConfig.js +196 -0
- package/bin/executable/internal/nestia.config.getter.d.ts +2 -0
- package/bin/executable/internal/nestia.config.getter.d.ts.map +1 -0
- package/bin/executable/internal/nestia.config.getter.js +60 -0
- package/bin/executable/nestia.d.ts +3 -0
- package/bin/executable/nestia.d.ts.map +1 -0
- package/bin/executable/nestia.js +136 -0
- package/bin/executable/sdk.d.ts +2 -0
- package/bin/executable/sdk.d.ts.map +1 -0
- package/bin/executable/sdk.js +206 -0
- package/bin/generates/FileGenerator.d.ts +6 -0
- package/bin/generates/FileGenerator.d.ts.map +1 -0
- package/bin/generates/FileGenerator.js +302 -0
- package/bin/generates/FunctionGenerator.d.ts +5 -0
- package/bin/generates/FunctionGenerator.d.ts.map +1 -0
- package/bin/generates/FunctionGenerator.js +207 -0
- package/bin/generates/SdkGenerator.d.ts +6 -0
- package/bin/generates/SdkGenerator.d.ts.map +1 -0
- package/bin/generates/SdkGenerator.js +147 -0
- package/bin/index.d.ts +3 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +28 -0
- package/bin/module.d.ts +3 -0
- package/bin/module.d.ts.map +1 -0
- package/bin/module.js +19 -0
- package/{src/structures/IController.ts → bin/structures/IController.d.ts} +6 -13
- package/bin/structures/IController.d.ts.map +1 -0
- package/bin/structures/IController.js +3 -0
- package/{src/structures/IRoute.ts → bin/structures/IRoute.d.ts} +5 -11
- package/bin/structures/IRoute.d.ts.map +1 -0
- package/bin/structures/IRoute.js +3 -0
- package/bin/structures/MethodType.d.ts +5 -0
- package/bin/structures/MethodType.d.ts.map +1 -0
- package/bin/structures/MethodType.js +8 -0
- package/bin/structures/ParamCategory.d.ts +2 -0
- package/bin/structures/ParamCategory.d.ts.map +1 -0
- package/bin/structures/ParamCategory.js +3 -0
- package/bin/utils/ArrayUtil.d.ts +6 -0
- package/bin/utils/ArrayUtil.d.ts.map +1 -0
- package/bin/utils/ArrayUtil.js +144 -0
- package/bin/utils/DirectoryUtil.d.ts +6 -0
- package/bin/utils/DirectoryUtil.d.ts.map +1 -0
- package/bin/utils/DirectoryUtil.js +190 -0
- package/bin/utils/ImportDictionary.d.ts +7 -0
- package/bin/utils/ImportDictionary.d.ts.map +1 -0
- package/bin/utils/ImportDictionary.js +85 -0
- package/bin/utils/StringUtil.d.ts +4 -0
- package/bin/utils/StringUtil.d.ts.map +1 -0
- package/bin/utils/StringUtil.js +13 -0
- package/bin/utils/stripJsonComments.d.ts +4 -0
- package/bin/utils/stripJsonComments.d.ts.map +1 -0
- package/bin/utils/stripJsonComments.js +76 -0
- package/package.json +14 -10
- package/tsconfig.json +8 -7
- package/src/NestiaApplication.ts +0 -96
- package/src/analyses/ControllerAnalyzer.ts +0 -154
- package/src/analyses/GenericAnalyzer.ts +0 -52
- package/src/analyses/ImportAnalyzer.ts +0 -93
- package/src/analyses/ReflectAnalyzer.ts +0 -221
- package/src/analyses/SourceFinder.ts +0 -73
- package/src/bin/nestia.ts +0 -59
- package/src/bundle/HttpError.ts +0 -1
- package/src/bundle/IConnection.ts +0 -1
- package/src/bundle/Primitive.ts +0 -1
- package/src/bundle/__internal/AesPkcs5.ts +0 -1
- package/src/bundle/__internal/Fetcher.ts +0 -1
- package/src/executable/sdk.ts +0 -84
- package/src/generates/FileGenerator.ts +0 -150
- package/src/generates/FunctionGenerator.ts +0 -201
- package/src/generates/SdkGenerator.ts +0 -39
- package/src/internal/NestiaConfig.ts +0 -36
- package/src/internal/TsConfig.ts +0 -123
- package/src/internal/tsconfig.default.json +0 -81
- package/src/structures/MethodType.ts +0 -6
- package/src/structures/ParamCategory.ts +0 -1
- package/src/utils/ArrayUtil.ts +0 -26
- package/src/utils/DirectoryUtil.ts +0 -48
- package/src/utils/ImportDictionary.ts +0 -44
- package/src/utils/StringUtil.ts +0 -10
- package/src/utils/stripJsonComments.ts +0 -79
package/src/internal/TsConfig.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import * as process from "process";
|
|
4
|
-
import * as tsc from "typescript";
|
|
5
|
-
import * as CSON from "comment-json"
|
|
6
|
-
|
|
7
|
-
export interface TsConfig
|
|
8
|
-
{
|
|
9
|
-
compilerOptions?: tsc.CompilerOptions;
|
|
10
|
-
}
|
|
11
|
-
export namespace TsConfig
|
|
12
|
-
{
|
|
13
|
-
/* -----------------------------------------------------------
|
|
14
|
-
DEFAULT VALUES
|
|
15
|
-
----------------------------------------------------------- */
|
|
16
|
-
const DEFAULT_OPTIONS = {
|
|
17
|
-
target: "es5",
|
|
18
|
-
module: "commonjs",
|
|
19
|
-
types: [
|
|
20
|
-
"node",
|
|
21
|
-
"reflect-metadata"
|
|
22
|
-
],
|
|
23
|
-
esModuleInterop: true,
|
|
24
|
-
experimentalDecorators: true,
|
|
25
|
-
emitDecoratorMetadata: true,
|
|
26
|
-
plugins: [
|
|
27
|
-
{ transform: "typescript-is/lib/transform-inline/transformer" },
|
|
28
|
-
// { transform: "typescript-transform-paths" }
|
|
29
|
-
]
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export async function fulfill(): Promise<void>
|
|
33
|
-
{
|
|
34
|
-
if (fs.existsSync("tsconfig.json") === false)
|
|
35
|
-
{
|
|
36
|
-
// NO TSCONFIG.JSON EXISTS
|
|
37
|
-
await fs.promises.copyFile
|
|
38
|
-
(
|
|
39
|
-
path.relative(process.cwd(), __dirname + "/tsconfig.default.json"),
|
|
40
|
-
"tsconfig.json"
|
|
41
|
-
);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
|
|
46
|
-
const config: CSON.CommentObject = CSON.parse(content) as CSON.CommentObject;
|
|
47
|
-
|
|
48
|
-
if (!config.compilerOptions)
|
|
49
|
-
{
|
|
50
|
-
// NO COMPILER-OPTION EXISTS
|
|
51
|
-
const defaultConfig: CSON.CommentObject = JSON.parse
|
|
52
|
-
(
|
|
53
|
-
await fs.promises.readFile
|
|
54
|
-
(
|
|
55
|
-
path.relative(process.cwd(), __dirname + "/tsconfig.default.json"),
|
|
56
|
-
"utf8"
|
|
57
|
-
)
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
config.compilerOptions = defaultConfig.compilerOptions;
|
|
61
|
-
await fs.promises.writeFile
|
|
62
|
-
(
|
|
63
|
-
"tsconfig.json",
|
|
64
|
-
CSON.stringify(config, null, 2),
|
|
65
|
-
"utf8"
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
else if (emend(config.compilerOptions as CSON.CommentObject) === true)
|
|
69
|
-
{
|
|
70
|
-
// OVERWRITE THE CONTENT
|
|
71
|
-
await fs.promises.writeFile
|
|
72
|
-
(
|
|
73
|
-
"tsconfig.json",
|
|
74
|
-
CSON.stringify(config, null, 2),
|
|
75
|
-
"utf8"
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function emend(options: CSON.CommentObject): boolean
|
|
81
|
-
{
|
|
82
|
-
if (options.paths && Object.entries(options.paths).length !== 0)
|
|
83
|
-
DEFAULT_OPTIONS.plugins.push({ transform: "typescript-transform-paths" });
|
|
84
|
-
|
|
85
|
-
let changed: boolean = false;
|
|
86
|
-
for (const [key, value] of Object.entries(DEFAULT_OPTIONS))
|
|
87
|
-
if (options[key] instanceof Array && value instanceof Array)
|
|
88
|
-
{
|
|
89
|
-
merge<any>(options[key] as Array<any>, value,
|
|
90
|
-
key !== "plugins"
|
|
91
|
-
? (x, y) => x === y
|
|
92
|
-
: (x, y) => x.transform === y.transform
|
|
93
|
-
);
|
|
94
|
-
changed ||= true;
|
|
95
|
-
}
|
|
96
|
-
else if (options[key] !== value)
|
|
97
|
-
{
|
|
98
|
-
CSON.assign(options, { [key]: value });
|
|
99
|
-
changed ||= true;
|
|
100
|
-
}
|
|
101
|
-
return changed;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function merge<T>
|
|
105
|
-
(
|
|
106
|
-
origin: T[],
|
|
107
|
-
must: T[],
|
|
108
|
-
pred: (a: T, b: T) => boolean
|
|
109
|
-
): boolean
|
|
110
|
-
{
|
|
111
|
-
let changed: boolean = false;
|
|
112
|
-
for (const m of must)
|
|
113
|
-
{
|
|
114
|
-
const found: T | undefined = origin.find(elem => pred(elem, m));
|
|
115
|
-
if (found !== undefined)
|
|
116
|
-
continue;
|
|
117
|
-
|
|
118
|
-
origin.push(m);
|
|
119
|
-
changed ||= true;
|
|
120
|
-
}
|
|
121
|
-
return changed;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
-
|
|
5
|
-
/* Basic Options */
|
|
6
|
-
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
-
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
-
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
-
"lib": [
|
|
10
|
-
"DOM",
|
|
11
|
-
"ES2015"
|
|
12
|
-
], /* Specify library files to be included in the compilation. */
|
|
13
|
-
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
14
|
-
// "checkJs": true, /* Report errors in .js files. */
|
|
15
|
-
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
16
|
-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
17
|
-
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
18
|
-
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
19
|
-
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
20
|
-
// "outDir": "./lib", /* Redirect output structure to the directory. */
|
|
21
|
-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
22
|
-
// "composite": true, /* Enable project compilation */
|
|
23
|
-
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
24
|
-
// "removeComments": true, /* Do not emit comments to output. */
|
|
25
|
-
"noEmit": true, /* Do not emit outputs. */
|
|
26
|
-
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
27
|
-
"downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
28
|
-
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
29
|
-
|
|
30
|
-
/* Strict Type-Checking Options */
|
|
31
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
32
|
-
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
33
|
-
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
34
|
-
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
35
|
-
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
36
|
-
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
37
|
-
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
38
|
-
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
39
|
-
|
|
40
|
-
/* Additional Checks */
|
|
41
|
-
"noUnusedLocals": true, /* Report errors on unused locals. */
|
|
42
|
-
"noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
43
|
-
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
44
|
-
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
45
|
-
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
|
|
46
|
-
|
|
47
|
-
/* Module Resolution Options */
|
|
48
|
-
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
49
|
-
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
50
|
-
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
51
|
-
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
52
|
-
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
53
|
-
"types": [
|
|
54
|
-
"node",
|
|
55
|
-
"reflect-metadata"
|
|
56
|
-
], /* Type declaration files to be included in compilation. */
|
|
57
|
-
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
58
|
-
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
59
|
-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
60
|
-
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
61
|
-
|
|
62
|
-
/* Source Map Options */
|
|
63
|
-
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
64
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
65
|
-
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
66
|
-
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
67
|
-
|
|
68
|
-
/* Experimental Options */
|
|
69
|
-
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
70
|
-
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
71
|
-
"stripInternal": true,
|
|
72
|
-
|
|
73
|
-
/* Advanced Options */
|
|
74
|
-
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
75
|
-
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
|
76
|
-
"plugins": [
|
|
77
|
-
{ "transform": "typescript-is/lib/transform-inline/transformer" },
|
|
78
|
-
{ "transform": "typescript-transform-paths" }
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type ParamCategory = "param" | "query" | "body";
|
package/src/utils/ArrayUtil.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export namespace ArrayUtil
|
|
2
|
-
{
|
|
3
|
-
export function has<T>(array: T[], ...items: T[]): boolean
|
|
4
|
-
{
|
|
5
|
-
return items.every(elem => array.find(org => org === elem) !== undefined);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function asyncMap<Input, Output>
|
|
9
|
-
(array: Input[], closure: (input: Input) => Promise<Output>): Promise<Output[]>
|
|
10
|
-
{
|
|
11
|
-
const ret: Output[] = [];
|
|
12
|
-
for (const elem of array)
|
|
13
|
-
ret.push(await closure(elem));
|
|
14
|
-
return ret;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function asyncFilter<Input>
|
|
18
|
-
(array: Input[], closure: (input: Input) => Promise<boolean>): Promise<Input[]>
|
|
19
|
-
{
|
|
20
|
-
const ret: Input[] = [];
|
|
21
|
-
for (const elem of array)
|
|
22
|
-
if (await closure(elem) === true)
|
|
23
|
-
ret.push(elem);
|
|
24
|
-
return ret;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import del from "del";
|
|
2
|
-
import * as fs from "fs";
|
|
3
|
-
|
|
4
|
-
export namespace DirectoryUtil
|
|
5
|
-
{
|
|
6
|
-
export async function remove(path: string): Promise<void>
|
|
7
|
-
{
|
|
8
|
-
try
|
|
9
|
-
{
|
|
10
|
-
await del(path);
|
|
11
|
-
}
|
|
12
|
-
catch {}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function remake(path: string): Promise<void>
|
|
16
|
-
{
|
|
17
|
-
await remove(path);
|
|
18
|
-
await fs.promises.mkdir(path);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function copy(from: string, to: string): Promise<void>
|
|
22
|
-
{
|
|
23
|
-
await remake(to);
|
|
24
|
-
await _Copy(from, to);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function _Copy(from: string, to: string): Promise<void>
|
|
28
|
-
{
|
|
29
|
-
const directory: string[] = await fs.promises.readdir(from);
|
|
30
|
-
for (const file of directory)
|
|
31
|
-
{
|
|
32
|
-
const fromPath: string = `${from}/${file}`;
|
|
33
|
-
const toPath: string = `${to}/${file}`;
|
|
34
|
-
const stats: fs.Stats = await fs.promises.stat(fromPath);
|
|
35
|
-
|
|
36
|
-
if (stats.isDirectory() === true)
|
|
37
|
-
{
|
|
38
|
-
await fs.promises.mkdir(toPath);
|
|
39
|
-
await _Copy(fromPath, toPath);
|
|
40
|
-
}
|
|
41
|
-
else
|
|
42
|
-
{
|
|
43
|
-
const content: string = await fs.promises.readFile(fromPath, "utf8");
|
|
44
|
-
await fs.promises.writeFile(toPath, content.split("\r\n").join("\n"), "utf8");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
|
|
3
|
-
import { HashMap } from "tstl/container/HashMap";
|
|
4
|
-
import { HashSet } from "tstl/container/HashSet";
|
|
5
|
-
import { Pair } from "tstl/utility/Pair";
|
|
6
|
-
|
|
7
|
-
export class ImportDictionary
|
|
8
|
-
{
|
|
9
|
-
private readonly dict_: HashMap<string, Pair<boolean, HashSet<string>>> = new HashMap();
|
|
10
|
-
|
|
11
|
-
public empty(): boolean
|
|
12
|
-
{
|
|
13
|
-
return this.dict_.empty();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public emplace(file: string, realistic: boolean, instance: string): void
|
|
17
|
-
{
|
|
18
|
-
if (file.substr(-5) === ".d.ts")
|
|
19
|
-
file = file.substr(0, file.length - 5);
|
|
20
|
-
else if (file.substr(-3) === ".ts")
|
|
21
|
-
file = file.substr(0, file.length - 3);
|
|
22
|
-
else
|
|
23
|
-
throw new Error(`Error on ImportDictionary.emplace(): extension of the target file "${file}" is not "ts".`);
|
|
24
|
-
|
|
25
|
-
let it = this.dict_.find(file);
|
|
26
|
-
if (it.equals(this.dict_.end()) === true)
|
|
27
|
-
it = this.dict_.emplace(file, new Pair(realistic, new HashSet())).first;
|
|
28
|
-
it.second.second.insert(instance);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public toScript(outDir: string): string
|
|
32
|
-
{
|
|
33
|
-
const statements: string[] = [];
|
|
34
|
-
for (const it of this.dict_)
|
|
35
|
-
{
|
|
36
|
-
const file: string = path.relative(outDir, it.first).split("\\").join("/");
|
|
37
|
-
const realistic: boolean = it.second.first;
|
|
38
|
-
const instances: string[] = it.second.second.toJSON();
|
|
39
|
-
|
|
40
|
-
statements.push(`import ${!realistic ? "type " : ""}{ ${instances.join(", ")} } from "./${file}";`);
|
|
41
|
-
}
|
|
42
|
-
return statements.join("\n");
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/utils/StringUtil.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// https://github.com/sindresorhus/strip-json-comments
|
|
2
|
-
|
|
3
|
-
const singleComment: any = Symbol('singleComment');
|
|
4
|
-
const multiComment: any = Symbol('multiComment');
|
|
5
|
-
|
|
6
|
-
const stripWithoutWhitespace = () => '';
|
|
7
|
-
const stripWithWhitespace = (string: string, start: number, end: number) => string.slice(start, end).replace(/\S/g, ' ');
|
|
8
|
-
|
|
9
|
-
const isEscaped = (jsonString: string, quotePosition: number) => {
|
|
10
|
-
let index = quotePosition - 1;
|
|
11
|
-
let backslashCount = 0;
|
|
12
|
-
|
|
13
|
-
while (jsonString[index] === '\\') {
|
|
14
|
-
index -= 1;
|
|
15
|
-
backslashCount += 1;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return Boolean(backslashCount % 2);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export function stripJsonComments(jsonString: string, {whitespace = true} = {}) {
|
|
22
|
-
if (typeof jsonString !== 'string') {
|
|
23
|
-
throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
27
|
-
|
|
28
|
-
let isInsideString = false;
|
|
29
|
-
let isInsideComment = false;
|
|
30
|
-
let offset = 0;
|
|
31
|
-
let result = '';
|
|
32
|
-
|
|
33
|
-
for (let index = 0; index < jsonString.length; index++) {
|
|
34
|
-
const currentCharacter = jsonString[index];
|
|
35
|
-
const nextCharacter = jsonString[index + 1];
|
|
36
|
-
|
|
37
|
-
if (!isInsideComment && currentCharacter === '"') {
|
|
38
|
-
const escaped = isEscaped(jsonString, index);
|
|
39
|
-
if (!escaped) {
|
|
40
|
-
isInsideString = !isInsideString;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isInsideString) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!isInsideComment && currentCharacter + nextCharacter === '//') {
|
|
49
|
-
result += jsonString.slice(offset, index);
|
|
50
|
-
offset = index;
|
|
51
|
-
isInsideComment = singleComment;
|
|
52
|
-
index++;
|
|
53
|
-
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === '\r\n') {
|
|
54
|
-
index++;
|
|
55
|
-
isInsideComment = false;
|
|
56
|
-
result += strip(jsonString, offset, index);
|
|
57
|
-
offset = index;
|
|
58
|
-
continue;
|
|
59
|
-
} else if (isInsideComment === singleComment && currentCharacter === '\n') {
|
|
60
|
-
isInsideComment = false;
|
|
61
|
-
result += strip(jsonString, offset, index);
|
|
62
|
-
offset = index;
|
|
63
|
-
} else if (!isInsideComment && currentCharacter + nextCharacter === '/*') {
|
|
64
|
-
result += jsonString.slice(offset, index);
|
|
65
|
-
offset = index;
|
|
66
|
-
isInsideComment = multiComment;
|
|
67
|
-
index++;
|
|
68
|
-
continue;
|
|
69
|
-
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === '*/') {
|
|
70
|
-
index++;
|
|
71
|
-
isInsideComment = false;
|
|
72
|
-
result += strip(jsonString, offset, index + 1);
|
|
73
|
-
offset = index + 1;
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return result + (isInsideComment ? (strip as any)(jsonString.slice(offset)) : jsonString.slice(offset));
|
|
79
|
-
}
|