UNPKG

intreface.cli

Version:

Intreface Dev Tools

67 lines (66 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getBitrixLockedProject = exports.unLockBitrix = exports.lockBitrix = exports.getBitrixLicenseKey = void 0; const axios_1 = require("axios"); const path = require("path"); const io_1 = require("./io"); const fs = require("fs"); const slash = require('slash'); exports.getBitrixLicenseKey = async () => { const params = new URLSearchParams(); params.append('first_name', 'Intreface'); params.append('sur_name', 'Trial'); params.append('email', 'trial@intreface.com'); params.append('site', 'localhost'); params.append('lang', 'en'); params.append('bx', 'Y'); params.append('edition', 'intranet_ent'); let response = await axios_1.default.post('https://www.bitrixsoft.com/bsm_register_key.php', params, { headers: { "user-agent": "bitrixKeyReq" } }); return response.data.split("\n")[1].replace(/\r/g, ''); }; const getBitrixLock = (strict = false) => { const pathPartList = slash(process.cwd()).split('/'); let loopData = [...pathPartList]; while (loopData.length > 0) { let lockPath = path.join(loopData.join('/'), '.project.lock'); if (io_1.isFileExist(lockPath)) { return lockPath; } loopData.pop(); } if (strict) { return false; } loopData = [...pathPartList]; while (loopData.length > 0) { let directoryName = loopData[loopData.length - 1]; if (directoryName.toLowerCase() == 'www') { return path.join(loopData.join('/'), '.project.lock'); } loopData.pop(); } return false; }; exports.lockBitrix = (projectName) => { const lockPath = getBitrixLock(); let isLocked = false; if (lockPath !== false) { fs.writeFileSync(lockPath, projectName, { flag: 'w', encoding: 'utf8' }); isLocked = true; } return isLocked; }; exports.unLockBitrix = () => { const lockPath = getBitrixLock(true); if (lockPath !== false) { fs.unlinkSync(lockPath); } return true; }; exports.getBitrixLockedProject = () => { const lockPath = getBitrixLock(true); if (lockPath !== false) { return fs.readFileSync(lockPath, 'utf-8'); } return false; };