vscode 插件初始化

This commit is contained in:
OBKoro1 2019-12-26 17:47:37 +08:00
parent 17d8c881bc
commit fede0d0836
24 changed files with 5798 additions and 97 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
out
node_modules node_modules
.vscode-test/
*.vsix

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.vscode-typescript-tslint-plugin"
]
}

49
.vscode/launch.json vendored
View File

@ -1,17 +1,36 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{ {
// 使 IntelliSense "version": "0.2.0",
// "configurations": [
// 访: https://go.microsoft.com/fwlink/?linkid=830387 {
"version": "0.2.0", "name": "Run Extension",
"configurations": [ "type": "extensionHost",
{ "request": "launch",
"type": "node", "runtimeExecutable": "${execPath}",
"request": "launch", "args": [
"name": "启动程序", "--extensionDevelopmentPath=${workspaceFolder}"
"skipFiles": [ ],
"<node_internals>/**" "outFiles": [
], "${workspaceFolder}/out/**/*.js"
"program": "${workspaceFolder}/src/index.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}"
}
]
} }

11
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,11 @@
// 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"
}

20
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

10
.vscodeignore Normal file
View File

@ -0,0 +1,10 @@
.vscode/**
.vscode-test/**
out/test/**
src/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts

11
CHANGELOG.md Normal file
View File

@ -0,0 +1,11 @@
# 更新日志
### 如果觉得本插件还不错的话,给个[Star](https://github.com/OBKoro1/autoCommit)吧~
<!-- TODO: package 关键词 -->
<!-- TODO: wiki readme -->
<!-- TODO: npm包形式 -->
### [V1.0.0]
- Initial release

65
README.md Normal file
View File

@ -0,0 +1,65 @@
# autoCommit README
This is the README for your extension "autoCommit". After writing up a brief description, we recommend including the following sections.
## Features
Describe specific features of your extension including screenshots of your extension in action. Image paths are relative to this README file.
For example if there is an image subfolder under your extension project workspace:
\!\[feature X\]\(images/feature-x.png\)
> Tip: Many popular extensions utilize animations. This is an excellent way to show off your extension! We recommend short, focused animations that are easy to follow.
## Requirements
If you have any requirements or dependencies, add a section describing those and how to install and configure them.
## Extension Settings
Include if your extension adds any VS Code settings through the `contributes.configuration` extension point.
For example:
This extension contributes the following settings:
* `myExtension.enable`: enable/disable this extension
* `myExtension.thing`: set to `blah` to do something
## Known Issues
Calling out known issues can help limit users opening duplicate issues against your extension.
## Release Notes
Users appreciate release notes as you update your extension.
### 1.0.0
Initial release of ...
### 1.0.1
Fixed issue #.
### 1.1.0
Added features X, Y, and Z.
-----------------------------------------------------------------------------------------------------------
## Working with Markdown
**Note:** You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts:
* Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+CMD+V` on macOS or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (macOS) to see a list of Markdown snippets
### For more information
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
**Enjoy!**

4930
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,63 @@
{ {
"name": "autocommit", "name": "autoCommit",
"version": "1.0.0", "displayName": "autoCommit",
"description": "自动commit工具", "description": "自动提交commit到github",
"main": "src/index.js", "version": "0.0.1",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile",
"test": "node ./out/test/runTest.js"
}, },
"repository": { "engines": {
"type": "git", "vscode": "^1.40.0"
"url": "git+https://github.com/OBKoro1/autoCommit.git"
}, },
"author": "", "categories": [
"license": "ISC", "Other"
"bugs": { ],
"url": "https://github.com/OBKoro1/autoCommit/issues" "activationEvents": [
"onCommand:extension.autoCommit"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
{
"command": "extension.autoCommit",
"title": "Github自动提交 autoCommit"
}
]
},
"keywords": [
"vscode korofileheader",
"korofileheader",
"annotation",
"comment",
"vscode comment",
"vscode annotation",
"vscode 注释",
"vscode 文件头部注释",
"注释",
"文件注释",
"头部注释",
"函数注释",
"fileheader",
"vscode-fileheader",
"Document This",
"obkoro1",
"koro1"
],
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.11.7",
"@types/vscode": "^1.41.0",
"glob": "^7.1.5",
"mocha": "^6.2.2",
"typescript": "^3.6.4",
"tslint": "^5.20.0",
"vscode-test": "^1.2.2"
}, },
"homepage": "https://github.com/OBKoro1/autoCommit#readme",
"dependencies": { "dependencies": {
"moment": "^2.24.0" "moment": "^2.24.0"
} }

29
src/extension.ts Normal file
View File

@ -0,0 +1,29 @@
/*
* Author : OBKoro1
* Date : 2019-12-25 15:15:42
* LastEditors : OBKoro1
* LastEditTime : 2019-12-25 17:49:37
* FilePath : /autoCommit/src/extension.ts
* Description : 自动commit插件
* https://github.com/OBKoro1
*/
import * as vscode from 'vscode';
import ExtensionLogic from './models/index'
import { setExtensionContext } from './util/vscodeUtil'
// 扩展激活 默认运行
export function activate(context: vscode.ExtensionContext) {
setExtensionContext(context)
const autoCommit = vscode.commands.registerCommand('extension.autoCommit', () => {
new ExtensionLogic(context)
})
// 当插件关闭时被清理的可清理列表
context.subscriptions.push(autoCommit);
}
// 扩展被禁用 调用
export function deactivate() {}

