Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
New command for starting a new project (#26)
Browse files Browse the repository at this point in the history
PBI: 29090
Task: 29812, 29121
* Basic functionality of template file working

* Update template file content

* Small refactoring

* Address PR concerns.

* Update localization for commands
  • Loading branch information
jonathanwangg authored Jun 27, 2019
1 parent 377bc3e commit 48daf24
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@
},
"activationEvents": [
"onCommand:pacifica.openSimulator",
"onCommand:pacifica.runSimulator"
"onCommand:pacifica.runSimulator",
"onCommand:pacifica.newProject"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "pacifica.openSimulator",
"title": "Open Simulator",
"title": "%pacificaExtension.commands.openSimulator%",
"category": "%pacificaExtension.commands.label%"
},
{
"command": "pacifica.runSimulator",
"title": "Run the Simulator",
"title": "%pacificaExtension.commands.runSimulator%",
"category": "%pacificaExtension.commands.label%"
},
{
"command": "pacifica.newProject",
"title": "%pacificaExtension.commands.newProject%",
"category": "%pacificaExtension.commands.label%"
}
]
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"pacificaExtension.commands.label": "Adafruit",
"pacificaExtension.commands.openSimulator": "Open Simulator",
"pacificaExtension.commands.runSimulator": "Run Simulator"
"pacificaExtension.commands.runSimulator": "Run Simulator",
"pacificaExtension.commands.newProject": "New Project"
}
21 changes: 19 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from "vscode";
import * as path from "path";
import * as cp from "child_process";
import * as fs from "fs";
import { CONSTANTS } from "./constants";

function loadScript(context: vscode.ExtensionContext, path: string) {
Expand Down Expand Up @@ -54,8 +55,24 @@ export function activate(context: vscode.ExtensionContext) {
}
);

let newProject = vscode.commands.registerCommand(
"pacifica.newProject",
() => {
const fileName = "template.py";
const filePath = __dirname + path.sep + fileName;
const file = fs.readFileSync(filePath, "utf8");

vscode.workspace.openTextDocument({content: file, language: "en"})
.then((template: vscode.TextDocument) => {
vscode.window.showTextDocument(template, 1, false);
}), (error: any) => {
console.error(`Failed to open a new text document: ${error}`);
}
}
);

// Send message to the webview
let runSimulator = vscode.commands.registerCommand(
const runSimulator = vscode.commands.registerCommand(
"pacifica.runSimulator",
() => {
if (!currentPanel) {
Expand Down Expand Up @@ -186,7 +203,7 @@ export function activate(context: vscode.ExtensionContext) {
}
);

context.subscriptions.push(openSimulator, runSimulator);
context.subscriptions.push(openSimulator, runSimulator, newProject);
}

const updatePythonExtraPaths = () => {
Expand Down
14 changes: 14 additions & 0 deletions src/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'''
Save your file as "code.py" or "main.py" to run on the actual device
Getting started with CPX and CircuitPython intro on: https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library
Find example code for CPX on: https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples
'''

# import CPX library
from adafruit_circuitplayground.express import cpx

while True:
# start your code here
pass

0 comments on commit 48daf24

Please sign in to comment.