Skip to content

Commit

Permalink
refactor: extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinFay committed May 28, 2024
1 parent a110d20 commit c91e6b1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ const fs = require("fs");
const { installOnePackage } = require('./install-utils');
const { create_mount_folder_init_webr } = require('./config-utils.js');

const append_package_json = function (package_to_add){
const package_json_path = process.cwd() + "/package.json";
// append package.json with package_to_install
if (fs.existsSync(package_json_path)) {
const package_json = JSON.parse(fs.readFileSync(package_json_path));

if (!package_json.rdependencies) {
package_json.rdependencies = [];
}

package_json.rdependencies.push(package_to_add);
package_json.rdependencies = [...new Set(package_json.rdependencies)]
fs.writeFileSync(package_json_path, JSON.stringify(package_json, null, 2));
} else {
console.log("❗️ No package.json file found");
}
}

const installIt = async function (
package_to_install,
destination_folder
Expand Down Expand Up @@ -44,6 +62,8 @@ const installIt = async function (
)
}

append_package_json(package_to_install)

await webR.close();

return true
Expand All @@ -53,7 +73,7 @@ const installFromDesc = async function (
description_file,
destination_folder,
with_exit = true
){
) {

const webR = new WebR();

Expand Down

0 comments on commit c91e6b1

Please sign in to comment.