typescript-assistant
Version:
Combines and integrates professional Typescript tools into your project
43 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const path = require("path");
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);
};
let escapeSpaces = (filePath) => {
let escapeSequence = (path.sep === '/') ? '\\ ' : '^ ';
return filePath.replace(/ /g, escapeSequence);
};
exports.npmInstall = () => {
let scriptPath = `${process.cwd()}/build/npm-install.js`;
let currentDir = process.cwd().replace(/\\/g, '\\\\');
fs_1.writeFileSync(scriptPath, `
const child_process = require('child_process');
try {
child_process.execSync('npm install', { cwd: '${currentDir}', encoding: 'UTF-8', stdio: [0, 1, 2] });
child_process.execSync('npm dedupe', { cwd: '${currentDir}', encoding: 'UTF-8', stdio: [0, 1, 2] });
} catch (e) {
console.error('npm install failed', e);
console.log('Press enter to continue');
process.stdin.once('data', function(){
process.exit(1);
});
}
`);
let install = child_process_1.spawn('node', [escapeSpaces(scriptPath)], { stdio: 'ignore', shell: true, detached: true });
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