scp2Is a mock implementation of SSH2 using NodeJS, which allows us to push the project to the test environment after compilation for easy testing.
Install SCP2
npm i scp2 -D
Copy the code
Writing a configuration file
Create the scp2 configuration file upload.server.js
Const serInfo = json.parse (process.env.npm_config_argv).cooked // Get terminal command const server = {host: SerInfo [2], / / server IP port: '22', / / port general default username: 22 serInfo [3] | | 'root', / / the user name password: SerInfo [4] | | 'root', / / password pathNmae: "', / / the location of the uploaded to the server locaPath: Const argv1 = process.argv console.log(argv1) console.log(serInfo) // Introduce scp2 const client = Require ('scp2') const ora = require('scp2') const spinner = ora(' scp2') const spinner = ora(' scp2') const spinner = ora(' scp2') ') const Client = require('ssh2').client const conn = new Client() console.log(' establishing connection ') conn.on('ready', () => {console.log(' connected ') if (! Server.pathnmae) {console.log(' connection closed ') conn.end() return false} conn.exec('rm -rf' + server.pathnmae + '/*', (err, Log (err + 'delete file ') stream.on('close', (code, Spinner. Start () client.scp(server.locapath, {'host': server.host, 'port': server.port, 'username': server.username, 'password': server.password, 'path': server.pathNmae }, err => { spinner.stop() if (! Err) {the console. The log (' project done ')} else {the console. The log (' err, err)} conn. End ()})})})}). Connect ({host: Server.host, port: server.port, username: server.username, password: server.password // privateKey: "// privateKey})Copy the code
Configuration package. Json
There are two ways to upload, and I prefer the second one
- Build :pub: One-click package and upload to server
- Build: Package the upload and then run the NPM Run Publish upload server
Practical example
To complete the above configuration, type NPM run build and then NPM Run publish on the terminal.
Has been published to the specified IP know the directory of the server, so that we do not have to upload through the third-party FTP tool oh, is not a lot of convenience, if you think the article is helpful to you, please click a little like it.
One day
The following is the chapter front – end black technology tools oh, greatly improve the front-end development efficiency.
1. Plop, the front end of the black tech chapter, lets you also have your own scaffolding