nestia 2.0.4 → 2.0.5

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 CHANGED
@@ -79,15 +79,20 @@ Just type the `nestia sdk <input> --out <output>` command in the console. When t
79
79
  Also, when generating a SDK using the cli options, `compilerOptions` would follow the `tsconfig.json`, that is configured for the backend server. If no `tsconfig.json` file exists in your project, the configuration would be default option (`ES5` with `strict` mode). If you want to use different `compilerOptions` with the `tsconfig.json`, you should configure the [nestia.config.ts](#nestiaconfigts).
80
80
 
81
81
  ### Dependencies
82
- SDK library generated by the **Nestia** requires the [nestia-fetcher](https://github.com/samchon/nestia-fetcher) module.
82
+ ```bash
83
+ npx nestia install
84
+ ```
85
+
86
+ SDK library generated by the **Nestia** requires the [nestia-fetcher](https://github.com/samchon/nestia-fetcher) and [typescript-is](https://github.com/woutervh-/typescript-is) modules.
83
87
 
84
- Therefore, when you publish an SDK library generated by this **Nestia**, you have to write the [nestia-fetcher](https://github.com/samchon/nestia-fetcher) module into the `dependencies` property of the `package.json` file like below. You also can configure the `dependencies` property of the `package.json` file by typing the `npm install --save nestia-fetcher` command in the console, too.
88
+ The `npx nestia install` command installs those dependencies with `package.json` configuration.
85
89
 
86
90
  ```json
87
91
  {
88
92
  "name": "payments-server-api",
89
93
  "dependencies": {
90
- "nestia-fetcher": "^1.0.2"
94
+ "nestia-fetcher": "^2.0.0",
95
+ "typescript-is": "^0.19.0"
91
96
  }
92
97
  }
93
98
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestia",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Automatic SDK and Document generator for the NestJS",
5
5
  "main": "src/index.ts",
6
6
  "bin": {
@@ -33,9 +33,10 @@
33
33
  "@types/node": "^17.0.23",
34
34
  "@types/reflect-metadata": "^0.1.0",
35
35
  "cli": "^1.0.1",
36
+ "comment-json": "^4.2.2",
36
37
  "del": "^6.0.0",
37
38
  "glob": "^7.2.0",
38
- "ts-node": "^10.7.0",
39
+ "ts-node": "^9.1.1",
39
40
  "tstl": "^2.5.3",
40
41
  "ttypescript": "^1.5.13",
41
42
  "typescript": "^4.6.3",
package/src/bin/nestia.ts CHANGED
@@ -1,17 +1,10 @@
1
1
  #!/usr/bin/env ts-node
2
2
 
3
3
  import * as cp from "child_process";
4
- import * as fs from "fs";
5
4
  import * as path from "path";
6
5
  import * as process from "process";
7
6
 
8
- import { CompilerOptions } from "../internal/CompilerOptions";
9
- import { stripJsonComments } from "../utils/stripJsonComments";
10
-
11
- interface IConfig
12
- {
13
- compilerOptions?: CompilerOptions;
14
- }
7
+ import { TsConfig } from "../internal/TsConfig";
15
8
 
16
9
  function install(): void
17
10
  {
@@ -23,11 +16,14 @@ function install(): void
23
16
  }
24
17
  }
25
18
 
26
- function sdk(file: string): void
19
+ async function sdk(): Promise<void>
27
20
  {
28
- // PREPARE COMMAND
21
+ // PREPARE TSCONFIG
22
+ await TsConfig.fulfill();
23
+
24
+ // CONSTRUCT COMMAND
29
25
  const parameters: string[] = [
30
- `npx ts-node -C ttypescript --project "${file}"`,
26
+ `npx ts-node`,
31
27
  `"${path.relative(process.cwd(), `${__dirname}/../executable/sdk`)}"`,
32
28
  ...process.argv.slice(3)
33
29
  ];
@@ -41,80 +37,18 @@ function sdk(file: string): void
41
37
  stdio: "inherit",
42
38
  env: {
43
39
  ...process.env,
40
+ "TS_NODE_COMPILER": "ttypescript",
44
41
  "NODE_NO_WARNINGS": "1"
45
42
  }
46
43
  }
47
44
  );
48
45
  }
49
-
50
- function configure(config: IConfig): boolean
51
- {
52
- if (!config.compilerOptions)
53
- {
54
- config.compilerOptions = CompilerOptions.DEFAULT;
55
- return true;
56
- }
57
- else
58
- return CompilerOptions.emend(config.compilerOptions);
59
- }
60
-
61
- async function tsconfig(task: (file: string) => void): Promise<void>
62
- {
63
- //----
64
- // PREPARE ASSETS
65
- //----
66
- let prepare: null | (() => Promise<[string, () => Promise<void>]>) = null;
67
-
68
- // NO TSCONFIG.JSON?
69
- if (fs.existsSync("tsconfig.json") === false)
70
- {
71
- const config = { compilerOptions: CompilerOptions.DEFAULT };
72
- prepare = CompilerOptions.temporary(config);
73
- }
74
- else
75
- {
76
- // HAS TSCONFIG.JSON
77
- const content: string = await fs.promises.readFile("tsconfig.json", "utf8");
78
- const config = JSON.parse(stripJsonComments(content));
79
-
80
- // NEED TO ADD TRANSFORM PLUGINS
81
- const changed: boolean = configure(config);
82
- if (changed === true)
83
- prepare = CompilerOptions.temporary(config);
84
- }
85
-
86
- //----
87
- // EXECUTION
88
- //----
89
- // CREATE TEMPORARY TSCONFIG
90
- const [file, erasure] = prepare ? await prepare() : ["tsconfig.json", null];
91
-
92
- // EXECUTE THE TASK
93
- let error: Error | null = null;
94
- try
95
- {
96
- task(file);
97
- }
98
- catch (exp)
99
- {
100
- error = exp as Error;
101
- }
102
-
103
- // REMOVE THE TEMPORARY TSCONFIG
104
- if (erasure)
105
- await erasure();
106
-
107
- // THROW ERROR IF EXISTS
108
- if (error)
109
- throw error;
110
- }
111
-
112
46
  async function main()
113
47
  {
114
48
  if (process.argv[2] === "install")
115
49
  await install();
116
50
  else if (process.argv[2] === "sdk")
117
- await tsconfig(sdk);
51
+ await sdk();
118
52
  else
119
53
  throw new Error(`nestia supports only two commands; install and sdk, however you typed ${process.argv[2]}`);
120
54
  }
@@ -0,0 +1,115 @@
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
69
+ {
70
+ // FILL ESSENTIAL PROPS
71
+ const options: CSON.CommentObject = config.compilerOptions as CSON.CommentObject;
72
+ for (const [key, value] of Object.entries(DEFAULT_OPTIONS))
73
+ {
74
+ if (!options[key])
75
+ CSON.assign(config.compilerOptions, { [key]: value });
76
+ else if (options[key] instanceof Array && value instanceof Array && key !== "plugins")
77
+ CSON.assign
78
+ (
79
+ config.compilerOptions,
80
+ {
81
+ [key]:
82
+ [
83
+ ...new Set
84
+ ([
85
+ ...value,
86
+ ...options[key] as string[]
87
+ ])
88
+ ]
89
+ }
90
+ );
91
+ }
92
+
93
+ if (!options.plugins)
94
+ CSON.assign(options.plugins, { plugins: DEFAULT_OPTIONS.plugins });
95
+ else
96
+ {
97
+ const optionPlugins: CSON.CommentArray<CSON.CommentObject> = options.plugins as CSON.CommentArray<CSON.CommentObject>;
98
+ for (const plugin of DEFAULT_OPTIONS.plugins)
99
+ {
100
+ const found = optionPlugins.find(elem => elem.transform === plugin.transform);
101
+ if (!found)
102
+ optionPlugins.push(plugin);
103
+ }
104
+ }
105
+ }
106
+
107
+ // OVERWRITE THE CONTENT
108
+ await fs.promises.writeFile
109
+ (
110
+ "tsconfig.json",
111
+ CSON.stringify(config, null, 2),
112
+ "utf8"
113
+ );
114
+ }
115
+ }
@@ -0,0 +1,81 @@
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,142 +0,0 @@
1
- import * as fs from "fs";
2
-
3
- export interface CompilerOptions
4
- {
5
- target: string;
6
- module: string;
7
- lib: string[];
8
- strict: boolean;
9
- downlevelIteration: boolean;
10
- esModuleInterop?: boolean;
11
- plugins?: Array<{
12
- transform?: string
13
- }>;
14
- types?: string[];
15
- experimentalDecorators?: boolean;
16
- emitDecoratorMetadata?: boolean;
17
- }
18
- export namespace CompilerOptions
19
- {
20
- /* -----------------------------------------------------------
21
- DEFAULT VALUES
22
- ----------------------------------------------------------- */
23
- export const DEPENDENCIES: string[] = [
24
- "nestia-fetcher",
25
- "typescript-is"
26
- ];
27
-
28
- export const TRANSFORMERS: string[] = [
29
- "typescript-is/lib/transform-inline/transformer",
30
- "typescript-transform-paths"
31
- ];
32
-
33
- export const TYPES: string[] = []
34
-
35
- export const DEFAULT = {
36
- target: "es5",
37
- module: "commonjs",
38
- lib: [
39
- "DOM",
40
- "ES2015"
41
- ],
42
- strict: true,
43
- downlevelIteration: true,
44
- esModuleInterop: true,
45
- plugins: TRANSFORMERS.map(transform => ({ transform })),
46
- types: [
47
- "node",
48
- "reflect-metadata"
49
- ],
50
- experimentalDecorators: true,
51
- emitDecoratorMetadata: true,
52
- };
53
-
54
- export function emend(options: CompilerOptions): boolean
55
- {
56
- // FILL ARRAY DATA
57
- if (!options.plugins)
58
- options.plugins = [];
59
- if (!options.types)
60
- options.types = [];
61
-
62
- // CONSTRUCT CHECKERS
63
- const emended: Required<CompilerOptions> = options as Required<CompilerOptions>;
64
- const checkers: Array<() => boolean> = [
65
- () =>
66
- {
67
- let changed: boolean = false;
68
- for (const transform of CompilerOptions.TRANSFORMERS)
69
- {
70
- if (emended.plugins.find(elem => elem.transform === transform) !== undefined)
71
- continue;
72
-
73
- changed = true;
74
- emended.plugins.push({ transform });
75
- }
76
- return changed;
77
- },
78
- () =>
79
- {
80
- let changed: boolean = false;
81
- for (const type of CompilerOptions.TYPES)
82
- {
83
- if (emended.types.find(elem => elem === type) !== undefined)
84
- continue;
85
-
86
- changed = true;
87
- emended.types.push(type);
88
- }
89
- return changed;
90
- },
91
- () =>
92
- {
93
- const changed: boolean = emended.experimentalDecorators !== true;
94
- if (changed)
95
- emended.experimentalDecorators = true;
96
- return changed;
97
- },
98
- () =>
99
- {
100
- const changed: boolean = emended.emitDecoratorMetadata !== true;
101
- if (changed)
102
- emended.emitDecoratorMetadata = true;
103
- return changed;
104
- },
105
- () =>
106
- {
107
- const changed: boolean = emended.esModuleInterop !== true;
108
- if (changed)
109
- emended.esModuleInterop = true;
110
- return changed;
111
- }
112
- ];
113
-
114
- // DO CHECK IT
115
- const checks: boolean[] = checkers.map(func => func());
116
- return checks.some(flag => flag);
117
- }
118
-
119
- /* -----------------------------------------------------------
120
- PROCEDURES
121
- ----------------------------------------------------------- */
122
- export function temporary(config: IConfig): () => Promise<[string, () => Promise<void>]>
123
- {
124
- return async () =>
125
- {
126
- const file: string = `nestia.temporary.tsconfig.${Math.random().toString().substr(2)}.json`;
127
-
128
- await fs.promises.writeFile
129
- (
130
- file,
131
- JSON.stringify(config, null, 2),
132
- "utf8"
133
- );
134
- return [file, () => fs.promises.unlink(file)];
135
- };
136
- }
137
- }
138
-
139
- interface IConfig
140
- {
141
- compilerOptions?: CompilerOptions;
142
- }