-
Notifications
You must be signed in to change notification settings - Fork 229
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 #274 from Telegram-Mini-Apps/feature/better-create…
…-mini-app Add interactive template selection in @tma.js/create-mini-app
- Loading branch information
Showing
10 changed files
with
591 additions
and
162 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@tma.js/create-mini-app": minor | ||
--- | ||
|
||
Add interactive template selection |
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
This file was deleted.
Oops, something went wrong.
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,48 @@ | ||
import { existsSync } from 'node:fs'; | ||
import { basename } from 'node:path'; | ||
|
||
import { confirm, input } from '@inquirer/prompts'; | ||
import chalk from 'chalk'; | ||
|
||
import { templatePrompt } from './prompts/templatePrompt.js'; | ||
import { toAbsolute } from './toAbsolute.js'; | ||
import type { AnyTemplate } from './types.js'; | ||
|
||
/** | ||
* Prompts current user project root directory. | ||
* @returns Directory name. | ||
*/ | ||
export async function promptRootDir(): Promise<string | null> { | ||
const rootDir = await input({ | ||
message: 'Enter the directory name:', | ||
validate(value) { | ||
if (value.length === 0) { | ||
return 'Directory name should not be empty.'; | ||
} | ||
|
||
const dir = toAbsolute(value); | ||
if (existsSync(dir)) { | ||
return `Directory already exists: ${dir}`; | ||
} | ||
|
||
if (value !== basename(value)) { | ||
return `Value "${value}" contains invalid symbols.`; | ||
} | ||
|
||
return true; | ||
}, | ||
}); | ||
|
||
const confirmed = await confirm({ | ||
message: `Is this your desired directory? ${chalk.green(toAbsolute(rootDir))}`, | ||
}); | ||
|
||
return confirmed ? rootDir : null; | ||
} | ||
|
||
/** | ||
* Prompts a preferred template. | ||
*/ | ||
export async function promptTemplate(): Promise<AnyTemplate> { | ||
return templatePrompt({}); | ||
} |
Oops, something went wrong.