@vnejs/plugins.vars.flags 0.1.2 → 0.1.4

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/const/const.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export const TYPE = "flag";
2
+ export const EXEC_NAME = "flag";
2
3
 
3
- export const LINE_REG = /^(?<name>[a-zA-Z0-9_\-]+)( (?<action>set|unset))?( global)?$/;
4
4
  export const ACTIONS = { SET: "set", UNSET: "unset" };
package/const/events.js CHANGED
@@ -1,3 +1,6 @@
1
1
  export const SUBSCRIBE_EVENTS = {
2
2
  SET: "vne:vars_flags:set",
3
+ GET: "vne:vars_flags:get",
4
+ EXEC_INFO: "vne:vars_flags:exec_info",
5
+ EXEC_CHECK: "vne:vars_flags:exec_check",
3
6
  };
package/index.js CHANGED
@@ -3,6 +3,7 @@ import { regPlugin } from "@vnejs/shared";
3
3
  import * as constants from "./const/const";
4
4
  import { SUBSCRIBE_EVENTS } from "./const/events";
5
5
 
6
+ import { FlagsExec } from "./modules/exec";
6
7
  import { Flags } from "./modules/flags";
7
8
 
8
- regPlugin("VARS_FLAGS", { constants, events: SUBSCRIBE_EVENTS }, [Flags]);
9
+ regPlugin("VARS_FLAGS", { constants, events: SUBSCRIBE_EVENTS }, [FlagsExec, Flags]);
@@ -0,0 +1,26 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ export class FlagsExec extends Module {
4
+ name = "vars.flags.exec";
5
+
6
+ init = () =>
7
+ Promise.all([
8
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.CONST.VARS_FLAGS.EXEC_NAME, handler: this.onLineExecBlock }),
9
+ this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.CONST.VARS_FLAGS.EXEC_NAME, handler: this.onLineExecModule }),
10
+ ]);
11
+
12
+ onLineExecModule = async ({ line = "", keywords = [] } = {}) => {
13
+ const { name, isSet: value, isGlobal } = await this.emitOne(this.EVENTS.VARS_FLAGS.EXEC_INFO, { line, keywords, withValue: false });
14
+
15
+ await this.emit(this.EVENTS.VARS_FLAGS.SET, { name, value, isGlobal });
16
+
17
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
18
+ };
19
+ onLineExecBlock = async ({ line = "", keywords = [] } = {}) => {
20
+ const { value, isSet } = await this.emitOne(this.EVENTS.VARS_FLAGS.EXEC_INFO, { line, keywords });
21
+
22
+ await this.emit(this.EVENTS.VARS.SCENARIO, { shouldGoInside: isSet === value });
23
+
24
+ this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
25
+ };
26
+ }
package/modules/flags.js CHANGED
@@ -3,49 +3,26 @@ import { Module } from "@vnejs/module";
3
3
  export class Flags extends Module {
4
4
  name = "vars.flags";
5
5
 
6
- execName = "flag";
7
-
8
6
  subscribe = () => {
9
7
  this.on(this.EVENTS.VARS_FLAGS.SET, this.onFlagSet);
8
+ this.on(this.EVENTS.VARS_FLAGS.GET, this.onFlagGet);
9
+ this.on(this.EVENTS.VARS_FLAGS.EXEC_INFO, this.onFlagExecInfo);
10
+ this.on(this.EVENTS.VARS_FLAGS.EXEC_CHECK, this.onFlagExecCheck);
10
11
  };
11
12
 
12
- init = () =>
13
- Promise.all([
14
- this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.execName, handler: this.execHandlerBlock }),
15
- this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.execName, handler: this.execHandlerModule }),
16
- ]);
17
-
18
- execHandlerModule = async (line = "") => {
19
- const defaultActions = this.CONST.VARS_FLAGS.ACTIONS.SET;
20
- const { name = "", action = defaultActions } = line.match(this.CONST.VARS_FLAGS.LINE_REG).groups;
21
- const isGlobal = line.endsWith(" global");
22
-
23
- await this.emit(this.EVENTS.VARS_FLAGS.SET, { name, value: action === defaultActions, isGlobal });
13
+ onFlagSet = ({ name = "", isGlobal = false, value = false } = {}) =>
14
+ this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_FLAGS.TYPE, value, isGlobal });
15
+ onFlagGet = ({ name = "", isGlobal = false } = {}) => this.emitOne(this.EVENTS.VARS.GET, { name, type: this.CONST.VARS_FLAGS.TYPE, isGlobal }).then(Boolean);
16
+ onFlagExecInfo = async ({ line = "", keywords = [], withValue = true } = {}) => {
17
+ const [name = "", action = ""] = line.split(" ");
18
+ const [isSet, isGlobal] = [!action || action === this.CONST.VARS_FLAGS.ACTIONS.SET, keywords.includes("global")];
19
+ const result = { name, isSet, isGlobal };
24
20
 
25
- this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
21
+ return withValue ? { ...result, value: await this.emitOne(this.EVENTS.VARS_FLAGS.GET, { name, isGlobal }) } : result;
26
22
  };
23
+ onFlagExecCheck = async ({ line = "", keywords = [] } = {}) => {
24
+ const { value = false, isSet = false } = await this.emitOne(this.EVENTS.VARS_FLAGS.EXEC_INFO, { line, keywords });
27
25
 
28
- execHandlerBlock = async (line, args) => {
29
- const { curLine = 0, label } = this.globalState.scenario;
30
- const { name = "" } = line.match(this.CONST.VARS_FLAGS.LINE_REG).groups;
31
- const isGlobal = line.endsWith(" global");
32
- const varValue = (isGlobal ? this.shared : this.globalState).vars[`${this.CONST.VARS_FLAGS.TYPE}:${name}`];
33
-
34
- if (varValue) return this.increaseCurLineAndGoNext(1);
35
-
36
- const lines = await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label });
37
-
38
- let indexShift = 1;
39
-
40
- while (lines[curLine + indexShift] && lines[curLine + indexShift].indent > lines[curLine].indent) indexShift++;
41
-
42
- return this.increaseCurLineAndGoNext(indexShift);
26
+ return value === isSet;
43
27
  };
44
-
45
- increaseCurLineAndGoNext = (indexShift) => {
46
- this.globalState.scenario.curLine += indexShift;
47
- this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
48
- };
49
-
50
- onFlagSet = ({ name, isGlobal = false, value = false }) => this.emit(this.EVENTS.VARS.SET, { name, type: this.CONST.VARS_FLAGS.TYPE, value, isGlobal });
51
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.vars.flags",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",