Skip to content

goodylabs/pm2-deploysmith

Repository files navigation

🛠️ pm2-deploysmith

CLI tool to generate a PM2 post-deploy command using the standard releases/ + current/ symlink pattern.

Built for Node.js environments using pnpm, pm2, and optionally nvm.

CI npm version npm downloads license node built with pnpm open issues codecov


🚀 What It Does

Generates a one-liner post-deploy command for your ecosystem.config.js, which:

  • creates a timestamped release folder (e.g., releases/build-202507111402)
  • copies code from source/ to new release directory
  • installs dependencies using pnpm
  • compiles your code using a build:staging or build:production script from package.json
  • sets current/ symlink
  • reloads pm2
  • deletes old builds (keeps last n, default: 4)

🧑‍💻 Installation

pnpm add -g pm2-deploysmith

🏃 Usage

pm2-deploysmith demo

Interactive mode:

pm2-deploysmith

This will prompt you to enter:

  • system user (e.g., ubuntu)
  • project sub-directory (e.g., my-app)
  • environment (e.g., production)

With CLI flags (no prompts):

pm2-deploysmith --systemUser ubuntu --projectSubDir my-app --environment production

Additional optional flags:

--numOfKeptReleases - how many old releases to keep (default: 4)

--skipSourceNvm - if you don't want to run source ~/.nvm/nvm.sh first

--addSourceProfile - if you want to run source ~/.profile first

Example:

pm2-deploysmith \
  --systemUser ubuntu \
  --projectSubDir my-app \
  --environment production \
  --numOfKeptReleases 6 \
  --skipSourceNvm \
  --addSourceProfile

🧪 Output

You wiil get a full post-deploy command like this:

source ~/.profile \
&& BUILD_TIMESTAMP=$(date +%Y%m%d%H%M) \
&& mkdir -p /home/ubuntu/my-app/releases/build-$BUILD_TIMESTAMP \
&& cp -a /home/ubuntu/my-app/source/. /home/ubuntu/my-app/releases/build-$BUILD_TIMESTAMP/ \
&& cd /home/ubuntu/my-app/releases/build-$BUILD_TIMESTAMP/ \
&& nvm install \
&& nvm use \
&& npm install -g pnpm \
&& npm install -g pm2 \
&& pnpm install \
&& pnpm build:production \
&& rm /home/ubuntu/my-app/current \
&& ln -sfn /home/ubuntu/my-app/releases/build-$BUILD_TIMESTAMP /home/ubuntu/my-app/current \
&& cd /home/ubuntu/my-app/current \
&& pm2 reload ecosystem.config.js --env production --cwd /home/ubuntu/my-app/current \
&& ls -dt /home/ubuntu/my-app/releases/* | tail -n +4 | xargs rm -rf

Copy-paste that into your ecosystem.config.js:

module.exports = {
  apps: [...],
  deploy: {
    production: {
      user: 'ubuntu',
      host: 'your-server',
      ref: 'origin/master',
      repo: '[email protected]:you/your-repo.git',
      path: '/home/ubuntu/my-app',
      'post-deploy': '<< PASTE OUTPUT HERE >>'
    }
  }
}

Upgrades and versioning

pnpm version patch  # or minor or major
git push --follow-tags

Manual publishing

pnpm publish --access public

📄 License MIT © 2025 goodylabs

About

CLI for generating zero-downtime deployment scripts

Resources

License

Stars

Watchers

Forks

Packages

No packages published