mirror of
https://github.com/tauri-apps/tauri-vscode.git
synced 2026-01-31 00:35:18 +01:00
chore: remove unused code, update deps and use node18 in CI (#244)
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"rules": {
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
}
|
||||
}
|
||||
2
.github/workflows/covector-status.yml
vendored
2
.github/workflows/covector-status.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: covector status
|
||||
|
||||
@@ -14,7 +14,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: git config
|
||||
|
||||
6
.github/workflows/publish.yml
vendored
6
.github/workflows/publish.yml
vendored
@@ -13,7 +13,11 @@ jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
cache: 'yarn'
|
||||
- run: yarn
|
||||
- name: Publish to Open VSX Registry
|
||||
uses: HaaLeo/publish-vscode-extension@v1
|
||||
|
||||
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
@@ -14,11 +14,11 @@ jobs:
|
||||
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: setup node
|
||||
uses: actions/setup-node@v1
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 14
|
||||
node-version: 18
|
||||
cache: 'yarn'
|
||||
- name: install dependencies
|
||||
run: yarn
|
||||
- name: compile extension
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
}
|
||||
|
||||
8
.vscode/extensions.json
vendored
8
.vscode/extensions.json
vendored
@@ -1,8 +0,0 @@
|
||||
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": ["dbaeumer.vscode-eslint"]
|
||||
}
|
||||
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@@ -14,24 +14,9 @@
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--disable-extensions"
|
||||
],
|
||||
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
|
||||
"outFiles": ["${workspaceFolder}/out/**/*.js"],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
},
|
||||
{
|
||||
"name": "Extension Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||
],
|
||||
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
16
.vscode/settings.json
vendored
16
.vscode/settings.json
vendored
@@ -1,16 +0,0 @@
|
||||
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off",
|
||||
"npm.runInTerminal": false
|
||||
}
|
||||
@@ -9,6 +9,5 @@ src/**
|
||||
.gitignore
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/.eslintrc.json
|
||||
**/*.map
|
||||
**/*.ts
|
||||
|
||||
71
package.json
71
package.json
@@ -2,6 +2,7 @@
|
||||
"name": "tauri-vscode",
|
||||
"publisher": "tauri-apps",
|
||||
"displayName": "Tauri",
|
||||
"version": "0.2.6",
|
||||
"description": "Enhances the experience of Tauri apps development",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"icon": "assets/icon.png",
|
||||
@@ -13,28 +14,28 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/tauri-apps/tauri-vscode.git"
|
||||
},
|
||||
"version": "0.2.6",
|
||||
"engines": {
|
||||
"vscode": "^1.66.0"
|
||||
"vscode": "^1.75.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other",
|
||||
"Snippets"
|
||||
"Snippets",
|
||||
"Linters",
|
||||
"Other"
|
||||
],
|
||||
"keywords": [
|
||||
"tauri",
|
||||
"desktop",
|
||||
"gui",
|
||||
"development",
|
||||
"rust"
|
||||
"rust",
|
||||
"javascript",
|
||||
"framework"
|
||||
],
|
||||
"activationEvents": [
|
||||
"workspaceContains:**/tauri.conf.json",
|
||||
"onCommand:tauri.init",
|
||||
"onCommand:tauri.deps-install",
|
||||
"onCommand:tauri.deps-update",
|
||||
"onCommand:tauri.dev",
|
||||
"onCommand:tauri.build",
|
||||
"onCommand:tauri.build-debug",
|
||||
"workspaceContains:**/tauri.*.conf.json",
|
||||
"workspaceContains:**/tauri.conf.json5",
|
||||
"workspaceContains:**/tauri.*.conf.json5",
|
||||
"onFileSystem:tauri"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
@@ -56,16 +57,6 @@
|
||||
"title": "Init",
|
||||
"category": "Tauri"
|
||||
},
|
||||
{
|
||||
"command": "tauri.deps-install",
|
||||
"title": "Install Missing Dependencies",
|
||||
"category": "Tauri"
|
||||
},
|
||||
{
|
||||
"command": "tauri.deps-update",
|
||||
"title": "Update Dependencies",
|
||||
"category": "Tauri"
|
||||
},
|
||||
{
|
||||
"command": "tauri.dev",
|
||||
"title": "Dev",
|
||||
@@ -86,43 +77,25 @@
|
||||
{
|
||||
"language": "rust",
|
||||
"path": "./snippets/rust.json"
|
||||
},
|
||||
{
|
||||
"language": "markdown",
|
||||
"path": "./snippets/markdown.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "yarn run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"lint": "eslint src --ext ts",
|
||||
"format": "prettier ./**/*.{json,ts,js} -w --ignore-path .gitignore",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "yarn run compile && yarn run lint",
|
||||
"test": "node ./out/test/runTest.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "8.0.1",
|
||||
"@types/mocha": "10.0.1",
|
||||
"@types/node": "16.18.16",
|
||||
"@types/vscode": "1.66.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.51.0",
|
||||
"@typescript-eslint/parser": "5.51.0",
|
||||
"@vscode/test-electron": "2.1.5",
|
||||
"eslint": "8.33.0",
|
||||
"mocha": "10.2.0",
|
||||
"prettier": "2.8.6",
|
||||
"typescript": "4.9.5"
|
||||
"format": "prettier ./**/*.{json,ts,js} -w --ignore-path .gitignore"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/semver": "^7.3.12",
|
||||
"axios": "^1.0.0",
|
||||
"glob": "8.1.0",
|
||||
"run-in-terminal": "^0.0.3",
|
||||
"strip-ansi": "^6.0.1"
|
||||
"axios": "1.6.8",
|
||||
"glob": "10.3.12",
|
||||
"run-in-terminal": "0.0.3",
|
||||
"strip-ansi": "6.0.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"brace-expansion": "^2.0.1"
|
||||
"devDependencies": {
|
||||
"@types/node": "18.11.9",
|
||||
"@types/vscode": "1.75.0",
|
||||
"prettier": "3.2.5",
|
||||
"typescript": "5.4.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"Create a covector change file": {
|
||||
"prefix": ["covector", "---"],
|
||||
"body": [
|
||||
"---",
|
||||
"\"${3:$WORKSPACE_NAME}\": \"${1|patch,minor,major|}\"",
|
||||
"---",
|
||||
"",
|
||||
"$2"
|
||||
]
|
||||
}
|
||||
}
|
||||
329
src/extension.ts
329
src/extension.ts
@@ -2,48 +2,47 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { exec, execSync, ChildProcess } from 'child_process';
|
||||
import { runInTerminal } from 'run-in-terminal';
|
||||
import { join } from 'path';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import axios from 'axios';
|
||||
import * as vscode from 'vscode'
|
||||
import { exec, execSync, ChildProcess } from 'child_process'
|
||||
import { runInTerminal } from 'run-in-terminal'
|
||||
import { join } from 'path'
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import axios from 'axios'
|
||||
|
||||
import stripAnsi = require('strip-ansi');
|
||||
|
||||
const glob = require('glob');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const stripAnsi = require('strip-ansi')
|
||||
const glob = require('glob')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
interface Process {
|
||||
process: ChildProcess;
|
||||
cmd: string;
|
||||
process: ChildProcess
|
||||
cmd: string
|
||||
}
|
||||
|
||||
let outputChannel: vscode.OutputChannel;
|
||||
let terminal: vscode.Terminal | null = null;
|
||||
const runningProcesses: Map<number, Process> = new Map();
|
||||
let outputChannel: vscode.OutputChannel
|
||||
let terminal: vscode.Terminal | null = null
|
||||
const runningProcesses: Map<number, Process> = new Map()
|
||||
|
||||
// this method is called when your extension is activated
|
||||
// your extension is activated the very first time the command is executed
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
registerCommands(context);
|
||||
registerSchemasHandler(context);
|
||||
registerCommands(context)
|
||||
registerSchemasHandler(context)
|
||||
|
||||
outputChannel = vscode.window.createOutputChannel('tauri');
|
||||
context.subscriptions.push(outputChannel);
|
||||
outputChannel = vscode.window.createOutputChannel('tauri')
|
||||
context.subscriptions.push(outputChannel)
|
||||
|
||||
vscode.window.onDidCloseTerminal((closedTerminal) => {
|
||||
if (terminal === closedTerminal) {
|
||||
terminal = null;
|
||||
terminal = null
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
export function deactivate() {
|
||||
if (terminal) {
|
||||
terminal.dispose();
|
||||
terminal.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,15 +52,15 @@ function registerCommands(context: vscode.ExtensionContext) {
|
||||
vscode.commands.registerCommand('tauri.dev', runTauriDev),
|
||||
vscode.commands.registerCommand('tauri.build', runTauriBuild),
|
||||
vscode.commands.registerCommand('tauri.build-debug', runTauriBuildDebug)
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function registerSchemasHandler(context: vscode.ExtensionContext) {
|
||||
vscode.workspace.registerTextDocumentContentProvider(
|
||||
'tauri',
|
||||
new (class implements vscode.TextDocumentContentProvider {
|
||||
onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
onDidChange = this.onDidChangeEmitter.event;
|
||||
onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>()
|
||||
onDidChange = this.onDidChangeEmitter.event
|
||||
|
||||
async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
|
||||
if (uri.authority === 'schemas' && uri.path === '/config.json') {
|
||||
@@ -70,38 +69,38 @@ function registerSchemasHandler(context: vscode.ExtensionContext) {
|
||||
await vscode.workspace.findFiles(
|
||||
'**/node_modules/@tauri-apps/cli/schema.json'
|
||||
)
|
||||
)[0];
|
||||
if (schemaFile) return readFileSync(schemaFile.fsPath, 'utf-8');
|
||||
)[0]
|
||||
if (schemaFile) return readFileSync(schemaFile.fsPath, 'utf-8')
|
||||
|
||||
async function getSchemaFromRelease(version: string) {
|
||||
const res = await axios.get(
|
||||
`https://github.com/tauri-apps/tauri/releases/download/tauri-build-v${version}/schema.json`
|
||||
);
|
||||
return res.status == 200 ? JSON.stringify(res.data) : null;
|
||||
)
|
||||
return res.status == 200 ? JSON.stringify(res.data) : null
|
||||
}
|
||||
|
||||
// get schema form github release based on tauri-build version in Cargo.lock
|
||||
const cargoLockPath = (
|
||||
await vscode.workspace.findFiles('**/Cargo.lock')
|
||||
)[0];
|
||||
)[0]
|
||||
if (cargoLockPath) {
|
||||
const cargoLock = readFileSync(cargoLockPath.fsPath, 'utf-8');
|
||||
const cargoLock = readFileSync(cargoLockPath.fsPath, 'utf-8')
|
||||
const matches =
|
||||
/\[\[package\]\]\nname = "tauri-build"\nversion = "(.*)"/g.exec(
|
||||
cargoLock
|
||||
);
|
||||
)
|
||||
if (matches && matches[1]) {
|
||||
const schema = await getSchemaFromRelease(matches[1]);
|
||||
if (schema) return schema;
|
||||
const schema = await getSchemaFromRelease(matches[1])
|
||||
if (schema) return schema
|
||||
}
|
||||
}
|
||||
|
||||
// get schema form github release based on tauri-build version in Cargo.toml
|
||||
const cargoTomlPath = (
|
||||
await vscode.workspace.findFiles('**/Cargo.toml')
|
||||
)[0];
|
||||
)[0]
|
||||
if (cargoTomlPath) {
|
||||
const cargoToml = readFileSync(cargoTomlPath.fsPath, 'utf-8');
|
||||
const cargoToml = readFileSync(cargoTomlPath.fsPath, 'utf-8')
|
||||
|
||||
for (const regex of [
|
||||
// specifying a dependency in Cargo.toml can be done in 4 ways
|
||||
@@ -118,12 +117,12 @@ function registerSchemasHandler(context: vscode.ExtensionContext) {
|
||||
// 4th,
|
||||
// [dependencies.tauri-build]
|
||||
// \n version = "1.0.2"
|
||||
/\[.*tauri-build\][\s\S.]*version = "(.*)"\n/g,
|
||||
/\[.*tauri-build\][\s\S.]*version = "(.*)"\n/g
|
||||
]) {
|
||||
const matches = regex.exec(cargoToml);
|
||||
const matches = regex.exec(cargoToml)
|
||||
if (matches && matches[1]) {
|
||||
const schema = await getSchemaFromRelease(matches[1]);
|
||||
if (schema) return schema;
|
||||
const schema = await getSchemaFromRelease(matches[1])
|
||||
if (schema) return schema
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,167 +130,167 @@ function registerSchemasHandler(context: vscode.ExtensionContext) {
|
||||
// fallback to latest release
|
||||
let res = await axios.get(
|
||||
`https://api.github.com/repos/tauri-apps/tauri/releases`
|
||||
);
|
||||
)
|
||||
let tag_name = (res.data as Array<{ tag_name: string }>).find((e) =>
|
||||
e.tag_name.startsWith('tauri-build-v')
|
||||
)?.tag_name;
|
||||
)?.tag_name
|
||||
if (tag_name) {
|
||||
const matches =
|
||||
/((\d|x|\*)+\.(\d|x|\*)+\.(\d|x|\*)+(-[a-zA-Z-0-9]*(.[0-9]+))*)/g.exec(
|
||||
tag_name
|
||||
);
|
||||
)
|
||||
if (matches && matches[1]) {
|
||||
const schema = await getSchemaFromRelease(matches[1]);
|
||||
if (schema) return schema;
|
||||
const schema = await getSchemaFromRelease(matches[1])
|
||||
if (schema) return schema
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
return ''
|
||||
}
|
||||
})()
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function runTauriInit(): void {
|
||||
__pickProjectAndRunTauriScript(
|
||||
(projectPath) => {
|
||||
let installCommand: string;
|
||||
let onInstall = () => {};
|
||||
let installCommand: string
|
||||
let onInstall = () => {}
|
||||
if (__isVueCliApp(projectPath)) {
|
||||
installCommand = 'vue add tauri';
|
||||
installCommand = 'vue add tauri'
|
||||
} else if (__isNodeProject(projectPath)) {
|
||||
installCommand = __usePnpm(projectPath)
|
||||
? 'pnpm add -D @tauri-apps/cli'
|
||||
: __useYarn(projectPath)
|
||||
? 'yarn add @tauri-apps/cli --dev'
|
||||
: `${__getNpmBin()} install @tauri-apps/cli --save-dev`;
|
||||
: `${__getNpmBin()} install @tauri-apps/cli --save-dev`
|
||||
onInstall = () => {
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync(`${projectPath}/package.json`)
|
||||
);
|
||||
)
|
||||
if (!packageJson.scripts) {
|
||||
packageJson.scripts = {};
|
||||
packageJson.scripts = {}
|
||||
}
|
||||
if (!packageJson.scripts['tauri']) {
|
||||
packageJson.scripts['tauri'] = 'tauri';
|
||||
packageJson.scripts['tauri'] = 'tauri'
|
||||
fs.writeFileSync(
|
||||
`${projectPath}/package.json`,
|
||||
JSON.stringify(packageJson, null, 4)
|
||||
);
|
||||
)
|
||||
}
|
||||
__runTauriScript(['init'], {
|
||||
cwd: projectPath,
|
||||
noOutputWindow: true,
|
||||
});
|
||||
};
|
||||
noOutputWindow: true
|
||||
})
|
||||
}
|
||||
} else {
|
||||
installCommand = 'cargo install tauri-cli';
|
||||
installCommand = 'cargo install tauri-cli'
|
||||
}
|
||||
|
||||
const [command, ...args] = installCommand.split(' ');
|
||||
const [command, ...args] = installCommand.split(' ')
|
||||
__runScript(command, args, {
|
||||
cwd: projectPath,
|
||||
noOutputWindow: command === 'vue',
|
||||
}).then(onInstall);
|
||||
noOutputWindow: command === 'vue'
|
||||
}).then(onInstall)
|
||||
},
|
||||
() => {
|
||||
const paths = __getNpmProjectsPaths();
|
||||
const paths = __getNpmProjectsPaths()
|
||||
return paths.filter((p) => {
|
||||
return fs.existsSync(path.join(p, 'src-tauri'));
|
||||
});
|
||||
return fs.existsSync(path.join(p, 'src-tauri'))
|
||||
})
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function runTauriDev(): void {
|
||||
__pickProjectAndRunTauriScript((projectPath) =>
|
||||
__runTauriScript(['dev'], { cwd: projectPath })
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function runTauriBuild(): void {
|
||||
__pickProjectAndRunTauriScript((projectPath) =>
|
||||
__runTauriScript(['build'], { cwd: projectPath })
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function runTauriBuildDebug(): void {
|
||||
__pickProjectAndRunTauriScript((projectPath) =>
|
||||
__runTauriScript(['build', '--debug'], { cwd: projectPath })
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function __isVueCliApp(cwd: string): boolean {
|
||||
const packageJson = __getPackageJson(cwd);
|
||||
return '@vue/cli-service' in (packageJson?.devDependencies ?? {});
|
||||
const packageJson = __getPackageJson(cwd)
|
||||
return '@vue/cli-service' in (packageJson?.devDependencies ?? {})
|
||||
}
|
||||
|
||||
function __isNodeProject(cwd: string): boolean {
|
||||
return existsSync(join(cwd, 'package.json'));
|
||||
return existsSync(join(cwd, 'package.json'))
|
||||
}
|
||||
|
||||
interface PackageJson {
|
||||
dependencies: {
|
||||
[name: string]: any;
|
||||
};
|
||||
[name: string]: any
|
||||
}
|
||||
devDependencies: {
|
||||
[name: string]: any;
|
||||
};
|
||||
[name: string]: any
|
||||
}
|
||||
}
|
||||
|
||||
function __getPackageJson(path: string): PackageJson | null {
|
||||
const packagePath = join(path, 'package.json');
|
||||
const packagePath = join(path, 'package.json')
|
||||
if (existsSync(packagePath)) {
|
||||
const packageStr = readFileSync(packagePath).toString();
|
||||
return JSON.parse(packageStr) as PackageJson;
|
||||
const packageStr = readFileSync(packagePath).toString()
|
||||
return JSON.parse(packageStr) as PackageJson
|
||||
} else {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function __getNpmProjectsPaths(): string[] {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
const folders = vscode.workspace.workspaceFolders
|
||||
if (!folders) {
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
const paths = [];
|
||||
const paths = []
|
||||
for (const folder of folders) {
|
||||
const npmProjectRoots: string[] = glob
|
||||
.sync(folder.uri.fsPath.split('\\').join('/') + '/**/package.json')
|
||||
.map((p: string) => path.dirname(p));
|
||||
paths.push(...npmProjectRoots.filter((p) => !p.includes('node_modules')));
|
||||
.map((p: string) => path.dirname(p))
|
||||
paths.push(...npmProjectRoots.filter((p) => !p.includes('node_modules')))
|
||||
}
|
||||
|
||||
if (paths.length === 0) {
|
||||
return folders.map((f) => f.uri.fsPath);
|
||||
return folders.map((f) => f.uri.fsPath)
|
||||
}
|
||||
|
||||
return paths;
|
||||
return paths
|
||||
}
|
||||
|
||||
function __getTauriProjectsPaths(): string[] {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
const folders = vscode.workspace.workspaceFolders
|
||||
if (!folders) {
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
const paths = [];
|
||||
const paths = []
|
||||
for (const folder of folders) {
|
||||
const tauriProjectRoots: string[] = glob
|
||||
.sync(folder.uri.fsPath.split('\\').join('/') + '/**/src-tauri')
|
||||
.map((p: string) => path.dirname(p));
|
||||
paths.push(...tauriProjectRoots.filter((p) => !p.includes('node_modules')));
|
||||
.map((p: string) => path.dirname(p))
|
||||
paths.push(...tauriProjectRoots.filter((p) => !p.includes('node_modules')))
|
||||
}
|
||||
return paths;
|
||||
return paths
|
||||
}
|
||||
|
||||
function __isMultiRoot(): boolean {
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
return vscode.workspace.workspaceFolders.length > 1;
|
||||
return vscode.workspace.workspaceFolders.length > 1
|
||||
}
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
function __runCommandInTerminal(
|
||||
@@ -304,14 +303,14 @@ function __runCommandInTerminal(
|
||||
return new Promise((resolve, reject) => {
|
||||
process.on('exit', (code) => {
|
||||
if (code) {
|
||||
reject();
|
||||
reject()
|
||||
} else {
|
||||
resolve();
|
||||
resolve()
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
})
|
||||
}
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
function __runCommandInIntegratedTerminal(
|
||||
@@ -320,17 +319,17 @@ function __runCommandInIntegratedTerminal(
|
||||
cwd: string | undefined
|
||||
): Promise<void> {
|
||||
if (!terminal) {
|
||||
terminal = vscode.window.createTerminal('tauri');
|
||||
terminal = vscode.window.createTerminal('tauri')
|
||||
}
|
||||
|
||||
terminal.show();
|
||||
terminal.show()
|
||||
if (cwd) {
|
||||
// Replace single backslash with double backslash.
|
||||
const textCwd = cwd.replace(/\\/g, '\\\\');
|
||||
terminal.sendText(['cd', `"${textCwd}"`].join(' '));
|
||||
const textCwd = cwd.replace(/\\/g, '\\\\')
|
||||
terminal.sendText(['cd', `"${textCwd}"`].join(' '))
|
||||
}
|
||||
terminal.sendText(command + ' ' + args.join(' '));
|
||||
return Promise.resolve();
|
||||
terminal.sendText(command + ' ' + args.join(' '))
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function __runCommandInOutputWindow(
|
||||
@@ -339,76 +338,76 @@ function __runCommandInOutputWindow(
|
||||
cwd: string | undefined
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cmd = command + ' ' + args.join(' ');
|
||||
const p = exec(cmd, { cwd, env: process.env });
|
||||
const cmd = command + ' ' + args.join(' ')
|
||||
const p = exec(cmd, { cwd, env: process.env })
|
||||
|
||||
if (p.pid === undefined) {
|
||||
return reject();
|
||||
return reject()
|
||||
}
|
||||
|
||||
runningProcesses.set(p.pid, { process: p, cmd: cmd });
|
||||
runningProcesses.set(p.pid, { process: p, cmd: cmd })
|
||||
|
||||
p.stderr?.on('data', (data: string) => {
|
||||
outputChannel.append(stripAnsi(data));
|
||||
});
|
||||
outputChannel.append(stripAnsi(data))
|
||||
})
|
||||
p.stdout?.on('data', (data: string) => {
|
||||
outputChannel.append(stripAnsi(data));
|
||||
});
|
||||
outputChannel.append(stripAnsi(data))
|
||||
})
|
||||
p.on('exit', (_code: number, signal: string) => {
|
||||
runningProcesses.delete(p.pid!);
|
||||
runningProcesses.delete(p.pid!)
|
||||
|
||||
if (signal === 'SIGTERM') {
|
||||
outputChannel.appendLine('Successfully killed process');
|
||||
outputChannel.appendLine('-----------------------');
|
||||
outputChannel.appendLine('');
|
||||
reject();
|
||||
outputChannel.appendLine('Successfully killed process')
|
||||
outputChannel.appendLine('-----------------------')
|
||||
outputChannel.appendLine('')
|
||||
reject()
|
||||
} else {
|
||||
outputChannel.appendLine('-----------------------');
|
||||
outputChannel.appendLine('');
|
||||
resolve();
|
||||
outputChannel.appendLine('-----------------------')
|
||||
outputChannel.appendLine('')
|
||||
resolve()
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
outputChannel.show(true);
|
||||
});
|
||||
outputChannel.show(true)
|
||||
})
|
||||
}
|
||||
|
||||
interface TauriProject {
|
||||
label: string;
|
||||
projectPath: string;
|
||||
label: string
|
||||
projectPath: string
|
||||
}
|
||||
|
||||
function __useTerminal() {
|
||||
return vscode.workspace.getConfiguration('npm')['runInTerminal'];
|
||||
return vscode.workspace.getConfiguration('npm')['runInTerminal']
|
||||
}
|
||||
|
||||
function __usePnpm(projectPath: string) {
|
||||
return fs.existsSync(path.join(projectPath, 'pnpm-lock.yaml'));
|
||||
return fs.existsSync(path.join(projectPath, 'pnpm-lock.yaml'))
|
||||
}
|
||||
|
||||
function __useYarn(projectPath: string) {
|
||||
return fs.existsSync(path.join(projectPath, 'yarn.lock'));
|
||||
return fs.existsSync(path.join(projectPath, 'yarn.lock'))
|
||||
}
|
||||
|
||||
function __useNpm(projectPath: string) {
|
||||
return fs.existsSync(path.join(projectPath, 'package-lock.json'));
|
||||
return fs.existsSync(path.join(projectPath, 'package-lock.json'))
|
||||
}
|
||||
|
||||
function __useCargo() {
|
||||
try {
|
||||
execSync('cargo tauri --version', { windowsHide: true });
|
||||
return true;
|
||||
execSync('cargo tauri --version', { windowsHide: true })
|
||||
return true
|
||||
} catch {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function __getNpmBin() {
|
||||
return vscode.workspace.getConfiguration('npm')['bin'] || 'npm';
|
||||
return vscode.workspace.getConfiguration('npm')['bin'] || 'npm'
|
||||
}
|
||||
|
||||
function __getNpmCommand() {
|
||||
return __getNpmBin() + ' run';
|
||||
return __getNpmBin() + ' run'
|
||||
}
|
||||
|
||||
function __getPackageManagerCommand(projectPath: string): string | null {
|
||||
@@ -420,54 +419,54 @@ function __getPackageManagerCommand(projectPath: string): string | null {
|
||||
? __getNpmCommand()
|
||||
: __useCargo()
|
||||
? 'cargo'
|
||||
: null;
|
||||
: null
|
||||
|
||||
if (!m) {
|
||||
vscode.window.showErrorMessage(
|
||||
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
return m;
|
||||
return m
|
||||
}
|
||||
|
||||
interface RunOptions {
|
||||
noOutputWindow?: boolean;
|
||||
cwd: string;
|
||||
noOutputWindow?: boolean
|
||||
cwd: string
|
||||
}
|
||||
|
||||
function __runScript(command: string, args: string[], options: RunOptions) {
|
||||
vscode.window.showInformationMessage(
|
||||
`Running \`${command} ${args.join(' ')}\` in ${options.cwd}`
|
||||
);
|
||||
)
|
||||
|
||||
return vscode.workspace.saveAll().then(() => {
|
||||
if (__useTerminal() || options.noOutputWindow) {
|
||||
if (typeof vscode.window.createTerminal === 'function') {
|
||||
return __runCommandInIntegratedTerminal(command, args, options.cwd);
|
||||
return __runCommandInIntegratedTerminal(command, args, options.cwd)
|
||||
} else {
|
||||
return __runCommandInTerminal(command, args, options.cwd);
|
||||
return __runCommandInTerminal(command, args, options.cwd)
|
||||
}
|
||||
} else {
|
||||
outputChannel.clear();
|
||||
return __runCommandInOutputWindow(command, args, options.cwd);
|
||||
outputChannel.clear()
|
||||
return __runCommandInOutputWindow(command, args, options.cwd)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function __runTauriScript(args: string[], options: RunOptions): void {
|
||||
const command = __getPackageManagerCommand(options.cwd);
|
||||
if (!command) return;
|
||||
const command = __getPackageManagerCommand(options.cwd)
|
||||
if (!command) return
|
||||
|
||||
if (__isVueCliApp(options.cwd)) {
|
||||
const [cmd, ...cmgArgs] = args;
|
||||
const [cmd, ...cmgArgs] = args
|
||||
__runScript(
|
||||
command,
|
||||
[`tauri:${cmd === 'dev' ? 'serve' : cmd}`, ...cmgArgs],
|
||||
options
|
||||
);
|
||||
)
|
||||
} else {
|
||||
__runScript(command, ['tauri', ...args], options);
|
||||
__runScript(command, ['tauri', ...args], options)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,36 +474,36 @@ function __pickProjectAndRunTauriScript(
|
||||
runner: (projectPath: string) => void,
|
||||
getProjectPathsFn = __getTauriProjectsPaths
|
||||
): void {
|
||||
const tauriProjectsPaths = getProjectPathsFn();
|
||||
const projectList: TauriProject[] = [];
|
||||
const tauriProjectsPaths = getProjectPathsFn()
|
||||
const projectList: TauriProject[] = []
|
||||
|
||||
for (const p of tauriProjectsPaths) {
|
||||
let label = path.basename(p);
|
||||
let label = path.basename(p)
|
||||
if (__isMultiRoot()) {
|
||||
const root = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(p));
|
||||
const root = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(p))
|
||||
if (root && root.name !== label) {
|
||||
label = `${root.name}: ${label}`;
|
||||
label = `${root.name}: ${label}`
|
||||
}
|
||||
}
|
||||
|
||||
projectList.push({
|
||||
label,
|
||||
projectPath: p,
|
||||
});
|
||||
projectPath: p
|
||||
})
|
||||
}
|
||||
|
||||
if (projectList.length === 0) {
|
||||
vscode.window.showErrorMessage('Tauri project not found');
|
||||
return;
|
||||
vscode.window.showErrorMessage('Tauri project not found')
|
||||
return
|
||||
}
|
||||
|
||||
if (projectList.length === 1) {
|
||||
runner(projectList[0].projectPath);
|
||||
runner(projectList[0].projectPath)
|
||||
} else {
|
||||
vscode.window.showQuickPick(projectList).then((project) => {
|
||||
if (project) {
|
||||
runner(project.projectPath);
|
||||
runner(project.projectPath)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import * as path from 'path';
|
||||
|
||||
import { runTests } from '@vscode/test-electron';
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
} catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Extension Test Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
vscode.window.showInformationMessage(
|
||||
JSON.stringify(vscode.workspace.workspaceFolders)
|
||||
);
|
||||
setTimeout(() => {}, 2000);
|
||||
});
|
||||
});
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import * as path from 'path';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as glob from 'glob';
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
color: true,
|
||||
});
|
||||
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
|
||||
return new Promise((c, e) => {
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
|
||||
// Add files to the test suite
|
||||
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run((failures) => {
|
||||
if (failures > 0) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
} else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -1,19 +1,14 @@
|
||||
// Copyright 2020-2022 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"target": "es2020",
|
||||
"lib": ["es2020"],
|
||||
"outDir": "out",
|
||||
"lib": ["es6"],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
"skipLibCheck": true,
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"rootDir": "src"
|
||||
},
|
||||
"exclude": ["node_modules", ".vscode-test"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user