function generateTemplate(templateFile, snippetsDir) {
  const titleTemplateFile = templateFile.replace('.template.html', '.title-template.html');
  const outputTemplateFile = templateFile.replace('.template.html', '.html');
  const codeFile = templateFile.replace('.template.html', '.ts');
  const styleFile = templateFile.replace('.template.html', '.scss');

  const titleTemplateFileContent = fs.readFileSync(path.resolve(snippetsDir, titleTemplateFile), { encoding: 'utf8' });

  const templateFileContent = fs.readFileSync(path.resolve(snippetsDir, templateFile), { encoding: 'utf8' });
  const templateTabHtml = tabHtml(path.basename(outputTemplateFile), templateFileContent, 'html');

  let codeFileContent = fs.readFileSync(path.resolve(snippetsDir, codeFile), { encoding: 'utf8' });
  // The only modification to the source file is to remove the @local prefix from slider import
  codeFileContent = codeFileContent.replace(/@local\/ng5-slider/g, "ng5-slider");
  const codeTabHtml = tabHtml(path.basename(codeFile), codeFileContent, 'typescript');

  let styleTabHtml = '';
  if (fs.existsSync(path.resolve(snippetsDir, styleFile))) {
    const styleFileContent = fs.readFileSync(path.resolve(snippetsDir, styleFile), { encoding: 'utf8' });
    styleTabHtml = tabHtml(path.basename(styleFile), styleFileContent, 'scss');
  }

  const outputHtmlFileContent = `<h2 class="snippet-title">${titleTemplateFileContent}</h2>
<div class="snippet-card card">
  <div class="card-body">
    <div class="snippet-content">
      ${templateFileContent}
    </div>

    <ngb-tabset class="snippet-code-tabset">
      ${codeTabHtml}

      ${templateTabHtml}

      ${styleTabHtml}
    </ngb-tabset>
  </div>
</div>`;

  fs.writeFileSync(path.resolve(snippetsDir, outputTemplateFile), outputHtmlFileContent, { encoding: 'utf8' });
}
function generateTemplate(templateFile, snippetsDir) {
  const titleTemplateFile = templateFile.replace('.template.html', '.title-template.html');
  const outputTemplateFile = templateFile.replace('.template.html', '.html');
  const codeFile = templateFile.replace('.template.html', '.ts');
  const styleFile = templateFile.replace('.template.html', '.scss');

  const titleTemplateFileContent = fs.readFileSync(path.resolve(snippetsDir, titleTemplateFile), { encoding: 'utf8' });

  const templateFileContent = fs.readFileSync(path.resolve(snippetsDir, templateFile), { encoding: 'utf8' });
  const templateTabHtml = tabHtml(path.basename(outputTemplateFile), templateFileContent, 'html');

  let codeFileContent = fs.readFileSync(path.resolve(snippetsDir, codeFile), { encoding: 'utf8' });
  
  codeFileContent = codeFileContent.replace(/@local\/ng5-slider/g, "ng5-slider");
  const codeTabHtml = tabHtml(path.basename(codeFile), codeFileContent, 'typescript');

  let styleTabHtml = '';
  if (fs.existsSync(path.resolve(snippetsDir, styleFile))) {
    const styleFileContent = fs.readFileSync(path.resolve(snippetsDir, styleFile), { encoding: 'utf8' });
    styleTabHtml = tabHtml(path.basename(styleFile), styleFileContent, 'scss');
  }

  const outputHtmlFileContent = `<h2 class="snippet-title">${titleTemplateFileContent}</h2>
<div class="snippet-card card">
  <div class="card-body">
    <div class="snippet-content">
      ${templateFileContent}
    </div>

    <ngb-tabset class="snippet-code-tabset">
      ${codeTabHtml}

      ${templateTabHtml}

      ${styleTabHtml}
    </ngb-tabset>
  </div>
</div>`;

  fs.writeFileSync(path.resolve(snippetsDir, outputTemplateFile), outputHtmlFileContent, { encoding: 'utf8' });
}
function generateTemplate ( templateFile , snippetsDir ) { const titleTemplateFile = templateFile . replace ( '.template.html' , '.title-template.html' ) ; const outputTemplateFile = templateFile . replace ( '.template.html' , '.html' ) ; const codeFile = templateFile . replace ( '.template.html' , '.ts' ) ; const styleFile = templateFile . replace ( '.template.html' , '.scss' ) ; const titleTemplateFileContent = fs . readFileSync ( path . resolve ( snippetsDir , titleTemplateFile ) , { encoding : 'utf8' } ) ; const templateFileContent = fs . readFileSync ( path . resolve ( snippetsDir , templateFile ) , { encoding : 'utf8' } ) ; const templateTabHtml = tabHtml ( path . basename ( outputTemplateFile ) , templateFileContent , 'html' ) ; let codeFileContent = fs . readFileSync ( path . resolve ( snippetsDir , codeFile ) , { encoding : 'utf8' } ) ; // The only modification to the source file is to remove the @local prefix from slider import codeFileContent = codeFileContent . replace ( / @local\/ng5-slider / g , "ng5-slider" ) ; const codeTabHtml = tabHtml ( path . basename ( codeFile ) , codeFileContent , 'typescript' ) ; let styleTabHtml = '' ; if ( fs . existsSync ( path . resolve ( snippetsDir , styleFile ) ) ) { const styleFileContent = fs . readFileSync ( path . resolve ( snippetsDir , styleFile ) , { encoding : 'utf8' } ) ; styleTabHtml = tabHtml ( path . basename ( styleFile ) , styleFileContent , 'scss' ) ; } const outputHtmlFileContent = ` ${ titleTemplateFileContent } ${ templateFileContent } ${ codeTabHtml } ${ templateTabHtml } ${ styleTabHtml } ` ; fs . writeFileSync ( path . resolve ( snippetsDir , outputTemplateFile ) , outputHtmlFileContent , { encoding : 'utf8' } ) ; }
Generate template for a single file
Generate template for a single file