Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf731c60

Browse files
committed
Add catchHandler for CRA promises
1 parenta96fc4b commitf731c60

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
constspawn=require("cross-spawn");
3838
constdns=require("dns");
3939
consturl=require("url");
40-
// const envinfo = require("envinfo");
4140

4241
constpackageJson=require("./package.json");
4342
const_wpThemeVersion=packageJson.version;
@@ -52,8 +51,7 @@ const _getScriptsPath = function() {
5251
constscriptsFromNpm=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
letcreateWpThemeReactRoot="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
functioncreateReactApp(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
functioncheckAppName(appName){
@@ -339,3 +320,21 @@ function checkIfOnline(useYarn) {
339320
});
340321
});
341322
}
323+
324+
functioncatchHandler(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)

[8]ページ先頭

©2009-2025 Movatter.jp