@digshare/script
Advanced tools
Comparing version 0.2.0 to 0.2.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.devRun = void 0; | ||
const _utils_1 = require("./@utils"); | ||
const api_1 = require("./api"); | ||
const storage_1 = require("./storage"); | ||
async function devRun(script, { storage = {}, payload, dryRun = false } = {}) { | ||
await script(payload, { | ||
dryRun, | ||
requestId: 'dev', | ||
token: 'dev', | ||
api: new api_1.DevScriptAPI(storage), | ||
storage: new storage_1.ScriptStorage(storage), | ||
}); | ||
let done = _utils_1.devLog; | ||
try { | ||
let api = new api_1.DevScriptAPI(storage); | ||
let storageObject = new storage_1.ScriptStorage(await api.getStorage()); | ||
let context = { | ||
dryRun, | ||
requestId: 'dev', | ||
token: 'dev', | ||
api, | ||
storage: storageObject, | ||
}; | ||
let creation = await script(payload, context); | ||
if (dryRun) { | ||
return done({ | ||
creation, | ||
storage: storageObject.raw, | ||
}); | ||
} | ||
if (creation) { | ||
await api.publishMessage(creation); | ||
} | ||
if (storageObject.changed) { | ||
await api.updateStorage(storageObject.raw); | ||
} | ||
return done({}); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
return done({ | ||
error: error.message, | ||
}); | ||
} | ||
} | ||
exports.devRun = devRun; | ||
//# sourceMappingURL=dev-run.js.map |
{ | ||
"name": "@digshare/script", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Chengdu Mufan Technology Co., Ltd.", |
@@ -0,1 +1,2 @@ | ||
import {devLog} from './@utils'; | ||
import {DevScriptAPI} from './api'; | ||
@@ -22,9 +23,41 @@ import {Script} from './script'; | ||
): Promise<void> { | ||
await script(payload, { | ||
dryRun, | ||
requestId: 'dev', | ||
token: 'dev', | ||
api: new DevScriptAPI(storage), | ||
storage: new ScriptStorage(storage), | ||
}); | ||
let done = devLog; | ||
try { | ||
let api = new DevScriptAPI(storage); | ||
let storageObject = new ScriptStorage(await api.getStorage()); | ||
let context = { | ||
dryRun, | ||
requestId: 'dev', | ||
token: 'dev', | ||
api, | ||
storage: storageObject, | ||
}; | ||
let creation = await script(payload, context); | ||
if (dryRun) { | ||
return done({ | ||
creation, | ||
storage: storageObject.raw, | ||
}); | ||
} | ||
if (creation) { | ||
await api.publishMessage(creation); | ||
} | ||
if (storageObject.changed) { | ||
await api.updateStorage(storageObject.raw); | ||
} | ||
return done({}); | ||
} catch (error: any) { | ||
console.error(error); | ||
return done({ | ||
error: error.message, | ||
}); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
65572
758