Skip to content

Commit f731c60

Browse files
committed
Add catchHandler for CRA promises
1 parent a96fc4b commit f731c60

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

packages/create-react-wptheme/createReactWpTheme.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const execSync = require("child_process").execSync;
3737
const spawn = require("cross-spawn");
3838
const dns = require("dns");
3939
const url = require("url");
40-
// const envinfo = require("envinfo");
4140

4241
const packageJson = require("./package.json");
4342
const _wpThemeVersion = packageJson.version;
@@ -52,8 +51,7 @@ const _getScriptsPath = function() {
5251
const scriptsFromNpm = function() {
5352
//console.log("SCRIPTS FROM NPM");
5453
return {
55-
path: `@devloco/react-scripts-wptheme@${_reactScriptsWpThemeVersion}`,
56-
callback: function() {}
54+
path: `@devloco/react-scripts-wptheme@${_reactScriptsWpThemeVersion}`
5755
};
5856
};
5957

@@ -210,24 +208,9 @@ function createWpTheme(root, appName, version, verbose, originalDirectory, templ
210208
}
211209

212210
let createWpThemeReactRoot = "react-src";
213-
createReactApp(createWpThemeReactRoot, appName, version, verbose, originalDirectory, template, useYarn, usePnp);
211+
createReactApp(createWpThemeReactRoot, appName, version, verbose, originalDirectory, template, useYarn, usePnp).catch(catchHandler);
214212
})
215-
.catch((reason) => {
216-
console.log();
217-
console.log("Aborting installation.");
218-
219-
if (reason.command) {
220-
console.log(` ${chalk.cyan(reason.command)} has failed.`);
221-
} else {
222-
console.log(chalk.red("Unexpected error."), reason);
223-
console.log("Please report it as a bug here:");
224-
console.log("https://github.com/devloco/create-react-wptheme/issues");
225-
}
226-
227-
console.log();
228-
console.log("Done.");
229-
process.exit(1);
230-
});
213+
.catch(catchHandler);
231214
}
232215

233216
function createReactApp(createWpThemeReactRoot, appName, version, verbose, originalDirectory, template, useYarn, usePnp) {
@@ -271,12 +254,10 @@ function createReactApp(createWpThemeReactRoot, appName, version, verbose, origi
271254
return;
272255
}
273256

274-
scriptsPath.callback();
257+
scriptsPath && scriptsPath.callback && scriptsPath.callback();
275258
resolve();
276259
});
277-
}).catch((code) => {
278-
reject(code);
279-
});
260+
}).catch(catchHandler);
280261
}
281262

282263
function checkAppName(appName) {
@@ -339,3 +320,21 @@ function checkIfOnline(useYarn) {
339320
});
340321
});
341322
}
323+
324+
function catchHandler(reason) {
325+
console.log();
326+
console.log(chalk.red("Aborting installation."));
327+
328+
if (reason && reason.command) {
329+
console.log(` ${chalk.cyan(reason.command)} has failed.`);
330+
} else {
331+
console.log(chalk.red("Unexpected error."), reason);
332+
console.log();
333+
console.log("Please report it as a bug here:");
334+
console.log("https://github.com/devloco/create-react-wptheme/issues");
335+
}
336+
337+
console.log();
338+
console.log("Done.");
339+
process.exit(1);
340+
}

packages/create-react-wptheme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devloco/create-react-wptheme",
3-
"version": "3.3.1-wp.3",
3+
"version": "3.3.1-wp.4",
44
"description": "Create React-enabled WP themes.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)