github.com/hyperledger/aries-framework-go@v0.3.2/test/aries-js-worker/init.js (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  const fs = require("fs");
     8  const exec = require("child_process");
     9  const minimist = require("minimist");
    10  
    11  process.env.CHROME_BIN = require("puppeteer").executablePath();
    12  const ENV_CONFIG = "fixtures/.env";
    13  const ENV_CONFIG_OUT = "test/environment.js";
    14  
    15  (async () => {
    16      require("dotenv").config({ path: ENV_CONFIG });
    17      const util = require("util");
    18      const config = {};
    19      for (const attr in process.env) {
    20          if (attr.startsWith("E2E_")) {
    21              config[attr.replace("E2E_", "")] = process.env[attr];
    22          }
    23          if (attr.startsWith("HTTP_")) {
    24              config[attr] = process.env[attr];
    25          }
    26      }
    27  
    28      let didID = await createDID();
    29      console.log(didID);
    30      config["DID_ID"] = didID.trim();
    31  
    32      let args = minimist(process.argv.slice(2), {
    33          default: {
    34              "log-level": "CRITICAL",
    35          },
    36      });
    37  
    38      config["LOG_LEVEL"] = args["log-level"];
    39  
    40      fs.writeFileSync(
    41          ENV_CONFIG_OUT,
    42          "export const environment = " + util.inspect(config)
    43      );
    44  })();
    45  
    46  function createDID() {
    47      return new Promise((resolve, reject) => {
    48          exec.exec(
    49              "../../build/bin/sidetree http://localhost:48326/sidetree/0.0.1/operations key1 axETCKcguKigxZiJIPtgotDbVe72AIXRTbF2MRpZIk0 http://www.example.com",
    50              (err, stdout, stderr) => {
    51                  let v;
    52                  if (err) {
    53                      //some err occurred
    54                      console.error(err);
    55                  } else {
    56                      v = stdout;
    57                  }
    58                  resolve(v);
    59              }
    60          );
    61      });
    62  }