Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling and messages to prevent running develop #148

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions utils/checkBeforeDevelop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Logger from "../utils/logger.js";
import pathExists from "./pathExists.js";
import checkPort from "./checkPort.js";
import getProjectType from "./getProjectType.js";

/**
* @summary check that the API server is running
Expand All @@ -17,6 +18,10 @@ async function checkForApi() {
* @returns {Promise<boolean>} - If everything is ready for develop
*/
export default async function checkBeforeDevelop(type = "api") {
if ( await getProjectType() !== type ) {
Logger.error(`Cannot run develop, no project of type "${type}" in current directory.`);
return false;
}
if (!await pathExists("node_modules")) {
if (type === "storefront") {
Logger.error("It looks like you have not run `yarn install` in this directory");
Expand Down
24 changes: 19 additions & 5 deletions utils/getProjectType.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,25 @@ const validProjectTypes = ["api", "admin-meteor", "storefront-example"];
*/
export default async function getProjectType() {
Logger.info("Getting project type");
const packageJson = fs.readFileSync("package.json", {
encoding: "utf8",
flag: "r"
});
const packageJsonData = JSON.parse(packageJson);
try {
const packageJson = fs.readFileSync("package.json", {
encoding: "utf8",
flag: "r"
});
} catch (err) {
if (err.code === 'ENOENT') {
Logger.error("Cannot read package.json in current directory");
return "";
} else {
throw err;
}
}
try {
const packageJsonData = JSON.parse(packageJson);
} catch (err) {
Logger.error("Error while parsing package.json");
return "";
}
const { projectType } = packageJsonData;

if (!projectType || projectType === "") {
Expand Down