-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add start in VSCode option and support python for dev container (…
- Loading branch information
Showing
11 changed files
with
148 additions
and
5 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 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Add "Start in VSCode" option to postInstallAction |
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 @@ | ||
--- | ||
"create-llama": patch | ||
--- | ||
|
||
Add devcontainers to generated code |
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,61 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { TemplateFramework } from "./types"; | ||
|
||
function renderDevcontainerContent( | ||
templatesDir: string, | ||
framework: TemplateFramework, | ||
frontend: boolean, | ||
) { | ||
const devcontainerJson: any = JSON.parse( | ||
fs.readFileSync(path.join(templatesDir, "devcontainer.json"), "utf8"), | ||
); | ||
|
||
// Modify postCreateCommand | ||
if (frontend) { | ||
devcontainerJson.postCreateCommand = | ||
framework === "fastapi" | ||
? "cd backend && poetry install && cd ../frontend && npm install" | ||
: "cd backend && npm install && cd ../frontend && npm install"; | ||
} else { | ||
devcontainerJson.postCreateCommand = | ||
framework === "fastapi" ? "poetry install" : "npm install"; | ||
} | ||
|
||
// Modify containerEnv | ||
if (framework === "fastapi") { | ||
if (frontend) { | ||
devcontainerJson.containerEnv = { | ||
...devcontainerJson.containerEnv, | ||
PYTHONPATH: "${PYTHONPATH}:${workspaceFolder}/backend", | ||
}; | ||
} else { | ||
devcontainerJson.containerEnv = { | ||
...devcontainerJson.containerEnv, | ||
PYTHONPATH: "${PYTHONPATH}:${workspaceFolder}", | ||
}; | ||
} | ||
} | ||
|
||
return JSON.stringify(devcontainerJson, null, 2); | ||
} | ||
|
||
export const writeDevcontainer = async ( | ||
root: string, | ||
templatesDir: string, | ||
framework: TemplateFramework, | ||
frontend: boolean, | ||
) => { | ||
console.log("Adding .devcontainer"); | ||
const devcontainerContent = renderDevcontainerContent( | ||
templatesDir, | ||
framework, | ||
frontend, | ||
); | ||
const devcontainerDir = path.join(root, ".devcontainer"); | ||
fs.mkdirSync(devcontainerDir); | ||
await fs.promises.writeFile( | ||
path.join(devcontainerDir, "devcontainer.json"), | ||
devcontainerContent, | ||
); | ||
}; |
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
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,35 @@ | ||
{ | ||
"image": "mcr.microsoft.com/vscode/devcontainers/typescript-node:dev-20-bullseye", | ||
"features": { | ||
"ghcr.io/devcontainers-contrib/features/turborepo-npm:1": {}, | ||
"ghcr.io/devcontainers-contrib/features/typescript:2": {}, | ||
"ghcr.io/devcontainers/features/python:1": { | ||
"version": "3.11", | ||
"toolsToInstall": ["flake8", "black", "mypy", "poetry"] | ||
} | ||
}, | ||
"customizations": { | ||
"codespaces": { | ||
"openFiles": ["README.md"] | ||
}, | ||
"vscode": { | ||
"extensions": [ | ||
"ms-vscode.typescript-language-features", | ||
"esbenp.prettier-vscode", | ||
"ms-python.python", | ||
"ms-python.black-formatter", | ||
"ms-python.vscode-flake8", | ||
"ms-python.vscode-pylance" | ||
], | ||
"settings": { | ||
"python.formatting.provider": "black", | ||
"python.languageServer": "Pylance", | ||
"python.analysis.typeCheckingMode": "basic" | ||
} | ||
} | ||
}, | ||
"containerEnv": { | ||
"POETRY_VIRTUALENVS_CREATE": "false" | ||
}, | ||
"forwardPorts": [3000, 8000] | ||
} |