Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "nestia", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Automatic SDK and Document generator for the NestJS", | ||
@@ -11,3 +11,3 @@ "main": "src/index.ts", | ||
"dev": "tsc --watch", | ||
"test": "ts-node src/bin/nestia src/test/controllers --out api" | ||
"test": "ts-node src/bin/nestia sdk src/test/controllers --out api" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -15,4 +15,4 @@ # Nestia | ||
```bash | ||
npm install -g nestia | ||
nestia "src/controller" --out "src/api" | ||
npm install --save-dev nestia | ||
npx nestia sdk "src/controller" --out "src/api" | ||
``` | ||
@@ -31,31 +31,24 @@ | ||
### Installation | ||
There're two ways to installing the **Nestia**. | ||
The first way is to installing the nestia in the global scope. | ||
```bash | ||
npm install -g nestia | ||
nestia "src/controllers" --out "src/api" | ||
npm install --save-dev nestia | ||
npx nestia sdk "src/controllers" --out "src/api" | ||
``` | ||
The second way is to installing the nestia in the project scope with --save-dev option | ||
Installing the **Nestia** is very easy. | ||
```bash | ||
npm install --save-dev nestia | ||
npx nestia src/controllers --out src/api | ||
``` | ||
Just type the `npm install --save-dev nestia` command in your NestJS backend project. | ||
### CLI options | ||
```bash | ||
nestia <source_controller_directory> --out <output_sdk_directory> | ||
nestia sdk <source_controller_directory> --out <output_sdk_directory> | ||
nestia "src/controllers" --out "src/api" | ||
nestia "src/consumers/controllers" "src/sellers/controllers" --out "src/api | ||
nestia sdk "src/controllers" --out "src/api" | ||
nestia sdk "src/consumers/controllers" "src/sellers/controllers" --out "src/api | ||
``` | ||
To generate a SDK library through the **Nestia** is very easy. Just type the `nestia <input> --out <output>` command in the console. If there're multiple source directories containing the NestJS controller classes, type all of them separating by a `space` word. | ||
To generate a SDK library through the **Nestia** is very easy. Just type the `nestia sdk <input> --out <output>` command in the console. If there're multiple source directories containing the NestJS controller classes, type all of them separating by a `space` word. | ||
```bash | ||
nestia --install | ||
nestia install | ||
``` | ||
@@ -62,0 +55,0 @@ |
@@ -17,11 +17,9 @@ #!/usr/bin/env ts-node | ||
async function generate(input: string, command: ICommand): Promise<void> | ||
async function sdk(inputList: string[], command: ICommand): Promise<void> | ||
{ | ||
const inputStats: fs.Stats = await fs.promises.stat(input); | ||
if (inputStats.isDirectory() === false) | ||
throw new Error(`Target "${input}" is not a directory.`); | ||
else if (command.out === null) | ||
// VALIDATE OUTPUT | ||
if (command.out === null) | ||
throw new Error(`Output directory is not specified. Add the "--out <output_directory>" option.`); | ||
// VALIDATE OUTPUT | ||
const parentPath: string = path.resolve(command.out + "/.."); | ||
@@ -32,11 +30,15 @@ const parentStats: fs.Stats = await fs.promises.stat(parentPath); | ||
// VALIDATE INPUTS | ||
for (const input of inputList) | ||
{ | ||
const inputStats: fs.Stats = await fs.promises.stat(input); | ||
if (inputStats.isDirectory() === false) | ||
throw new Error(`Target "${inputList}" is not a directory.`); | ||
} | ||
//---- | ||
// GENERATE | ||
//---- | ||
// ADJUST PATH | ||
if (path.isAbsolute(input) === false) | ||
input = `./${input}`; | ||
// CALL THE APP.SDK() | ||
const app: NestiaApplication = new NestiaApplication(input, command.out); | ||
const app: NestiaApplication = new NestiaApplication(inputList, command.out); | ||
await app.sdk(); | ||
@@ -56,14 +58,18 @@ } | ||
{ | ||
const command: ICommand = cli.parse({ | ||
out: ["o", "Output path of the SDK files", "string", null], | ||
install: ["i", "Install Dependencies", "boolean", false] | ||
}); | ||
if (command.install === true) | ||
if (process.argv[2] === "install") | ||
await install(); | ||
else | ||
else if (process.argv[2] === "sdk") | ||
{ | ||
const command: ICommand = cli.parse({ | ||
out: ["o", "Output path of the SDK files", "string", null], | ||
install: ["i", "Install Dependencies", "boolean", false] | ||
}); | ||
try | ||
{ | ||
await generate(process.argv[2], command); | ||
const inputs: string[] = []; | ||
for (const arg of process.argv.slice(3)) | ||
if (arg[0] !== "-") | ||
inputs.push(arg); | ||
await sdk(inputs, command); | ||
} | ||
@@ -76,3 +82,8 @@ catch (exp) | ||
} | ||
else | ||
{ | ||
console.log(`nestia supports only two commands; install and sdk, however you typed ${process.argv[2]}`); | ||
process.exit(-1); | ||
} | ||
} | ||
main(); |
@@ -21,6 +21,6 @@ import * as fs from "fs"; | ||
const defaultImportDict: ImportDictionary = new ImportDictionary(); | ||
defaultImportDict.emplace(`${outDir}/__internal/AesPkcs5.ts`, "AesPkcs5"); | ||
defaultImportDict.emplace(`${outDir}/__internal/Fetcher.ts`, "Fetcher"); | ||
defaultImportDict.emplace(`${outDir}/IConnection.ts`, "IConnection"); | ||
defaultImportDict.emplace(`${outDir}/Primitive.ts`, "Primitive"); | ||
defaultImportDict.emplace(`${outDir}/__internal/AesPkcs5.ts`, true, "AesPkcs5"); | ||
defaultImportDict.emplace(`${outDir}/__internal/Fetcher.ts`, true, "Fetcher"); | ||
defaultImportDict.emplace(`${outDir}/IConnection.ts`, false, "IConnection"); | ||
defaultImportDict.emplace(`${outDir}/Primitive.ts`, false, "Primitive"); | ||
@@ -38,7 +38,6 @@ await DirectoryUtil.remove(outDir + "/functional"); | ||
{ | ||
// DO EMPLACE | ||
// EMPLACE IF REQUIRED | ||
let it: HashMap.Iterator<string, Directory> = directory.directories.find(key); | ||
if (it.equals(directory.directories.end()) === true) | ||
it = directory.directories.emplace(key, new Directory(key)).first; | ||
it.second.routes.push(route); | ||
@@ -48,2 +47,3 @@ // FOR THE NEXT STEP | ||
} | ||
directory.routes.push(route); | ||
} | ||
@@ -78,10 +78,11 @@ | ||
for (const instance of tuple[1]) | ||
importDict.emplace(tuple[0], instance); | ||
importDict.emplace(tuple[0], false, instance); | ||
content += FunctionGenerator.generate(route) + "\n\n"; | ||
} | ||
content = defaultImportDict.toScript(outDir) + "\n\n" | ||
+ importDict.toScript(outDir) + "\n\n" | ||
+ content + "\n\n" | ||
+ defaultImportDict.listUp(); | ||
if (directory.routes.length !== 0) | ||
content = defaultImportDict.toScript(outDir) + "\n\n" | ||
+ importDict.toScript(outDir) + "\n\n" | ||
+ content + "\n\n" | ||
+ defaultImportDict.listUp(); | ||
await fs.promises.writeFile(`${outDir}/index.ts`, content, "utf8"); | ||
@@ -93,8 +94,10 @@ } | ||
{ | ||
public readonly directories: HashMap<string, Directory> = new HashMap(); | ||
public readonly routes: IRoute[] = []; | ||
public readonly directories: HashMap<string, Directory>; | ||
public readonly routes: IRoute[]; | ||
public constructor(readonly name: string) | ||
{ | ||
this.directories = new HashMap(); | ||
this.routes = []; | ||
} | ||
} |
@@ -76,2 +76,3 @@ import { Pair } from "tstl/utility/Pair"; | ||
return `// ${route.method} ${route.path}\n` | ||
+ `// ${route.controller}\n` | ||
+ `export function ${route.name}(connection: IConnection, ${parameters}): Promise<${route.name}.Output>\n` | ||
@@ -78,0 +79,0 @@ + "{"; |
@@ -13,3 +13,3 @@ import * as tsc from "typescript"; | ||
{ | ||
public constructor(readonly input: string, readonly output: string) | ||
public constructor(readonly inputs: string[], readonly output: string) | ||
{ | ||
@@ -21,7 +21,10 @@ } | ||
// LOAD CONTROLLER FILES | ||
const unique: WeakSet<any> = new WeakSet(); | ||
const fileList: string[] = await SourceFinder.find(this.input); | ||
const fileList: string[] = []; | ||
for (const input of this.inputs) | ||
fileList.push(...await SourceFinder.find(input)); | ||
// ANALYZE REFLECTS | ||
const unique: WeakSet<any> = new WeakSet(); | ||
const controllerList: IController[] = []; | ||
for (const file of fileList) | ||
@@ -28,0 +31,0 @@ controllerList.push(...await ReflectAnalyzer.analyze(unique, file)); |
import * as path from "path"; | ||
import { HashMap } from "tstl/container/HashMap"; | ||
import { HashSet } from "tstl/container/HashSet"; | ||
import { Pair } from "tstl/utility/Pair"; | ||
export class ImportDictionary | ||
{ | ||
private readonly dict_: HashMap<string, HashSet<string>> = new HashMap(); | ||
private readonly dict_: HashMap<string, Pair<boolean, HashSet<string>>> = new HashMap(); | ||
public emplace(file: string, instance: string): void | ||
public emplace(file: string, realistic: boolean, instance: string): void | ||
{ | ||
@@ -20,4 +22,4 @@ if (file.substr(-5) === ".d.ts") | ||
if (it.equals(this.dict_.end()) === true) | ||
it = this.dict_.emplace(file, new HashSet()).first; | ||
it.second.insert(instance); | ||
it = this.dict_.emplace(file, new Pair(realistic, new HashSet())).first; | ||
it.second.second.insert(instance); | ||
} | ||
@@ -31,3 +33,6 @@ | ||
const file: string = path.relative(outDir, it.first).split("\\").join("/"); | ||
statements.push(`import { ${it.second.toJSON().join(", ")} } from "./${file}";`); | ||
const realistic: boolean = it.second.first; | ||
const instances: string[] = it.second.second.toJSON(); | ||
statements.push(`import ${!realistic ? "type " : ""}{ ${instances.join(", ")} } from "./${file}";`); | ||
} | ||
@@ -44,11 +49,7 @@ return statements.join("\n"); | ||
for (const it of this.dict_) | ||
for (const instance of it.second) | ||
content += instance + "\n"; | ||
if (it.second.first === true) | ||
for (const instance of it.second.second) | ||
content += instance + ";\n"; | ||
return content; | ||
} | ||
public toJSON(): Array<[string, string[]]> | ||
{ | ||
return this.dict_.toJSON().map(it => [it.first, it.second.toJSON()]); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import cp from "child_process"; | ||
import * as cp from "child_process"; | ||
import { Pair } from "tstl/utility/Pair"; | ||
@@ -3,0 +3,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55871
29
1197
57