Skip to content

Commit c62495b

Browse files
authored
Merge pull request #114 from reactioncommerce/fix/clone-plugins-monorepo
fix: get plugins.json from correct url
2 parents b1fea5c + 767815d commit c62495b

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

commands/clone-api-plugins.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ import fs from "fs";
33
import inquirer from "inquirer";
44
import isProjectOfType from "../utils/isProjectOfType.js";
55
import Logger from "../utils/logger.js";
6-
import wget from "../utils/wget.js";
6+
import getFileFromCore from "../utils/getFileFromCore.js";
77

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

15+
try {
1716
return JSON.parse(pluginsJson);
1817
} catch (error) {
19-
Logger.error("Unable to get local plugins.json");
18+
Logger.error("Unable to parse remote plugins.json");
2019
Logger.error(error);
2120
throw error;
2221
}

commands/create-project-api.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import { mkdir, writeFile } from "fs/promises";
22
import { parse, stringify } from "envfile";
33
import simpleGit from "simple-git";
4-
import wget from "../utils/wget.js";
54
import getFilesFromRepo from "../utils/getFilesFromRepo.js";
65
import pathExists from "../utils/pathExists.js";
76
import Logger from "../utils/logger.js";
8-
9-
10-
const reactionAppRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/apps/reaction";
11-
const reactionRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/";
7+
import getFileFromCore, { reactionRoot } from "../utils/getFileFromCore.js";
128

139
/**
1410
* @summary create project directory
@@ -29,8 +25,7 @@ async function makeProject(projectName) {
2925
async function getNodeMonVersionFromRoot() {
3026
const rootPackage = await getFileFromCore("package.json", reactionRoot);
3127
const packageData = JSON.parse(rootPackage);
32-
const nodeMon = packageData.devDependencies.nodemon;
33-
return nodeMon;
28+
return packageData.devDependencies.nodemon;
3429
}
3530

3631

@@ -64,22 +59,10 @@ async function updatePackageJson(packageJson, projectName) {
6459
delete packageData.bugs;
6560
packageData.main = "./index.js";
6661
packageData.nodemonConfig.watch.push("custom-packages");
67-
const nodemon = await getNodeMonVersionFromRoot();
68-
packageData.devDependencies.nodemon = nodemon;
62+
packageData.devDependencies.nodemon = await getNodeMonVersionFromRoot();
6963
return JSON.stringify(packageData, null, 2);
7064
}
7165

72-
/**
73-
* @summary get a single file via HTTP
74-
* @param {String} fileName - The file to get
75-
* @param {String} rootDir - path to root for file
76-
* @returns {Promise<string|*>} The contents of the file
77-
*/
78-
async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
79-
const contents = await wget(`${rootDir}/${fileName}`);
80-
return contents;
81-
}
82-
8366
/**
8467
* @summary update dotenv file to point to local mongo
8568
* @param {String} envData - file extracted from the reaction repo
@@ -88,8 +71,7 @@ async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
8871
function updateEnv(envData) {
8972
const env = parse(envData);
9073
env.MONGO_URL = "mongodb://localhost:27017/reaction";
91-
const updatedEnv = stringify(env);
92-
return updatedEnv;
74+
return stringify(env);
9375
}
9476

9577
/**

utils/getFileFromCore.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import wget from "./wget.js";
2+
import Logger from "./logger.js";
3+
4+
export const reactionAppRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/apps/reaction";
5+
export const reactionRoot = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/";
6+
7+
/**
8+
* @summary get a single file via HTTP
9+
* @param {String} fileName - The file to get
10+
* @param {String} rootDir - path to root for file
11+
* @returns {Promise<string|*>} The contents of the file
12+
*/
13+
export default async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
14+
try {
15+
return wget(`${rootDir}/${fileName}`);
16+
} catch (error) {
17+
Logger.error(`Unable to get file from ${rootDir}/${fileName}`);
18+
throw error;
19+
}
20+
}

0 commit comments

Comments
 (0)