@vnejs/plugins.scenario.random 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/random.d.ts +7 -0
- package/dist/modules/random.js +22 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/dist/utils/random.d.ts +4 -0
- package/dist/utils/random.js +1 -0
- package/package.json +33 -6
- package/src/index.ts +6 -0
- package/{modules/random.js → src/modules/random.ts} +11 -7
- package/src/types.ts +11 -0
- package/src/utils/random.ts +4 -0
- package/tsconfig.json +9 -0
- package/index.js +0 -5
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { RandomPluginConstants, RandomPluginEvents, RandomPluginParams, RandomPluginSettings } from "../types.js";
|
|
3
|
+
export declare class Random extends Module<RandomPluginEvents, RandomPluginConstants, RandomPluginSettings, RandomPluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
init: () => Promise<unknown[]> | undefined;
|
|
6
|
+
onLineExec: () => Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
export class Random extends Module {
|
|
3
|
+
name = "random";
|
|
4
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.name, handler: this.onLineExec });
|
|
5
|
+
onLineExec = async () => {
|
|
6
|
+
const { label, curLine } = this.globalState.scenario;
|
|
7
|
+
const options = [];
|
|
8
|
+
const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label }));
|
|
9
|
+
let indexShift = 1;
|
|
10
|
+
let curLineObj = lines[curLine + indexShift];
|
|
11
|
+
while (curLineObj && (curLineObj.indent ?? 0) > (lines[curLine].indent ?? 0)) {
|
|
12
|
+
if (curLineObj.line.startsWith("% option") && curLineObj.indent === (lines[curLine].indent ?? 0) + 2)
|
|
13
|
+
options.push(curLine + indexShift);
|
|
14
|
+
indexShift++;
|
|
15
|
+
curLineObj = lines[curLine + indexShift];
|
|
16
|
+
}
|
|
17
|
+
const index = Math.floor(Math.random() * options.length);
|
|
18
|
+
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { type: "option", index, curLine: options[index] + 1 } });
|
|
19
|
+
this.globalState.scenario.curLine = options[index] + 1;
|
|
20
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
21
|
+
};
|
|
22
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/plugins.core.logs.contract";
|
|
3
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
4
|
+
export type RandomPluginEvents = VnePluginEventsMapRegistry & Record<LogsPluginName, LogsSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents>;
|
|
5
|
+
export type RandomPluginConstants = VnePluginConstantsMapRegistry;
|
|
6
|
+
export type RandomPluginSettings = VnePluginSettingsMapRegistry;
|
|
7
|
+
export type RandomPluginParams = VnePluginParamsMapRegistry;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.scenario.random",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"publish:patch": "
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.scenario.random.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/module": "~0.0.1",
|
|
37
|
+
"@vnejs/plugins.core.logs.contract": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.core.scenario.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/shared": "~0.0.9"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
43
|
+
}
|
|
17
44
|
}
|
package/src/index.ts
ADDED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { Module } from "@vnejs/module";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { RandomPluginConstants, RandomPluginEvents, RandomPluginParams, RandomPluginSettings } from "../types.js";
|
|
4
|
+
import type { ScenarioLine } from "../utils/random.js";
|
|
5
|
+
|
|
6
|
+
export class Random extends Module<RandomPluginEvents, RandomPluginConstants, RandomPluginSettings, RandomPluginParams> {
|
|
4
7
|
name = "random";
|
|
5
8
|
|
|
6
|
-
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.name, handler: this.
|
|
9
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.name, handler: this.onLineExec });
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
onLineExec = async () => {
|
|
9
12
|
const { label, curLine } = this.globalState.scenario;
|
|
10
|
-
const options = [];
|
|
11
|
-
const lines = await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label });
|
|
13
|
+
const options: number[] = [];
|
|
14
|
+
const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label })) as ScenarioLine[];
|
|
12
15
|
|
|
13
16
|
let indexShift = 1;
|
|
14
17
|
let curLineObj = lines[curLine + indexShift];
|
|
15
18
|
|
|
16
|
-
while (curLineObj && curLineObj.indent > lines[curLine].indent) {
|
|
17
|
-
if (curLineObj.line.startsWith("% option") && curLineObj.indent === lines[curLine].indent + 2) options.push(curLine + indexShift);
|
|
19
|
+
while (curLineObj && (curLineObj.indent ?? 0) > (lines[curLine].indent ?? 0)) {
|
|
20
|
+
if (curLineObj.line.startsWith("% option") && curLineObj.indent === (lines[curLine].indent ?? 0) + 2) options.push(curLine + indexShift);
|
|
21
|
+
|
|
18
22
|
indexShift++;
|
|
19
23
|
curLineObj = lines[curLine + indexShift];
|
|
20
24
|
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { PluginName as LogsPluginName, SubscribeEvents as LogsSubscribeEvents } from "@vnejs/plugins.core.logs.contract";
|
|
3
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
4
|
+
|
|
5
|
+
export type RandomPluginEvents = VnePluginEventsMapRegistry & Record<LogsPluginName, LogsSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents>;
|
|
6
|
+
|
|
7
|
+
export type RandomPluginConstants = VnePluginConstantsMapRegistry;
|
|
8
|
+
|
|
9
|
+
export type RandomPluginSettings = VnePluginSettingsMapRegistry;
|
|
10
|
+
|
|
11
|
+
export type RandomPluginParams = VnePluginParamsMapRegistry;
|
package/tsconfig.json
ADDED