Use inquirer for inputs over hardcoded values (#113)
This commit is contained in:
parent
437315b4cd
commit
6500b6b540
4 changed files with 98 additions and 47 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -127,4 +127,8 @@ dist
|
|||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
.pnp.*
|
||||
|
||||
# intellij
|
||||
.idea/
|
||||
*.iml
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue