@plurid/joiner
Version:
Multi/Mono-Repository Task Runner
100 lines (90 loc) • 4.31 kB
JavaScript
;
var worker_threads = require('worker_threads');
var path = require('path');
var child_process = require('child_process');
var checkUpdates = require('npm-check-updates');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var checkUpdates__default = /*#__PURE__*/_interopDefaultLegacy(checkUpdates);
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
// #endregion external
// #endregion imports
// #region module
const updateExecution = (configPackage, configurationFile) => __awaiter(void 0, void 0, void 0, function* () {
const inThePackage = `in the package '${configPackage.name}'`;
console.log(`\n\tChecking for updates ${inThePackage}...`);
try {
const updatedPackages = yield checkUpdates__default["default"]({
packageFile: path__default["default"].join(configPackage.path, 'package.json'),
silent: true,
jsonUpgraded: true,
upgrade: true,
dep: 'prod,dev',
cache: true,
});
if (!updatedPackages) {
console.log(`\n\tCould not find updates ${inThePackage}...`);
return;
}
if (Object.keys(updatedPackages).length > 0) {
console.log(`\n\t'${configPackage.name}' dependencies updated:\n`);
for (const [key, value] of Object.entries(updatedPackages)) {
console.log(`\t\t${key}: ${value}`);
}
console.log(`\n\tInstalling the updates ${inThePackage}...`);
installCommand(configPackage, configurationFile);
console.log(`\tUpdates installed ${inThePackage}.\n`);
}
else {
console.log(`\n\tNo dependencies updates ${inThePackage}.\n`);
console.log(`\n\tInstalling the dependencies ${inThePackage}...`);
installCommand(configPackage, configurationFile);
console.log(`\tDependencies installed ${inThePackage}.\n`);
}
}
catch (error) {
console.log(`\n\tSomething went wrong.\n`);
}
});
const installCommand = (configPackage, configurationFile) => {
const install = `${configurationFile.package.manager} install`;
child_process.execSync(install, {
cwd: configPackage.path,
stdio: 'ignore',
});
};
// #endregion exports
// #region imports
// #endregion external
// #endregion imports
// #region module
const main = () => {
if (!worker_threads.parentPort) {
return;
}
worker_threads.parentPort.postMessage('Update Worker Started');
updateExecution(worker_threads.workerData.configPackage, worker_threads.workerData.configurationFile);
};
main();
// #endregion module
//# sourceMappingURL=worker-update.js.map