runok
Version:
NPM scripts on steroids! Replace your scripts with pure JS
22 lines (21 loc) • 516 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Changes directory for commands executed in callback function.
*
* ```js
* // copy file in "base" directory
* chdir('./base', () => copy('a.txt', 'b.txt')));
* ```
*
* @param workDir
* @param callback
*/
async function chdir(workDir, callback) {
const currentDir = process.cwd();
process.chdir(workDir);
let result = await callback();
process.chdir(currentDir);
return result;
}
exports.default = chdir;