kremalicious/blog

View on GitHub
scripts/new/index.ts

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
import path from 'node:path'
import ora from 'ora'
import { createArticlePost } from './createArticlePost.js'
import { createPhotoPost } from './createPhotoPost.js'

const postsPath = path.join('.', 'content', 'articles')
const photosPath = path.join('.', 'content', 'photos')
const spinner = ora('Adding new post').start()

if (!process.argv[2]) {
  spinner.fail(
    'Use the format `npm run new "Title of post"` or `npm run new photo path/to/photo.jpg`'
  )
}

const isPhoto = process.argv[2] === 'photo'

if (isPhoto) {
  const photo = process.argv[3]
  const photoTitle = process.argv[4]
  createPhotoPost(photosPath, spinner, photo, photoTitle)
} else {
  const title = process.argv[2]
  const newDate = process.argv[3]
  createArticlePost(postsPath, spinner, title, newDate)
}