diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..234a19d3d1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,36 @@ +FROM --platform=linux/amd64 mcr.microsoft.com/devcontainers/base:bullseye + +# Install .NET SDK 2.1 +RUN apt-get update \ + && apt-get install -y wget curl git \ + && wget https://dot.net/v1/dotnet-install.sh -O /tmp/dotnet-install.sh \ + && chmod +x /tmp/dotnet-install.sh \ + && /tmp/dotnet-install.sh --channel 2.1 --install-dir /usr/share/dotnet \ + && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/*.sh + +# Set up nvs (Node Version Switcher) for vscode user +ARG USERNAME=vscode +USER ${USERNAME} +ENV NVS_HOME="/home/${USERNAME}/.nvs" + +# Install nvs and Node.js 20.19.0 +RUN git clone https://github.com/jasongin/nvs "${NVS_HOME}" \ + && . "${NVS_HOME}/nvs.sh" install \ + && nvs add 20.19.0 \ + && nvs use 20.19.0 \ + && nvs link 20.19.0 + +# Install Rush and AutoRest globally +RUN . "${NVS_HOME}/nvs.sh" \ + && npm install -g @microsoft/rush@5.112.2 \ + && npm install -g autorest@latest + +# Add nvs to shell profiles +RUN echo 'export NVS_HOME="$HOME/.nvs"' >> ~/.bashrc \ + && echo '[ -s "$NVS_HOME/nvs.sh" ] && . "$NVS_HOME/nvs.sh"' >> ~/.bashrc \ + && echo 'export NVS_HOME="$HOME/.nvs"' >> ~/.zshrc \ + && echo '[ -s "$NVS_HOME/nvs.sh" ] && . "$NVS_HOME/nvs.sh"' >> ~/.zshrc + +USER root diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..2dcf1540ea --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +{ + "name": "AutoRest PowerShell", + "build": { + "context": "..", + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/devcontainers/features/powershell:1": { + "version": "latest" + } + }, + "postCreateCommand": "bash .devcontainer/postcreate.sh", + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.powershell", + "dbaeumer.vscode-eslint" + ] + } + } +} diff --git a/.devcontainer/postcreate.sh b/.devcontainer/postcreate.sh new file mode 100644 index 0000000000..4817bfbd4a --- /dev/null +++ b/.devcontainer/postcreate.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +echo "Dev container setup complete!" +echo "" +echo "Installed versions:" +echo " Node: $(node -v 2>/dev/null || echo 'Run: source ~/.bashrc')" +echo " npm: $(npm -v 2>/dev/null || echo 'Run: source ~/.bashrc')" +echo " Rush: $(rush --version 2>/dev/null | head -n1 || echo 'Run: source ~/.bashrc')" +echo " .NET: $(dotnet --version)" +echo " PowerShell: $(pwsh -v)" +echo "" +echo "If node/npm/rush are not found, run: source ~/.bashrc" +echo "" +echo "Ready to build: rush sync-versions && rush update && rush rebuild" diff --git a/docs/development.md b/docs/development.md index 017e9cc5b8..4d1284c408 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1,5 +1,37 @@ # AutoRest PowerShell Generator - Development +## Getting Started with Dev Containers (Recommended) + +The easiest way to get started is using the provided Dev Container configuration, which automatically sets up all required tools and dependencies. + +### Prerequisites +- [Docker](https://www.docker.com/get-started) or [Podman](https://podman.io/) +- [Visual Studio Code](https://code.visualstudio.com/) with the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) + +### Setup +1. Clone the repository: + ```powershell + git clone https://github.com/azure/autorest.powershell + cd autorest.powershell + ``` + +2. Open in VS Code and reopen in container: + - Open the folder in VS Code + - When prompted, click "Reopen in Container" (or press `F1` and select "Dev Containers: Reopen in Container") + - Wait for the container to build and initialize (this may take a few minutes on first run) + +3. Once the container is ready, all tools are pre-installed and configured: + - Node.js 20.19.0 + - Rush 5.112.2 + - PowerShell 7.5+ + - .NET SDK 2.1 + +4. Build the project: + ```powershell + rush update + rush rebuild + ``` + ## Requirements Use of this project requires the following: @@ -14,7 +46,7 @@ Use of this project requires the following: ## Cloning this repository -``` powershell +```powershell # clone recursively git clone https://github.com/azure/autorest.powershell @@ -27,14 +59,14 @@ npm install This repository is built as a 'monorepo' using [RushJS](https://rushjs.io/) - which manages multiple nodejs projects in a single repository. -``` powershell +```powershell # install nodejs modules for all projects in the monorepo rush update ``` Rush is used to make sure that package versions are consistent between sub-projects -``` powershell +```powershell # ensure all projects are using the same versions rush sync-versions @@ -46,7 +78,7 @@ rush update Rush is used to build `autorest.powershell` -``` powershell +```powershell # build everything rush rebuild ``` @@ -54,7 +86,7 @@ rush rebuild You can use `watch` to compile when a file is changed, which will rebuild dependencies automatically. Just kill the process with ctrl-c to stop it. -``` powershell +```powershell # start watching rush watch ``` @@ -63,15 +95,14 @@ rush watch To use the locally built version of the plugin, add `--use:` to the command line -``` powershell -# using a local build -> autorest --use:c:/work/autorest.powershell <...arguments> - +```powershell +# using a local build (adjust path for your platform) +autorest --use:/path/to/autorest.powershell <...arguments> ``` ### Debugging -1. Start generating: `autorest --use:C:\path\to\local\autorest.powershell --powershell.debugger`. It will wait for debugger to attach. +1. Start generating: `autorest --use:/path/to/local/autorest.powershell --powershell.debugger`. It will wait for debugger to attach. 1. Start debugging: open autorest.powershell repo in vscode; press `F5`. You will see "Debugger attached." in your autorest console, then you can start debugging. ### Testing