Skip to content

Commit

Permalink
feat: ability to run non-interactively
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jan 26, 2025
1 parent 138a976 commit 155a93f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lint:fix": "npm run lint:js:fix",
"lint:js:fix": "eslint --ext .js,.ts . --fix",
"lint:js": "eslint --ext .js,.ts .",
"lint": "npm run lint:js"
"lint": "npm run lint:js",
"main": "npx tsx src/index.ts"
},
"repository": {
"type": "git",
Expand Down
27 changes: 26 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,45 @@ program
"--output <directory>",
"Specify custom output directory or name",
process.cwd()

Check failure on line 29 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
)
.option(
"--example <exampleName>",
"Specify the example to use and skip the prompt"

Check failure on line 33 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
);

program.parse(process.argv);

const options = program.opts();
const isVerbose = options.verbose;
const outputDir = options.output;
const exampleName = options.example;

const main = async () => {
try {
clear();
await cloneRepository(REPO_URL, TEMP_DIR, BRANCH_NAME, options, isVerbose);
const directories = await getExampleDirectories(EXAMPLES_DIR);
const chosenExample = await promptForExample(directories);

let chosenExample;
if (exampleName) {
const matchingExample = directories.find(
(dir) => dir.name === exampleName

Check failure on line 52 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
);
if (!matchingExample) {
console.error(`Error: Example "${exampleName}" not found.`);
console.error(
"Available examples:",
directories
.map((dir) => `${dir.name} - ${dir.description}`)
.join("\n")

Check failure on line 60 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `,`
);
process.exit(1);
}
chosenExample = matchingExample.name;
} else {
chosenExample = await promptForExample(directories);
}

await copyExample(chosenExample, EXAMPLES_DIR, outputDir, isVerbose);
} catch (error: any) {
if (isVerbose) {
Expand Down

0 comments on commit 155a93f

Please sign in to comment.