@kitschpatrol/prettier-config 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +12 -9
- package/init/.prettierrc.js +6 -3
- package/package.json +3 -2
package/bin/cli.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import O from"chalk";import{execa as x}from"execa";import A from"meow";import f from"node:path";import{Transform as $}from"node:stream";import{fileURLToPath as
|
|
2
|
+
import O from"chalk";import{execa as x}from"execa";import A from"meow";import f from"node:path";import{Transform as $}from"node:stream";import{fileURLToPath as N}from"node:url";import{packageUp as k}from"package-up";function S(r,n){return new $({transform(e,t,o){let l=e.toString().split(/\r?\n/).filter(m=>m.trim().length>0).map(m=>`${r?O[n]("["+r+"] "):""}${m}`).join(`
|
|
3
3
|
`)+`
|
|
4
|
-
`;this.push(
|
|
4
|
+
`;this.push(l),o()}})}function j(r,n){let e=`
|
|
5
5
|
Usage
|
|
6
6
|
$ ${r} [<file|glob> ...]
|
|
7
|
-
`;if(Object.keys(
|
|
8
|
-
Options`;for(let t of Object.keys(
|
|
9
|
-
--init, -i Initialize by copying starter config files to your project root.`;break}case"check":{
|
|
10
|
-
--check, -c Check for and report issues. Same as ${r}.`;break}case"fix":{
|
|
11
|
-
--fix, -f Fix all auto-fixable issues, and report the un-fixable.`;break}case"printConfig":{
|
|
12
|
-
--print-config <file> Print the effective configuration for a file`;break}default:console.error(`Unknown command name: ${t}`)}}return
|
|
13
|
-
|
|
7
|
+
`;if(Object.keys(n).length>0){e+=`
|
|
8
|
+
Options`;for(let t of Object.keys(n))switch(t){case"init":{e+=`
|
|
9
|
+
--init, -i Initialize by copying starter config files to your project root.`;break}case"check":{e+=`
|
|
10
|
+
--check, -c Check for and report issues. Same as ${r}.`;break}case"fix":{e+=`
|
|
11
|
+
--fix, -f Fix all auto-fixable issues, and report the un-fixable.`;break}case"printConfig":{e+=`
|
|
12
|
+
--print-config <file> Print the effective configuration for a file`;break}default:console.error(`Unknown command name: ${t}`)}}return e}function T(r){return Object.keys(r).reduce((n,e)=>{let t={};switch(e){case"init":{t={shortFlag:"i",type:"boolean"};break}case"check":{t={aliases:["lint",""],shortFlag:"l",type:"boolean"};break}case"fix":{t={shortFlag:"f",type:"boolean"};break}case"printConfig":{t={type:"boolean"};break}default:console.error(`Unknown command name: ${e}`)}return n[e]=t,n},{})}async function h(r,n,e=[]){if(n.command!==void 0&&typeof n.command=="string"){let t;try{let o=x(n.command,[...n.options??[],...e],{env:{FORCE_COLOR:"true"},stdin:"inherit"});o.stdout?.pipe(r,{end:!1}),o.stderr?.pipe(r,{end:!1}),await o,t=o.exitCode??1}catch(o){t=typeof o.exitCode=="number"?o.exitCode:1}return t}return r.write(`Error: Invalid optionCommand: ${JSON.stringify(n,void 0,2)}`),1}function y(r,n,e){r.length===0&&!n.defaultArguments&&(e.write(`Error: This command must be used with a file argument
|
|
13
|
+
`),process.exit(1))}async function C(r,n,e,t){let o=A(j(r,t),{allowUnknownFlags:!1,booleanDefault:void 0,flags:T(t),importMeta:import.meta}),{flags:u,input:l}=o,m=Object.keys(t).reduce((c,i)=>(u[i]&&(c[i]=t[i]),c),{});Object.keys(m).length===0&&(m.check=t.check);let s=S(n,e);s.pipe(process.stdout);let a=0;for(let[c,i]of Object.entries(m))if(typeof i.command=="function"){y(l,i,s);let p=l.length===0?i.defaultArguments??[]:l,g=i.options??[];a+=await i.command(s,p,g)}else if(typeof i.command=="string")y(l,i,s),a+=await h(s,i,l.length===0?i.defaultArguments:l);else switch(c){case"init":{let p=await k();if(p===void 0){s.write("Error: The `--init` flag must be used in a directory with a package.json file\n"),a+=1;break}let g=await k({cwd:N(import.meta.url)});if(g===void 0){s.write(`Error: The script being called was not in a package, weird.
|
|
14
|
+
`),a+=1;break}let d=f.join(f.dirname(g),"init/"),b=f.dirname(p);s.write(`Copying initial configuration files from:
|
|
15
|
+
"${d}" \u2192 "${b}"
|
|
16
|
+
`);let F={command:"cp",options:["-Ri",`${d}`,`${b}`]};a+=await h(s,F);break}case"check":{console.error("No default implementation for check"),a+=1;break}case"fix":{console.error("No default implementation for fix"),a+=1;break}case"printConfig":{console.error("No default implementation for print-config"),a+=1;break}default:{console.error(`Unknown command name: ${c}`),a+=1;break}}process.exit(a>0?1:0)}import{resolveConfig as v}from"prettier";var w=["--log-level=warn","--plugin=@prettier/plugin-php","--plugin=@prettier/plugin-ruby","--plugin=@prettier/plugin-xml","--plugin=prettier-plugin-astro","--plugin=prettier-plugin-pkg","--plugin=prettier-plugin-sh","--plugin=prettier-plugin-sql","--plugin=prettier-plugin-svelte","--plugin=prettier-plugin-tailwindcss","--plugin=prettier-plugin-toml"];await C("prettier-config","Prettier","blue",{check:{command:"prettier",defaultArguments:["."],options:[...w,"--check"]},fix:{command:"prettier",defaultArguments:["."],options:[...w,"--write"]},init:{},printConfig:{async command(r,n){let e=n?.at(0);return e?(r.write(JSON.stringify(await v(e,{}),void 0,2)),r.write(`
|
|
14
17
|
`),0):1}}});
|
package/init/.prettierrc.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import sharedConfig from '@kitschpatrol/prettier-config';
|
|
2
2
|
|
|
3
3
|
/** @type {import("prettier").Config} */
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const localConfig = {
|
|
5
|
+
// Overrides
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export default
|
|
8
|
+
export default {
|
|
9
|
+
...sharedConfig,
|
|
10
|
+
...localConfig,
|
|
11
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/prettier-config",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Prettier config for @kitschpatrol/shared-config",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"prettier-plugin-sql": "^0.17.1",
|
|
48
48
|
"prettier-plugin-svelte": "^3.1.2",
|
|
49
49
|
"prettier-plugin-tailwindcss": "^0.5.9",
|
|
50
|
-
"prettier-plugin-toml": "^2.0.1"
|
|
50
|
+
"prettier-plugin-toml": "^2.0.1",
|
|
51
|
+
"up": "^1.0.2"
|
|
51
52
|
},
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|