@kitschpatrol/prettier-config 1.0.1 → 2.1.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 +14 -0
- package/init/.prettierignore +1 -1
- package/package.json +14 -2
- package/readme.md +6 -4
- package/init.js +0 -22
package/bin/cli.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 S}from"node:url";import{packageUp as k}from"package-up";function N(r,e){return new $({transform(n,t,i){let s=n.toString().split(/\r?\n/).filter(l=>l.trim().length>0).map(l=>`${r?O[e]("["+r+"] "):""}${l}`).join(`
|
|
3
|
+
`)+`
|
|
4
|
+
`;this.push(s),i()}})}function j(r,e){let n=`
|
|
5
|
+
Usage
|
|
6
|
+
$ ${r} [<file|glob> ...]
|
|
7
|
+
`;if(Object.keys(e).length>0){n+=`
|
|
8
|
+
Options`;for(let t of Object.keys(e))switch(t){case"init":{n+=`
|
|
9
|
+
--init, -i Initialize by copying starter config files to your project root.`;break}case"check":{n+=`
|
|
10
|
+
--check, -c Check for and report issues. Same as ${r}.`;break}case"fix":{n+=`
|
|
11
|
+
--fix, -f Fix all auto-fixable issues, and report the un-fixable.`;break}case"printConfig":{n+=`
|
|
12
|
+
--print-config <file> Print the effective configuration for a file`;break}default:console.error(`Unknown command name: ${t}`)}}return n}function T(r){return Object.keys(r).reduce((e,n)=>{let t={};switch(n){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: ${n}`)}return e[n]=t,e},{})}async function h(r,e,n=[]){if(e.command!==void 0&&typeof e.command=="string"){let t;try{let i=x(e.command,[...e.options??[],...n],{env:{FORCE_COLOR:"true"},stdin:"inherit"});i.stdout?.pipe(r,{end:!1}),await i,t=i.exitCode??1}catch(i){t=typeof i.exitCode=="number"?i.exitCode:1}return t}return console.error(`Invalid optionCommand: ${JSON.stringify(e,void 0,2)}`),1}function y(r,e){r.length===0&&!e.defaultArguments&&(console.error("This command must be used with a file argument"),process.exit(1))}async function C(r,e,n,t){let i=A(j(r,t),{allowUnknownFlags:!1,booleanDefault:void 0,flags:T(t),importMeta:import.meta}),{flags:u,input:s}=i,l=Object.keys(t).reduce((c,o)=>(u[o]&&(c[o]=t[o]),c),{});Object.keys(l).length===0&&(l.check=t.check);let m=N(e,n);m.pipe(process.stdout);let a=0;for(let[c,o]of Object.entries(l))if(typeof o.command=="function"){y(s,o);let g=s.length===0?o.defaultArguments??[]:s,p=o.options??[];a+=await o.command(m,g,p)}else if(typeof o.command=="string")y(s,o),a+=await h(m,o,s.length===0?o.defaultArguments:s);else switch(c){case"init":{let g=await k();if(g===void 0){console.error("The `--init` flag must be used in a directory with a package.json file"),a+=1;break}let p=await k({cwd:S(import.meta.url)});if(p===void 0){console.error("The script being called was not in a package, weird."),a+=1;break}let d=f.join(f.dirname(p),"init/"),b=f.dirname(g);console.log(`Copying initial configuration files from:
|
|
13
|
+
"${d}" \u2192 "${b}"`);let F={command:"cp",options:["-Ri",`${d}`,`${b}`]};a+=await h(m,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,e){let n=e?.at(0);return n?(r.write(JSON.stringify(await v(n,{}),void 0,2)),r.write(`
|
|
14
|
+
`),0):1}}});
|
package/init/.prettierignore
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
pnpm-lock.yaml
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/prettier-config",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Prettier config for @kitschpatrol/shared-config",
|
|
6
6
|
"repository": {
|
|
@@ -23,9 +23,13 @@
|
|
|
23
23
|
"pnpm": ">=8.0.0"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
|
-
"prettier-config
|
|
26
|
+
"prettier-config": "bin/cli.js"
|
|
27
27
|
},
|
|
28
28
|
"main": "main.js",
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"init"
|
|
32
|
+
],
|
|
29
33
|
"peerDependencies": {
|
|
30
34
|
"prettier": "^3.0.0"
|
|
31
35
|
},
|
|
@@ -33,6 +37,10 @@
|
|
|
33
37
|
"@prettier/plugin-php": "^0.21.0",
|
|
34
38
|
"@prettier/plugin-ruby": "^4.0.3",
|
|
35
39
|
"@prettier/plugin-xml": "^3.2.2",
|
|
40
|
+
"chalk": "^5.3.0",
|
|
41
|
+
"execa": "^8.0.1",
|
|
42
|
+
"meow": "^12.1.1",
|
|
43
|
+
"package-up": "^5.0.0",
|
|
36
44
|
"prettier-plugin-astro": "^0.12.2",
|
|
37
45
|
"prettier-plugin-pkg": "^0.18.0",
|
|
38
46
|
"prettier-plugin-sh": "^0.13.1",
|
|
@@ -43,5 +51,9 @@
|
|
|
43
51
|
},
|
|
44
52
|
"publishConfig": {
|
|
45
53
|
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "../../scripts/build.ts",
|
|
57
|
+
"cli": "node ./bin/cli.js"
|
|
46
58
|
}
|
|
47
59
|
}
|
package/readme.md
CHANGED
|
@@ -25,25 +25,27 @@ To use just this Prettier config in isolation:
|
|
|
25
25
|
3. Add the starter `.prettierrc.js` and `.prettierignore` files to your project root, and add any customizations you'd like:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
|
-
pnpm exec prettier-config
|
|
28
|
+
pnpm exec prettier-config --init
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Usage
|
|
32
32
|
|
|
33
33
|
The Prettier binary should be picked up automatically by VSCode plugins.
|
|
34
34
|
|
|
35
|
+
You can call it directly, or use the script bundled with the config.
|
|
36
|
+
|
|
35
37
|
Integrate with your `package.json` scripts as you see fit, for example:
|
|
36
38
|
|
|
37
39
|
```json
|
|
38
40
|
...
|
|
39
41
|
"scripts": {
|
|
40
|
-
"lint": "prettier --check
|
|
41
|
-
"format": "prettier --
|
|
42
|
+
"lint": "prettier-config --check"
|
|
43
|
+
"format": "prettier-config --fix"
|
|
42
44
|
}
|
|
43
45
|
...
|
|
44
46
|
```
|
|
45
47
|
|
|
46
|
-
You might need to pass certain plugins in explicitly. The `shared-config
|
|
48
|
+
You might need to pass certain plugins in explicitly. The `shared-config --fix` and `shared-config --lint` scripts take care of this for you.
|
|
47
49
|
|
|
48
50
|
## Ruby support
|
|
49
51
|
|
package/init.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import console from 'node:console';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import process from 'node:process';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
|
|
7
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
|
|
9
|
-
const sourceDirectory = path.join(__dirname, 'init');
|
|
10
|
-
const destinationDirectory = process.cwd(); // (project root)
|
|
11
|
-
|
|
12
|
-
for (const file of fs.readdirSync(sourceDirectory)) {
|
|
13
|
-
const sourcePath = path.join(sourceDirectory, file);
|
|
14
|
-
const destinationPath = path.join(destinationDirectory, file);
|
|
15
|
-
|
|
16
|
-
if (fs.existsSync(destinationPath)) {
|
|
17
|
-
console.log(`${file} already exists in project root, skipping.`);
|
|
18
|
-
} else {
|
|
19
|
-
fs.copyFileSync(sourcePath, destinationPath);
|
|
20
|
-
console.log(`Copied ${file} to project root.`);
|
|
21
|
-
}
|
|
22
|
-
}
|