Skip to content

Commit

Permalink
ask for main page Id
Browse files Browse the repository at this point in the history
use chalk for output
  • Loading branch information
velsa committed Jan 28, 2024
1 parent d064689 commit 21c3e6f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@
},
"dependencies": {
"@inquirer/prompts": "^3.3.2",
"chalk": "^5.3.0",
"change-case-all": "^2.1.0",
"commander": "^11.1.0",
"ejs": "^3.1.9",
"is-valid-domain": "^0.1.6"
},
"devDependencies": {
"prettier": "3.2.2",
"@changesets/cli": "^2.27.1",
"@cloudflare/workers-types": "^4.20231218.0",
"@stylistic/eslint-plugin": "^1.5.4",
"@types/node": "^20.11.6",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"eslint-plugin-import": "^2.29.1",
"@changesets/cli": "^2.27.1",
"@cloudflare/workers-types": "^4.20231218.0",
"@types/node": "^20.11.6",
"prettier": "3.2.2",
"tsc": "^2.0.4",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/cli/init-repo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { confirm, select } from "@inquirer/prompts";
import chalk from "chalk";
import fs from "fs";
import path from "path";
import { copyFilesToSDK } from "./output";
Expand All @@ -11,7 +12,7 @@ export async function initRepo(domain, options) {
? path.join(process.argv[1], "../../../..", "notehost")
: path.join(process.argv[1], "../..", "notehost");

const parserConfig = await getParserConfig(domain, options);
const parserConfig = await getParserConfig(domain);

const templates = fs.readdirSync(path.join(originDir, "templates"));
const template =
Expand All @@ -34,9 +35,13 @@ export async function initRepo(domain, options) {
});

console.log(`\n🎉 Done! Your worker is in`, sdkDir);
console.log("\nGo into this directory and run `npm install`");
console.log("Edit `src/site-config.ts` to setup your website.");
console.log("And finally run `npm run deploy` to publish your website.");
console.log(`\nGo into this directory and run ${chalk.bold("npm install")}`);
console.log(
`Edit ${chalk.bold("src/site-config.ts")} to setup your website.`
);
console.log(
`And finally run ${chalk.bold("npm run deploy")} to publish your website.`
);

process.exit(0);
}
6 changes: 3 additions & 3 deletions src/cli/parser-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export interface ParserConfig extends SiteConfig {
}

export async function getParserConfig(
domainName: string | undefined,
options?: any
domainName: string | undefined
): Promise<ParserConfig> {
const { siteName, siteDescription, siteImage } =
const { mainPageId, siteName, siteDescription, siteImage } =
await getSiteConfigFromUser(domainName);

const kebabDomain = changeCase.kebabCase(domainName);

return {
domainName,
mainPageId,
siteName,
siteDescription,
siteImage,
Expand Down
11 changes: 7 additions & 4 deletions src/cli/site-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { validDomainName } from "./validators";

export interface SiteConfig {
domainName: string;

mainPageId: string;
siteName: string;
siteDescription: string;
siteImage: string;
Expand All @@ -30,12 +30,15 @@ export async function getSiteConfigFromUser(
"\nYou can skip those fields now (press Enter) and fill them later via the config file.\n"
);

siteConfig.siteName = await input({ message: "Enter your site name:" });
siteConfig.mainPageId = await input({
message: "ID of your Notion Page:",
});
siteConfig.siteName = await input({ message: "Your site name:" });
siteConfig.siteDescription = await input({
message: "Enter your site description:",
message: "Your site description:",
});
siteConfig.siteImage = await input({
message: "Enter link preview image URL:",
message: "Link preview image URL:",
});

return siteConfig;
Expand Down
2 changes: 1 addition & 1 deletion templates/default/src/site-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const SITE_CONFIG: NoteHostSiteConfig = {
// Map slugs (short page names) to Notion page IDs
// Empty slug is your main page
slugToPage: {
"": "NOTION_PAGE_ID",
"": "<%= mainPageId %>",
about: "NOTION_PAGE_ID",
contact: "NOTION_PAGE_ID",
},
Expand Down

0 comments on commit 21c3e6f

Please sign in to comment.