neon-cli
Version:
Build and load native Rust/Neon modules.
93 lines (92 loc) • 3.07 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const build_settings_1 = __importDefault(require("./build-settings"));
const fs_1 = require("fs");
const JSON = __importStar(require("ts-typed-json"));
/**
* The current state of build artifacts, for all targets.
*/
class Artifacts {
constructor(active = null, targets = {}) {
this.active = active;
this.targets = targets;
}
static load(file) {
try {
return Artifacts.fromJSON(JSON.loadSync(file));
}
catch (e) {
return new Artifacts();
}
}
static fromJSON(json) {
json = JSON.asObject(json, "json");
const active = json.active;
if (typeof active !== "string" && active !== null) {
throw new TypeError("json.active is not a string or null");
}
const jsonTargets = JSON.asObject(json.targets, "json.targets");
let targets = {};
for (let key of Object.keys(jsonTargets)) {
targets[key] = build_settings_1.default.fromJSON(jsonTargets[key]);
}
return new Artifacts(active, targets);
}
toJSON() {
let targets = {};
for (let target of Object.keys(this.targets)) {
targets[target] = this.targets[target].toJSON();
}
return {
active: this.active,
targets: targets,
};
}
save(file) {
(0, fs_1.writeFileSync)(file, JSON.stringify(this.toJSON()));
}
lookup(path) {
return this.targets[path];
}
activate(path, settings) {
this.targets[path] = settings;
this.active = path;
}
haveActivated(path) {
return this.active === path;
}
delete(path) {
delete this.targets[path];
// If the path being deleted was the active one, there's no more active path.
if (this.active === path) {
this.active = null;
}
}
reset() {
this.active = null;
this.targets = {};
}
}
exports.default = Artifacts;
;