mirror of
https://github.com/tauri-apps/tauri-vscode.git
synced 2026-01-31 00:35:18 +01:00
Merge pull request #3 from tauri-apps/dev
This commit is contained in:
18
.github/workflows/publish.yml
vendored
Normal file
18
.github/workflows/publish.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- release
|
||||
|
||||
name: Publish Extension
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: yarn
|
||||
- uses: lannonbr/vsce-action@master
|
||||
with:
|
||||
args: "publish -p $VSCE_TOKEN"
|
||||
env:
|
||||
VSCE_TOKEN: ${{ secrets.VSCE_TOKEN }}
|
||||
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 283 KiB |
18
package.json
18
package.json
@@ -2,6 +2,15 @@
|
||||
"name": "tauri-vscode",
|
||||
"displayName": "Tauri",
|
||||
"description": "Enhances the experience of Tauri apps development",
|
||||
"icon": "./assets/icon.png",
|
||||
"bugs": {
|
||||
"url": "https://github.com/tauri-apps/tauri-vscode/issues",
|
||||
"email": "smcbreen@microsoft.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tauri-apps/tauri-vscode.git"
|
||||
},
|
||||
"version": "0.0.1",
|
||||
"engines": {
|
||||
"vscode": "^1.46.0"
|
||||
@@ -11,7 +20,10 @@
|
||||
],
|
||||
"activationEvents": [
|
||||
"workspaceContains:**/tauri.conf.json",
|
||||
"onCommand:tauri.build"
|
||||
"onCommand:tauri.init",
|
||||
"onCommand:tauri.dev",
|
||||
"onCommand:tauri.build",
|
||||
"onCommand:tauri.build-debug"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
@@ -20,6 +32,10 @@
|
||||
"url": "https://gist.githubusercontent.com/lucasfernog/e945806ea3c8fb1b9aae728005cf9304/raw/0a0947f4561e6419ea43b2ee74ae897f6e31eced/schema.json"
|
||||
}],
|
||||
"commands": [{
|
||||
"command": "tauri.init",
|
||||
"title": "Init",
|
||||
"category": "Tauri"
|
||||
}, {
|
||||
"command": "tauri.dev",
|
||||
"title": "Dev",
|
||||
"category": "Tauri"
|
||||
|
||||
5
renovate.json
Normal file
5
renovate.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
||||
153
src/extension.ts
153
src/extension.ts
@@ -3,6 +3,7 @@ import { exec, ChildProcess } from 'child_process';
|
||||
import { runInTerminal } from 'run-in-terminal';
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
interface Process {
|
||||
process: ChildProcess;
|
||||
@@ -39,20 +40,59 @@ function registerCommands(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('tauri.dev', runTauriDev),
|
||||
vscode.commands.registerCommand('tauri.build', runTauriBuild),
|
||||
vscode.commands.registerCommand('tauri.build-debug', runTauriBuildDebug)
|
||||
vscode.commands.registerCommand('tauri.build-debug', runTauriBuildDebug),
|
||||
vscode.commands.registerCommand('tauri.init', runTauriInit)
|
||||
);
|
||||
}
|
||||
|
||||
function runTauriInit(): void {
|
||||
__pickProjectAndRunTauriScript(projectPath => {
|
||||
const installCommand = fs.existsSync(path.join(projectPath, 'yarn.lock'))
|
||||
? 'yarn add tauri'
|
||||
: `${__getNpmBin()} install tauri`;
|
||||
|
||||
const [command, ...args] = (installCommand).split(' ');
|
||||
__runScript(command, args, projectPath).then(() => {
|
||||
__runTauriScript(projectPath, ['init']);
|
||||
});
|
||||
}, () => {
|
||||
const paths = __getNpmProjectsPaths();
|
||||
return paths.filter(p => {
|
||||
return !(p.includes('node_modules') || fs.existsSync(path.join(p, 'src-tauri')));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runTauriDev(): void {
|
||||
__pickProjectAndRunTauriScript(['dev']);
|
||||
__pickProjectAndRunTauriScript(projectPath => __runTauriScript(projectPath, ['dev']));
|
||||
}
|
||||
|
||||
function runTauriBuild(): void {
|
||||
__pickProjectAndRunTauriScript(['build']);
|
||||
__pickProjectAndRunTauriScript(projectPath => __runTauriScript(projectPath, ['build']));
|
||||
}
|
||||
|
||||
function runTauriBuildDebug(): void {
|
||||
__pickProjectAndRunTauriScript(['build', '--debug']);
|
||||
__pickProjectAndRunTauriScript(projectPath => __runTauriScript(projectPath, ['build', '--debug']));
|
||||
}
|
||||
|
||||
function __getNpmProjectsPaths(): string[] {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (!folders) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const paths = [];
|
||||
for (const folder of folders) {
|
||||
const npmProjectRoots = glob.sync(folder.uri.fsPath + '/**/package.json')
|
||||
.map((p: string) => path.dirname(p));
|
||||
paths.push(...npmProjectRoots);
|
||||
}
|
||||
|
||||
if (paths.length === 0) {
|
||||
return folders.map(f => f.uri.fsPath);
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
function __getTauriProjectsPaths(): string[] {
|
||||
@@ -77,13 +117,21 @@ function __isMultiRoot(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
function __runCommandInTerminal(args: string[], cwd: string | undefined): void {
|
||||
runInTerminal(__getNpmBin(), ['run', ...args], { cwd, env: process.env });
|
||||
function __runCommandInTerminal(command: string, args: string[], cwd: string | undefined): Promise<void> {
|
||||
return runInTerminal(command, args, { cwd, env: process.env }).then(process => {
|
||||
return new Promise((resolve, reject) => {
|
||||
process.on('exit', code => {
|
||||
if (code) {
|
||||
reject();
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function __runCommandInIntegratedTerminal(args: string[], cwd: string | undefined): void {
|
||||
const cmdArgs = Array.from(args);
|
||||
|
||||
function __runCommandInIntegratedTerminal(command: string, args: string[], cwd: string | undefined): Promise<void> {
|
||||
if (!terminal) {
|
||||
terminal = vscode.window.createTerminal('tauri');
|
||||
}
|
||||
@@ -94,35 +142,40 @@ function __runCommandInIntegratedTerminal(args: string[], cwd: string | undefine
|
||||
const textCwd = cwd.replace(/\\/g, '\\\\');
|
||||
terminal.sendText(['cd', `"${textCwd}"`].join(' '));
|
||||
}
|
||||
terminal.sendText(__getNpmBin() + ' run ' + cmdArgs.join(' '));
|
||||
terminal.sendText(command + ' ' + args.join(' '));
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function __runCommandInOutputWindow(args: string[], cwd: string | undefined) {
|
||||
const cmd = __getNpmBin() + ' run ' + args.join(' ');
|
||||
const p = exec(cmd, { cwd, env: process.env });
|
||||
function __runCommandInOutputWindow(command: string, args: string[], cwd: string | undefined): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cmd = command + ' ' + args.join(' ');
|
||||
const p = exec(cmd, { cwd, env: process.env });
|
||||
|
||||
runningProcesses.set(p.pid, { process: p, cmd: cmd });
|
||||
runningProcesses.set(p.pid, { process: p, cmd: cmd });
|
||||
|
||||
p.stderr?.on('data', (data: string) => {
|
||||
outputChannel.append(data);
|
||||
p.stderr?.on('data', (data: string) => {
|
||||
outputChannel.append(data);
|
||||
});
|
||||
p.stdout?.on('data', (data: string) => {
|
||||
outputChannel.append(data);
|
||||
});
|
||||
p.on('exit', (_code: number, signal: string) => {
|
||||
runningProcesses.delete(p.pid);
|
||||
|
||||
if (signal === 'SIGTERM') {
|
||||
outputChannel.appendLine('Successfully killed process');
|
||||
outputChannel.appendLine('-----------------------');
|
||||
outputChannel.appendLine('');
|
||||
reject();
|
||||
} else {
|
||||
outputChannel.appendLine('-----------------------');
|
||||
outputChannel.appendLine('');
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
outputChannel.show(true);
|
||||
});
|
||||
p.stdout?.on('data', (data: string) => {
|
||||
outputChannel.append(data);
|
||||
});
|
||||
p.on('exit', (_code: number, signal: string) => {
|
||||
runningProcesses.delete(p.pid);
|
||||
|
||||
if (signal === 'SIGTERM') {
|
||||
outputChannel.appendLine('Successfully killed process');
|
||||
outputChannel.appendLine('-----------------------');
|
||||
outputChannel.appendLine('');
|
||||
} else {
|
||||
outputChannel.appendLine('-----------------------');
|
||||
outputChannel.appendLine('');
|
||||
}
|
||||
});
|
||||
|
||||
outputChannel.show(true);
|
||||
}
|
||||
|
||||
interface TauriProject {
|
||||
@@ -135,36 +188,44 @@ function __useTerminal() {
|
||||
}
|
||||
|
||||
function __getNpmBin() {
|
||||
vscode.window.showInformationMessage(vscode.workspace.getConfiguration('npm')['bin']);
|
||||
return vscode.workspace.getConfiguration('npm')['bin'] || 'npm';
|
||||
}
|
||||
|
||||
function __runTauriScript(cwd: string, args: string[]): void {
|
||||
const tauriCmd = `tauri ${args.join(' ')}`;
|
||||
vscode.window.showInformationMessage(`Running ${tauriCmd}`);
|
||||
vscode.workspace.saveAll().then(() => {
|
||||
function __getNpxBin() {
|
||||
const npmBin = __getNpmBin();
|
||||
return npmBin.slice(0, npmBin.length - 1) + 'x';
|
||||
}
|
||||
|
||||
function __runScript(command: string, args: string[], cwd: string) {
|
||||
vscode.window.showInformationMessage(`Running \`${command} ${args.join(' ')}\` in ${cwd}`);
|
||||
|
||||
return vscode.workspace.saveAll().then(() => {
|
||||
if (__useTerminal()) {
|
||||
if (typeof vscode.window.createTerminal === 'function') {
|
||||
__runCommandInIntegratedTerminal(args, cwd);
|
||||
return __runCommandInIntegratedTerminal(command, args, cwd);
|
||||
} else {
|
||||
__runCommandInTerminal(args, cwd);
|
||||
return __runCommandInTerminal(command, args, cwd);
|
||||
}
|
||||
} else {
|
||||
outputChannel.clear();
|
||||
__runCommandInOutputWindow(args, cwd);
|
||||
return __runCommandInOutputWindow(command, args, cwd);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function __pickProjectAndRunTauriScript(args: string[]): void {
|
||||
const tauriProjectsPaths = __getTauriProjectsPaths();
|
||||
function __runTauriScript(cwd: string, args: string[]): void {
|
||||
__runScript(__getNpxBin(), ['tauri', ...args], cwd);
|
||||
}
|
||||
|
||||
function __pickProjectAndRunTauriScript(runner: (projectPath: string) => void, getProjectPathsFn = __getTauriProjectsPaths): void {
|
||||
const tauriProjectsPaths = getProjectPathsFn();
|
||||
const projectList: TauriProject[] = [];
|
||||
|
||||
for (const p of tauriProjectsPaths) {
|
||||
let label = path.basename(p);
|
||||
if (__isMultiRoot()) {
|
||||
const root = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(p));
|
||||
if (root) {
|
||||
if (root && root.name !== label) {
|
||||
label = `${root.name}: ${label}`;
|
||||
}
|
||||
}
|
||||
@@ -181,11 +242,11 @@ function __pickProjectAndRunTauriScript(args: string[]): void {
|
||||
}
|
||||
|
||||
if (projectList.length === 1) {
|
||||
__runTauriScript(projectList[0].projectPath, args);
|
||||
runner(projectList[0].projectPath);
|
||||
} else {
|
||||
vscode.window.showQuickPick(projectList).then(project => {
|
||||
if (project) {
|
||||
__runTauriScript(project.projectPath, args);
|
||||
runner(project.projectPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user