DEV Community

longlongago
longlongago

Posted on

Command line tools for deploying based on node.js

Image description

@nebulae-cli/deploy

Command line tools for deploying, github: https://github.com/longlongago2/deploy-cli

Since my native language is Chinese, please forgive me for the language of the CLI tool, you can modify it after forking

Features

  • ๐Ÿช„ Support multiple configuration file formats, such as json, yaml, js.

  • ๐Ÿšฉ Supports configuring multiple tasks.

  • โšก Supports individual step execution, such as connect, clean, backup, upload.

  • ๐ŸŒ Support global configuration

Translations

็ฎ€ไฝ“ไธญๆ–‡

Installation

  • Global install
npm install @nebulae-cli/deploy -g
Enter fullscreen mode Exit fullscreen mode

test deploy --version, If the version number is successfully displayed, it means the installation is successful

or

  • Project install
npm install @nebulae-cli/deploy -D
Enter fullscreen mode Exit fullscreen mode

If you did not install globally, the command should be invoked using ./node_modules/.bin/deploy --version

Usage

How to use command line tools?

1. Generate deploy config file

deploy init
Enter fullscreen mode Exit fullscreen mode

usage:

Usage: deploy init|generate [options]

init(generate) deploy config file

Options:
  -t, --type <type>      file type: "json" | "yaml" | "javascript" (default: "javascript")
  -m, --module <module>  javascript module type: "commonjs" | "cjs" | "esm" | "mjs" (default: "cjs")
  -g, --global           generate global config file
  -h, --help             display help for command
Enter fullscreen mode Exit fullscreen mode

2. Modify the configuration file

/** @type {import("@nebulae-cli/deploy").ConfigOptions} */
module.exports = {
  host: 'xxx.xx.xxx.x',
  port: 22,
  username: 'server_ssh_name',
  // password: '',
  // privateKey: '',
  // autoBackup: true,
  // autoClean: false, // If the task attribute does not exist, it will take effect
  tasks: [
    {
      name: 'task name',
      disabled: false,
      target: 'your/dist/path',
      remoteDir: '/your/server/path',
      autoBackup: true,
      autoClean: false, // All attributes support upward merging. For example, configuration common to all tasks can be configured on the root property
      // backupDir: '',
      // deployedCommands: [], // Remote commands executed after deployment, such as ['cd/var/applications', 'java - jar xxx. jar'], will use && to merge multiple commands
    },
  ],
};
Enter fullscreen mode Exit fullscreen mode

3. Test the connection

deploy connect
Enter fullscreen mode Exit fullscreen mode

usage:

Usage: deploy connect [options]

test the connection to server

Options:
  -h, --host <host>              ssh server address
  -p, --port <port>              ssh server port (default: "22")
  -u, --username <username>      ssh server username
  -w, --password <password>      ssh server password
  -k, --privateKey <privateKey>  ssh private key path
  -c, --config <config>          config file path
  --help                         display help for command
Enter fullscreen mode Exit fullscreen mode

4. Deploy

deploy
Enter fullscreen mode Exit fullscreen mode

useage:

Usage: deploy [options] [command]

CLI for deploy project to server

Options:
  -V, --version            output the version number
  -c, --config             config file path
  -h, --help               display help for command

Commands:
  init|generate [options]  init(generate) deploy config file
  connect [options]        test the connection to server
  backup [options]         backup remote project from server to local
  clean [options]          clean server directory
  upload [options]         upload local project dist to ssh server
Enter fullscreen mode Exit fullscreen mode

you can add scripts to package.json

  "scripts": {
    "deploy": "deploy",
  },
Enter fullscreen mode Exit fullscreen mode

then, use npm run deploy

5. Other commands

deploy view config
Enter fullscreen mode Exit fullscreen mode

useage:

Usage: deploy view [options] <config>

view deploy config file info

Options:
  -c, --config <config>  config file path
  -h, --help             display help for command
Enter fullscreen mode Exit fullscreen mode

Top comments (0)