msync
Version:
Easily manage building and syncing multiple node-modules in a flexibly defined workspace.
55 lines (54 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SaveUtil = void 0;
var tslib_1 = require("tslib");
var libs_1 = require("./libs");
exports.SaveUtil = {
formatSavePath: function (input) {
if (!input)
return undefined;
if (input === true)
return 'msync.list.json';
if (typeof input === 'string') {
var text = (input || '')
.toString()
.trim()
.replace(/^\/*/, '')
.replace(/\.json$/, '');
return "".concat(text, ".json");
}
return undefined;
},
toJson: function (modules) {
var timestamp = libs_1.time.now.timestamp;
var json = {
timestamp: timestamp,
order: 'DepthFirst',
modules: modules.map(function (module) {
var _a;
var name = module.name, version = module.version, dir = module.dir;
var latest = (_a = module.npm) === null || _a === void 0 ? void 0 : _a.latest;
var npm = latest ? { version: latest } : undefined;
return { dir: dir, name: name, version: version, npm: npm };
}),
};
return json;
},
write: function (path, modules) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var obj, json;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
path = libs_1.fs.resolve(path);
obj = exports.SaveUtil.toJson(modules);
json = "".concat(JSON.stringify(obj, null, ' '), "\n");
return [4, libs_1.fs.writeFile(path, json)];
case 1:
_a.sent();
return [2];
}
});
});
},
};