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
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -128,3 +128,7 @@ dist
|
||||||
.yarn/build-state.yml
|
.yarn/build-state.yml
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
# intellij
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
"@types/better-sqlite3": "^7.6.4",
|
"@types/better-sqlite3": "^7.6.4",
|
||||||
"@types/express": "^4.17.17",
|
"@types/express": "^4.17.17",
|
||||||
"@types/node": "^20.1.2",
|
"@types/node": "^20.1.2",
|
||||||
|
"inquirer": "^12.0.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
import inquirer from 'inquirer'
|
||||||
import { AtpAgent, BlobRef } from '@atproto/api'
|
import { AtpAgent, BlobRef } from '@atproto/api'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import { ids } from '../src/lexicon/lexicons'
|
import { ids } from '../src/lexicon/lexicons'
|
||||||
|
@ -6,44 +7,64 @@ import { ids } from '../src/lexicon/lexicons'
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
dotenv.config()
|
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) {
|
if (!process.env.FEEDGEN_SERVICE_DID && !process.env.FEEDGEN_HOSTNAME) {
|
||||||
throw new Error('Please provide a hostname in the .env file')
|
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 =
|
const feedGenDid =
|
||||||
process.env.FEEDGEN_SERVICE_DID ?? `did:web:${process.env.FEEDGEN_HOSTNAME}`
|
process.env.FEEDGEN_SERVICE_DID ?? `did:web:${process.env.FEEDGEN_HOSTNAME}`
|
||||||
|
|
||||||
// only update this if in a test environment
|
// 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.login({ identifier: handle, password})
|
||||||
|
|
||||||
let avatarRef: BlobRef | undefined
|
let avatarRef: BlobRef | undefined
|
||||||
if (avatar) {
|
if (avatar) {
|
||||||
|
|
|
@ -2,29 +2,54 @@ import dotenv from 'dotenv'
|
||||||
import { AtpAgent, BlobRef } from '@atproto/api'
|
import { AtpAgent, BlobRef } from '@atproto/api'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import { ids } from '../src/lexicon/lexicons'
|
import { ids } from '../src/lexicon/lexicons'
|
||||||
|
import inquirer from 'inquirer'
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
// YOUR bluesky handle
|
const answers = await inquirer
|
||||||
// Ex: user.bsky.social
|
.prompt([
|
||||||
const handle = ''
|
{
|
||||||
|
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)
|
const { handle, password, recordName, service, confirm } = answers
|
||||||
// Ex: abcd-1234-efgh-5678
|
|
||||||
const password = ''
|
|
||||||
|
|
||||||
// A short name for the record that will show in urls
|
if (!confirm) {
|
||||||
// Lowercase with no spaces.
|
console.log('Aborting...')
|
||||||
// Ex: whats-hot
|
return
|
||||||
const recordName = ''
|
}
|
||||||
|
|
||||||
// -------------------------------------
|
|
||||||
// NO NEED TO TOUCH ANYTHING BELOW HERE
|
|
||||||
// -------------------------------------
|
|
||||||
|
|
||||||
// only update this if in a test environment
|
// 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.login({ identifier: handle, password })
|
||||||
|
|
||||||
await agent.api.com.atproto.repo.deleteRecord({
|
await agent.api.com.atproto.repo.deleteRecord({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue