Skip to content

Commit

Permalink
Merge pull request #112 from reactioncommerce/monorepo-changes
Browse files Browse the repository at this point in the history
fix: get files from new monorepo layout
  • Loading branch information
brent-hoover authored Sep 23, 2022
2 parents 4a53f63 + 5b6e78b commit b1fea5c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
14.18.1
23 changes: 19 additions & 4 deletions commands/create-project-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import pathExists from "../utils/pathExists.js";
import Logger from "../utils/logger.js";


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

/**
* @summary create project directory
Expand All @@ -21,6 +22,17 @@ async function makeProject(projectName) {
await mkdir(`${projectName}/custom-packages`);
}

/**
* @summary fetch the right nodemon from root
* @return {Promise<string>} - the nodemon package.json line
*/
async function getNodeMonVersionFromRoot() {
const rootPackage = await getFileFromCore("package.json", reactionRoot);
const packageData = JSON.parse(rootPackage);
const nodeMon = packageData.devDependencies.nodemon;
return nodeMon;
}


/**
* @summary modify package.json for use as a thin development project
Expand Down Expand Up @@ -52,16 +64,19 @@ 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;
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) {
const contents = await wget(`${reactionRepoRoot}/${fileName}`);
async function getFileFromCore(fileName, rootDir = reactionAppRoot) {
const contents = await wget(`${rootDir}/${fileName}`);
return contents;
}

Expand Down Expand Up @@ -100,7 +115,7 @@ async function getFilesFromCore(projectName) {
const checkNode = await getFileFromCore("src/checkNodeVersion.cjs");
await writeFile(`${projectName}/utils/checkNodeVersion.cjs`, checkNode);

const nvmrc = await getFileFromCore(".nvmrc");
const nvmrc = await getFileFromCore(".nvmrc", reactionRoot);
await writeFile(`${projectName}/.nvmrc`, nvmrc);

const dotenv = await getFileFromCore(".env.example");
Expand Down
2 changes: 1 addition & 1 deletion commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getLocalPackageJson = async () => {
* @returns {Object} - return the remote dependencies as object
*/
export const getRemoteDependencies = async () => {
const remotePackageJsonUrl = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/package.json";
const remotePackageJsonUrl = "https://raw.githubusercontent.com/reactioncommerce/reaction/trunk/apps/reaction/package.json";
try {
const remotePackageJson = await wget(remotePackageJsonUrl);
return (JSON.parse(remotePackageJson)).dependencies;
Expand Down
2 changes: 1 addition & 1 deletion tests/create-api-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("The create-project-api command", () => {
const responseLines = response.trim().split(EOL);
// eslint-disable-next-line jest/valid-expect
expect(responseLines[1]).to.equal("reaction-cli: Project creation complete. Change to your directory and run `npm install`");
}).timeout(5000);
}).timeout(15000);
});

afterEach(async () => {
Expand Down

0 comments on commit b1fea5c

Please sign in to comment.