From 539a5a5af4aa67e95c796bd756e126a348b2dd17 Mon Sep 17 00:00:00 2001 From: Loris Bettazza Date: Tue, 19 Oct 2021 13:06:43 +0200 Subject: [PATCH 1/3] Use prettier to format output files --- src/commands/firebase-init/index.js | 3 ++- src/commands/init/index.js | 10 ++++++---- src/utils/formatter.js | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/utils/formatter.js diff --git a/src/commands/firebase-init/index.js b/src/commands/firebase-init/index.js index 8611b22..79ff10d 100644 --- a/src/commands/firebase-init/index.js +++ b/src/commands/firebase-init/index.js @@ -11,6 +11,7 @@ import { } from "../../templates"; import { Intro } from '../../utils/interactiveOutputs'; +import { prettify } from "../../utils/formatter"; const createFolder = (folderPath) => { fs.mkdirSync( @@ -30,7 +31,7 @@ const createFolder = (folderPath) => { const createFile = (filePath, fileContent) => { fs.writeFile( process.cwd() + filePath, - fileContent, + prettify(fileContent), (error) => { if (error) { console.log("ERROR OCCURED:", error); diff --git a/src/commands/init/index.js b/src/commands/init/index.js index 7c35311..8dfd02a 100644 --- a/src/commands/init/index.js +++ b/src/commands/init/index.js @@ -10,6 +10,8 @@ import { import { Intro } from "../../utils/interactiveOutputs"; import firebaseInit from '../firebase-init'; +import { prettify } from "../../utils/formatter"; + const createFolder = (path, dir) => { fs.mkdirSync( process.cwd() + dir + "/src" + path, @@ -28,7 +30,7 @@ const createFolder = (path, dir) => { const createAppFile = (pages, path) => { fs.writeFile( process.cwd() + path + `/src/App.js`, - appTemplate(pages), + prettify(appTemplate(pages)), (error) => { if (error) { console.log("ERROR OCCURED:", error); @@ -43,7 +45,7 @@ const createAppFile = (pages, path) => { const createComponentFile = (component, path) => { fs.writeFile( process.cwd() + path + `/src/components/${component}.js`, - componentTemplate(component), + prettify(componentTemplate(component)), (error) => { if (error) { console.log("ERROR OCCURED:", error); @@ -58,7 +60,7 @@ const createComponentFile = (component, path) => { const createPageFile = (component, path) => { fs.writeFile( process.cwd() + path + `/src/pages/${component}.js`, - componentTemplate(component), + prettify(componentTemplate(component)), (error) => { if (error) { console.log("ERROR OCCURED:", error); @@ -73,7 +75,7 @@ const createPageFile = (component, path) => { const createRouteFile = (pages, path) => { fs.writeFile( process.cwd() + path + `/src/routes/index.js`, - routesTemplate(pages), + prettify(routesTemplate(pages)), (error) => { if (error) { console.log("ERROR OCCURED:", error); diff --git a/src/utils/formatter.js b/src/utils/formatter.js new file mode 100644 index 0000000..09c13bc --- /dev/null +++ b/src/utils/formatter.js @@ -0,0 +1,3 @@ +import prettier from "prettier"; + +export const prettify = str => prettier.format(str, { parser: 'babel' }); From fc6c1ee93a6d921694e85f7f7026fb97c0d11190 Mon Sep 17 00:00:00 2001 From: Loris Bettazza Date: Tue, 19 Oct 2021 13:13:03 +0200 Subject: [PATCH 2/3] Fix new issue caused by prettier formatting Filtering out empty strings that can throw errors --- src/commands/firebase-init/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/firebase-init/index.js b/src/commands/firebase-init/index.js index 79ff10d..16dda9b 100644 --- a/src/commands/firebase-init/index.js +++ b/src/commands/firebase-init/index.js @@ -55,6 +55,8 @@ const getPages = (path) => { const content = fs.readFileSync(x); let y = content.toString().match(/export default ([\s\S]*?);/); y = y[1].replace(/\s/g, '').replace('{','').replace('}','').split(','); + // Filter out falsy values (empty strings) that can cause problems + y = y.filter(Boolean); let pages = [] y.forEach(object => { let tmp = object.split(":"); From 1e911f4d20766d880673c45789b8c2b39b6e60b1 Mon Sep 17 00:00:00 2001 From: Loris Bettazza Date: Tue, 19 Oct 2021 13:13:21 +0200 Subject: [PATCH 3/3] Fix await in non-async function Would cause an error with babel parser otherwise --- src/templates/firebase/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templates/firebase/index.js b/src/templates/firebase/index.js index 0e020c2..ba70d93 100644 --- a/src/templates/firebase/index.js +++ b/src/templates/firebase/index.js @@ -25,7 +25,7 @@ const resetPassword = (email) => { ` const providerAuthTemplate = (name) => ` -const ${name}Signin = () => { +const ${name}Signin = async () => { try { await auth.signInWithPopup(${name}Provider).then(async user => { if(user.additionalUserInfo.isNewUser){