Compare commits

...

1 commit

Author SHA1 Message Date
Matt Seccafien 0c1f28ce05 feat: format CLI output with prettier 2021-11-11 11:08:25 +01:00
3 changed files with 16 additions and 13 deletions

View file

@ -37,7 +37,9 @@
"fs-extra": "^10.0.0",
"glob": "^7.2.0",
"inquirer": "^8.1.2",
"minimist": "^1.2.5"
"minimist": "^1.2.5",
"prettier": "^2.4.1",
"@shopify/prettier-config": "^1.1.2"
},
"devDependencies": {
"@types/change-case": "^2.3.1",

View file

@ -0,0 +1,12 @@
import prettier from 'prettier';
const PRETTIER_CONFIG = {
...require('@shopify/prettier-config'),
};
export function formatFile(content: string) {
// TODO: Search for local project config with fallback to Shopify
const formattedContent = prettier.format(content, PRETTIER_CONFIG);
return formattedContent;
}

View file

@ -6,6 +6,7 @@ export * from './error';
export * from './feature';
export {merge} from './merge';
export {componentName, validComponentName} from './react';
export {formatFile} from './format';
const DEFAULT_SUBCOMMANDS = {
create: 'app',
@ -27,15 +28,3 @@ export function parseCliArguments(rawInputs?: string[]) {
command: [command, subcommand].join('/'),
};
}
export function formatFile(file: string) {
const match = file.match(/^[^\S\n]*(?=\S)/gm);
const indent = match && Math.min(...match.map((el) => el.length));
if (indent) {
const regexp = new RegExp(`^.{${indent}}`, 'gm');
return file.replace(regexp, '').trim() + '\n';
}
return file.trim() + '\n';
}