e1c-repo-tools
Version:
Tools for 1C enterprise repository
65 lines (64 loc) • 3.06 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDirStatus = exports.stageDir = exports.getStagedFiles = exports.revParse = void 0;
const path_1 = __importDefault(require("path"));
const process_1 = require("process");
const console_operations_1 = require("./console-operations");
const gitErrorCallback = async (result) => {
const errorMessage = result.split('\n')
.map((str) => str.trim())
.filter((str) => str.length > 0)[0];
return errorMessage;
};
const revParse = async (revision = 'HEAD', workDir = '') => {
const spawnOptions = workDir.length === 0 ? undefined : { 'cwd': workDir };
let hash = '';
await console_operations_1.performOsTask('git', ['rev-parse', '--verify', revision], 'Git: rev-parse', spawnOptions, async (result) => {
hash = result.split('\n')
.map((str) => str.trim())
.filter((str) => str.length > 0)
.pop() || '';
return hash;
}, gitErrorCallback);
return hash;
};
exports.revParse = revParse;
const getStagedFiles = async (workDir = '') => {
const spawnOptions = workDir.length === 0 ? undefined : { 'cwd': workDir };
const hash = await exports.revParse();
const diffParams = ['--cached', '--name-only', '--diff-filter=AM'];
if (hash) {
diffParams.push(hash);
}
let files = [];
await console_operations_1.performOsTask('git', ['diff', ...diffParams], 'Git: diff', spawnOptions, async (result) => {
files = result.split('\n')
.map((str) => str.trim())
.filter((str) => str.length > 0);
return files.length.toString();
}, gitErrorCallback);
return files;
};
exports.getStagedFiles = getStagedFiles;
const stageDir = async (pathToDir, workDir = '') => {
const spawnOptions = workDir.length === 0 ? undefined : { 'cwd': workDir };
const relPathToDir = path_1.default.relative(workDir.length === 0 ? process_1.cwd() : workDir, pathToDir);
await console_operations_1.performOsTask('git', ['add', pathToDir], `Git: add new files '${relPathToDir}'`, spawnOptions, undefined, gitErrorCallback);
};
exports.stageDir = stageDir;
const getDirStatus = async (pathToDir, workDir = '') => {
const spawnOptions = workDir.length === 0 ? undefined : { 'cwd': workDir };
const relPathToDir = path_1.default.relative(workDir.length === 0 ? process_1.cwd() : workDir, pathToDir);
let files = [];
await console_operations_1.performOsTask('git', ['status', '--porcelain', '-uall', pathToDir], `Git: status '${relPathToDir}'`, spawnOptions, async (result) => {
files = result.split('\n')
.map((str) => str.trim())
.filter((str) => str.length > 0);
return files.length.toString();
}, gitErrorCallback);
return files;
};
exports.getDirStatus = getDirStatus;