scripts/generate-demo-app-docs.js
function generateModuleFile(componentsMetadata, demoAppDocsModuleDir) {
  const imports = componentsMetadata
    .map(componentMetadata => `import { ${componentMetadata.name} } from './${componentMetadata.file}';`)
    .join('\n');

  const components = componentsMetadata
    .map(componentMetadata => `    ${componentMetadata.name},`)
    .join('\n');

  const routes = componentsMetadata
    .map(componentMetadata => `    { path: 'docs/${componentMetadata.route}', component: ${componentMetadata.name} },`)
    .join('\n');

  const moduleTsFileContents = `import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

${imports}

const routes: Routes = [
    { path: 'docs', component: IndexComponent }, // always start with index
${routes}
];

@NgModule({
  imports: [
    RouterModule.forChild(routes),
  ],
  declarations: [
${components}
  ],
  exports: [
${components}
  ]
})
export class DocsModule { }
`;

  const moduleTsFile = path.join(demoAppDocsModuleDir, 'docs.module.ts');
  fs.writeFileSync(moduleTsFile, moduleTsFileContents, { encoding: 'utf8' });
}
function generateModuleFile(componentsMetadata, demoAppDocsModuleDir) {
  const imports = componentsMetadata
    .map(componentMetadata => `import { ${componentMetadata.name} } from './${componentMetadata.file}';`)
    .join('\n');

  const components = componentsMetadata
    .map(componentMetadata => `    ${componentMetadata.name},`)
    .join('\n');

  const routes = componentsMetadata
    .map(componentMetadata => `    { path: 'docs/${componentMetadata.route}', component: ${componentMetadata.name} },`)
    .join('\n');

  const moduleTsFileContents = `import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

${imports}

const routes: Routes = [
    { path: 'docs', component: IndexComponent }, // always start with index
${routes}
];

@NgModule({
  imports: [
    RouterModule.forChild(routes),
  ],
  declarations: [
${components}
  ],
  exports: [
${components}
  ]
})
export class DocsModule { }
`;

  const moduleTsFile = path.join(demoAppDocsModuleDir, 'docs.module.ts');
  fs.writeFileSync(moduleTsFile, moduleTsFileContents, { encoding: 'utf8' });
}
function generateModuleFile ( componentsMetadata , demoAppDocsModuleDir ) { const imports = componentsMetadata . map ( componentMetadata => ` ${ componentMetadata . name } ${ componentMetadata . file } ` ) . join ( '\n' ) ; const components = componentsMetadata . map ( componentMetadata => ` ${ componentMetadata . name } ` ) . join ( '\n' ) ; const routes = componentsMetadata . map ( componentMetadata => ` ${ componentMetadata . route } ${ componentMetadata . name } ` ) . join ( '\n' ) ; const moduleTsFileContents = ` ${ imports } ${ routes } ${ components } ${ components } ` ; const moduleTsFile = path . join ( demoAppDocsModuleDir , 'docs.module.ts' ) ; fs . writeFileSync ( moduleTsFile , moduleTsFileContents , { encoding : 'utf8' } ) ; }
Generate module file based on metadata from generated components
Generate module file based on metadata from generated components