Skip to content

Commit

Permalink
update cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed May 31, 2023
1 parent 16176fc commit f0ed99a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
## 简介
Turbowarp ClipX 是一个高效开发部署turbowarp扩展的插件, 提供:
-**更好的接口风格** 使用类和装饰器来定义扩展,更简洁和优雅
-**便捷的缓存功能** 提供缓存功能, 优化性能 (可在接口中自定义)
- 🔨 **更好的开发环境** 自动补全Turbowarp类型
- 📦 **webpack 压缩** 缩小打包JS文件体积, 提高加载速度和性能
- 🎃 **注册异常检测** 注册扩展时检查异常情况并拦截汇报
Expand All @@ -18,20 +19,24 @@ Turbowarp ClipX 是一个高效开发部署turbowarp扩展的插件, 提供:
- 🎉 **Action 自动打包** 使用action实现自动打包并加入release中, 方便在线获取

## 开发
入口 **/src/index.ts** (**javascript**同理)
1. 初始化安装依赖 (**yarn** **pnpm**同理, 推荐**pnpm**)
```commandline
```shell
npm install
```
2. 入口编写扩展程序 **/src/index.ts** (**javascript**同理)
2. dev
```shell
npm run dev
```
3. eslint 修复
```commandline
```shell
npm run lint
```
4. 打包生成
```commandline
4. 打包
> webpack 打包生成的js文件位于 **dist/extension.js**
```shell
npm run build
```
webpack打包生成的js文件位于**dist/extension.js**

## 接口

Expand All @@ -46,8 +51,11 @@ webpack打包生成的js文件位于**dist/extension.js**
- `Scratch.BlockType.REPORTER` 圆形的带返回值的积木
- `Scratch.BlockType.BOOLEAN` 六边形的返回布尔值的积木
- `Scratch.BlockType.COMMAND` 一个键积木
- `bind` 接受一个**function**, 允许异步执行返回Promise
- `text` 是一个字符串,用于定义积木在编辑器中的名称 格式为 **[参数:类型]**
- ✨ `bind` 接受一个**function**, 允许异步执行返回Promise
- ✨ `cache` 缓存
- `enable` 是否开启缓存
- `expiration` 缓存时间, 单位秒, 如果为**0**则永不过期
- ✨ `text` 是一个字符串,用于定义积木在编辑器中的名称 格式为 **[参数:类型]**
- `参数` 定义积木接受的参数的对象, 可能将在`default``menu`字段中引用
- `类型`定义要创建的输入形状 *(不区分大小写)*
- `STRING` 字符串类型
Expand All @@ -60,7 +68,9 @@ webpack打包生成的js文件位于**dist/extension.js**
- `default` 是参数的初始值, 接受一个字典, 键对应`参数`, 值对应参数的`默认值`
- `menu` 如果有参数需选择多个给定的值, 则可加入至此参数, 接受一个字典, 键对应`参数`, 值对应多个给定的值的列表类型, 将生成下拉菜单
- `disableMonitor` 是否积木强制删除复选框来创建监视器, 适用类型为**REPORTER** *(带返回值的积木)*, 如果为真, 则删除变量左处的复选框
5. `docsURI`对应文档链接
5. `docsURI` 对应文档链接
6. ✨ `debug` 是否开启控制台调试 (默认关闭, 即此插件本身不会有任何输出)
7. ✨ `uptime` 定期缓存清理时间间隔, 单位秒, 默认为**60**

没太看懂? 下面展示一个示例
```typescript
Expand Down
26 changes: 18 additions & 8 deletions docs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Introduction
-**Better interface style** Use classes and decorators to define extensions, more concise and elegant
-**Convenient caching functionality** Provides caching functionality to optimize performance (customizable in the interface)
- 🔨 **Better development environment** Auto-completion of Turbowarp types
- 📦 **webpack compression** Reduces the size of packaged JS files, improves loading speed and performance
- 🎃 **Registration Exception Detection** Check for exceptions and intercept reports when registering extensions
Expand All @@ -17,20 +18,24 @@
- 🎉 **Action Auto Build** Use action to implement auto-package and add to release, easy to get online

## Development
entrypoint **/src/index.ts** (**javascript** same)
1. Initial installation of dependencies (**yarn** **pnpm** same, **pnpm** recommended)
```commandline
```shell
npm install
```
2. import write extensions **/src/index.ts** (**javascript** same)
2. dev
```shell
npm run dev
```
3. eslint fix
```commandline
```shell
npm run lint
```
4. package generation
```commandline
4. build
> The js file generated by webpack packaging is located in **dist/extension.js**
```shell
npm run build
```
The js file generated by **webpack** packaging is located in **dist/extension.js**

## Interface

Expand All @@ -45,8 +50,11 @@ The js file generated by **webpack** packaging is located in **dist/extension.js
- `Scratch.BlockType.REPORTER` Round block with return value
- `Scratch.BlockType.BOOLEAN` A hexagonal block that returns a boolean value
- `Scratch.BlockType.COMMAND` A key block
- `bind` accepts a **function**, allowing asynchronous execution to return a Promise
- `text` is a string that defines the name of the block in the editor in the format **[parameter:type]**
- ✨ `bind` accepts a **function**, allowing asynchronous execution to return a Promise
- ✨ `cache` Cache
- `enable` whether to turn on caching
- `expiration` cache time, in seconds, if **0** then never expires
- ✨ `text` is a string that defines the name of the block in the editor in the format **[parameter:type]**
- `parameters` defines the objects that the building block accepts as parameters, possibly referenced in the `default` and `menu` fields
- `TYPE` defines the input shape to be created *(case-insensitive)*
- `STRING` string type
Expand All @@ -60,6 +68,8 @@ The js file generated by **webpack** packaging is located in **dist/extension.js
- `menu` can be added to this parameter if there are parameters to select more than one given value, accepts a dictionary, key corresponds to `parameter`, value corresponds to the list type of more than one given value, will generate a drop-down menu
- `disableMonitor` if or not the block forces to remove the checkbox to create a monitor, applicable type is **REPORTER** *(block with return value)*, if true, then remove the checkbox to the left of the variable
5. `docsURI` corresponds to document link
6. ✨ `debug` whether to open the console debugging (default is false, that is, the plugin itself will not have any output)
7. ✨ `uptime` periodic cache cleaning interval, in seconds, default is **60** seconds
Don't quite get it? Here's an example
```typescript
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "📦 TurboWarp development-env extension plugin",
"main": "index.ts",
"scripts": {
"dev": "webpack --watch",
"build": "webpack",
"lint": "eslint src/** --fix"
},
Expand Down
2 changes: 1 addition & 1 deletion src/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default interface Option {
docsURI?: string // Should be a data: URI
blocks: Block[]
debug?: boolean // Defaults to false if not specified.
secs?: number // Timing of cache cleaning. Defaults to 60(secs) if not specified.
uptime?: number // Timing of cache cleaning. Defaults to 60(secs) if not specified.
}

const $ = Scratch.BlockType
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Extension {

public constructor(option: Option) {
this.option = option;
this.cache = new Cache(option.secs || 60, option.debug || false);
this.cache = new Cache(option.uptime, option.debug);
this.blocks = [];
this.menus = {};

Expand Down

0 comments on commit f0ed99a

Please sign in to comment.