javascript Executar comandos做CMD direto de arquivos JS com o NODE.js e montar arquivos HTML

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Executar comandos做CMD direto de arquivos JS com o NODE.js e montar arquivos HTML相关的知识,希望对你有一定的参考价值。

const fs = require("fs");
const createHTML = require("create-html");
const { exec } = require("child_process");

// Templating of Reporter
function template(items) {
  console.log("TCL: template -> items", items);
  return `<div id="root">
  <div class="container">
      <div class="header">
          <div class="header-title">Interface report</div>
          <div class="header-container-search">
            <div class="header-container-search-buttons">
              <button class="mobile">Mobile</button>
              <button class="tablet">Tablet</button>
              <button class="desktop">Desktop</button>
            </div>
            <div class="header-container-search-input">
              <input type="text">
              <button type="submit">Buscar</button>
            </div>
          </div>
        </div>
        ${items
          .map((item, i) =>
            `
        <div class="card">
          <div class="card-label">Página: ${item.scenarioLabel}</div>
           <div class="card-content">
             <div class="card-content-column reference">
               <div class="card-content-column-label">Reference</div>
               <div class="card-content-column-img">
                 <img src="../reference/${item.imageFilePng}" alt="">
               </div>
             </div>
             <div class="card-content-column test">
               <div class="card-content-column-label">Test</div>
               <div class="card-content-column-img">
                 <img src="../${item.today}" alt="">
               </div>
             </div>
             <div class="card-content-column result">
               <div class="card-content-column-label">Result</div>
               <div class="card-content-column-img">
                 <img src="../${item.test}" alt="">
               </div>
             </div>
           </div>
           <div class="card-filename">filename: ${item.imageFilePng}</div>
         </div>
        `.trim()
          )
          .join("")}
  </div>
</div>`;
}

// Mount HTML reporter
async function makeReporter(items) {
  const html = createHTML({
    title: "Interface Report",
    script: "script.js",
    scriptAsync: true,
    css: "style.css",
    lang: "pt-br",
    head: `<meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="description" content="">
      <meta name="viewport" content="width=device-width, initial-scale=1">`,
    body: template(items),
    favicon: "favicon.png"
  });

  // Write HTML file report in Reporter folder
  await fs.writeFile("./reporter/index2.html", html, function(err) {
    if (err) console.log(err);
  });

  // Open Report in Google Chrome
  await exec("google-chrome ./reporter/index2.html", (err, stdout, stderr) => {
    if (err) {
      console.error(err);
    } else {
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    }
  });
}

module.exports = makeReporter;

以上是关于javascript Executar comandos做CMD direto de arquivos JS com o NODE.js e montar arquivos HTML的主要内容,如果未能解决你的问题,请参考以下文章

火绒 网站控制

JavaScript介绍

javascript的题。

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)