From 6500b6b5402e50d0999fa3ceda585087f21c2fbe Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 31 Oct 2024 09:23:53 -0700 Subject: [PATCH] Use inquirer for inputs over hardcoded values (#113) --- .gitignore | 6 ++- package.json | 1 + scripts/publishFeedGen.ts | 83 +++++++++++++++++++++++-------------- scripts/unpublishFeedGen.ts | 55 +++++++++++++++++------- 4 files changed, 98 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 6a7d6d8..43e9736 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,8 @@ dist .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz -.pnp.* \ No newline at end of file +.pnp.* + +# intellij +.idea/ +*.iml diff --git a/package.json b/package.json index 620753d..3ec3662 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@types/better-sqlite3": "^7.6.4", "@types/express": "^4.17.17", "@types/node": "^20.1.2", + "inquirer": "^12.0.1", "ts-node": "^10.9.1", "typescript": "^5.0.4" } diff --git a/scripts/publishFeedGen.ts b/scripts/publishFeedGen.ts index 587db4d..95df0b9 100644 --- a/scripts/publishFeedGen.ts +++ b/scripts/publishFeedGen.ts @@ -1,4 +1,5 @@ import dotenv from 'dotenv' +import inquirer from 'inquirer' import { AtpAgent, BlobRef } from '@atproto/api' import fs from 'fs/promises' import { ids } from '../src/lexicon/lexicons' @@ -6,44 +7,64 @@ import { ids } from '../src/lexicon/lexicons' const run = async () => { dotenv.config() - // YOUR bluesky handle - // Ex: user.bsky.social - const handle = '' - - // YOUR bluesky password, or preferably an App Password (found in your client settings) - // Ex: abcd-1234-efgh-5678 - const password = '' - - // A short name for the record that will show in urls - // Lowercase with no spaces. - // Ex: whats-hot - const recordName = '' - - // A display name for your feed - // Ex: What's Hot - const displayName = '' - - // (Optional) A description of your feed - // Ex: Top trending content from the whole network - const description = '' - - // (Optional) The path to an image to be used as your feed's avatar - // Ex: ~/path/to/avatar.jpeg - const avatar: string = '' - - // ------------------------------------- - // NO NEED TO TOUCH ANYTHING BELOW HERE - // ------------------------------------- - if (!process.env.FEEDGEN_SERVICE_DID && !process.env.FEEDGEN_HOSTNAME) { throw new Error('Please provide a hostname in the .env file') } + + const answers = await inquirer + .prompt([ + { + type: 'input', + name: 'handle', + message: 'Enter your Bluesky handle:', + required: true, + }, + { + type: 'password', + name: 'password', + message: 'Enter your Bluesky password (preferably an App Password):', + }, + { + type: 'input', + name: 'service', + message: 'Optionally, enter a custom PDS service to sign in with:', + default: 'https://bsky.social', + required: false, + }, + { + type: 'input', + name: 'recordName', + message: 'Enter a short name or the record. This will be shown in the feed\'s URL:', + required: true, + }, + { + type: 'input', + name: 'displayName', + message: 'Enter a display name for your feed:', + required: true, + }, + { + type: 'input', + name: 'description', + message: 'Optionally, enter a brief description of your feed:', + required: false, + }, + { + type: 'input', + name: 'avatar', + message: 'Optionally, enter a local path to an avatar that will be used for the feed:', + required: false, + }, + ]) + + const { handle, password, recordName, displayName, description, avatar, service } = answers + const feedGenDid = process.env.FEEDGEN_SERVICE_DID ?? `did:web:${process.env.FEEDGEN_HOSTNAME}` // only update this if in a test environment - const agent = new AtpAgent({ service: 'https://bsky.social' }) - await agent.login({ identifier: handle, password }) + const agent = new AtpAgent({ service: service ? service : 'https://bsky.social' }) + await agent.login({ identifier: handle, password}) let avatarRef: BlobRef | undefined if (avatar) { diff --git a/scripts/unpublishFeedGen.ts b/scripts/unpublishFeedGen.ts index 87a6bc7..59ffb23 100644 --- a/scripts/unpublishFeedGen.ts +++ b/scripts/unpublishFeedGen.ts @@ -2,29 +2,54 @@ import dotenv from 'dotenv' import { AtpAgent, BlobRef } from '@atproto/api' import fs from 'fs/promises' import { ids } from '../src/lexicon/lexicons' +import inquirer from 'inquirer' const run = async () => { dotenv.config() - // YOUR bluesky handle - // Ex: user.bsky.social - const handle = '' + const answers = await inquirer + .prompt([ + { + type: 'input', + name: 'handle', + message: 'Enter your Bluesky handle', + required: true, + }, + { + type: 'password', + name: 'password', + message: 'Enter your Bluesky password (preferably an App Password):', + }, + { + type: 'input', + name: 'service', + message: 'Optionally, enter a custom PDS service to sign in with:', + default: 'https://bsky.social', + required: false, + }, + { + type: 'input', + name: 'recordName', + message: 'Enter the short name for the record you want to delete:', + required: true, + }, + { + type: 'confirm', + name: 'confirm', + message: 'Are you sure you want to delete this record? Any likes that your feed has will be lost:', + default: false, + } + ]) - // YOUR bluesky password, or preferably an App Password (found in your client settings) - // Ex: abcd-1234-efgh-5678 - const password = '' + const { handle, password, recordName, service, confirm } = answers - // A short name for the record that will show in urls - // Lowercase with no spaces. - // Ex: whats-hot - const recordName = '' - - // ------------------------------------- - // NO NEED TO TOUCH ANYTHING BELOW HERE - // ------------------------------------- + if (!confirm) { + console.log('Aborting...') + return + } // only update this if in a test environment - const agent = new AtpAgent({ service: 'https://bsky.social' }) + const agent = new AtpAgent({ service: service ? service : 'https://bsky.social' }) await agent.login({ identifier: handle, password }) await agent.api.com.atproto.repo.deleteRecord({