mdat 3.1.0 → 3.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/dist/bin/cli.js CHANGED
@@ -29,7 +29,7 @@ import { confirm, group, intro, note, outro, select } from "@clack/prompts";
29
29
 
30
30
  //#region package.json
31
31
  var name = "mdat";
32
- var version = "3.1.0";
32
+ var version = "3.2.0";
33
33
 
34
34
  //#endregion
35
35
  //#region src/lib/deep-merge-defined.ts
@@ -571,11 +571,11 @@ const gzipCompressAsync = promisify(gzip);
571
571
  * @param bytes - Size in bytes
572
572
  * @param originalSize - Original file size for percentage calculation
573
573
  */
574
- function createSizeInfo(bytes, originalSize) {
574
+ function createSizeInfo(bytes, originalSize, precision) {
575
575
  const percent = originalSize === 0 ? 0 : (originalSize - bytes) / originalSize * 100;
576
576
  return {
577
577
  bytes,
578
- bytesPretty: prettyBytes(bytes, { maximumFractionDigits: 1 }),
578
+ bytesPretty: prettyBytes(bytes, { maximumFractionDigits: precision }),
579
579
  percent,
580
580
  percentPretty: `${Math.round(percent)}%`
581
581
  };
@@ -584,19 +584,20 @@ function createSizeInfo(bytes, originalSize) {
584
584
  * Analyzes a file's size and its compressed sizes using Brotli and Gzip
585
585
  *
586
586
  * @param filePath - Path to the file to analyze
587
+ * @param precision - Maximum number of decimal places in formatted byte sizes
587
588
  *
588
589
  * @returns Promise containing detailed size report
589
590
  * @throws {Error} If file cannot be read or compressed
590
591
  */
591
- async function createSizeReport(filePath) {
592
+ async function createSizeReport(filePath, precision = 1) {
592
593
  try {
593
594
  const fileContent = await fs.readFile(filePath);
594
595
  const originalSize = fileContent.length;
595
596
  const [brotliCompressed, gzipCompressed] = await Promise.all([brotliCompressAsync(fileContent), gzipCompressAsync(fileContent)]);
596
597
  return {
597
- brotli: createSizeInfo(brotliCompressed.length, originalSize),
598
- gzip: createSizeInfo(gzipCompressed.length, originalSize),
599
- original: createSizeInfo(originalSize, originalSize)
598
+ brotli: createSizeInfo(brotliCompressed.length, originalSize, precision),
599
+ gzip: createSizeInfo(gzipCompressed.length, originalSize, precision),
600
+ original: createSizeInfo(originalSize, originalSize, precision)
600
601
  };
601
602
  } catch (error) {
602
603
  throw new Error(`Failed to analyze file: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
@@ -634,12 +635,14 @@ const optionsSchema = z.union([z.object({
634
635
  file: fileSchema,
635
636
  gzip: z.boolean().optional().default(true),
636
637
  original: z.boolean().optional().default(true),
638
+ precision: z.number().int().min(0).max(100).optional().default(0),
637
639
  showPercentage: z.boolean().optional().default(false)
638
640
  }), z.object({
639
641
  brotli: z.boolean().optional().default(true),
640
642
  files: fileSchema,
641
643
  gzip: z.boolean().optional().default(true),
642
644
  original: z.boolean().optional().default(true),
645
+ precision: z.number().int().min(0).max(100).optional().default(0),
643
646
  showPercentage: z.boolean().optional().default(false)
644
647
  })]).transform((options) => {
645
648
  if ("file" in options) {
@@ -674,7 +677,7 @@ var size_table_default = { "size-table": { async content(options) {
674
677
  const validOptions = optionsSchema.parse(options);
675
678
  return formatMarkdownTable(await Promise.all(validOptions.files.map(async (file) => {
676
679
  const fullPath = path.join(process.cwd(), file);
677
- return [file, await createSizeReport(fullPath)];
680
+ return [file, await createSizeReport(fullPath, validOptions.precision)];
678
681
  })), {
679
682
  brotli: validOptions.brotli,
680
683
  gzip: validOptions.gzip,
package/dist/lib/index.js CHANGED
@@ -569,11 +569,11 @@ const gzipCompressAsync = promisify(gzip);
569
569
  * @param bytes - Size in bytes
570
570
  * @param originalSize - Original file size for percentage calculation
571
571
  */
572
- function createSizeInfo(bytes, originalSize) {
572
+ function createSizeInfo(bytes, originalSize, precision) {
573
573
  const percent = originalSize === 0 ? 0 : (originalSize - bytes) / originalSize * 100;
574
574
  return {
575
575
  bytes,
576
- bytesPretty: prettyBytes(bytes, { maximumFractionDigits: 1 }),
576
+ bytesPretty: prettyBytes(bytes, { maximumFractionDigits: precision }),
577
577
  percent,
578
578
  percentPretty: `${Math.round(percent)}%`
579
579
  };
@@ -582,19 +582,20 @@ function createSizeInfo(bytes, originalSize) {
582
582
  * Analyzes a file's size and its compressed sizes using Brotli and Gzip
583
583
  *
584
584
  * @param filePath - Path to the file to analyze
585
+ * @param precision - Maximum number of decimal places in formatted byte sizes
585
586
  *
586
587
  * @returns Promise containing detailed size report
587
588
  * @throws {Error} If file cannot be read or compressed
588
589
  */
589
- async function createSizeReport(filePath) {
590
+ async function createSizeReport(filePath, precision = 1) {
590
591
  try {
591
592
  const fileContent = await fs.readFile(filePath);
592
593
  const originalSize = fileContent.length;
593
594
  const [brotliCompressed, gzipCompressed] = await Promise.all([brotliCompressAsync(fileContent), gzipCompressAsync(fileContent)]);
594
595
  return {
595
- brotli: createSizeInfo(brotliCompressed.length, originalSize),
596
- gzip: createSizeInfo(gzipCompressed.length, originalSize),
597
- original: createSizeInfo(originalSize, originalSize)
596
+ brotli: createSizeInfo(brotliCompressed.length, originalSize, precision),
597
+ gzip: createSizeInfo(gzipCompressed.length, originalSize, precision),
598
+ original: createSizeInfo(originalSize, originalSize, precision)
598
599
  };
599
600
  } catch (error) {
600
601
  throw new Error(`Failed to analyze file: ${error instanceof Error ? error.message : "Unknown error"}`, { cause: error });
@@ -629,12 +630,14 @@ const optionsSchema = z.union([z.object({
629
630
  file: fileSchema,
630
631
  gzip: z.boolean().optional().default(true),
631
632
  original: z.boolean().optional().default(true),
633
+ precision: z.number().int().min(0).max(100).optional().default(0),
632
634
  showPercentage: z.boolean().optional().default(false)
633
635
  }), z.object({
634
636
  brotli: z.boolean().optional().default(true),
635
637
  files: fileSchema,
636
638
  gzip: z.boolean().optional().default(true),
637
639
  original: z.boolean().optional().default(true),
640
+ precision: z.number().int().min(0).max(100).optional().default(0),
638
641
  showPercentage: z.boolean().optional().default(false)
639
642
  })]).transform((options) => {
640
643
  if ("file" in options) {
@@ -668,7 +671,7 @@ function formatMarkdownTable(reports, options) {
668
671
  var size_table_default = { "size-table": { async content(options) {
669
672
  const validOptions = optionsSchema.parse(options);
670
673
  return formatMarkdownTable(await Promise.all(validOptions.files.map(async (file) => {
671
- return [file, await createSizeReport(path.join(process.cwd(), file))];
674
+ return [file, await createSizeReport(path.join(process.cwd(), file), validOptions.precision)];
672
675
  })), {
673
676
  brotli: validOptions.brotli,
674
677
  gzip: validOptions.gzip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdat",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "CLI tool and TypeScript library implementing the Markdown Autophagic Template (MDAT) system. MDAT lets you use comments as dynamic content templates in Markdown files, making it easy to generate and update readme boilerplate.",
5
5
  "keywords": [
6
6
  "mdat",
@@ -44,50 +44,50 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@clack/prompts": "^1.7.0",
47
- "cosmiconfig": "^10.0.0",
47
+ "cosmiconfig": "^10.0.1",
48
48
  "cosmiconfig-typescript-loader": "^6.3.0",
49
- "deepmerge-ts": "^7.1.5",
50
- "globby": "^16.2.2",
49
+ "deepmerge-ts": "^8.0.2",
50
+ "globby": "^16.2.4",
51
51
  "lognow": "^0.8.0",
52
52
  "mdast-util-toc": "^7.1.0",
53
- "metascope": "^0.10.0",
53
+ "metascope": "^0.11.1",
54
54
  "path-type": "^6.0.0",
55
55
  "picocolors": "^1.1.1",
56
56
  "plur": "^6.0.0",
57
- "pretty-bytes": "^7.1.1",
58
- "pretty-ms": "^9.3.0",
57
+ "pretty-bytes": "^7.1.2",
58
+ "pretty-ms": "^9.3.1",
59
59
  "remark": "^15.0.1",
60
60
  "remark-gfm": "^4.0.1",
61
61
  "remark-mdat": "^3.0.1",
62
62
  "to-vfile": "^8.0.0",
63
- "type-fest": "^5.8.0",
63
+ "type-fest": "^5.9.0",
64
64
  "unified-engine": "^11.2.2",
65
65
  "untildify": "^6.0.0",
66
66
  "vfile": "^6.0.3",
67
67
  "yargs": "^18.1.0",
68
- "zod": "^4.4.3"
68
+ "zod": "^4.5.4"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@arethetypeswrong/core": "^0.18.5",
72
- "@kitschpatrol/shared-config": "^8.6.0",
72
+ "@kitschpatrol/shared-config": "^8.7.0",
73
73
  "@types/mdast": "^4.0.4",
74
74
  "@types/node": "~24.13.3",
75
75
  "@types/unist": "^3.0.3",
76
76
  "@types/yargs": "^17.0.35",
77
- "@vitest/coverage-v8": "^4.1.10",
78
- "bumpp": "^12.1.1",
77
+ "@vitest/coverage-v8": "^4.1.11",
78
+ "bumpp": "^12.2.2",
79
79
  "execa": "^10.0.1",
80
- "mdat-plugin-cli-help": "^3.1.0",
80
+ "mdat-plugin-cli-help": "^3.2.0",
81
81
  "mdat-plugin-example": "^3.0.0",
82
82
  "mdat-plugin-tldraw": "^3.0.0",
83
83
  "nanoid": "^6.0.1",
84
84
  "prettier": "^3.9.6",
85
- "publint": "^0.3.22",
85
+ "publint": "^0.3.24",
86
86
  "shx": "^0.4.0",
87
87
  "tsdown": "^0.22.14",
88
88
  "typescript": "~6.0.3",
89
- "unplugin-raw": "^0.7.0",
90
- "vitest": "^4.1.10"
89
+ "unplugin-raw": "^0.8.0",
90
+ "vitest": "^4.1.11"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "prettier": "^3.0.0"
@@ -108,7 +108,7 @@
108
108
  "coverage": "vitest --coverage --run",
109
109
  "fix": "ksc fix",
110
110
  "lint": "ksc lint",
111
- "release": "bumpp --commit 'Release: %s' && pnpm build && NPM_AUTH_TOKEN=$(op read 'op://Personal/npm/token') pnpm publish",
111
+ "release": "bumpp --commit 'Release: %s' && pnpm build && pnpm publish --otp $(op item get npm --otp)",
112
112
  "test": "vitest run"
113
113
  }
114
114
  }
package/readme.md CHANGED
@@ -604,7 +604,7 @@ See the [Examples section](https://github.com/kitschpatrol/remark-mdat#examples)
604
604
 
605
605
  - ##### `<!-- size-table({ files: [".gitignore", "license.txt"] }) -->`
606
606
 
607
- A table of files and their compressed sizes:
607
+ A table of files and their compressed sizes. The optional `precision` sets the maximum number of decimal places and defaults to `0`:
608
608
 
609
609
  <!-- size-table({ files: [".gitignore", "license.txt"] }) -->
610
610
 
@@ -796,7 +796,7 @@ There's quite a bit of prior art and similar explorations of this problem space:
796
796
  - lillallol's [md-in-place](https://www.npmjs.com/package/md-in-place)
797
797
 
798
798
  - [AutoMD](https://automd.unjs.io/)\
799
- Extremely similar functionality to mdat. The project was initiated around the same time as MDAT, but I didn't find the project until a few years later. Ships in the night.
799
+ Extremely similar functionality to mdat. The project was initiated around the same time as MDAT, but I didn't find the project until a few years later. Ships passing in the night.
800
800
 
801
801
  - Franck Abgrall's [readme-md-generator](https://github.com/kefranabg/readme-md-generator)
802
802
 
@@ -806,7 +806,8 @@ There's quite a bit of prior art and similar explorations of this problem space:
806
806
 
807
807
  - Hiroki Osame's [comment-mark](https://github.com/privatenumber/comment-mark)
808
808
 
809
- - Hiroki Osame's [mdeval](https://github.com/privatenumber/mdeval)
809
+ - Hiroki Osame's [mdeval](https://github.com/privatenumber/mdeval)\
810
+ The best name!
810
811
 
811
812
  ### Implementation notes
812
813