View File

@ -2,91 +2,96 @@
* Author : OBKoro1 * Author : OBKoro1
* Date : 2019-12-19 20:23:57 * Date : 2019-12-19 20:23:57
* LastEditors : OBKoro1 * LastEditors : OBKoro1
* LastEditTime : 2019-12-23 19:56:54 * LastEditTime : 2019-12-25 15:23:38
* FilePath : /autoCommit/index.js * FilePath : /autoCommit/src/index.js
* Description : 自动commit * Description : 自动commit
* https://github.com/OBKoro1 * https://github.com/OBKoro1
*/ */
const { execSync } = require('child_process'); const { execSync } = require('child_process')
const moment = require('moment'); const moment = require('moment')
const fs = require('fs'); const fs = require('fs')
class autoCommit { class autoCommit {
constructor() { constructor () {
this.init(); this.init()
} }
getData() { getData () {
this.getAllDay(this.paramsObj.beginDay, this.paramsObj.endDay); this.getAllDay(this.paramsObj.beginDay, this.paramsObj.endDay)
this.readyCommit(); this.readyCommit()
console.log('timeArr', this.timeArr);
} }
formatTime(time) { // 格式化日期
return `${time} 08:00`; formatTime (time) {
return `${time} 08:00`
} }
getAllDay(begin, end) { // 获取两个日期之间的间隔: [ '2019-02-02', '2019-02-03' ... ]
this.timeArr = []; getAllDay (begin, end) {
const beginSplit = begin.split('-'); this.timeArr = []
const endSplit = end.split('-'); const beginSplit = begin.split('-')
const beginDate = new Date(); const endSplit = end.split('-')
beginDate.setUTCFullYear(beginSplit[0], beginSplit[1] - 1, beginSplit[2]); const beginDate = new Date()
const endDate = new Date(); beginDate.setUTCFullYear(beginSplit[0], beginSplit[1] - 1, beginSplit[2])
endDate.setUTCFullYear(endSplit[0], endSplit[1] - 1, endSplit[2]); const endDate = new Date()
const beginNumber = beginDate.getTime(); endDate.setUTCFullYear(endSplit[0], endSplit[1] - 1, endSplit[2])
const endNumber = endDate.getTime(); const beginNumber = beginDate.getTime()
for (let k = beginNumber; k <= endNumber; ) { const endNumber = endDate.getTime()
const day = new Date(parseInt(k)); for (let k = beginNumber; k <= endNumber;) {
const dayFormat = moment(day).format('YYYY-MM-DD'); const day = new Date(parseInt(k))
this.timeArr.push(dayFormat); const dayFormat = moment(day).format('YYYY-MM-DD')
k = k + 24 * 60 * 60 * 1000; this.timeArr.push(dayFormat)
k = k + 24 * 60 * 60 * 1000
} }
} }
// 只commit今天 init () {
commitToday() { // TODO: 获取参数
const time = moment().format('DD/MM/YYYY HH:MM:ss');
// TODO:
}
init() {
let paramsObj = { let paramsObj = {
beginDay: '2019-02-02', beginDay: '2019-12-20',
endDay: '2019-03-02', itemSrc: '/Users/koro/work/web_my/testCommit' // 要commit的项目地址
itemSrc: '../../testCommit', // 要commit的项目地址 }
commitNumber: 1 // 每天commit 次数
};
let defaultOption = { let defaultOption = {
beginDay: moment().format('YYYY-MM-DD'), // 默认为今天
endDay: moment().format('YYYY-MM-DD'), // 默认为今天 endDay: moment().format('YYYY-MM-DD'), // 默认为今天
fileSrc: `${paramsObj.itemSrc}/commit.md` fileSrc: `commit.md`,
}; commitNumber: 1 // 每天commit 次数
this.paramsObj = paramsObj; }
this.getData(); this.paramsObj = Object.assign(defaultOption, paramsObj)
// this.commit(); this.getData()
} }
readyCommit() { // commit
readyCommit () {
console.log('日期数组:', this.timeArr)
console.log('每个日期提交次数:', this.paramsObj.commitNumber)
let totalNum = 0 // 总commit次数
// 遍历日期 // 遍历日期
this.timeArr.forEach(item => { this.timeArr.forEach(item => {
// 每个日期commit次数 // 每个日期commit次数
for (let i = 0; i++; i < this.paramsObj.commitNumber) { for (let i = 0; i < this.paramsObj.commitNumber; i++) {
let time = this.formatTime(item); // 2019-01-02 08:00 let time = this.formatTime(item) // 2019-01-02 08:00
time = moment(time).format(); // 2019-01-02T00:00:00+0800 time = moment(time).format() // 2019-01-02T00:00:00+0800
const commitContent = `${time}${i}`
fs.writeFileSync( fs.writeFileSync(
`${this.paramsObj.itemSrc}/commit.md`, `${this.paramsObj.itemSrc}/${this.paramsObj.fileSrc}`,
`${time}${i}`, commitContent,
'utf-8' 'utf-8'
); )
console.log('each', time); this.myExecSync(
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${time}' && git pull && git push origin master`
)
let cmd = `git log -1 \
--date=iso --pretty=format:'{"commit": "%h","author": "%aN <%aE>","date": "%ad","message": "%s"},' \
$@ | \
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
perl -pe 's/},]/}]/'`
this.myExecSync(cmd)
this.totalNum++
console.log('commit内容', commitContent)
console.log(`总commit次数${totalNum}`)
} }
// this.commit() })
});
}
commit(commitTime) {
// git commit --amend --date="2019-01-02T00:00:00+0800" -am 'autoCommit'
// TODO: cd 项目 重写文件和commit
this.myExecSync(
`cd ${this.paramsObj.itemSrc} && git add . && git commit -m 'autoCommit' --date='${commitTime}' && git pull && git push origin master`
);
} }
myExecSync(cmd) { myExecSync (cmd) {
// 除了该方法直到子进程完全关闭后才返回 执行完毕 返回 // 除了该方法直到子进程完全关闭后才返回 执行完毕 返回
try { try {
const res = execSync(cmd, { const res = execSync(cmd, {
@ -96,12 +101,12 @@ class autoCommit {
killSignal: 'SIGTERM', killSignal: 'SIGTERM',
cwd: undefined, cwd: undefined,
env: undefined env: undefined
}); })
return res; return res
} catch (err) { } catch (err) {
console.log(`执行命令出错:${cmd}`); console.log(`执行命令出错:${cmd}`)
} }
} }
} }
new autoCommit(); new autoCommit()

111
src/models/WebView.ts Normal file
View File

@ -0,0 +1,111 @@
/*
* Author : OBKoro1
* Date : 2019-12-26 13:49:02
* LastEditors : OBKoro1
* LastEditTime : 2019-12-26 15:24:08
* FilePath : /autoCommit/src/models/WebView.ts
* Description : 创建webview
* https://github.com/OBKoro1
*/
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { showMessage } from '../util/vscodeUtil';
import { webviewMsg } from '../util/dataStatement'
// webview 设置
interface WebviewPanelOption {
type: string; // webview type
title: string; // webview title
fileName: string; // webview 加载的资源
}
class WebView {
private currentPanel!: vscode.WebviewPanel;
public readonly context: vscode.ExtensionContext;
public MessageCallBack: Function; // webview消息回调
public constructor(context: vscode.ExtensionContext, callBack: Function) {
this.context = context;
this.MessageCallBack = callBack;
}
public create(
WebviewPanelOption: WebviewPanelOption,
column: vscode.ViewColumn = vscode.ViewColumn.One
) {
// 获取资源地址
// TODO: 打包
const srcPath = process.env.NODE_ENV !== 'production' ? 'src' : 'dist';
this.currentPanel = vscode.window.createWebviewPanel(
WebviewPanelOption.type,
WebviewPanelOption.title,
column,
{
// 只允许webview加载我们插件的`src/assets`目录下的资源
localResourceRoots: [
vscode.Uri.file(
path.join(this.context.extensionPath, `${srcPath}/assets`)
)
],
// 启用javascript
enableScripts: true,
retainContextWhenHidden: true // 隐藏保存状态
}
);
const htmlPath = path.join(
this.context.extensionPath,
`${srcPath}/views/${WebviewPanelOption.fileName}.html`
);
this.currentPanel.webview.html = this.getWebViewContent(htmlPath);
// 接收webview的消息回调
this.currentPanel.webview.onDidReceiveMessage(
this.handleMessage.bind(this),
undefined,
this.context.subscriptions
);
}
/**
* html模板内容
* @param templatePath
* @param content
*/
private getWebViewContent(templatePath: string, content?: string): string {
const dirPath = path.dirname(templatePath);
content = content || fs.readFileSync(templatePath, 'utf-8');
content = content.replace(
/(<link.+?href="|<script.+?src="|<img.+?src=")(.+?)"/g,
(m, $1, $2) => {
return `${$1}${vscode.Uri.file(path.resolve(dirPath, $2))
.with({ scheme: 'vscode-resource' })
.toString()}"`;
}
);
return content;
}
/**
* webview
*/
public close() {
const panel = this.currentPanel;
if (!panel) return;
panel.dispose();
}
// webview消息回调
public handleMessage(message: webviewMsg) {
const { command, data } = message;
if (command === 'event') {
this.MessageCallBack(message);
return;
}
showMessage(data, command);
}
}
export default WebView;

40
src/models/index.ts Normal file
View File

@ -0,0 +1,40 @@
/*
* Author : OBKoro1
* Date : 2019-12-25 17:08:18
* LastEditors : OBKoro1
* LastEditTime : 2019-12-26 17:41:05
* FilePath : /autoCommit/src/models/index.ts
* Description : 插件逻辑入口
* https://github.com/OBKoro1
*/
import * as vscode from 'vscode';
import WebView from './WebView';
import { webviewMsg } from '../util/dataStatement'
class ExtensionLogic {
public readonly context: vscode.ExtensionContext;
public MessageCallBack: any;
public autoCommitView: WebView;
public constructor(context: vscode.ExtensionContext) {
this.context = context;
this.autoCommitView = new WebView(this.context, this.messageCallBack);
}
createView() {
const option = {
type: 'autoCommit',
title: 'Github自动提交commit工具',
fileName: 'autoCommit'
}
this.autoCommitView.create(option)
}
// 处理webview的消息
private messageCallBack(message: webviewMsg) {
if (message.data.id === 'user-login-message') {
// this.userLogin(message.params);
}
}
}
export default ExtensionLogic;

23
src/test/runTest.ts Normal file
View File

@ -0,0 +1,23 @@
import * as path from 'path';
import { runTests } from 'vscode-test';
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();

View File

@ -0,0 +1,15 @@
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', () => {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});

37
src/test/suite/index.ts Normal file
View File

@ -0,0 +1,37 @@
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',
});
mocha.useColors(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) {
e(err);
}
});
});
}

