@kitschpatrol/mdat-config 6.2.0 → 7.0.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 +6 -4
- package/dist/index.d.ts +7 -9
- package/dist/index.js +2 -2
- package/package.json +3 -9
- package/readme.md +14 -16
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{cosmiconfig as e}from"cosmiconfig";import{TypeScriptLoader as t}from"cosmiconfig-typescript-loader";import{execa as n}from"execa";import r from"fs-extra";import i from"node:fs";import a from"node:path";import{PassThrough as o,Transform as s}from"node:stream";import{fileURLToPath as c}from"node:url";import{packageUp as l,packageUpSync as u}from"package-up";import d from"picocolors";import f from"yargs";import{hideBin as p}from"yargs/helpers";import m from"@pinojs/json-colorizer";import h from"decircular";import g from"deepmerge";import _ from"json-stringify-pretty-compact";import{findWorkspaces as v,findWorkspacesRoot as y}from"find-workspaces";import b from"node:fs/promises";import{
|
|
3
|
-
`);
|
|
4
|
-
`),
|
|
5
|
-
`);for(let
|
|
2
|
+
import{cosmiconfig as e}from"cosmiconfig";import{TypeScriptLoader as t}from"cosmiconfig-typescript-loader";import{execa as n}from"execa";import r from"fs-extra";import i from"node:fs";import a from"node:path";import{PassThrough as o,Transform as s}from"node:stream";import{fileURLToPath as c}from"node:url";import{packageUp as l,packageUpSync as u}from"package-up";import d from"picocolors";import f from"yargs";import{hideBin as p}from"yargs/helpers";import m from"@pinojs/json-colorizer";import h from"decircular";import g from"deepmerge";import _ from"json-stringify-pretty-compact";import{findWorkspaces as v,findWorkspacesRoot as y}from"find-workspaces";import b from"node:fs/promises";import{stripVTControlCharacters as x}from"node:util";import{loadConfig as S}from"mdat";var C=`7.0.0`;function w(e){return e instanceof Error&&`exitCode`in e&&typeof e.exitCode==`number`}function T(e){return m(_(h(e),{indent:2,replacer(e,t){return typeof t==`function`?t.name:t}}),{colors:{BRACKET:`gray`}})}const E=(e,t,n)=>{let r=[...e];for(let[i,a]of t.entries())r[i]===void 0?r[i]=n.cloneUnlessOtherwiseSpecified(a,n):n.isMergeableObject(a)?r[i]=D(e[i],a,n):e.includes(a)||r.push(a);return r};function D(e,t,n={arrayMerge:E}){return g(e,t,n)}function O(e,t){return e.startsWith(t+a.sep)}function k(){let e=A(),t=new Set([e]),n=v();if(n!==null)for(let r of n){let n=a.resolve(r.location);O(n,e)&&t.add(n)}return[...t]}function A(){let e=u();if(e===void 0)throw Error(`No package.json found.`);return a.dirname(e)}function j(){let e=y();return e===null?A():a.resolve(e.location)}function M(e){if(e===`workspace-root`)return j();if(e===`package-dir`)return A();if(typeof e==`string`){if(!r.pathExistsSync(e))throw Error(`Custom cwd directory does not exist: ${e}`);return e}return process.cwd()}async function N(e,t){try{let{default:n}=await import(`prettier`),r=await n.resolveConfig(e),i=await n.format(t,{filepath:e,...r});await b.writeFile(e,i,`utf8`)}catch{console.warn(`Skipped formatting ${e} since Prettier is not installed.`)}}async function P(e){try{await N(e,await b.readFile(e,`utf8`))}catch{}}const F=/\r?\n/;function I(e){return new s({transform(t,n,r){let i=t.toString().split(F).filter(t=>t.trim()!==``&&!e(x(t))).join(`
|
|
3
|
+
`);this.push(i+`
|
|
4
|
+
`),r()}})}function L(e,t){return new s({transform(n,r,i){let a=n.toString().split(F).filter(e=>e.trim().length>0).map(n=>`${e?t===void 0?e:d[t](e):``} ${n}\n`).join(``);this.push(a),i()}})}async function R(e){let t=[];return new Promise((n,r)=>{e.on(`data`,e=>t.push(e)),e.on(`error`,e=>{r(e)}),e.on(`end`,()=>{n(Buffer.concat(t).toString(`utf8`))})})}function z(e,t){return t===1?e:e+`s`}async function B(e,t,n,r,i){let a=1,o;if(r.logPrefix===void 0)o=e;else{let t=L(r.logPrefix,r.logColor);t.pipe(e),o=t}i&&o.write(d.bold(`Running: "${r.name}() with Positional arguments: ${String(t)} and Option flags: ${String(n)}"`));try{a=await r.execute(o,t,n)}catch(e){console.error(String(e)),a=1}return a}async function V(e,t,r,i,a){let s=1,c;if(i.logPrefix===void 0)c=e;else{let t=L(i.logPrefix,i.logColor);t.pipe(e),c=t}let l=i.subcommands??[],u=[...i.receivePositionalArguments?t:[],...i.positionalArguments??[]],d=[...i.receiveOptionFlags?r:[],...i.optionFlags??[]],f=[...l,...d,...u],p=M(i.cwdOverride);a&&c.write(`Running: "${i.name} ${f.join(` `)}"`);let m=i.prettyJsonOutput?new o:c;try{let e=n(i.name,f,{cwd:p,env:{...process.env.NO_COLOR===void 0?{FORCE_COLOR:`true`}:{}},preferLocal:!0,reject:!1,stdin:`inherit`});if(i.outputFilter){let t=I(i.outputFilter),n=I(i.outputFilter);e.stdout.pipe(t).pipe(m,{end:!1}),e.stderr.pipe(n).pipe(m,{end:!1})}else e.stdout.pipe(m,{end:!1}),e.stderr.pipe(m,{end:!1});if(await e,i.prettyJsonOutput){m.end();let e=await R(m),t=T(JSON.parse(e)).split(`
|
|
5
|
+
`);for(let e of t)c.write(`${e}\n`)}s=e.exitCode??1}catch(e){console.error(`${i.name} failed with error:`),console.error(e),w(e)&&(s=typeof e.exitCode==`number`?e.exitCode:1)}return s}function H(e){return`execute`in e}async function U(e,t,n,r,i,a){let o=[];for(let a of r){let r=await(H(a)?B(e,t,n,a,i):V(e,t,n,a,i));o.push({exitCode:r,name:a.name})}if(a){let t=o.filter(({exitCode:e})=>e===0).map(({name:e})=>e),n=o.filter(({exitCode:e})=>e!==0).map(({name:e})=>e),r=o.length;t.length>0&&e.write(`✅ ${d.green(d.bold(`${t.length} / ${r} ${z(`Command`,t.length)} Succeeded:`))} ${d.green(t.join(`, `))}\n`),n.length>0&&e.write(`❌ ${d.red(d.bold(`${n.length} / ${r} ${z(`Command`,n.length)} Failed:`))} ${d.red(n.join(`, `))}\n`)}return o.every(({exitCode:e})=>e===0)?0:1}async function W(e,t,n,o){let s=await l();if(s===void 0)throw Error("The `init` command must be used in a directory with a package.json file");let u=await l({cwd:c(import.meta.url)});if(u===void 0)return e.write(`Error: The script being called was not in a package, weird.
|
|
6
|
+
`),1;let d=a.join(a.dirname(u),`init`),f=a.dirname(s),p=(t===`file`||t===`package`)&&n!==void 0&&o!==void 0;try{if(p){let n=Object.keys(o)[0];if(t===`package`){let t=r.readJsonSync(s);e.write(`Merging: \nPackage config key "${n}" → "${f}" (Because --location is set to "package")\n`);let i=D(t,o);r.writeJSONSync(s,i,{spaces:` `}),await P(s)}else{let t=r.readJsonSync(s);Object.keys(t).includes(n)&&(e.write(`Deleting: \nPackage config key "${n}" in "${f}" (Because --location is set to "file")\n`),delete t[n],r.writeJSONSync(s,t,{spaces:` `}),await P(s))}}if(!await r.pathExists(d))return 0;if((await r.readdir(d)).length===0)return e.write(`Source directory "${d}" is empty.\n`),0;e.write(`Adding initial configuration files from:\n"${d}" → "${f}"\n`),await r.copy(d,f,{async filter(o,s){let c=i.statSync(o).isFile(),l=i.existsSync(s);if(c){if(p&&t===`package`&&o.includes(n))return l?(e.write(`Deleting: \n"${o}" → "${s}" (Because --location is set to "package")\n`),r.removeSync(s)):e.write(`Skipping: \n"${o}" → "${s}" (Because --location is set to "package")\n`),!1;if(l&&(s.includes(`.vscode/`)||s.includes(`package.json`))&&a.extname(s)===`.json`){e.write(`Merging: \n"${o}" → "${s}"\n`);let t=r.readJSONSync(o),n=D(r.readJSONSync(s),t);return r.writeJSONSync(s,n,{spaces:` `}),await P(s),!1}return l?(e.write(`Overwriting: \n"${o}" → "${s}"\n`),await P(s),!0):(e.write(`Copying: \n"${o}" → "${s}"\n`),await P(s),!0)}return!0},overwrite:!0})}catch(e){return console.error(String(e)),1}return 0}async function G(e){let{commands:{fix:t,init:n,lint:r,printConfig:i},description:a,logColor:o,logPrefix:s,name:c,showSummary:l,verbose:u}=e,d=L(s,o);d.pipe(process.stdout);let m=f(p(process.argv)).scriptName(c).usage(`$0 <command>`,a);n!==void 0&&m.command({builder(e){return n.locationOptionFlag?e.option(`location`,{choices:[`file`,`package`],default:`file`,describe:`Where to store the configuration.`,type:`string`}):e},command:`init`,describe:n.description??`Initialize by copying starter config files to your project root${n.locationOptionFlag?` or to your package.json file.`:`.`}`,async handler(e){let t=n.locationOptionFlag?e.location:void 0,r=await U(d,[],t===void 0?[]:[`--location`,t],[{async execute(e,t,r){return W(e,r.at(1),n.configFile,n.configPackageJson)},name:`copyAndMergeInitFiles`},...n.commands??[]]);process.exit(r)}}),r!==void 0&&m.command({builder(e){return r.positionalArgumentMode===`none`?e:e.positional(`files`,{array:!0,...r.positionalArgumentDefault===void 0?{}:{default:r.positionalArgumentDefault},describe:`Files or glob pattern to lint.`,type:`string`})},command:r.positionalArgumentMode===`none`?`lint`:r.positionalArgumentMode===`optional`?`lint [files..]`:`lint <files..>`,describe:r.description,async handler(e){let t=await U(d,e.files??[],[],r.commands,u,l);process.exit(t)}}),t!==void 0&&m.command({builder(e){return t.positionalArgumentMode===`none`?e:e.positional(`files`,{array:!0,...t.positionalArgumentDefault===void 0?{}:{default:t.positionalArgumentDefault},describe:`Files or glob pattern to fix.`,type:`string`})},command:t.positionalArgumentMode===`none`?`fix`:t.positionalArgumentMode===`optional`?`fix [files..]`:`fix <files..>`,describe:t.description,async handler(e){let n=await U(d,e.files??[],[],t.commands);process.exit(n)}}),i!==void 0&&m.command({builder(e){return i.positionalArgumentMode===`none`?e:e.positional(`file`,{...i.positionalArgumentDefault===void 0?{}:{default:i.positionalArgumentDefault},describe:`File or glob pattern to print configuration for.`,type:`string`})},command:i.positionalArgumentMode===`none`?`print-config`:i.positionalArgumentMode===`optional`?`print-config [file]`:`print-config <file>`,describe:i.description,async handler(e){let t=e.file??void 0,n=await U(d,t===void 0?[]:[t],[],i.commands,u,l);process.exit(n)}}),m.alias(`h`,`help`),m.version(C),m.alias(`v`,`version`),m.help(),m.wrap(process.stdout.isTTY?Math.min(120,m.terminalWidth()):0),await m.parseAsync()}async function K(n){let r=e(n,{loaders:{".ts":t()},searchStrategy:`project`});try{let e=await r.search();if(e===null){console.error(`No ${n} configuration found.`);return}return e}catch(e){console.error(`Error while searching for ${n} configuration:`,e);return}}const q={fileRun:`Matches files below the current working directory by default.`,monorepoRun:`In a monorepo, it will also run in all packages below the current working directory.`,monorepoSearch:`Searches up to the root of a monorepo if necessary.`,multiArgumentCaveat:`Will use file arguments / globs where possible if provided, but some of the invoked tools only operate at the package-scope.`,multiOptionCaveat:`Will use option flags where possible if provided, but some of the invoked tools will ignore them.`,optionalFileRun:`Package-scoped by default, file-scoped if a file argument is provided.`,packageRun:`Package-scoped.`,packageSearch:`Package-scoped.`};async function J(){return(await K(`mdat`))?.filepath}async function Y(e){let t=`mdat`,n=await K(t);n!==void 0&&e.write(`Found ${t} readme configuration at "${n.filepath}"\n`);let r=T(await S({additionalConfig:await S()})).split(`
|
|
7
|
+
`);for(let t of r)e.write(`${t}\n`);return 0}async function X(e){let t=k(),n=await J(),r=[];for(let i of t)r.push({cwdOverride:i,name:`mdat`,optionFlags:n?[`--config`,n,`--format`]:[`--format`],subcommands:[e]});return r}await G({commands:{fix:{commands:await X(`expand`),description:`Expand all Mdat content placeholders in your readme.md file(s). ${q.packageRun} ${q.monorepoRun}`,positionalArgumentMode:`none`},init:{configFile:`mdat.config.ts`,configPackageJson:{mdat:{$import:`node_modules/@kitschpatrol/mdat-config/dist/index.js`}},locationOptionFlag:!0},lint:{commands:await X(`check`),description:`Validate that all Mdat content placeholders in your readme.md file(s) have been expanded and are up to date. ${q.packageRun} ${q.monorepoRun}`,positionalArgumentMode:`none`},printConfig:{commands:[{execute:Y,name:Y.name}],description:`Print the effective Mdat configuration. ${q.packageSearch}. ${q.monorepoSearch}.`,positionalArgumentMode:`none`}},description:`Kitschpatrol's Mdat shared configuration tools.`,logColor:`green`,logPrefix:`[Mdat Config]`,name:`ksc-mdat`,order:2});export{};
|
package/dist/index.d.ts
CHANGED
|
@@ -3,17 +3,15 @@ import { Config } from "mdat";
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
declare const sharedMdatConfig: Config;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @see [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config)
|
|
6
|
+
* **@Kitschpatrol's Shared Mdat Configuration**
|
|
7
|
+
*
|
|
9
8
|
* @example
|
|
10
|
-
*
|
|
11
|
-
* export default mdatConfig({
|
|
12
|
-
* rules: {
|
|
9
|
+
* export default mdatConfig({
|
|
13
10
|
* test: '**This is a test rule.**',
|
|
14
|
-
* }
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* @see [@kitschpatrol/mdat-config](https://github.com/kitschpatrol/shared-config/tree/main/packages/mdat-config)
|
|
14
|
+
* @see [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config)
|
|
17
15
|
*/
|
|
18
16
|
declare function mdatConfig(config?: Config): Config;
|
|
19
17
|
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{mergeConfig as e}from"mdat";const t={"shared-config":`## Project configuration
|
|
2
2
|
|
|
3
|
-
This project uses [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) to consolidate various linting and formatting tool configurations under a single dependency and the CLI command \`ksc\`. (ESLint, Prettier, CSpell, etc.)`}
|
|
3
|
+
This project uses [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) to consolidate various linting and formatting tool configurations under a single dependency and the CLI command \`ksc\`. (ESLint, Prettier, CSpell, etc.)`};function n(n){return e(t,n??{})}export{t as default,n as mdatConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/mdat-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "MDAT configuration for @kitschpatrol/shared-config.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shared-config",
|
|
@@ -53,20 +53,14 @@
|
|
|
53
53
|
"find-workspaces": "^0.3.1",
|
|
54
54
|
"fs-extra": "^11.3.4",
|
|
55
55
|
"json-stringify-pretty-compact": "^4.0.0",
|
|
56
|
-
"mdat": "^
|
|
56
|
+
"mdat": "^2.0.0",
|
|
57
57
|
"package-up": "^5.0.0",
|
|
58
58
|
"picocolors": "^1.1.1",
|
|
59
59
|
"prettier": "^3.8.1",
|
|
60
60
|
"yargs": "^18.0.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
64
|
-
},
|
|
65
|
-
"devEngines": {
|
|
66
|
-
"runtime": {
|
|
67
|
-
"name": "node",
|
|
68
|
-
"version": ">=22.18.0"
|
|
69
|
-
}
|
|
63
|
+
"node": ">=22.18.0"
|
|
70
64
|
},
|
|
71
65
|
"publishConfig": {
|
|
72
66
|
"access": "public"
|
package/readme.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
<!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +-->
|
|
2
|
-
|
|
3
1
|
<!-- title -->
|
|
4
2
|
|
|
5
3
|
# @kitschpatrol/mdat-config
|
|
@@ -74,7 +72,7 @@ Integrate with your `package.json` scripts as you see fit, for example:
|
|
|
74
72
|
|
|
75
73
|
"Fix" in this case is a slight misnomer for consistency with the other shared-config tools.
|
|
76
74
|
|
|
77
|
-
It runs `mdat
|
|
75
|
+
It runs `mdat expand` to expand placeholder comments in your readme.md using the bundled [`mdat`](https://github.com/kitschpatrol/mdat/blob/main/packages/mdat/readme.md) expansion rules, plus custom rules provided by `mdat-config`'s `mdat.config.ts` file, plus any additional rules specified in the repository-specific `mdat.config.ts` file.
|
|
78
76
|
|
|
79
77
|
### Configuration
|
|
80
78
|
|
|
@@ -112,12 +110,12 @@ Usage:
|
|
|
112
110
|
ksc-mdat <command>
|
|
113
111
|
```
|
|
114
112
|
|
|
115
|
-
| Command | Description
|
|
116
|
-
| -------------- |
|
|
117
|
-
| `init` | Initialize by copying starter config files to your project root or to your package.json file.
|
|
118
|
-
| `lint` | Validate that all Mdat content placeholders in your readme.md file(s) have been expanded. Package-scoped. In a monorepo, it will also run in all packages below the current working directory. |
|
|
119
|
-
| `fix` | Expand all Mdat content placeholders in your readme.md file(s). Package-scoped. In a monorepo, it will also run in all packages below the current working directory.
|
|
120
|
-
| `print-config` | Print the effective Mdat configuration. Package-scoped.. Searches up to the root of a monorepo if necessary..
|
|
113
|
+
| Command | Description |
|
|
114
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `init` | Initialize by copying starter config files to your project root or to your package.json file. |
|
|
116
|
+
| `lint` | Validate that all Mdat content placeholders in your readme.md file(s) have been expanded and are up to date. Package-scoped. In a monorepo, it will also run in all packages below the current working directory. |
|
|
117
|
+
| `fix` | Expand all Mdat content placeholders in your readme.md file(s). Package-scoped. In a monorepo, it will also run in all packages below the current working directory. |
|
|
118
|
+
| `print-config` | Print the effective Mdat configuration. Package-scoped.. Searches up to the root of a monorepo if necessary.. |
|
|
121
119
|
|
|
122
120
|
| Option | Description | Type |
|
|
123
121
|
| ------------------- | ------------------- | --------- |
|
|
@@ -136,15 +134,15 @@ Usage:
|
|
|
136
134
|
ksc-mdat init
|
|
137
135
|
```
|
|
138
136
|
|
|
139
|
-
| Option | Description
|
|
140
|
-
| ------------------- |
|
|
141
|
-
| `--location` |
|
|
142
|
-
| `--help`<br>`-h` | Show help
|
|
143
|
-
| `--version`<br>`-v` | Show version number
|
|
137
|
+
| Option | Description | Type | Default |
|
|
138
|
+
| ------------------- | --------------------------------- | -------------------- | -------- |
|
|
139
|
+
| `--location` | Where to store the configuration. | `"file"` `"package"` | `"file"` |
|
|
140
|
+
| `--help`<br>`-h` | Show help | `boolean` | |
|
|
141
|
+
| `--version`<br>`-v` | Show version number | `boolean` | |
|
|
144
142
|
|
|
145
143
|
#### Subcommand: `ksc-mdat lint`
|
|
146
144
|
|
|
147
|
-
Validate that all Mdat content placeholders in your readme.md file(s) have been expanded. Package-scoped. In a monorepo, it will also run in all packages below the current working directory.
|
|
145
|
+
Validate that all Mdat content placeholders in your readme.md file(s) have been expanded and are up to date. Package-scoped. In a monorepo, it will also run in all packages below the current working directory.
|
|
148
146
|
|
|
149
147
|
Usage:
|
|
150
148
|
|
|
@@ -174,7 +172,7 @@ ksc-mdat fix
|
|
|
174
172
|
|
|
175
173
|
#### Subcommand: `ksc-mdat print-config`
|
|
176
174
|
|
|
177
|
-
Print the effective Mdat configuration. Package-scoped.. Searches up to the root of a monorepo if necessary..
|
|
175
|
+
Print the effective Mdat configuration. Package-scoped.. Searches up to the root of a monorepo if necessary..
|
|
178
176
|
|
|
179
177
|
Usage:
|
|
180
178
|
|