private emitSampleFiles()

in packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts [213:280]


  private emitSampleFiles(
    dir: string,
    pathPrefixes: string[] = [],
    mustacheConfig: any
  ) {
    fs.readdirSync(dir, { withFileTypes: true }).forEach((f) => {
      if (f.isDirectory()) {
        this.emitSampleFiles(
          `${dir}/${f.name}`,
          [...pathPrefixes, f.name],
          mustacheConfig
        );
      } else if (f.name.endsWith("websocketapi.ts.mustache")) {
        mustacheConfig.typeSafeWebSocketApis.forEach((tsApi: any) => {
          new SampleFile(
            this,
            `${path.join(...pathPrefixes, `${tsApi.apiNameLowercase}.ts`)}`,
            {
              contents: Mustache.render(
                fs.readFileSync(`${dir}/${f.name}`).toString(),
                tsApi
              ),
            }
          );
        });
      } else if (f.name.endsWith("api.ts.mustache")) {
        mustacheConfig.typeSafeApis.forEach((tsApi: any) => {
          new SampleFile(
            this,
            `${path.join(...pathPrefixes, `${tsApi.apiNameLowercase}.ts`)}`,
            {
              contents: Mustache.render(
                fs.readFileSync(`${dir}/${f.name}`).toString(),
                tsApi
              ),
            }
          );
        });
      } else if (f.name.endsWith("website.ts.mustache")) {
        mustacheConfig.cloudscapeReactTsWebsites.forEach((csWebsite: any) => {
          new SampleFile(
            this,
            `${path.join(
              ...pathPrefixes,
              `${csWebsite.websiteNameLowercase}.ts`
            )}`,
            {
              contents: Mustache.render(
                fs.readFileSync(`${dir}/${f.name}`).toString(),
                csWebsite
              ),
            }
          );
        });
      } else {
        new SampleFile(
          this,
          `${path.join(...pathPrefixes, f.name.replace(".mustache", ""))}`,
          {
            contents: Mustache.render(
              fs.readFileSync(`${dir}/${f.name}`).toString(),
              mustacheConfig
            ),
          }
        );
      }
    });
  }