generated from adams549659584/utools-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5e1a6d
Showing
18 changed files
with
12,653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
# Log files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw* | ||
|
||
/distCopyConfig/cdnPurgeUrl.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "启动程序", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${file}", | ||
"outFiles": [ | ||
"${workspaceFolder}/**/*.js" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"javascript.validate.enable": false, | ||
"editor.tabSize": 2, //代码缩进修改成2个空格 | ||
"editor.formatOnSave": false, //每次保存的时候自动格式化 | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, //每次保存的时候将代码按eslint格式进行修复 | ||
"javascript.format.insertSpaceBeforeFunctionParenthesis": true, //让函数(名)和后面的括号之间加个空格 | ||
"vetur.format.defaultFormatter.html": "prettyhtml", //prettyhtml | ||
"vetur.format.defaultFormatter.css": "prettier", | ||
"vetur.format.defaultFormatter.postcss": "prettier", | ||
"vetur.format.defaultFormatter.scss": "prettier", | ||
"vetur.format.defaultFormatter.less": "prettier", | ||
"vetur.format.defaultFormatter.stylus": "stylus-supremacy", | ||
"vetur.format.defaultFormatter.js": "prettier", | ||
"vetur.format.defaultFormatter.ts": "prettier", | ||
"vetur.format.options.tabSize": 2, | ||
"vetur.format.options.useTabs": false, | ||
"vetur.format.defaultFormatterOptions": { | ||
"js-beautify-html": { | ||
"wrap_attributes": "force-aligned" //vue组件中html代码格式化样式 | ||
}, | ||
// /vue组件中html代码格式化配置 | ||
"prettyhtml": { | ||
"printWidth": 180, // 使用不同的最大行长度(默认值:80) | ||
"singleQuote": false, // 使用单引号代替双引号(默认值:false) | ||
}, | ||
// vue 文件内的js/ts格式化配置 | ||
"prettier": { | ||
"printWidth": 180, | ||
"semi": true, //代码结尾的分号 | ||
"singleQuote": true, //使用单引号替代双引号 | ||
"eslintIntegration": true, ////让prettier使用eslint的代码格式进行校验 | ||
"arrowParens": "avoid", // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号 | ||
} | ||
}, | ||
"search.followSymlinks": false, | ||
"eslint.packageManager": "yarn", | ||
"editor.minimap.enabled": false, | ||
"workbench.editor.enablePreview": false, | ||
//mock setting | ||
"EasyMock.corsHeaders": "token,auth", | ||
"EasyMock.helloPage": true, | ||
"EasyMock.mockFolderName": "src/mock", | ||
"EasyMock.mockParse": false, | ||
"EasyMock.responseTime": 0, | ||
"EasyMock.serverPort": 9999, | ||
// 单独js/ts 文件格式化配置 | ||
"prettier.singleQuote": true, | ||
"prettier.semi": true, | ||
"prettier.printWidth": 180, | ||
"prettier.arrowParens": "avoid", // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### utools-tmpl | ||
|
||
- 使用 uTools 模板插件的模板 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "utools-tmpl", | ||
"version": "1.0.0", | ||
"description": "使用 uTools 模板插件的模板", | ||
"main": "main.ts", | ||
"scripts": { | ||
"dev": "set NODE_ENV=development && rollup -c -w", | ||
"build": "set NODE_ENV=production && rollup -c" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"rollup": "^2.24.0", | ||
"rollup-plugin-cleaner": "^1.0.0", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-copy": "^3.3.0", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"rollup-plugin-typescript": "^1.0.1", | ||
"tslib": "^2.0.1", | ||
"typescript": "^3.9.7" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.19.2", | ||
"encoding": "^0.1.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @type { import ('./src/types/utools').PluginConfig } | ||
*/ | ||
const pluginConfig = { | ||
pluginName: 'utools-tmpl', | ||
version: 'v1.0.0', | ||
description: '使用模板插件模式', | ||
author: '罗君', | ||
homepage: 'https://github.com/adams549659584/utools-tmpl', | ||
// main: 'index.html', | ||
preload: 'preload.js', | ||
logo: 'assets/img/logo.png', | ||
platform: ['win32'], | ||
// development: { | ||
// main: '', | ||
// preload: '', | ||
// logo: '', | ||
// buildPath: '', | ||
// }, | ||
// pluginSetting: { | ||
// single: true, | ||
// height: 0, | ||
// }, | ||
features: [ | ||
{ | ||
code: 'utools_tmpl_hello_none', | ||
explain: '无 UI 模式', | ||
cmds: ['hello', 'none'], | ||
}, | ||
{ | ||
code: 'utools_tmpl_hello_list', | ||
explain: '列表模式', | ||
cmds: ['hello', 'list'], | ||
}, | ||
{ | ||
code: 'utools_tmpl_hello_doc', | ||
explain: '文档模式', | ||
cmds: ['hello', 'doc'], | ||
}, | ||
], | ||
}; | ||
export default pluginConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import cleaner from 'rollup-plugin-cleaner'; | ||
import json from 'rollup-plugin-json'; | ||
import typescript from 'rollup-plugin-typescript'; | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import pluginConfig from './plugin.config.js'; | ||
import copy from 'rollup-plugin-copy'; | ||
import replace from 'rollup-plugin-replace'; | ||
import { terser } from "rollup-plugin-terser"; | ||
|
||
/** | ||
* 当前环境 | ||
* @type {'development'|'production'} | ||
*/ | ||
const NODE_ENV = (process.env.NODE_ENV || 'development').trim(); | ||
|
||
/** plugin.json */ | ||
const pluginJsonStr = JSON.stringify(pluginConfig); | ||
|
||
/** 生成preload.js */ | ||
/** @type {import ('rollup').RollupOptions} */ | ||
const rollupOptions = { | ||
input: './src/main.ts', | ||
output: { | ||
file: './dist/preload.js', | ||
format: 'cjs', | ||
sourcemap: NODE_ENV === 'production' ? 'hidden' : 'inline', | ||
}, | ||
plugins: [ | ||
cleaner({ | ||
targets: ['dist'], | ||
}), | ||
json(), | ||
typescript({ lib: ['es5', 'es6', 'dom'], target: 'es5' }), | ||
resolve(), | ||
commonjs(), | ||
copy({ | ||
flatten: false, | ||
copyOnce: false, | ||
targets: [ | ||
{ | ||
src: 'plugin.config.js', | ||
dest: 'dist', | ||
transform: contents => pluginJsonStr, | ||
rename: (name, extension) => 'plugin.json', | ||
}, | ||
{ src: 'README.md', dest: 'dist' }, | ||
{ src: 'src/assets/**/*', dest: 'dist' }, | ||
], | ||
verbose: true, | ||
}), | ||
replace({ | ||
ENV: JSON.stringify(NODE_ENV), | ||
}), | ||
NODE_ENV === 'production' && terser(), | ||
], | ||
}; | ||
export default rollupOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default class Hello { | ||
static sayHello(message) { | ||
utools.showMessageBox({ | ||
message, | ||
}); | ||
} | ||
|
||
static repeat(message) { | ||
return utools.showMessageBox({ | ||
message, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import axios, { AxiosRequestConfig } from 'axios'; | ||
import { IncomingMessage } from 'electron'; | ||
import { convert } from 'encoding'; | ||
|
||
// 添加请求拦截器 | ||
axios.interceptors.request.use(request => { | ||
// // 默认请求头 | ||
// request.headers['X-Requested-With'] = 'XMLHttpRequest'; | ||
// // 类似 jquery cache false | ||
// if ((request.method || '').toLowerCase() === 'get') { | ||
// Object.assign(request.params, { _t: Date.now() }); | ||
// } | ||
return request; | ||
}); | ||
// 添加响应拦截器,响应拦截器会在then/catch处理之前执行 | ||
axios.interceptors.response.use( | ||
response => { | ||
return Promise.resolve(response); | ||
}, | ||
async err => { | ||
return Promise.reject(err); | ||
} | ||
); | ||
|
||
/** | ||
* get 请求 | ||
* @param url 请求链接 | ||
* @param params 参数 | ||
* @param config 配置 | ||
*/ | ||
const get = async <T = string>(url: string, params?: { [key: string]: any }, config?: AxiosRequestConfig): Promise<T> => { | ||
const res = await axios.get(url, { params, ...config }); | ||
return res.data as T; | ||
}; | ||
|
||
/** | ||
* get 请求中文站点等等 | ||
* @param url 请求链接 | ||
* @param coding 编码,默认gb2312 | ||
* @param params 参数 | ||
* @param config 配置 | ||
*/ | ||
const getByCoding = async (url: string, coding: string = 'gb2312', params?: { [key: string]: any }, config?: AxiosRequestConfig): Promise<string> => { | ||
// const oldResponseType = (config && config.responseType) || 'text'; | ||
config = { | ||
...config, | ||
responseType: 'stream', | ||
}; | ||
const resData = await get<IncomingMessage>(url, params, config); | ||
// 编码处理 | ||
return await hanldeCodingData(resData, coding); | ||
}; | ||
|
||
const hanldeCodingData = async (data: IncomingMessage, coding: string = 'gb2312'): Promise<string> => { | ||
// 编码处理 | ||
return new Promise((resolve, reject) => { | ||
const chunks = []; | ||
data.on('data', chunk => { | ||
chunks.push(chunk); | ||
}); | ||
data.on('end', () => { | ||
const buffer = Buffer.concat(chunks); | ||
const convertResult = convert(buffer, 'UTF-8', coding); | ||
resolve(convertResult.toString()); | ||
}); | ||
data.on('error', () => { | ||
reject('请求失败'); | ||
}); | ||
}); | ||
}; | ||
|
||
/** | ||
* post 请求 | ||
* @param url 请求链接 | ||
* @param data 参数 | ||
* @param config 配置 | ||
*/ | ||
const post = async <T = string>(url: string, data?: { [key: string]: any }, config?: AxiosRequestConfig): Promise<T> => { | ||
const res = await axios.post(url, data, config); | ||
return res.data as T; | ||
}; | ||
|
||
const postByCoding = async (url: string, coding: string = 'gb2312', data?: { [key: string]: any }, config?: AxiosRequestConfig): Promise<string> => { | ||
config = { | ||
...config, | ||
responseType: 'stream', | ||
}; | ||
const resData = await post<IncomingMessage>(url, data, config); | ||
// 编码处理 | ||
return await hanldeCodingData(resData, coding); | ||
}; | ||
|
||
export { get, post, getByCoding, postByCoding }; | ||
|
||
export default class HttpHelper { | ||
/** | ||
* get 请求 | ||
* @param url 请求链接 | ||
* @param params 参数 | ||
* @param config 配置 | ||
*/ | ||
static async get<T = string>(url: string, params?: { [key: string]: any }, config?: AxiosRequestConfig) { | ||
return get<T>(url, params, config); | ||
} | ||
|
||
/** | ||
* post 请求 | ||
* @param url 请求链接 | ||
* @param data 参数 | ||
* @param config 配置 | ||
*/ | ||
static async post<T = string>(url: string, data?: { [key: string]: any }, config?: AxiosRequestConfig) { | ||
return post<T>(url, data, config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>文档模式</title> | ||
</head> | ||
<body> | ||
<a href="https://github.com/adams549659584/utools-tmpl">去github</a> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.