Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
9,301 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
lib | ||
node_modules | ||
node_modules | ||
|
||
test/features/generate/input/generate_assert_clone.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import fs from "fs"; | ||
|
||
import { TypiaGenerator } from "../generate/TypiaGenerator"; | ||
import { ArgumentParser } from "./setup/ArgumentParser"; | ||
import { PackageManager } from "./setup/PackageManager"; | ||
|
||
export namespace TypiaGenerateWizard { | ||
export async function generate(): Promise<void> { | ||
console.log("----------------------------------------"); | ||
console.log(" Typia Generate Wizard"); | ||
console.log("----------------------------------------"); | ||
|
||
// LOAD PACKAGE.JSON INFO | ||
const pack: PackageManager = await PackageManager.mount(); | ||
const options: IArguments = await ArgumentParser.parse(pack)(false)( | ||
inquiry, | ||
); | ||
await TypiaGenerator.generate(options); | ||
} | ||
|
||
const inquiry: ArgumentParser.Inquiry<IArguments> = async ( | ||
_pack, | ||
command, | ||
prompt, | ||
action, | ||
) => { | ||
// PREPARE ASSETS | ||
command.option("--input <path>", "input directory"); | ||
command.option("--output <directory>", "output directory"); | ||
command.option("--project [project]", "tsconfig.json file location"); | ||
|
||
const questioned = { value: false }; | ||
|
||
const input = (name: string) => async (message: string) => { | ||
const result = await prompt()({ | ||
type: "input", | ||
name, | ||
message, | ||
default: "", | ||
}); | ||
return result[name] as string; | ||
}; | ||
const select = | ||
(name: string) => | ||
(message: string) => | ||
async <Choice extends string>( | ||
choices: Choice[], | ||
): Promise<Choice> => { | ||
questioned.value = true; | ||
return ( | ||
await prompt()({ | ||
type: "list", | ||
name: name, | ||
message: message, | ||
choices: choices, | ||
}) | ||
)[name]; | ||
}; | ||
const configure = async () => { | ||
const fileList: string[] = await ( | ||
await fs.promises.readdir(process.cwd()) | ||
).filter( | ||
(str) => | ||
str.substring(0, 8) === "tsconfig" && | ||
str.substring(str.length - 5) === ".json", | ||
); | ||
if (fileList.length === 0) | ||
throw new Error(`Unable to find "tsconfig.json" file.`); | ||
else if (fileList.length === 1) return fileList[0]; | ||
return select("tsconfig")("TS Config File")(fileList); | ||
}; | ||
|
||
return action(async (options) => { | ||
options.input ??= await input("input")("input directory"); | ||
options.output ??= await input("output")("output directory"); | ||
options.project ??= await configure(); | ||
return options as IArguments; | ||
}); | ||
}; | ||
|
||
export interface IArguments { | ||
input: string; | ||
output: string; | ||
project: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import type CommanderModule from "commander"; | ||
import type * as InquirerModule from "inquirer"; | ||
import path from "path"; | ||
|
||
import { PackageManager } from "./PackageManager"; | ||
|
||
export namespace ArgumentParser { | ||
export type Inquiry<T> = ( | ||
pack: PackageManager, | ||
command: CommanderModule.Command, | ||
prompt: ( | ||
opt?: InquirerModule.StreamOptions, | ||
) => InquirerModule.PromptModule, | ||
action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>, | ||
) => Promise<T>; | ||
|
||
export const parse = | ||
(pack: PackageManager) => | ||
(erase: boolean) => | ||
async <T>( | ||
inquiry: ( | ||
pack: PackageManager, | ||
command: CommanderModule.Command, | ||
prompt: ( | ||
opt?: InquirerModule.StreamOptions, | ||
) => InquirerModule.PromptModule, | ||
action: ( | ||
closure: (options: Partial<T>) => Promise<T>, | ||
) => Promise<T>, | ||
) => Promise<T>, | ||
): Promise<T> => { | ||
// INSTALL TEMPORARY PACKAGES | ||
const newbie = { | ||
commander: pack.install({ | ||
dev: true, | ||
modulo: "commander", | ||
version: "10.0.0", | ||
silent: true, | ||
}), | ||
inquirer: pack.install({ | ||
dev: true, | ||
modulo: "inquirer", | ||
version: "8.2.5", | ||
silent: true, | ||
}), | ||
}; | ||
|
||
// LOAD INSTALLED MODULES | ||
const { program: command }: typeof CommanderModule = await import( | ||
path.join(pack.directory, "node_modules", "commander") | ||
); | ||
const { createPromptModule: prompt }: typeof InquirerModule = | ||
await import( | ||
path.join(pack.directory, "node_modules", "inquirer") | ||
); | ||
|
||
// TAKE OPTIONS | ||
const action = (closure: (options: Partial<T>) => Promise<T>) => | ||
new Promise<T>((resolve, reject) => { | ||
command.action(async (options) => { | ||
try { | ||
resolve(await closure(options)); | ||
} catch (exp) { | ||
reject(exp); | ||
} | ||
}); | ||
command.parseAsync().catch(reject); | ||
}); | ||
const output: T | Error = await (async () => { | ||
try { | ||
return await inquiry(pack, command, prompt, action); | ||
} catch (error) { | ||
return error as Error; | ||
} | ||
})(); | ||
|
||
// REMOVE TEMPORARY PACKAGES | ||
if (erase === true) { | ||
if (newbie.commander) | ||
pack.erase({ modulo: "commander", silent: true }); | ||
if (newbie.inquirer) | ||
pack.erase({ modulo: "inquirer", silent: true }); | ||
} | ||
|
||
// RETURNS | ||
if (output instanceof Error) throw output; | ||
return output; | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.