-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
48 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.env | ||
.idea | ||
.direnv | ||
.pre-commit-config.yaml |
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 |
---|---|---|
@@ -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> | ||
``` |
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 |
---|---|---|
@@ -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: [], | ||
}; | ||
}); |