From f61d8e1858edc9c8d1acc32126dca88450cc90a4 Mon Sep 17 00:00:00 2001 From: Alexandre Marcondes Date: Wed, 25 Oct 2023 19:24:26 +0200 Subject: [PATCH 1/2] Prettier fixes --- package.json | 3 ++- utils/commands.js | 42 +++++++++++++++++++------------------ utils/dot-remake.js | 2 +- utils/helpers.js | 2 +- utils/inquirer-questions.js | 3 ++- utils/messages.js | 2 +- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 368d938..0ee6b75 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ }, "scripts": { "prepare": "husky install", - "prettier-check": "prettier --check ." + "prettier-check": "prettier --check .", + "prettier-fix": "prettier --write ." } } diff --git a/utils/commands.js b/utils/commands.js index f9c949f..f7eff46 100644 --- a/utils/commands.js +++ b/utils/commands.js @@ -92,16 +92,16 @@ const deploy = async () => { if (!dotRemakeObj.projectName) { const subdomainAnswer = await inquirer.prompt([questions.INPUT_SUBDOMAIN]); spinner = ora( - `Checking if ${subdomainAnswer.subdomain}.remakeapps.com is available` + `Checking if ${subdomainAnswer.subdomain}.remakeapps.com is available`, ).start(); // check if name is available const isSubdomainAvailable = await checkSubdomain( - subdomainAnswer.subdomain + subdomainAnswer.subdomain, ); if (!isSubdomainAvailable) { spinner.fail( - `${subdomainAnswer.subdomain}.remakeapps.com is not available` + `${subdomainAnswer.subdomain}.remakeapps.com is not available`, ); process.exit(); } @@ -118,14 +118,14 @@ const deploy = async () => { spinner = ora(`Registering ${subdomainAnswer.subdomain}`).start(); const subdomainRegistered = await registerSubdomain( - subdomainAnswer.subdomain + subdomainAnswer.subdomain, ); if (!subdomainRegistered.success) { spinner.fail(subdomainRegistered.message); process.exit(); } spinner.succeed( - `${subdomainAnswer.subdomain}.remakeapps.com belongs to your app.` + `${subdomainAnswer.subdomain}.remakeapps.com belongs to your app.`, ); spinner = ora(`Writing .remake file.`).start(); @@ -144,8 +144,8 @@ const deploy = async () => { removeDeploymentZip(dotRemakeObj.projectName); log( chalk.greenBright( - `The app is accessible at the URL: https://${dotRemakeObj.projectName}.remakeapps.com` - ) + `The app is accessible at the URL: https://${dotRemakeObj.projectName}.remakeapps.com`, + ), ); process.exit(); } catch (err) { @@ -180,22 +180,22 @@ const updateFramework = async () => { spinner = ora("Copying latest framework into _remake directory.").start(); shell.exec( "git clone --depth 1 https://github.com/remake/remake-framework.git", - { silent: true } + { silent: true }, ); // 4. MOVE THE _remake DIRECTORY TO WHERE THE OLD _remake DIRECTORY WAS shell.mv( path.join(cwd, "remake-framework/_remake"), - remakeFrameworkPathInApplicationDirectory + remakeFrameworkPathInApplicationDirectory, ); // 5. EXTEND APP'S PACKAGE.JSON WITH FRAMEWORK'S PACKAGE.JSON try { let packageJsonFromApp = JSON.parse( - fs.readFileSync(path.join(cwd, "package.json")) + fs.readFileSync(path.join(cwd, "package.json")), ); let packageJsonFromFramework = JSON.parse( - fs.readFileSync(path.join(cwd, "remake-framework/package.json")) + fs.readFileSync(path.join(cwd, "remake-framework/package.json")), ); let keysToDeepExtend = [ "ava", @@ -210,11 +210,11 @@ const updateFramework = async () => { }); fs.writeFileSync( path.join(cwd, "package.json"), - JSON.stringify(packageJsonFromApp, null, 2) + JSON.stringify(packageJsonFromApp, null, 2), ); } catch (packageJsonError) { spinner.fail( - "Error with package.json: Couldn't copy dependencies from framework to app's package.json." + "Error with package.json: Couldn't copy dependencies from framework to app's package.json.", ); return; } @@ -223,7 +223,7 @@ const updateFramework = async () => { if (rimrafError) { spinner.fail( - "Error cleaning up: Couldn't remove the ./remake-framework directory." + "Error cleaning up: Couldn't remove the ./remake-framework directory.", ); return; } @@ -261,8 +261,8 @@ const linkDomain = async () => { if (!dotRemakeObj.projectName) { log( chalk.bgRed( - "Please deploy your application first by running: remake deploy" - ) + "Please deploy your application first by running: remake deploy", + ), ); process.exit(); } @@ -277,8 +277,8 @@ const linkDomain = async () => { if (domain.split(".").length > 2) { log( chalk.yellow( - "Remake doesn't support sub-domains at the moment (e.g. app.myawesomeapp.com)" - ) + "Remake doesn't support sub-domains at the moment (e.g. app.myawesomeapp.com)", + ), ); log(chalk.yellow("You must use a root domain (e.g. myawesomeapp.com)")); process.exit(); @@ -372,7 +372,9 @@ async function removeDotGit(projectName) { const rimrafError = await rimraf(path.join(projectPath, ".git")); if (rimrafError) { spinner.fail( - chalk.bgRed("Error: Couldn't remove old .git directory from new project.") + chalk.bgRed( + "Error: Couldn't remove old .git directory from new project.", + ), ); process.exit(); } @@ -383,7 +385,7 @@ function cloneRemakeFramework(projectName) { spinner = ora("Creating new project.").start(); shell.exec( `git clone --branch master https://github.com/remake/remake-framework.git ${projectName}`, - { silent: true } + { silent: true }, ); spinner.succeed(); } diff --git a/utils/dot-remake.js b/utils/dot-remake.js index ba9c4b7..91821d8 100644 --- a/utils/dot-remake.js +++ b/utils/dot-remake.js @@ -9,7 +9,7 @@ const log = console.log; function getUniqueId() { return nanoidGenerate( "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", - 30 + 30, ); } diff --git a/utils/helpers.js b/utils/helpers.js index d0b1da0..7540993 100644 --- a/utils/helpers.js +++ b/utils/helpers.js @@ -112,7 +112,7 @@ const createDeploymentZip = (projectName) => { const cwd = process.cwd(); const output = fs.createWriteStream( path.join(cwd, `deployment-${projectName}.zip`), - { encoding: "base64" } + { encoding: "base64" }, ); const archive = archiver("zip", { zlib: { level: 9 } }); diff --git a/utils/inquirer-questions.js b/utils/inquirer-questions.js index 60facb3..85ed88c 100644 --- a/utils/inquirer-questions.js +++ b/utils/inquirer-questions.js @@ -9,7 +9,8 @@ const validateSubdomain = (subdomain) => { const validateEmail = (email) => { // regex source: https://stackoverflow.com/a/46181 - const emailRegex = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/; + const emailRegex = + /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/; if (!emailRegex.test(email)) { return "Please provide a valid email address."; } else return true; diff --git a/utils/messages.js b/utils/messages.js index 83248f1..2a23dd4 100644 --- a/utils/messages.js +++ b/utils/messages.js @@ -28,7 +28,7 @@ function showDnsMessage(domain) { log(`CNAME www @`); log( - `Your application will be available at https://${domain} and https://www.${domain}` + `Your application will be available at https://${domain} and https://www.${domain}`, ); log(`DNS propagation sometimes takes 4 hours or more.`); } From 365cc4180f10ff9ad9984f5d0c101d1bbd7943f9 Mon Sep 17 00:00:00 2001 From: Alexandre Marcondes Date: Wed, 25 Oct 2023 19:25:51 +0200 Subject: [PATCH 2/2] Fix for adding new keys to packages.json --- index.js | 2 ++ utils/commands.js | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0ddffdc..b1d8b49 100755 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + const program = require("commander"); const Configstore = require("configstore"); diff --git a/utils/commands.js b/utils/commands.js index f7eff46..e660a7a 100644 --- a/utils/commands.js +++ b/utils/commands.js @@ -198,6 +198,7 @@ const updateFramework = async () => { fs.readFileSync(path.join(cwd, "remake-framework/package.json")), ); let keysToDeepExtend = [ + "engines", "ava", "scripts", "nodemonConfig", @@ -205,6 +206,36 @@ const updateFramework = async () => { "dependencies", "devDependencies", ]; + + let insertMapping = new Map([ + ["engines", "main"], + ["ava", "engines"], + ["scripts", "ava"], + ["nodemonConfig", "scripts"], + ["husky", "alias"], + ["dependencies", "husky"], + ["devDependencies", "devDependencies"], + ]); + + spinner.succeed(); + + insertMapping.forEach((insertAt, key, _) => { + if (!packageJsonFromApp.hasOwnProperty(key)) { + spinner = ora("Migrating package.json key '" + key + "'.").start(); + let newPackageJsonFromApp = {}; + for (var item in packageJsonFromApp) { + newPackageJsonFromApp[item] = packageJsonFromApp[item]; + if (item === insertAt) { + newPackageJsonFromApp[key] = {}; + } + } + packageJsonFromApp = newPackageJsonFromApp; + spinner.succeed(); + } + }); + + spinner = ora("Updating package.json.").start(); + keysToDeepExtend.forEach((key) => { deepExtend(packageJsonFromApp[key], packageJsonFromFramework[key]); }); @@ -214,11 +245,17 @@ const updateFramework = async () => { ); } catch (packageJsonError) { spinner.fail( - "Error with package.json: Couldn't copy dependencies from framework to app's package.json.", + "Error with package.json: Couldn't copy dependencies from framework to app's package.json.\n" + + packageJsonError + + "\n" + + packageJsonError.stack, ); return; } + spinner.succeed(); + spinner = ora("Removing temporary files.").start(); + rimrafError = await rimraf(path.join(cwd, "remake-framework")); if (rimrafError) {