Skip to content

Commit

Permalink
fix: multiple choice
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Nov 14, 2023
1 parent a63d641 commit 30e004a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.env
.idea
.direnv
.pre-commit-config.yaml
12 changes: 3 additions & 9 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# CyanPrint Meta Template
# CyanPrint CookieCutter Adapter

Official CyanPrint template to create CyanPrint template, processor or plugins.

Supported language:
- C#
- JavaScript
- TypeScript
- Python
Run CookieCutter templates with CyanPrint

## Getting Started

1. Install [CyanPrint](https://cyanprint.dev) CLI
2. Create template
```bash
cyanprint create cyan/new <folder>
cyanprint create cyan/cookiecutter <folder>
```
100 changes: 61 additions & 39 deletions cyan/index.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,75 @@
import {QuestionType, StartTemplateWithLambda} from "@atomicloud/cyan-sdk";
import { QuestionType, StartTemplateWithLambda } from "@atomicloud/cyan-sdk";
import simpleGit from "simple-git";
import * as fs from "fs";
import {v4} from "uuid";
import { v4 } from "uuid";

const git = simpleGit();
StartTemplateWithLambda(async (i, d) => {
const url = await i.text("CookieCutter Git URL");

const url = await i.text("CookieCutter Git URL");
const tmpPath = `/tmp/cookiecutter/${v4()}`;
fs.mkdirSync(tmpPath, { recursive: true });

git.clone(url, tmpPath);

const tmpPath = `/tmp/cookiecutter/${v4()}`
fs.mkdirSync(tmpPath, {recursive: true});
const cookieCutterJson = fs.readFileSync(
`${tmpPath}/cookiecutter.json`,
"utf-8",
);

git.clone(url, tmpPath);
const cookieCutter = JSON.parse(cookieCutterJson);

const cookieCutterJson = fs.readFileSync(`${tmpPath}/cookiecutter.json`, 'utf-8');
const results: Record<string, string> = {};

const cookieCutter = JSON.parse(cookieCutterJson);

const results: Record<string, string> = {}

for (const [key, value] of Object.entries(cookieCutter)) {
if (typeof value === "string") {
if (["1", "true", "t", "yes", "y", "on", "0", "false", "f", "no", "n", "off"].includes(value.toLowerCase())) {
results[key] = (await i.confirm({
type: QuestionType.Confirm,
message: key,
})) ? "true" : "false";
} else {
results[key] = await i.text({
type: QuestionType.Text,
message: key,
default: value,
});
}
}
for (const [key, value] of Object.entries(cookieCutter)) {
if (typeof value === "string") {
if (
[
"1",
"true",
"t",
"yes",
"y",
"on",
"0",
"false",
"f",
"no",
"n",
"off",
].includes(value.toLowerCase())
) {
results[key] = (await i.confirm({
type: QuestionType.Confirm,
message: key,
}))
? "true"
: "false";
} else {
results[key] = await i.text({
type: QuestionType.Text,
message: key,
default: value,
});
}
} else if (Array.isArray(value)) {
results[key] = await i.select(key, value);
} else {
throw new Error(`Unknown type ${typeof value}`);
}
}

return {
processors: [
{
name: "cyan/cookiecutter",
files: [],
config: {
template: url,
config: results,
},
},
],
plugins: [],
}
return {
processors: [
{
name: "cyan/cookiecutter",
files: [],
config: {
template: url,
config: results,
},
},
],
plugins: [],
};
});

0 comments on commit 30e004a

Please sign in to comment.