nehemiah

A library for managing repositories

Usage no npm install needed!

<script type="module">
  import nehemiah from 'https://cdn.skypack.dev/nehemiah';
</script>

README

Logo Nehemiah

A library for managing repositories

Nehemiah was a high official in the Persian court of King Artaxerxes I of Persia and led the third return of the Jewish people after seventy years of exile. He organized the reconstruction of the wall of Jerusalem in record time while defending against opposition on all sides. His talent, his huge organizational accomplishments and his faith in God inspired the name for this package. Read the whole story.

Version License Issues CircleCI Dependencies Coverage LGTM

About

Basically monorepos without the monorepo. Nehemiah synchronizes directories and executes tasks within them, based on code you write using a simple API.

Features include:

  • Scan repo for files
  • Test if file exists --> find out what type of project it is, or if a certain dependency/config file is used
  • Copy file --> add file to repo if it doesn't exist, overwrite file, e.g. tslint.json
  • Delete file --> remove unwanted files for cleanup, e.g. logfiles
  • Merge file fragments --> insert partials into README.md
  • Edit json file --> update package.json with standardized values
  • Edit line-based file --> update .gitignore
  • Run shell commands in directory --> yarn install, git fetch, yarn upgrade, sort-package-json
  • Get warned if something deviates from expectations --> no tests in package.json, missing license

Install

yarn add nehemiah

Example

import Nehemiah from "nehemiah"

const projects = ["a", "b", "c"]

interface Package {
  author: string
  keywords: string[]
}

async function updateProject(dir: string) {
  const n = new Nehemiah(dir)

  const updatePackage = () => n.modify("package.json")
    .asJson<Package>(p => {
      p.author = "Esra"

      if (!Array.isArray(p.keywords) || p.keywords.length < 3) {
        n.warn("Not enough keywords")
      }
    })

  const shouldHaveLicense = async () => {
    if (!await n.exists("license*")) {
      n.warn("Missing license")
    }
  }

  const deleteLogs = async () => n.delete("*.log")

  const updateEditorConfig = async () =>
    n.copy(__dirname, "templates/.editorconfig").to(".editorconfig")

  const updateMinorPatch = async () =>
    n.run("yarn upgrade --mutext file")

  const gitFetchPrune = () => n.run("git fetch --prune")

  await Promise.all([
    updatePackage,
    shouldHaveLicense,
    deleteLogs,
    updateEditorConfig,
    updateMinorPatch,
    gitFetchPrune,
  ])
}

(async () => {
  for (const dir of projects) {
    await updateProject(dir)
  }
})()

Logo made by Freepik from www.flaticon.com is licensed by CC 3.0 BY