-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from expressots/40-create-scaffold-for-externa…
…l-provider-npm-package feat: add external provider scaffold
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 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
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,68 @@ | ||
import chalk from "chalk"; | ||
import degit from "degit"; | ||
import inquirer from "inquirer"; | ||
import { centerText } from "../../utils/center-text"; | ||
import { printError } from "../../utils/cli-ui"; | ||
|
||
async function printInfo(providerName: string): Promise<void> { | ||
console.log("\n"); | ||
console.log( | ||
"🐎 Provider", | ||
chalk.green(providerName), | ||
"created successfully!", | ||
); | ||
console.log("🤙 Run the following commands to start the provider:\n"); | ||
|
||
console.log(chalk.bold.gray(`$ cd ${providerName}`)); | ||
|
||
console.log("\n"); | ||
console.log(chalk.bold.green(centerText("Happy coding!"))); | ||
console.log( | ||
chalk.bold.gray( | ||
centerText("Please consider donating to support the project.\n"), | ||
), | ||
); | ||
console.log( | ||
chalk.bold.white( | ||
centerText("💖 Sponsor: https://github.com/sponsors/expressots"), | ||
), | ||
); | ||
console.log("\n"); | ||
} | ||
|
||
interface IExternalProvider { | ||
providerName: string; | ||
} | ||
|
||
const externalProvider = async (): Promise<void> => { | ||
return new Promise<void>(async (resolve, reject) => { | ||
const providerInfo = await inquirer.prompt<IExternalProvider>([ | ||
{ | ||
type: "input", | ||
name: "providerName", | ||
message: "Type the name of your provider:", | ||
default: "expressots-provider", | ||
transformer: (input: string) => { | ||
return chalk.yellow(chalk.bold(input)); | ||
}, | ||
}, | ||
]); | ||
|
||
try { | ||
const emitter = degit(`expressots/expressots-provider-template`); | ||
await emitter.clone(providerInfo.providerName); | ||
printInfo(providerInfo.providerName); | ||
|
||
resolve(); | ||
} catch (err: any) { | ||
console.log("\n"); | ||
printError( | ||
"Project already exists or Folder is not empty", | ||
"generate-external-provider", | ||
); | ||
reject(err); | ||
} | ||
}); | ||
}; | ||
|
||
export { externalProvider }; |