ソースを参照

Use nunjucks to generate READMEs

Loris Leiva 1 年間 前
コミット
e630d0f9c4
5 ファイル変更17 行追加29 行削除
  1. 0 7
      index.ts
  2. 12 0
      template/base/README.md.njk
  3. 0 17
      utils/generateReadme.ts
  4. 2 2
      utils/getLogs.ts
  5. 3 3
      utils/getRenderContext.ts

+ 0 - 7
index.ts

@@ -5,7 +5,6 @@ import * as fs from "node:fs";
 import * as path from "node:path";
 
 import { postOrderDirectoryTraverse } from "./utils/directoryTraverse";
-import { generateReadme } from "./utils/generateReadme";
 import { logBanner, logEnd, logStart } from "./utils/getLogs";
 import { RenderContext, getRenderContext } from "./utils/getRenderContext";
 import { renderTemplate } from "./utils/renderTemplate";
@@ -34,12 +33,6 @@ async function init() {
   //   render("config/jsx");
   // }
 
-  // README generation
-  fs.writeFileSync(
-    path.resolve(ctx.targetDirectory, "README.md"),
-    generateReadme(ctx)
-  );
-
   // Log end of scaffolding.
   logEnd(ctx);
 }

+ 12 - 0
template/base/README.md.njk

@@ -0,0 +1,12 @@
+# {{ programName | titleCase }}
+
+TODO
+
+```sh
+{{ getNpmCommand("programs:build") }}
+{{ getNpmCommand("programs:test") }}
+{{ getNpmCommand("programs:format") }}
+{{ getNpmCommand("programs:lint") }}
+```
+
+TODO

+ 0 - 17
utils/generateReadme.ts

@@ -1,17 +0,0 @@
-import { RenderContext } from "./getRenderContext";
-import { titleCase } from "./strings";
-
-export function generateReadme(ctx: RenderContext): string {
-  return `# ${titleCase(ctx.programName)}
-
-TODO
-
-\`\`\`sh
-${ctx.getCommand("programs:build")}
-${ctx.getCommand("programs:test")}
-${ctx.getCommand("programs:format")}
-${ctx.getCommand("programs:lint")}
-\`\`\`
-
-TODO`;
-}

+ 2 - 2
utils/getLogs.ts

@@ -23,11 +23,11 @@ export function logEnd(ctx: RenderContext) {
   }
 
   // Log next steps: Install dependencies.
-  const installCommand = ctx.getCommand("install");
+  const installCommand = ctx.getNpmCommand("install");
   console.log(`  ${chalk.bold(chalk.green(installCommand))}`);
 
   // Log next steps: Generate Idls and clients.
-  const generateCommand = ctx.getCommand("generate");
+  const generateCommand = ctx.getNpmCommand("generate");
   console.log(`  ${chalk.bold(chalk.green(generateCommand))}`);
 
   // Final line break.

+ 3 - 3
utils/getRenderContext.ts

@@ -11,7 +11,7 @@ import {
 export type RenderContext = Inputs & {
   clients: Client[];
   currentDirectory: string;
-  getCommand: (scriptName: string, args?: string) => string;
+  getNpmCommand: (scriptName: string, args?: string) => string;
   language: Language;
   packageManager: PackageManager;
   targetDirectory: string;
@@ -25,7 +25,7 @@ export async function getRenderContext(): Promise<RenderContext> {
   const clients = allClients.flatMap((client) =>
     inputs[`${client}Client`] ? [client] : []
   );
-  const getCommand: RenderContext["getCommand"] = (...args) =>
+  const getNpmCommand: RenderContext["getNpmCommand"] = (...args) =>
     getPackageManagerCommand(packageManager, ...args);
 
   // Directories.
@@ -40,7 +40,7 @@ export async function getRenderContext(): Promise<RenderContext> {
     ...inputs,
     clients,
     currentDirectory,
-    getCommand,
+    getNpmCommand,
     language,
     packageManager,
     targetDirectory,