-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add branch option to git clone * feat: pass branch to git cloner * feat: add `-b` or `--branch` option for custom branches * chore: update version * test: ignore `/lib` * test: fix tests for `git` module * refactor: move type check to functions * feat: `canUseDirAsName` binary helper * feat: add `getPresets` helper * chore: export new helpers * add preset options * feat: add lucky helpers * feat: add `lucky` option for random answers * docs: add new options to `--help` * docs: add new options to `readme.md` * docs: add `presets` to docs/references * fix: auto accept telemetry on presets * fix: handle `value` with `name` property * feat: add preset answers to extras * refactor: use `for` * refactor(1/2): supply only `yes` instead of answers for lucky * refactor(2/2): map prompts and change default for presets * chore: fix failing action
- Loading branch information
Showing
15 changed files
with
300 additions
and
81 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 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,54 @@ | ||
import path from "path"; | ||
|
||
export type ProjectPrompt = { | ||
name: string; | ||
type: "select"; | ||
choices: { name?: string; message: string; value?: string }[]; | ||
default?: string; | ||
skip?: ({ answers }: { answers: Record<string, string> }) => boolean; | ||
}; | ||
|
||
export const get_prompts_and_choices = async ( | ||
source: string, | ||
): Promise<ProjectPrompt[]> => { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const sourcePrompts = require(path.resolve(source, "prompt.js")); | ||
|
||
return (sourcePrompts.prompts ?? []) as ProjectPrompt[]; | ||
} catch (e) { | ||
return []; | ||
} | ||
}; | ||
|
||
export const get_random_answer = ( | ||
projectPrompt: ProjectPrompt, | ||
currentAnswers: Record<string, string>, | ||
): [key: string, value: string | undefined] | undefined => { | ||
if (projectPrompt.skip && projectPrompt.skip({ answers: currentAnswers })) { | ||
return undefined; | ||
} | ||
|
||
const randomIndex = Math.floor( | ||
Math.random() * projectPrompt.choices.length, | ||
); | ||
|
||
const { name, value } = projectPrompt.choices[randomIndex]; | ||
|
||
return [projectPrompt.name, name ?? value ?? undefined]; | ||
}; | ||
|
||
export const get_random_answers = ( | ||
projectPrompts: ProjectPrompt[], | ||
): Record<string, string> => { | ||
const answers: Record<string, string> = {}; | ||
|
||
for (const prompt of projectPrompts) { | ||
const [key, value] = get_random_answer(prompt, answers) ?? []; | ||
if (key && value) { | ||
answers[key] = value; | ||
} | ||
} | ||
|
||
return { ...answers }; | ||
}; |
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,17 @@ | ||
import path from "path"; | ||
|
||
export type Preset = { | ||
name: string; | ||
answers: Record<string, string>; | ||
}; | ||
|
||
export const get_presets = async (source: string): Promise<Preset[]> => { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const sourcePrompts = require(path.resolve(source, "prompt.js")); | ||
|
||
return (sourcePrompts.presets ?? []) as Preset[]; | ||
} catch (e) { | ||
return []; | ||
} | ||
}; |
Oops, something went wrong.