Simple tools for package release automation:
- Run tests or any other precondition commands
- Update version of package
- Build package release
- Create git commit for version and merge to release branch
- Publish on NPM registry
- Deploy to remote server using SFTP
Add package to your project:
npm install -D @jezvejs/release-toolsIt is recommended to use .env files to store sensitive data.
SFTP_SERVER='<your domain>'
SFTP_USER='<FTP user>'
SFTP_PASSWORD='<FTP password>'
SFTP_PORT=<FTP port>
DEPLOY_PATH='<path to domain directory on server>'
APP_DIR='<application subdirectory inside domain directory>'
SOURCE_DIR='<source directory relative to project root>'
PROJECT_GIT_DIR="<optional git directory for case it is different from project root>"
Create new Node.js script at your project, for example ./scripts/release.js
import { release } from "@jezvejs/release-tools";
if (process.argv.length < 3) {
console.log("Usage: release.js <newversion> [<package>]");
process.exit(1);
}
const MAIN_PACKAGE = "<your package name>";
const newVersion = process.argv[2];
const packageName = process.argv.length > 3 ? process.argv[3] : MAIN_PACKAGE;
const isMainPackage = packageName === MAIN_PACKAGE;
release({
packageName,
isMainPackage,
newVersion,
buildAllCommand: null,
});Add NPM script to package.json:
"scripts": {
...
"release": "node ./scripts/release.js"
}Release with following command:
npm run release patch subpackagepackageName(string, required): name of your project from package.jsonnewVersion(string, required): new version to release according to semverisMainPackage(boolean, default is true): if enabled run commands from 'buildAllCommand' and 'beforeCommit' options after version update stepbeforeVersion(string|string[], default is 'npm run all'): commands to run before version update stepbuildAllCommand(string|string[], default is 'npm run build-all'): commands to run after version update step if 'isMainPackage' option is truebeforeCommit(string|string[], default is null): commands to run after 'buildAllCommand' if 'isMainPackage' option is truecommitCommand(string|string[], default is 'npm run commit-version'): commands to run to create commits/merge branchesdeployCommand(string|string[], default is 'npm run deploy'): commands to upload build results to remote serverpublish(boolean, default is true): if enabled publish new version to NPM registry
import * as dotenv from "dotenv";
import { commitVersion } from "@jezvejs/release-tools";
dotenv.config();
commitVersion({
versionFiles: [
"package-lock.json",
"package.json",
"packages/release-tools/package.json",
],
packageName: "release-tools",
gitDir: process.env.PROJECT_GIT_DIR,
});packageName(string, required): name of your project from package.jsonmainBranch(string|string[], default is 'main'): main branch namereleaseBranch(string|string[], default is 'release'): release branch namegitDir(string): optional git directory for case it is different from project rootversionFiles(string|string[], default is 'release'): array of files to use for version commit
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import * as dotenv from "dotenv";
import { deploy } from "@jezvejs/release-tools";
const filename = fileURLToPath(import.meta.url);
const currentDir = dirname(filename);
dotenv.config();
if (!process.env.SFTP_SERVER) {
process.exit(0);
}
const processRes = await deploy({
clientConfig: {
host: process.env.SFTP_SERVER,
username: process.env.SFTP_USER,
password: process.env.SFTP_PASSWORD,
port: process.env.SFTP_PORT,
},
sourceDir: join(currentDir, "..", "dist"),
destDir: process.env.DEPLOY_PATH,
appDir: process.env.APP_DIR,
});
process.exit(processRes);clientConfig(object, required): configuration forssh2-sftp-clientsourceDir(string, required): source directorydestDir(string, required): destination directoryappDir(string, required): application directorydeployDir(string, default is `${appDir}-deploy`): optional name of upload directorybackupDir(string, default is ` ${appDir}-backup`): optional name of application backup directorycreateDirs(string|string[]): array of directories to create after uploaduploadSymLinks(boolean, default is false): if enabled includes symlinks to uploaduploadSymLinks(boolean, default is true): if enabled upload all filespartialUploadSkipList(string|string[], default is null): optional array of files to skip on partial uploadremoveSkipList(string|string[], default is null): optional array of files to skip on remove excesscleanAll(boolean, default is false): if enabled then remove all excess files in the destination directory on server after uploadextraUpload(string|string[], default is null): optional array of files to upload from alternative locationsextraUploadRoot(string|string[], default is null): optional array of alternative locations to upload files from