feat: format CLI output with prettier
This commit is contained in:
parent
2a8fc362f5
commit
0c1f28ce05
|
@ -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",
|
||||
|
|
12
packages/cli/src/utilities/format.ts
Normal file
12
packages/cli/src/utilities/format.ts
Normal 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;
|
||||
}
|
|
@ -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';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue