Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Beautify settings files on migration #323

Merged
merged 3 commits into from
Oct 30, 2017
Merged

Beautify settings files on migration #323

merged 3 commits into from
Oct 30, 2017

Conversation

maximevaillancourt
Copy link
Contributor

What are you trying to accomplish with this PR?

Beautify the settings files (settings_*.json) upon migration (fix #224).

Expected results

The settings files are pretty printed (indented with 2 spaces).

Checklist

For contributors:

For maintainers:

  • I have 🎩'd these changes.

@@ -4,7 +4,7 @@ import {join} from 'path';
import {prompt} from 'inquirer';
import {green, red, yellow} from 'chalk';
import figures from 'figures';
import {downloadFromUrl, startProcess, writePackageJsonSync, move, isShopifyTheme, isShopifyThemeWhitelistedDir} from '../utils';
import {downloadFromUrl, startProcess, writePackageJsonSync, move, beautifyJson, isShopifyTheme, isShopifyThemeSettingsFile, isShopifyThemeWhitelistedDir} from '../utils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this declaration is overkill -- what's your opinion on importing the whole utils object and call the methods from that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto!

* @param {string} directory - The path to the directory.
*/
export function isShopifyThemeSettingsFile(file) {
const whitelist = ['settings_schema.json', 'settings_data.json'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are buried pretty deep in the code. Makes me think this package could use a config file. Definitely not needed in this PR though.

*
* @param {string} file - The path to the file.
*/
export function beautifyJson(file) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find "beautify" a bit generic - thoughts on unminifyJson instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like unminifyJson assumes that the file is minified — which it might not be — though I don't hold to that opinion very strongly. unminifyJson works for me.

@@ -35,6 +35,7 @@ export default function(program) {
const configYml = join(workingDirectory, 'config.yml');
const pkgJson = join(workingDirectory, 'package.json');
const srcDir = join(workingDirectory, 'src');
const srcConfigDir = join(workingDirectory, 'src/config');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would rename to configDir.


await Promise.all(beautifyPromises);

console.log(` ${green(figures.tick)} Beautification of settings files completed`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can definitely be part of the migration task but do we need to output this "beautification" message to the user? Might lead to confusion. Perhaps it can run behind the scenes and worse case it fails - where the error would then be caught as part of the catch block.

@t-kelly @maximevaillancourt thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@@ -4,7 +4,7 @@ import {join} from 'path';
import {prompt} from 'inquirer';
import {green, red, yellow} from 'chalk';
import figures from 'figures';
import {downloadFromUrl, startProcess, writePackageJsonSync, move, isShopifyTheme, isShopifyThemeWhitelistedDir} from '../utils';
import {downloadFromUrl, startProcess, writePackageJsonSync, move, beautifyJson, isShopifyTheme, isShopifyThemeSettingsFile, isShopifyThemeWhitelistedDir} from '../utils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

* @param {string} file - The path to the file.
*/
export function isShopifyThemeSettingsFile(file) {
const whitelist = ['settings_schema.json', 'settings_data.json'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for future proof, we can use a Regex to check whether or not the format is settings_*.json instead of having a hardcoded whitelist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be as simple as that:

export function isShopifyThemeSettingsFile(file) {
  return /^settings_.+\.json/.test(file);
}

const movePromises = whitelistFiles.map(movePromiseFactory);

function beautifyJsonPromiseFactory(file) {
console.log(` Beautifying ${file}...`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See next comment.

@Shopify Shopify deleted a comment from bertiful Oct 16, 2017
@maximevaillancourt
Copy link
Contributor Author

This PR is good for another round of review. @chrisberthe @t-kelly

@t-kelly t-kelly added the bug label Oct 30, 2017
@t-kelly t-kelly merged commit e2d4a8a into Shopify:master Oct 30, 2017
@lock
Copy link

lock bot commented Oct 26, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance the migrate command to beautify the settings_schema.json and settings_data.json files
3 participants