Skip to content

Commit 3f52bc7

Browse files
committed
chore: init
0 parents  commit 3f52bc7

15 files changed

+2768
-0
lines changed

Diff for: .eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: '@antfu/eslint-config',
3+
}

Diff for: .gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
out
2+
node_modules
3+
.vscode-test/
4+
*.vsix
5+
.vscode/.as-fs
6+
.DS_Store
7+
dist

Diff for: .vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"runtimeExecutable": "${execPath}",
13+
"args": [
14+
"--extensionDevelopmentPath=${workspaceFolder}"
15+
],
16+
"outFiles": [
17+
"${workspaceFolder}/dist/**/*.js"
18+
],
19+
"preLaunchTask": "npm: dev"
20+
}
21+
]
22+
}

Diff for: .vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"dist": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"dist": true // set this to false to include "out" folder in search results
8+
}
9+
}

Diff for: .vscode/tasks.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "dev",
9+
"isBackground": true,
10+
"problemMatcher": {
11+
"fileLocation": "relative",
12+
"pattern": {
13+
"regexp": "_______",
14+
"file": 1,
15+
"location": 2,
16+
"severity": 3,
17+
"code": 4,
18+
"message": 5
19+
},
20+
"background": {
21+
"activeOnStart": true,
22+
"beginsPattern": "Building",
23+
"endsPattern": "^ CJS Build success"
24+
}
25+
},
26+
"presentation": {
27+
"reveal": "never"
28+
},
29+
"group": {
30+
"kind": "build",
31+
"isDefault": true
32+
}
33+
}
34+
]
35+
}

Diff for: .vscodeignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vscode/**
2+
.vscode-test/**
3+
out/test/**
4+
out/**/*.map
5+
node_modules/**
6+
src/**
7+
.gitignore
8+
package-lock.json
9+
.eslintrc.js
10+
tsconfig.json
11+
screenshots/**

Diff for: README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<p align="center">
2+
<img src="./res/icon.png" height="200" width="200">
3+
</p>
4+
5+
<h2 align="center">
6+
VS Code for Vite ⚡️
7+
</h2>
8+
9+
# {WIP}
10+
11+
## License
12+
13+
MIT

Diff for: package.json

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"name": "vite",
3+
"preview": true,
4+
"displayName": "Vite",
5+
"description": "VS Code for Vite",
6+
"version": "0.0.0",
7+
"publisher": "antfu",
8+
"license": "MIT",
9+
"icon": "res/icon.png",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/antfu/vscode-vite"
13+
},
14+
"engines": {
15+
"vscode": "^1.52.0"
16+
},
17+
"categories": [
18+
"Other"
19+
],
20+
"activationEvents": [
21+
"*",
22+
"onFileSystem:vite.config.js",
23+
"onFileSystem:vite.config.ts"
24+
],
25+
"main": "./dist/extension.js",
26+
"extensionPack": [
27+
"auchenberg.vscode-browser-preview"
28+
],
29+
"contributes": {
30+
"commands": [
31+
{
32+
"command": "vite.start",
33+
"category": "Vite",
34+
"title": "Restart Vite Server"
35+
},
36+
{
37+
"command": "vite.stop",
38+
"category": "Vite",
39+
"title": "Stop Vite Server"
40+
},
41+
{
42+
"command": "vite.restart",
43+
"category": "Vite",
44+
"title": "Restart Vite Server"
45+
}
46+
],
47+
"configuration": {
48+
"type": "object",
49+
"title": "Vite",
50+
"properties": {
51+
"vite.autoStart": {
52+
"type": "boolean",
53+
"default": true,
54+
"description": "Start Vite server with VS Code"
55+
},
56+
"vite.browser": {
57+
"type": "string",
58+
"enum": [
59+
"embedded",
60+
"system"
61+
],
62+
"default": "embedded",
63+
"description": "Browser to open Vite app"
64+
},
65+
"vite.port": {
66+
"type": "number",
67+
"default": 4000,
68+
"description": "Port for Vite server"
69+
}
70+
}
71+
}
72+
},
73+
"scripts": {
74+
"vscode:prepublish": "npm run build",
75+
"build": "tsup src/extension.ts --dts --external=vscode",
76+
"dev": "npm run build -- --watch",
77+
"release": "npx bumpp --commit --tag --push && vsce publish"
78+
},
79+
"devDependencies": {
80+
"@antfu/eslint-config": "^0.4.3",
81+
"@types/node": "^14.14.20",
82+
"@types/vscode": "^1.52.0",
83+
"eslint": "^7.17.0",
84+
"tsup": "^4.5.1",
85+
"typescript": "^4.1.3",
86+
"vite": "^2.0.4"
87+
}
88+
}

Diff for: res/icon.png

64.9 KB
Loading

Diff for: res/icon.svg

+15
Loading

Diff for: src/config.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { resolve } from 'path'
2+
import { workspace } from 'vscode'
3+
4+
export const Config = {
5+
get root() {
6+
return workspace.workspaceFolders?.[0]?.uri?.fsPath || ''
7+
},
8+
9+
get path() {
10+
return resolve(this.root, workspace.getConfiguration().get<string>('as-fs.path')!)
11+
},
12+
}

Diff for: src/extension.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { join } from 'path'
2+
import fs from 'fs'
3+
import { commands, ExtensionContext, Terminal, window } from 'vscode'
4+
import { Config } from './config'
5+
import { tryPort, timeout } from './utils'
6+
7+
let terminal: Terminal
8+
9+
export async function activate(ctx: ExtensionContext) {
10+
if (!fs.existsSync(join(Config.root, 'vite.config.ts')) && !fs.existsSync(join(Config.root, 'vite.config.js')))
11+
return
12+
13+
const port = await tryPort()
14+
const url = `http://localhost:${port}`
15+
window.showInformationMessage(`⚡️ Vite started at ${url}`)
16+
17+
console.log('Vite Project')
18+
terminal = window.createTerminal('Vite')
19+
terminal.sendText(`npx vite --port ${port}`)
20+
terminal.show(false)
21+
await timeout(1000)
22+
commands.executeCommand('browser-preview.openPreview', url)
23+
}
24+
25+
export async function deactivate() {
26+
if (terminal) {
27+
terminal.sendText('\x03')
28+
terminal.dispose()
29+
}
30+
}

Diff for: src/utils.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createServer } from 'http'
2+
3+
function isPortFree(port: number) {
4+
return new Promise((resolve) => {
5+
const server = createServer()
6+
.listen(port, () => {
7+
server.close()
8+
resolve(true)
9+
})
10+
.on('error', () => {
11+
resolve(false)
12+
})
13+
})
14+
}
15+
export function timeout(ms: number) {
16+
return new Promise(resolve => setTimeout(resolve, ms))
17+
}
18+
export async function tryPort(start = 4000): Promise<number> {
19+
if (await isPortFree(start))
20+
return start
21+
return tryPort(start + 1)
22+
}

Diff for: tsconfig.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es2017",
5+
"outDir": "out",
6+
"lib": ["esnext"],
7+
"sourceMap": true,
8+
"moduleResolution": "node",
9+
"esModuleInterop": true,
10+
"strict": true,
11+
"noUnusedLocals": true,
12+
"resolveJsonModule": true
13+
}
14+
}

0 commit comments

Comments
 (0)