copilot-core
Advanced tools
Comparing version 0.0.22 to 0.0.24
@@ -12,11 +12,18 @@ "use strict"; | ||
const copyPaste = require("clipboardy"); | ||
const { debug, error } = require("b-logger")("copilot.action.copy"); | ||
function copy(param, item) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let value = item.value; | ||
if (param && param.field && param.field in param) { | ||
if (param && param.field && param.field in item) { | ||
value = item[param.field]; | ||
} | ||
copyPaste.write(value); | ||
try { | ||
debug("copy ", value); | ||
yield copyPaste.write("" + value); | ||
} | ||
catch (e) { | ||
error("Failed to copy ", e); | ||
} | ||
}); | ||
} | ||
exports.copy = copy; |
@@ -9,4 +9,7 @@ import { IResult } from "../../types"; | ||
} | ||
export interface InitParam { | ||
cfg: IConfig; | ||
} | ||
declare var _default: { | ||
init(cfg: IConfig): Promise<void>; | ||
init({cfg}: InitParam): Promise<void>; | ||
list(): any; | ||
@@ -13,0 +16,0 @@ launch(op: IOption, list: IResult[]): { |
@@ -17,3 +17,3 @@ "use strict"; | ||
exports.default = { | ||
init(cfg) { | ||
init({ cfg }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -20,0 +20,0 @@ debug("Init apps:", cfg); |
@@ -17,2 +17,3 @@ "use strict"; | ||
const config_1 = require("../config"); | ||
const services_1 = require("../services"); | ||
const { asyncify } = require("array-asyncify"); | ||
@@ -27,4 +28,24 @@ const { debug, warn, error } = require("b-logger")("processor.loader"); | ||
const processors = {}; | ||
let param = { | ||
cfg: config_1.getConfig(name({ fileName, funName: "init" })), | ||
services: {} | ||
}; | ||
if (obj.declare && util.isFunction(obj.declare)) { | ||
let declare = obj.declare(); | ||
declare.params = declare.params || {}; | ||
debug("declared dependencies:", declare); | ||
if (declare.services) { | ||
param.services = declare.services | ||
.map(serviceName => { | ||
let serviceParam = declare.params[serviceName] || {}; | ||
return { | ||
key: serviceName, | ||
value: services_1.getServices(serviceName, Object.assign({}, serviceName, { namespace: name({ fileName, funName: "" }) })) | ||
}; | ||
}) | ||
.reduce((ret, next) => (ret[next.key] = next.value, ret), {}); | ||
} | ||
} | ||
if (obj.init && util.isFunction(obj.init)) { | ||
yield obj.init(config_1.getConfig(name({ fileName, funName: "init" }))); | ||
yield obj.init(param); | ||
} | ||
@@ -41,3 +62,3 @@ if (obj.check && util.isFunction(obj.check)) { | ||
.forEach(fun => { | ||
processors[name({ funName: fun.name, fileName })] = fun; | ||
processors[name({ funName: fun.name, fileName }).replace(/\.default$/, "")] = fun; | ||
}); | ||
@@ -78,3 +99,3 @@ return { | ||
let fun = obj[key]; | ||
processors[name({ funName: key, fileName })] = fun.bind(obj); | ||
processors[name({ funName: key, fileName }).replace(/\.default$/, "")] = fun.bind(obj); | ||
}); | ||
@@ -81,0 +102,0 @@ } |
@@ -21,2 +21,9 @@ export declare function suspend(): { | ||
}[]; | ||
export declare function xkill(): { | ||
title: string; | ||
param: { | ||
action: string; | ||
cmd: string; | ||
}; | ||
}[]; | ||
export declare function mute(): { | ||
@@ -23,0 +30,0 @@ title: string; |
@@ -29,2 +29,12 @@ "use strict"; | ||
exports.reboot = reboot; | ||
function xkill() { | ||
return [{ | ||
title: "Kill", | ||
param: { | ||
action: "cmd", | ||
cmd: "xkill" | ||
} | ||
}]; | ||
} | ||
exports.xkill = xkill; | ||
function mute() { | ||
@@ -31,0 +41,0 @@ return [{ |
@@ -30,2 +30,6 @@ import { IResult, IOption } from "../types"; | ||
value: string; | ||
param: { | ||
action: string; | ||
field: string; | ||
}; | ||
}[] | { | ||
@@ -59,1 +63,11 @@ title: string; | ||
}[]; | ||
export declare function copy(op: IOption, list: IResult[]): { | ||
param: { | ||
action: string; | ||
field: string; | ||
}; | ||
title: string; | ||
text: string; | ||
value: string; | ||
icon?: string; | ||
}[]; |
@@ -63,3 +63,7 @@ "use strict"; | ||
text: `${exp} = ${result}`, | ||
value: "" | ||
value: `${exp} = ${result}`, | ||
param: { | ||
action: "copy", | ||
field: "title" | ||
} | ||
}]; | ||
@@ -121,1 +125,9 @@ } | ||
exports.notify = notify; | ||
function copy(op, list) { | ||
let field = op.strings[0] || "value"; | ||
return list.map(item => (Object.assign({}, item, { param: { | ||
action: "copy", | ||
field | ||
} }))); | ||
} | ||
exports.copy = copy; |
@@ -7,3 +7,3 @@ "use strict"; | ||
.then(() => { | ||
index_1.handle("buildin.tldr.show tar") | ||
index_1.handle("bin") | ||
.then((ret) => { | ||
@@ -10,0 +10,0 @@ debug(ret); |
@@ -15,2 +15,7 @@ export declare type Processor = (op: any, list: IResult[]) => IResult[]; | ||
} | ||
export declare type IServiceParam = { | ||
namespace: string; | ||
} & { | ||
[name: string]: any; | ||
}; | ||
export interface IResult { | ||
@@ -23,2 +28,18 @@ title: string; | ||
} | ||
export interface IStore { | ||
set(key: string): Promise<void>; | ||
get(key: string): Promise<string>; | ||
setJson(key: string, value: any): Promise<void>; | ||
getJson(key: string): Promise<any>; | ||
} | ||
export interface ICache { | ||
get(key: string): Promise<any>; | ||
set(key: string, value: any): void; | ||
} | ||
export interface IProcessInitParam { | ||
cfg: IConfig; | ||
services: { | ||
store: IStore; | ||
}; | ||
} | ||
export declare type IOption = { | ||
@@ -25,0 +46,0 @@ strings: string[]; |
{ | ||
"name": "copilot-core", | ||
"version": "0.0.22", | ||
"version": "0.0.24", | ||
"description": "copilot", | ||
@@ -26,6 +26,7 @@ "license": "MIT", | ||
"watch:dev": "npm run build:dev -- --watch", | ||
"cp": " cp -r lib/* ../copilot-io/node_modules/copilot-core/lib", | ||
"cp": " cp -r {lib,icon} ../copilot-io/node_modules/copilot-core/", | ||
"watch:test": "npm run test -- --watch" | ||
}, | ||
"dependencies": { | ||
"@types/sqlite3": "^3.1.0", | ||
"array-asyncify": "^0.0.7", | ||
@@ -40,3 +41,5 @@ "b-logger": "^0.0.4", | ||
"js-yaml": "^3.8.4", | ||
"lru-cache": "^4.1.1", | ||
"scalc": "^2.0.1", | ||
"sqlite3": "^3.1.8", | ||
"tldr": "^2.0.1", | ||
@@ -43,0 +46,0 @@ "twss": "^0.1.6" |
94381
73
2167
15
+ Added@types/sqlite3@^3.1.0
+ Addedlru-cache@^4.1.1
+ Addedsqlite3@^3.1.8
+ Added@types/node@22.13.8(transitive)
+ Added@types/sqlite3@3.1.11(transitive)
+ Addednan@2.7.0(transitive)
+ Addedsqlite3@3.1.13(transitive)
+ Addedundici-types@6.20.0(transitive)