@leonardowlopes/bx-cli
Version:
A CLI tool used to configure projects for the Buildbox company.
45 lines • 1.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.packageJson = void 0;
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
class Package {
targetPkg;
constructor() {
this.targetPkg = this.load(node_path_1.default.join(process.cwd(), 'package.json'));
}
load(filePath) {
if (node_fs_1.default.existsSync(filePath)) {
return require(filePath);
}
throw new Error(`package.json file not found at ${filePath}`);
}
save(packageData) {
const targetPkgPath = node_path_1.default.join(process.cwd(), 'package.json');
node_fs_1.default.writeFileSync(targetPkgPath, JSON.stringify(packageData, null, 2));
}
add({ dependencies, devDependencies, scripts, }) {
this.targetPkg.scripts = {
...this.targetPkg.scripts,
...scripts,
};
this.targetPkg.dependencies = {
...this.targetPkg.dependencies,
...dependencies,
};
this.targetPkg.devDependencies = {
...this.targetPkg.devDependencies,
...devDependencies,
};
this.save(this.targetPkg);
}
get() {
return this.targetPkg;
}
}
const packageJson = new Package();
exports.packageJson = packageJson;
//# sourceMappingURL=package.js.map