18
src/util/dataStatement.ts Normal file
View File

@ -0,0 +1,18 @@
/*
* Author : OBKoro1
* Date : 2019-12-26 15:01:37
* LastEditors : OBKoro1
* LastEditTime : 2019-12-26 17:24:02
* FilePath : /autoCommit/src/models/dataStatement.ts
* Description : 数据类型
* https://github.com/OBKoro1
*/
interface webviewMsg {
command: string; // 回调类型
data: any; // 回调数据
}
export {
webviewMsg,
};

46
src/util/vscodeUtil.ts Normal file
View File

@ -0,0 +1,46 @@
/*
* Author : OBKoro1
* Date : 2019-12-25 17:13:30
* LastEditors : OBKoro1
* LastEditTime : 2019-12-26 14:51:21
* FilePath : /autoCommit/src/util/vscodeUtil.ts
* Description : vscode
* https://github.com/OBKoro1
*/
import * as vscode from 'vscode'
let extensionContext = ''
// 存储插件上下午文
function setExtensionContext(context: any) {
extensionContext = context;
}
// 获取插件上下文
function getExtensionContext() {
return extensionContext
}
// vscode 消息通知
function showMessage(message: string, type = 'error') {
const actions: any = {
info: () => {
vscode.window.showInformationMessage(message)
},
alert: () => {
vscode.window.showWarningMessage(message)
},
error: () => {
vscode.window.showErrorMessage(message)
}
}
actions[type]()
}
export {
showMessage, // vscode 消息通知
setExtensionContext, // 存储插件上下文
getExtensionContext // 获取插件上下文
}

