浏览代码

Add ability to exclude operations from Node API. Exclude flow control ops

d98762625 7 年之前
父节点
当前提交
f95f01b895
共有 2 个文件被更改,包括 22 次插入4 次删除
  1. 15 0
      src/node/config/excludedOperations.mjs
  2. 7 4
      src/node/config/scripts/generateNodeIndex.mjs

+ 15 - 0
src/node/config/excludedOperations.mjs

@@ -0,0 +1,15 @@
+/**
+ * Operations to exlude from the Node API
+ *
+ * @author d98762656 [d98762625@gmail.com]
+ * @copyright Crown Copyright 2018
+ * @license Apache-2.0
+ */
+export default  [
+    "Fork",
+    "Merge",
+    "Jump",
+    "ConditionalJump",
+    "Label",
+    "Comment",
+];

+ 7 - 4
src/node/config/scripts/generateNodeIndex.mjs

@@ -15,6 +15,9 @@ import fs from "fs";
 import path from "path";
 import * as operations from "../../../core/operations/index";
 import { decapitalise } from "../../apiUtils";
+import excludedOperations from "../excludedOperations";
+
+const includedOperations = Object.keys(operations).filter((op => excludedOperations.indexOf(op) === -1));
 
 const dir = path.join(`${process.cwd()}/src/node`);
 if (!fs.existsSync(dir)) {
@@ -40,7 +43,7 @@ import { wrap } from "./apiUtils";
 import {
 `;
 
-Object.keys(operations).forEach((op) => {
+includedOperations.forEach((op) => {
     // prepend with core_ to avoid name collision later.
     code += `    ${op} as core_${op},\n`;
 });
@@ -68,7 +71,7 @@ function generateChef() {
     return {
 `;
 
-Object.keys(operations).forEach((op) => {
+includedOperations.forEach((op) => {
     code += `        "${decapitalise(op)}": wrap(core_${op}),\n`;
 });
 
@@ -78,7 +81,7 @@ code += `    };
 const chef = generateChef();
 `;
 
-Object.keys(operations).forEach((op) => {
+includedOperations.forEach((op) => {
     code += `const ${decapitalise(op)} = chef.${decapitalise(op)};\n`;
 });
 
@@ -88,7 +91,7 @@ export default chef;
 export {
 `;
 
-Object.keys(operations).forEach((op) => {
+includedOperations.forEach((op) => {
     code += `    ${decapitalise(op)},\n`;
 });