diff --git a/dev/setup.js b/dev/setup/index.js similarity index 93% rename from dev/setup.js rename to dev/setup/index.js index 3beb106..acac65e 100644 --- a/dev/setup.js +++ b/dev/setup/index.js @@ -1,6 +1,6 @@ import crypto from "node:crypto"; import fs from "node:fs/promises"; -import registerGitHubApp from "./lib/register-github-app/index.js"; +import registerGitHubApp from "./lib/index.js"; // register app and retrieve credentials const appCredentials = await registerGitHubApp({ diff --git a/dev/setup/lib/content.html.js b/dev/setup/lib/content.html.js new file mode 100644 index 0000000..96b2716 --- /dev/null +++ b/dev/setup/lib/content.html.js @@ -0,0 +1,227 @@ +const headEl = ` + + + + + jargons.dev Contributor Setup + + +` + +/** + * Generate the start page HTML content + * @param {string} registerUrl + * @param {string} manifestJson + * @returns + */ +export function getStartPage(registerUrl, manifestJson) { + return `${headEl} + +
+

Setup

+

Welcome to the jargons.dev Local development setup guide

+
    +
  1. +

    Start by Registering your GitHub App

    +

    Click the button below to submit your app manifest to GitHub and start the registration process.

    +

    You will be directed to the GitHub

    +
    + + +
    +
  2. +
+
+ Need help? See the dev/setup guide. +
+
+ +`; +} + +/** + * Generate the next step page HTML content + * @param {import('./index').AppCredentials} appCredentials + * @returns + */ +export function getNextStepPage(appCredentials) { + return `${headEl} + +
+

Setup

+

Welcome to the jargons.dev Local development setup guide

+
    +
  1. +

    GitHub App Registered Sucessfully

    +
    + + + + GitHub App \`${appCredentials.name}\` created +
    +
    + + + + .env file created +
    +
    + + + + GitHub App details added to .env file +
    +
  2. +
  3. +

    Create Your Test Repository

    +

    Create a new github repository with name "jargons.dev-test"

    + Create Test Repo +
  4. +
  5. +

    Update Your .env File

    +

    + Copy and paste the repo name in full as value to the PUBLIC_PROJECT_REPO in the .env file created in step 1
    +

    + Example (assuming you chose the suggested name, your .env file should have the line below) +
    PUBLIC_PROJECT_REPO="${appCredentials.owner.login}/jargons.dev-test"
    +
  6. +
  7. +

    Install the GitHub App

    +

    + Follow the link provided after registration to install the app on your test repository. +

    + Install \`${appCredentials.name}\` GitHub App +
  8. +
+
+ Need help? See the dev/setup guide. +
+
+`; +} \ No newline at end of file diff --git a/dev/lib/register-github-app/index.d.ts b/dev/setup/lib/index.d.ts similarity index 100% rename from dev/lib/register-github-app/index.d.ts rename to dev/setup/lib/index.d.ts diff --git a/dev/lib/register-github-app/index.js b/dev/setup/lib/index.js similarity index 56% rename from dev/lib/register-github-app/index.js rename to dev/setup/lib/index.js index 8aaf92f..277acc8 100644 --- a/dev/lib/register-github-app/index.js +++ b/dev/setup/lib/index.js @@ -1,13 +1,13 @@ /** - * Register a GitHub App using the manifest flow - * @see https://github.com/gr2m/register-github-app + * Register a GitHub App via a local server and the GitHub App Manifest flow + * @uses https://github.com/gr2m/register-github-app * * @ts-check */ import { createServer } from "node:http"; - import { request as octokitRequest } from "@octokit/request"; +import { getStartPage, getNextStepPage } from "./content.html.js"; const DEFAULT_MANIFEST = { url: "https://github.com", @@ -19,9 +19,9 @@ const DEFAULT_META_OPTIONS = { }; /** - * @param {import('./index').Manifest} manifest - * @param {import('./index').MetaOptions} metaOptions - * @returns {Promise} + * @param {import('../index').Manifest} manifest + * @param {import('../index').MetaOptions} metaOptions + * @returns {Promise} */ export default async function registerGitHubApp( { org, ...manifest } = DEFAULT_MANIFEST, @@ -55,7 +55,7 @@ export default async function registerGitHubApp( // @ts-expect-error - I have yet to see a usecase when `server.address()` can be a string server.address().port; - log(`Open http://localhost:${port}`); + log(`Open http://localhost:${port} in the browser to get started`); server.on("error", (error) => { reject(new Error("A server error occured", { cause: error })); @@ -75,30 +75,7 @@ export default async function registerGitHubApp( console.log(appCredentials); response.writeHead(200, { "Content-Type": "text/html" }); - response.end(` - -

GitHub App registered successfully

-

- Now follow this steps below.. -

-

- `); + response.end(getNextStepPage(appCredentials)); resolve(appCredentials); @@ -115,25 +92,7 @@ export default async function registerGitHubApp( }); response.writeHead(200, { "Content-Type": "text/html" }); - response.end(` - -

Registering GitHub App

-
- - -
- -

- You will be redirected automatically … -

- - - `); + response.end(getStartPage(registerUrl, manifestJson)); }); }); } diff --git a/package.json b/package.json index 14af590..40083cf 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test:ui": "vitest --ui", "test:watch": "vitest", "test:coverage": "vitest run --coverage", - "setup": "node dev/setup.js", + "setup": "node dev/setup/index.js", "seed:jai": "node --env-file=.env dev/seed-vector-store.js", "ping:qdrant": "node --env-file=.env dev/ping-qdrant-cluster.js", "ping:qdrant:ci": "node dev/ping-qdrant-cluster.js"