|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +--- |
| 4 | + |
| 5 | +# Visual Studio Code |
| 6 | + |
| 7 | +[Visual Studio Code](https://code.visualstudio.com/) (`code`) is a popular editor for TypeScript program. It is the |
| 8 | +preferred editor for DeviceScript projects. |
| 9 | + |
| 10 | +The command line tool is compatible with container and virtual machines so you can run it |
| 11 | +in Docker, GitHub Codespaces, ... |
| 12 | + |
| 13 | +## Setting up the project |
| 14 | + |
| 15 | +Let's get started by installing the [DeviceScript command line](/developer/cli) and create an empty project |
| 16 | + |
| 17 | +- Open `code` in a new empty folder |
| 18 | +- Open a terminal (`` Ctrl + ` ``) |
| 19 | +- Install the command line globally. You can call it using `devsc` |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install -g -u @devicescript/cli |
| 23 | +``` |
| 24 | + |
| 25 | +- Use the `init` command to setup the files |
| 26 | + |
| 27 | +```bash |
| 28 | +devsc init |
| 29 | +``` |
| 30 | + |
| 31 | +You will have the following files created. |
| 32 | + |
| 33 | +``` |
| 34 | +.devicescript reserved folder for devicescript generated |
| 35 | + /lib supporting runtime types and libraries |
| 36 | + /bin compilation file output |
| 37 | +.gitignore if you are using git, make sure to ignore .devicescript |
| 38 | +main.ts usual name for your entry point application |
| 39 | +package.json additional dependencies and also has the `devicescript` field entry |
| 40 | +tsconfig.json configure the TypeScript compiler to compile DeviceScript syntax |
| 41 | +... A few additional files supporting the coding experience in VS Code |
| 42 | +``` |
| 43 | + |
| 44 | +## Launch the build watch |
| 45 | + |
| 46 | +Assuming `main.ts` is the root file of your application, |
| 47 | +launch a compilation task in watch mode using this command. |
| 48 | + |
| 49 | +```bash |
| 50 | +devsc build --watch |
| 51 | +``` |
| 52 | + |
| 53 | +The command line task will also start a local web server that will send the compiled bytecode |
| 54 | +to a developer tools page similar to the one hosted in the docs. |
| 55 | + |
| 56 | +- open the developer tools page (see cli output) |
| 57 | + |
| 58 | +## Edit, deploy, debug loop |
| 59 | + |
| 60 | +From here, your developer inner loop will be very similar to building/debugging a web site with hot reload. |
| 61 | + |
| 62 | +- make an edit in your source file, say `main.ts` |
| 63 | +- after a couple seconds, the compiler picks up the changes, produces a new bytecode and sends it to the developer tools |
| 64 | +- the developer tools automatically deploy thew bytecode to the select device (by default the simulator) |
| 65 | +- switch from VS Code to the browser and debug your new code |
0 commit comments