Skip to content

Commit

Permalink
Merge pull request #114 from reactioncommerce/fix/clone-plugins-monorepo
Browse files Browse the repository at this point in the history
fix: get plugins.json from correct url
  • Loading branch information
brent-hoover authored Sep 24, 2022
2 parents b1fea5c + 767815d commit c62495b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
9 changes: 4 additions & 5 deletions commands/clone-api-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ import fs from "fs";
import inquirer from "inquirer";
import isProjectOfType from "../utils/isProjectOfType.js";
import Logger from "../utils/logger.js";
import wget from "../utils/wget.js";
import getFileFromCore from "../utils/getFileFromCore.js";

/**
* @summary Get and parse local plugins.json file
* @returns {Object} - return the local plugins.json as object
*/
async function getRemotePluginsJson() {
const remotePackageJsonUrl = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/plugins.json";
try {
const pluginsJson = await wget(remotePackageJsonUrl);
const pluginsJson = await getFileFromCore("plugins.json");

try {
return JSON.parse(pluginsJson);
} catch (error) {
Logger.error("Unable to get local plugins.json");
Logger.error("Unable to parse remote plugins.json");
Logger.error(error);
throw error;
}
Expand Down
26 changes: 4 additions & 22 deletions commands/create-project-api.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { mkdir, writeFile } from "fs/promises";
import { parse, stringify } from "envfile";
import simpleGit from "simple-git";
import wget from "../utils/wget.js";
import getFilesFromRepo from "../utils/getFilesFromRepo.js";
import pathExists from "../utils/pathExists.js";
import Logger from "../utils/logger.js";


const reactionAppRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/apps/reaction";
const reactionRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/";
import getFileFromCore, { reactionRoot } from "../utils/getFileFromCore.js";

/**
* @summary create project directory
Expand All @@ -29,8 +25,7 @@ async function makeProject(projectName) {
async function getNodeMonVersionFromRoot() {
const rootPackage = await getFileFromCore("package.json", reactionRoot);
const packageData = JSON.parse(rootPackage);
const nodeMon = packageData.devDependencies.nodemon;
return nodeMon;
return packageData.devDependencies.nodemon;
}


Expand Down Expand Up @@ -64,22 +59,10 @@ async function updatePackageJson(packageJson, projectName) {
delete packageData.bugs;
packageData.main = "./index.js";
packageData.nodemonConfig.watch.push("custom-packages");
const nodemon = await getNodeMonVersionFromRoot();
packageData.devDependencies.nodemon = nodemon;
packageData.devDependencies.nodemon = await getNodeMonVersionFromRoot();
return JSON.stringify(packageData, null, 2);
}

/**
* @summary get a single file via HTTP
* @param {String} fileName - The file to get
* @param {String} rootDir - path to root for file
* @returns {Promise<string|*>} The contents of the file
*/
async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
const contents = await wget(`${rootDir}/${fileName}`);
return contents;
}

/**
* @summary update dotenv file to point to local mongo
* @param {String} envData - file extracted from the reaction repo
Expand All @@ -88,8 +71,7 @@ async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
function updateEnv(envData) {
const env = parse(envData);
env.MONGO_URL = "mongodb://localhost:27017/reaction";
const updatedEnv = stringify(env);
return updatedEnv;
return stringify(env);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions utils/getFileFromCore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import wget from "./wget.js";
import Logger from "./logger.js";

export const reactionAppRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/apps/reaction";
export const reactionRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/";

/**
* @summary get a single file via HTTP
* @param {String} fileName - The file to get
* @param {String} rootDir - path to root for file
* @returns {Promise<string|*>} The contents of the file
*/
export default async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
try {
return wget(`${rootDir}/${fileName}`);
} catch (error) {
Logger.error(`Unable to get file from ${rootDir}/${fileName}`);
throw error;
}
}

0 comments on commit c62495b

Please sign in to comment.