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 new keys to package json on upgrade #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

const program = require("commander");
const Configstore = require("configstore");

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
},
"scripts": {
"prepare": "husky install",
"prettier-check": "prettier --check ."
"prettier-check": "prettier --check .",
"prettier-fix": "prettier --write ."
}
}
79 changes: 59 additions & 20 deletions utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -180,50 +180,87 @@ 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 = [
"engines",
"ava",
"scripts",
"nodemonConfig",
"husky",
"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]);
});
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.\n" +
packageJsonError +
"\n" +
packageJsonError.stack,
);
return;
}

spinner.succeed();
spinner = ora("Removing temporary files.").start();

rimrafError = await rimraf(path.join(cwd, "remake-framework"));

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;
}
Expand Down Expand Up @@ -261,8 +298,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();
}
Expand All @@ -277,8 +314,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();
Expand Down Expand Up @@ -372,7 +409,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();
}
Expand All @@ -383,7 +422,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();
}
2 changes: 1 addition & 1 deletion utils/dot-remake.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const log = console.log;
function getUniqueId() {
return nanoidGenerate(
"1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
30
30,
);
}

Expand Down
2 changes: 1 addition & 1 deletion utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });

Expand Down
3 changes: 2 additions & 1 deletion utils/inquirer-questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion utils/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand Down