theme-utils.mjs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. import { spawn } from 'child_process';
  2. import fs from 'fs';
  3. import open from 'open';
  4. import inquirer from 'inquirer';
  5. import replace from 'replace-in-file';
  6. const remoteSSH = 'wpcom-sandbox';
  7. const sandboxPublicThemesFolder = '/home/wpdev/public_html/wp-content/themes/pub';
  8. const sandboxRootFolder = '/home/wpdev/public_html/';
  9. const isWin = process.platform === 'win32';
  10. (async function start() {
  11. let args = process.argv.slice(2);
  12. let command = args?.[0];
  13. switch (command) {
  14. case "push-button-deploy-git": return pushButtonDeploy('git');
  15. case "push-button-deploy-svn": return pushButtonDeploy('svn');
  16. case "clean-sandbox-git": return cleanSandboxGit();
  17. case "clean-sandbox-svn": return cleanSandboxSvn();
  18. case "clean-all-sandbox-git": return cleanAllSandboxGit();
  19. case "clean-all-sandbox-svn": return cleanAllSandboxSvn();
  20. case "push-to-sandbox": return pushToSandbox();
  21. case "push-changes-to-sandbox": return pushChangesToSandbox();
  22. case "land-diff-git": return landChangesGit(args?.[1]);
  23. case "land-diff-svn": return landChangesSvn(args?.[1]);
  24. case "deploy-preview": return deployPreview();
  25. case "deploy-theme": return deployThemes([args?.[1]]);
  26. case "build-com-zip": return buildComZip([args?.[1]]);
  27. case "version-bump-stylecss": return versionBumpStyleCss();
  28. }
  29. return showHelp();
  30. })();
  31. function showHelp(){
  32. // TODO: make this helpful
  33. console.log('Help info can go here');
  34. }
  35. /*
  36. Update version number in style.css and style-child-theme.css for each theme
  37. after version bump from conventional commits (via Lerna)
  38. Used by Lerna via update-stylecss command
  39. */
  40. async function versionBumpStyleCss() {
  41. let packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
  42. let newVersion = packageJson.version;
  43. let styleCss = fs.existsSync('./style.css') ? './style.css' : '';
  44. let styleChildThemeCss = fs.existsSync('./style-child-theme.css') ? './style-child-theme.css' : '';
  45. let files = [styleCss, styleChildThemeCss].filter(Boolean);
  46. await replace({
  47. files,
  48. from: /(?<=Version:\s*).*?(?=\s*\r?\n|\rg)/gs,
  49. to: ` ${newVersion}`,
  50. });
  51. }
  52. /*
  53. Determine what changes would be deployed
  54. */
  55. async function deployPreview() {
  56. console.clear();
  57. console.log('To ensure accuracy clean your sandbox before previewing. (It is not automatically done).');
  58. console.log('npm run sandbox:clean:git OR npm run sandbox:clean:svn')
  59. let message = await checkForDeployability();
  60. if (message) {
  61. console.log(`\n${message}\n\n`);
  62. }
  63. let hash = await getLastDeployedHash();
  64. console.log(`Last deployed hash: ${hash}`);
  65. let changedThemes = await getChangedThemes(hash);
  66. console.log(`The following themes have changes:\n${changedThemes}`);
  67. let logs = await executeCommand(`git log --reverse --pretty=format:%s ${hash}..HEAD`);
  68. console.log(`\n\nCommit log of changes to be deployed:\n\n${logs}\n\n`);
  69. }
  70. /*
  71. Execute the first phase of a deployment.
  72. Leverages git on the sandbox.
  73. * Gets the last deployed hash from the sandbox
  74. * Version bump all themes have have changes since the last deployment
  75. * Commit the version bump change to github
  76. * Clean the sandbox and ensure it is up-to-date
  77. * Push all changed files (including removal of deleted files) since the last deployment
  78. * Update the 'last deployed' hash on the sandbox
  79. * Create a phabricator diff based on the changes since the last deployment. The description including the commit messages since the last deployment.
  80. * Open the Phabricator Diff in your browser
  81. * Create a tag in the github repository at this point of change which includes the phabricator link in the description
  82. */
  83. async function pushButtonDeploy(repoType) {
  84. console.clear();
  85. let prompt = await inquirer.prompt([{
  86. type: 'confirm',
  87. message: 'You are about to deploy /trunk. Are you ready to continue?',
  88. name: "continue",
  89. default: false
  90. }]);
  91. if(!prompt.continue){
  92. return;
  93. }
  94. if (repoType != 'svn' && repoType != 'git' ) {
  95. return console.log('Specify a repo type to use push-button deploy');
  96. }
  97. let message = await checkForDeployability();
  98. if (message) {
  99. return console.log(`\n\n${message}\n\n`);
  100. }
  101. try {
  102. if (repoType === 'git' ) {
  103. await cleanSandboxGit();
  104. }
  105. else {
  106. await cleanSandboxSvn();
  107. }
  108. let hash = await getLastDeployedHash();
  109. let diffUrl;
  110. let changedThemes = await getChangedThemes(hash);
  111. await pushChangesToSandbox();
  112. await updateLastDeployedHash();
  113. if (repoType === 'git' ) {
  114. diffUrl = await createGitPhabricatorDiff(hash);
  115. }
  116. else {
  117. diffUrl = await createSvnPhabricatorDiff(hash);
  118. }
  119. let diffId = diffUrl.split('a8c.com/')[1];
  120. await tagDeployment({
  121. hash: hash,
  122. diffId: diffId
  123. });
  124. console.log(`\n\nPhase One Complete\n\nYour sandbox has been updated and the diff is available for review.\nPlease give your sandbox a smoke test to determine that the changes work as expected.\nThe following themes have had changes: \n\n${changedThemes.join(' ')}\n\n\n`);
  125. prompt = await inquirer.prompt([{
  126. type: 'confirm',
  127. message: 'Are you ready to land these changes?',
  128. name: "continue",
  129. default: false
  130. }]);
  131. if(!prompt.continue){
  132. console.log(`Aborted Automated Deploy Process Landing Phase\n\nYou will have to land these changes manually. The ID of the diff to land: ${diffId}` );
  133. return;
  134. }
  135. if (repoType === 'git' ) {
  136. await landChangesGit(diffId);
  137. }
  138. else {
  139. await landChangesSvn(diffId);
  140. }
  141. await deployThemes(changedThemes);
  142. await buildComZips(changedThemes);
  143. console.log(`The following themes have changed:\n${changedThemes.join('\n')}`)
  144. console.log('\n\nAll Done!!\n\n');
  145. }
  146. catch (err) {
  147. console.log("ERROR with deply script: ", err);
  148. }
  149. }
  150. /*
  151. Build .zip file for .com
  152. */
  153. async function buildComZip(themeSlug) {
  154. console.log( `Building ${themeSlug} .zip` );
  155. let styleCss = fs.readFileSync(`${themeSlug}/style.css`, 'utf8');
  156. // Gets the theme version (Version:) and minimum WP version (Tested up to:) from the theme's style.css
  157. let themeVersion = getThemeMetadata(styleCss, 'Version');
  158. let wpVersionCompat = getThemeMetadata(styleCss, 'Tested up to');
  159. if (themeVersion && wpVersionCompat) {
  160. await executeOnSandbox(`php ${sandboxRootFolder}bin/themes/theme-downloads/build-theme-zip.php --stylesheet=pub/${themeSlug} --themeversion=${themeVersion} --wpversioncompat=${wpVersionCompat}`, true);
  161. }
  162. else {
  163. console.log('Unable to build theme .zip.');
  164. if (!themeVersion) {
  165. console.log('Could not find theme version (Version:) in the theme style.css.');
  166. }
  167. if (!wpVersionCompat) {
  168. console.log('Could not find WP compat version (Tested up to:) in the theme style.css.');
  169. }
  170. console.log('Please build the .zip file for the theme manually.', themeSlug);
  171. open('https://mc.a8c.com/themes/downloads/');
  172. }
  173. }
  174. async function buildComZips(themes) {
  175. for ( let theme of themes ) {
  176. await buildComZip(theme);
  177. }
  178. }
  179. /*
  180. Check to ensure that:
  181. * The current branch is /trunk
  182. * That trunk is up-to-date with origin/trunk
  183. */
  184. async function checkForDeployability(){
  185. let branchName = await executeCommand('git symbolic-ref --short HEAD');
  186. if(branchName !== 'trunk' ) {
  187. return 'Only the /trunk branch can be deployed.';
  188. }
  189. await executeCommand('git remote update', true);
  190. let localMasterHash = await executeCommand('git rev-parse trunk')
  191. let remoteMasterHash = await executeCommand('git rev-parse origin/trunk')
  192. if(localMasterHash !== remoteMasterHash) {
  193. return 'Local /trunk is out-of-date. Pull changes to continue.'
  194. }
  195. return null;
  196. }
  197. /*
  198. Land the changes from the given diff ID. This is the "production merge".
  199. This is the git version of that action.
  200. */
  201. async function landChangesGit(diffId){
  202. return await executeOnSandbox(`cd ${sandboxPublicThemesFolder};arc patch ${diffId};arc land;exit;`, true, true);
  203. }
  204. /*
  205. Land the changes from the given diff ID. This is the "production merge".
  206. This is the svn version of that action.
  207. */
  208. async function landChangesSvn(diffId){
  209. return await executeOnSandbox(`
  210. cd ${sandboxPublicThemesFolder};
  211. svn ci -m ${diffId}
  212. `, true );
  213. }
  214. async function getChangedThemes(hash) {
  215. console.log('Determining all changed themes');
  216. let themes = await getActionableThemes();
  217. let changedThemes = [];
  218. for (let theme of themes) {
  219. let hasChanges = await checkThemeForChanges(theme, hash);
  220. if(hasChanges){
  221. changedThemes.push(theme);
  222. }
  223. }
  224. return changedThemes;
  225. }
  226. /*
  227. Deploy a collection of themes.
  228. Part of the push-button-deploy process.
  229. Can also be triggered to deploy a single theme with the command:
  230. node ./theme-utils.mjs deploy-theme THEMENAME
  231. */
  232. async function deployThemes( themes ) {
  233. let response;
  234. for ( let theme of themes ) {
  235. console.log( `Deploying ${theme}` );
  236. let deploySuccess = false;
  237. let attempt = 0;
  238. while ( ! deploySuccess) {
  239. attempt++;
  240. console.log(`\nattempt #${attempt}\n\n`);
  241. response = await executeOnSandbox( `deploy pub ${theme};exit;`, true, true );
  242. deploySuccess = response.includes( 'successfully deployed to' );
  243. if( ! deploySuccess ) {
  244. console.log( 'Deploy was not successful. Trying again in 10 seconds...' );
  245. await new Promise(resolve => setTimeout(resolve, 10000));
  246. }
  247. else {
  248. console.log( "Deploy successful." );
  249. }
  250. }
  251. }
  252. }
  253. /*
  254. Provide the hash of the last managed deployment.
  255. This hash is used to determine all the changes that have happened between that point and the current point.
  256. */
  257. async function getLastDeployedHash() {
  258. let result = await executeOnSandbox(`
  259. cat ${sandboxPublicThemesFolder}/.pub-git-hash
  260. `);
  261. return result;
  262. }
  263. /*
  264. Update the 'last deployed hash' on the server with the current hash.
  265. */
  266. async function updateLastDeployedHash() {
  267. let hash = await executeCommand(`git rev-parse HEAD`);
  268. await executeOnSandbox(`
  269. echo '${hash}' > ${sandboxPublicThemesFolder}/.pub-git-hash
  270. `);
  271. }
  272. function getThemeMetadata(styleCss, attribute) {
  273. if ( !styleCss || !attribute ) {
  274. return null;
  275. }
  276. switch ( attribute ) {
  277. case 'Version':
  278. return styleCss
  279. .match(/(?<=Version:\s*).*?(?=\s*\r?\n|\rg)/gs)[0]
  280. .trim()
  281. .replace('-wpcom', '');
  282. case 'Tested up to':
  283. return styleCss
  284. .match(/(?<=Tested up to:\s*).*?(?=\s*\r?\n|\rg)/gs);
  285. }
  286. }
  287. /*
  288. Provide a list of 'actionable' themes (those themes that have style.css files)
  289. */
  290. async function getActionableThemes() {
  291. let result = await executeCommand(`for d in */; do
  292. if test -f "./$d/style.css"; then
  293. echo $d;
  294. fi
  295. done`);
  296. return result
  297. .split('\n')
  298. .map(item=>item.replace('/', ''));
  299. }
  300. /*
  301. Clean the theme sandbox.
  302. Assumes sandbox is in 'git' mode
  303. checkout origin/develop and ensure it's up-to-date.
  304. Remove any other changes.
  305. */
  306. async function cleanSandboxGit() {
  307. console.log('Cleaning the Themes Sandbox');
  308. await executeOnSandbox(`
  309. cd ${sandboxPublicThemesFolder};
  310. git reset --hard HEAD;
  311. git clean -fd;
  312. git checkout develop;
  313. git pull;
  314. echo;
  315. git status
  316. `, true);
  317. console.log('All done cleaning.');
  318. }
  319. /*
  320. Clean the entire sandbox.
  321. Assumes sandbox is in 'git' mode
  322. checkout origin/develop and ensure it's up-to-date.
  323. Remove any other changes.
  324. */
  325. async function cleanAllSandboxGit() {
  326. console.log('Cleaning the Entire Sandbox');
  327. let response = await executeOnSandbox(`
  328. cd ${sandboxRootFolder};
  329. git reset --hard HEAD;
  330. git clean -fd;
  331. git checkout develop;
  332. git pull;
  333. echo;
  334. git status
  335. `, true);
  336. console.log('All done cleaning.');
  337. }
  338. /*
  339. Clean the theme sandbox.
  340. Assumes sandbox is in 'svn' mode
  341. ensure trunk is up-to-date
  342. Remove any other changes
  343. */
  344. async function cleanSandboxSvn() {
  345. console.log('Cleaning the theme sandbox');
  346. await executeOnSandbox(`
  347. cd ${sandboxPublicThemesFolder};
  348. svn revert -R .;
  349. svn cleanup --remove-unversioned;
  350. svn up;
  351. `, true);
  352. console.log('All done cleaning.');
  353. }
  354. /*
  355. Clean the entire sandbox.
  356. Assumes sandbox is in 'svn' mode
  357. ensure trunk is up-to-date
  358. Remove any other changes
  359. */
  360. async function cleanAllSandboxSvn() {
  361. console.log('Cleaning the entire sandbox');
  362. await executeOnSandbox(`
  363. cd ${sandboxRootFolder};
  364. svn revert -R .;
  365. svn cleanup --remove-unversioned;
  366. svn up .;
  367. `, true);
  368. console.log('All done cleaning.');
  369. }
  370. /*
  371. Push exactly what is here (all files) up to the sandbox (with the exclusion of files noted in .sandbox-ignore)
  372. */
  373. function pushToSandbox() {
  374. executeCommand(`
  375. rsync -av --no-p --no-times --exclude-from='.sandbox-ignore' ./ wpcom-sandbox:${sandboxPublicThemesFolder}/
  376. `);
  377. }
  378. /*
  379. Push only (and every) change since the point-of-diversion from /trunk
  380. Remove files from the sandbox that have been removed since the last deployed hash
  381. */
  382. async function pushChangesToSandbox() {
  383. console.log("Pushing Changes to Sandbox.");
  384. let hash = await getLastDeployedHash();
  385. let deletedFiles = await getDeletedFilesSince(hash);
  386. let changedFiles = await getComittedChangesSinceHash(hash);
  387. //remove deleted files from changed files
  388. changedFiles = changedFiles.filter( item => {
  389. return false === deletedFiles.includes(item);
  390. });
  391. if(deletedFiles.length > 0) {
  392. console.log('deleting from sandbox: ', deletedFiles);
  393. await executeOnSandbox(`
  394. cd ${sandboxPublicThemesFolder};
  395. rm -f ${deletedFiles.join(' ')}
  396. `, true);
  397. }
  398. if(changedFiles.length > 0) {
  399. console.log('pushing changed files to sandbox:', changedFiles);
  400. await executeCommand(`
  401. rsync -avR --no-p --no-times --exclude-from='.sandbox-ignore' ${changedFiles.join(' ')} wpcom-sandbox:${sandboxPublicThemesFolder}/
  402. `, true);
  403. }
  404. }
  405. /*
  406. Provide a collection of all files that have changed since the given hash.
  407. Used by pushChangesToSandbox
  408. */
  409. async function getComittedChangesSinceHash(hash) {
  410. let comittedChanges = await executeCommand(`git diff ${hash} HEAD --name-only`);
  411. comittedChanges = comittedChanges.replace(/\r?\n|\r/g, " ").split(" ");
  412. let uncomittedChanges = await executeCommand(`git diff HEAD --name-only`);
  413. uncomittedChanges = uncomittedChanges.replace(/\r?\n|\r/g, " ").split(" ");
  414. return comittedChanges.concat(uncomittedChanges);
  415. }
  416. /*
  417. Provide a collection of all files that have been deleted since the given hash.
  418. Used by pushChangesToSandbox
  419. */
  420. async function getDeletedFilesSince(hash){
  421. let deletedSinceHash = await executeCommand(`
  422. git log --format=format:"" --name-only -M100% --diff-filter=D ${hash}..HEAD
  423. `);
  424. deletedSinceHash = deletedSinceHash.replace(/\r?\n|\r/g, " ").trim().split(" ");
  425. let deletedAndUncomitted = await executeCommand(`
  426. git diff HEAD --name-only --diff-filter=D
  427. `);
  428. deletedAndUncomitted = deletedAndUncomitted.replace(/\r?\n|\r/g, " ").trim().split(" ");
  429. return deletedSinceHash.concat(deletedAndUncomitted).filter( item => {
  430. return item != '';
  431. });
  432. }
  433. /*
  434. Build the Phabricator commit message.
  435. This message contains the logs from all of the commits since the given hash.
  436. Used by create*PhabricatorDiff
  437. */
  438. async function buildPhabricatorCommitMessageSince(hash){
  439. let projectVersion = await executeCommand(`node -p "require('./package.json').version"`);
  440. let logs = await executeCommand(`git log --reverse --pretty=format:%s ${hash}..HEAD`);
  441. return `Deploy Themes ${projectVersion} to wpcom
  442. Summary:
  443. ${logs}
  444. Test Plan: Execute Smoke Test
  445. Reviewers:
  446. Subscribers:
  447. `;
  448. }
  449. /*
  450. Create a (git) Phabricator diff from a given hash.
  451. Open the phabricator diff in your browser.
  452. Provide the URL of the phabricator diff.
  453. */
  454. async function createGitPhabricatorDiff(hash) {
  455. console.log('creating Phabricator Diff');
  456. let commitMessage = await buildPhabricatorCommitMessageSince(hash);
  457. let result = await executeOnSandbox(`
  458. cd ${sandboxPublicThemesFolder};
  459. git branch -D deploy
  460. git checkout -b deploy
  461. git add --all
  462. git commit -m "${commitMessage}"
  463. arc diff --create --verbatim
  464. `, true);
  465. let phabricatorUrl = getPhabricatorUrlFromResponse(result);
  466. console.log('Diff Created at: ', phabricatorUrl);
  467. if(phabricatorUrl) {
  468. open(phabricatorUrl);
  469. }
  470. return phabricatorUrl;
  471. }
  472. /*
  473. Create a (svn) Phabricator diff from a given hash.
  474. Open the phabricator diff in your browser.
  475. Provide the URL of the phabricator diff.
  476. */
  477. async function createSvnPhabricatorDiff(hash) {
  478. console.log('creating Phabricator Diff');
  479. const commitTempFileLocation = '/tmp/theme-deploy-comment.txt';
  480. const commitMessage = await buildPhabricatorCommitMessageSince(hash);
  481. console.log(commitMessage);
  482. const result = await executeOnSandbox(`
  483. cd ${sandboxPublicThemesFolder};
  484. echo "${commitMessage}" > ${commitTempFileLocation};
  485. svn add --force * --auto-props --parents --depth infinity -q;
  486. svn status | grep "^\!" | sed 's/^\! *//g' | xargs svn rm;
  487. arc diff --create --message-file ${commitTempFileLocation}
  488. `, true);
  489. const phabricatorUrl = getPhabricatorUrlFromResponse(result);
  490. console.log('Diff Created at: ', phabricatorUrl);
  491. if(phabricatorUrl) {
  492. open(phabricatorUrl);
  493. }
  494. return phabricatorUrl;
  495. }
  496. /*
  497. Utility to pull the Phabricator URL from the diff creation command.
  498. Used by createGitPhabricatorDiff
  499. */
  500. function getPhabricatorUrlFromResponse(response){
  501. return response
  502. ?.split('\n')
  503. ?.find( item => {
  504. return item.includes('Revision URI: ');
  505. })
  506. ?.split("Revision URI: ")[1];
  507. }
  508. /*
  509. Create a git tag at the current hash.
  510. In the description include the commit logs since the given hash.
  511. Include the (cleansed) Phabricator link.
  512. */
  513. async function tagDeployment(options={}) {
  514. let hash = options.hash || await getLastDeployedHash();
  515. let workInTheOpenPhabricatorUrl = '';
  516. if (options.diffId) {
  517. workInTheOpenPhabricatorUrl = `Phabricator: ${options.diffId}-code`;
  518. }
  519. let projectVersion = await executeCommand(`node -p "require('./package.json').version"`);
  520. let logs = await executeCommand(`git log --reverse --pretty=format:%s ${hash}..HEAD`);
  521. let tag = `v${projectVersion}`;
  522. let message = `Deploy Themes ${tag} to wpcom. \n\n${logs} \n\n${workInTheOpenPhabricatorUrl}`;
  523. await executeCommand(`
  524. git tag -a ${tag} -m "${message}"
  525. git push origin ${tag}
  526. `);
  527. }
  528. /*
  529. Execute a command on the sandbox.
  530. Expects the following to be configured in your ~/.ssh/config file:
  531. Host wpcom-sandbox
  532. User wpdev
  533. HostName SANDBOXURL.wordpress.com
  534. ForwardAgent yes
  535. */
  536. function executeOnSandbox(command, logResponse, enablePsudoterminal){
  537. if(enablePsudoterminal){
  538. return executeCommand(`ssh -tt -A ${remoteSSH} << EOF
  539. ${command}
  540. EOF`, logResponse);
  541. }
  542. return executeCommand(`ssh -TA ${remoteSSH} << EOF
  543. ${command}
  544. EOF`, logResponse);
  545. }
  546. /*
  547. Execute a command locally.
  548. */
  549. async function executeCommand(command, logResponse) {
  550. return new Promise((resolove, reject) => {
  551. let child;
  552. let response = '';
  553. let errResponse = '';
  554. if (isWin) {
  555. child = spawn('cmd.exe', ['/s', '/c', '"' + command + '"'], {
  556. windowsVerbatimArguments: true,
  557. stdio: [process.stdin, 'pipe', 'pipe'],
  558. })
  559. } else {
  560. child = spawn(process.env.SHELL, ['-c', command]);
  561. }
  562. child.stdout.on('data', (data) => {
  563. response += data;
  564. if(logResponse){
  565. console.log(data.toString());
  566. }
  567. });
  568. child.stderr.on('data', (data) => {
  569. errResponse += data;
  570. if(logResponse){
  571. console.log(data.toString());
  572. }
  573. });
  574. child.on('exit', (code) => {
  575. if (code !== 0) {
  576. reject(errResponse.trim());
  577. }
  578. resolove(response.trim());
  579. });
  580. });
  581. }