101
src/view/autoCommit.html Normal file
View File

@ -0,0 +1,101 @@
<!--
* @Github: https://github.com/OBKoro1
* @Author: OBKoro1
* @Date: 2019-06-29 13:27:49
* @LastEditors: OBKoro1
* @LastEditTime: 2019-11-27 11:32:30
* @Description: webview 登录页面
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>晓黑板登录</title>
<link href="../assets/styles/base.css" rel="stylesheet" />
<link href="../assets/styles/login.css" rel="stylesheet" />
</head>
<body>
<div class="form-container text-center v-cloak" id="xpLogin">
<div class="form-head">
<p class="form-title">晓黑板账号密码登录</p>
</div>
<div class="form-input-group">
<input ref="elUserName" @keyup.enter="login" type="text" class="form-input" placeholder="一统账号" v-model.number="userName" />
</div>
<div class="form-input-group">
<input ref="elPassword" @keyup.enter="login" type="password" class="form-input" placeholder="一统密码" v-model="password" />
</div>
<div class="form-input-group">
<a href="javascript:;" class="btn-login" @click="login">登录</a>
</div>
</div>
<script src="../assets/scripts/vue.min.js"></script>
<script>
const vscode = acquireVsCodeApi()
new Vue({
data() {
return {
// userName: 18850985993,
// password: 'HgbOBKoro1'
userName: '',
password: ''
}
},
mounted() {
this.initListener()
},
methods: {
// 登录
login() {
const { elUserName, elPassword } = this.$refs
const { userName, password } = this.$data
const formData = {
username: String(userName),
password: String(password)
}
if (!userName) {
this.postMessage('用户名不能为空')
elUserName.focus()
return
}
if (!password) {
this.postMessage('密码不能为空')
elPassword.focus()
return
}
this.postMessage('user-login-message', 'event', formData)
},
// 发送消息到插件
postMessage(text, command = 'alert', params) {
vscode.postMessage({
command,
text,
params
})
},
// 注册
initListener() {
window.addEventListener('message', event => {
console.log('event', event)
const { command, data } = event.data
console.log('登录成功 addEventListener', event)
if (command === 'success') {
// 登录成功
}
})
},
}
}).$mount('#xpLogin')
</script>
</body>
</html>

