UNPKG

typescript-assistant

Version:

Combines and integrates professional Typescript tools into your project

58 lines (55 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const fs_1 = require("fs"); exports.findChangedFiles = (refA, refB) => { if (refA === undefined) { refA = 'HEAD'; } if (refB === undefined) { refB = ''; } let output = child_process_1.execSync(`git diff --name-only --diff-filter=ACMR ${refA} ${refB}`, { encoding: 'utf8' }); return output.split('\n').filter(fileName => fileName.length > 0); }; exports.npmInstall = () => { let scriptPath = `${process.cwd()}/build/npm-install.js`; let currentDir = process.cwd().replace(/\\/g, '\\\\'); fs_1.writeFileSync(scriptPath, ` var fs = require('fs'); var tryNpmInstall = function() { if (fs.existsSync('.git/index.lock')) { return false; } console.log('Updating dependencies, please wait...'); const child_process = require('child_process'); try { try { child_process.execSync('npm install', { encoding: 'UTF-8', stdio: [0, 1, 2] }); } catch (installError) { console.error('Retrying npm install'); child_process.execSync('npm install', { encoding: 'UTF-8', stdio: [0, 1, 2] }); } child_process.execSync('npm dedupe', { encoding: 'UTF-8', stdio: [0, 1, 2] }); } catch (secondError) { console.error('npm install failed'); console.log('Press enter to continue'); process.stdin.once('data', function(){ process.exit(1); }); } process.exit(0); } fs.watch('.git', {persistent: true}, tryNpmInstall); if (!tryNpmInstall()) { console.log('waiting for git before running npm install'); } `); let install = child_process_1.spawn('node', ['./build/npm-install.js'], { stdio: 'ignore', shell: true, detached: true, cwd: currentDir }); install.unref(); }; exports.packageJsonChanged = (refA, refB) => exports.findChangedFiles(refA, refB).filter(f => f.indexOf('package.json') !== -1).length >= 1; exports.filterTsFiles = (files) => { return files.filter(f => f.slice(-3) === '.ts' && f.slice(-5) !== '.d.ts'); }; //# sourceMappingURL=helpers.js.map