21
tsconfig.json Normal file
View File

@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"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. */
},
"exclude": [
"node_modules",
".vscode-test"
]
}

15
tslint.json Normal file
View File

@ -0,0 +1,15 @@
{
"rules": {
"no-string-throw": true,
"no-unused-expression": true,
"no-duplicate-variable": true,
"curly": true,
"class-name": true,
"semicolon": [
true,
"always"
],
"triple-equals": true
},
"defaultSeverity": "warning"
}

View File

@ -0,0 +1,42 @@
# Welcome to your VS Code Extension
## What's in the folder
* This folder contains all of the files necessary for your extension.
* `package.json` - this is the manifest file in which you declare your extension and command.
* The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesnt yet need to load the plugin.
* `src/extension.ts` - this is the main file where you will provide the implementation of your command.
* The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`.
* We pass the function containing the implementation of the command as the second parameter to `registerCommand`.
## Get up and running straight away
* Press `F5` to open a new window with your extension loaded.
* Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`.
* Set breakpoints in your code inside `src/extension.ts` to debug your extension.
* Find output from your extension in the debug console.
## Make changes
* You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`.
* You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
## Explore the API
* You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`.
## Run tests
* Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`.
* Press `F5` to run the tests in a new window with your extension loaded.
* See the output of the test result in the debug console.
* Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder.
* The provided test runner will only consider files matching the name pattern `**.test.ts`.
* You can create folders inside the `test` folder to structure your tests any way you want.
## Go further
* Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension).
* [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace.
* Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).

84
webpack.config.js Normal file
View File

@ -0,0 +1,84 @@
/*
* Author : OBKoro1
* Date : 2019-12-26 17:42:32
* LastEditors : OBKoro1
* LastEditTime : 2019-12-26 17:44:26
* FilePath : /autoCommit/webpack.config.js
* Description : webpack 配置
* https://github.com/OBKoro1
*/
//@ts-check
'use strict'
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const outputPathName = 'dist'
const pathResolve = p => {
return path.resolve(__dirname, p)
}
/**@type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode插件运行在Node.js环境中 📖 -> https://webpack.js.org/configuration/node/
entry: './src/extension.ts', // 插件的入口文件 📖 -> https://webpack.js.org/configuration/entry-context/
output: {
// 打包好的文件储存在'dist'文件夹中 (请参考package.json), 📖 -> https://webpack.js.org/configuration/output/
path: pathResolve(outputPathName),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]'
},
devtool: 'source-map',
externals: {
vscode: 'commonjs vscode' // vscode-module是热更新的临时目录所以要排除掉。 在这里添加其他不应该被webpack打包的文件, 📖 -> https://webpack.js.org/configuration/externals/
},
resolve: {
alias: {
'~': pathResolve('src')
},
// 支持读取TypeScript和JavaScript文件, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
// {
// test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
// loader: 'url-loader',
// options: {
// limit: 10000,
// name: pathResolve(`${outputPathName}/fonts/[name].[hash:7].[ext]`)
// }
// }
]
},
plugins: [
new CopyWebpackPlugin([
{
from: pathResolve('src/views'),
to: pathResolve(`${outputPathName}/views`),
ignore: ['.*']
},
{
from: pathResolve('src/assets'),
to: pathResolve(`${outputPathName}/assets`),
ignore: ['.*']
}
])
]
}
module.exports = config