create-pdf-forge 1.0.0-canary.0 → 1.0.0-canary.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # create-pdf-forge
2
2
 
3
+ ## 1.0.0-canary.2
4
+
5
+ ### Major Changes
6
+
7
+ - e1e950f: fix build
8
+
9
+ ## 1.0.0-canary.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 4a9d8a8: fix tree utility
14
+
3
15
  ## 1.0.0-canary.0
4
16
 
5
17
  ### Major Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pdf-forge",
3
- "version": "1.0.0-canary.0",
3
+ "version": "1.0.0-canary.2",
4
4
  "description": "The easiest way to get started with React PDF",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/tree.js ADDED
@@ -0,0 +1,89 @@
1
+ /* biome-ignore lint: JavaScript file, TypeScript strict checks not needed */
2
+ import { promises as fs } from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+
6
+ const SYMBOLS = {
7
+ BRANCH: '├── ',
8
+ EMPTY: '',
9
+ INDENT: ' ',
10
+ LAST_BRANCH: '└── ',
11
+ VERTICAL: '│ ',
12
+ };
13
+
14
+ const getTreeLines = async (
15
+ dirPath,
16
+ depth,
17
+ currentDepth = 0,
18
+ filter = null,
19
+ ) => {
20
+ const dirFullpath = path.resolve(dirPath);
21
+ const dirname = path.basename(dirFullpath);
22
+ let lines = [dirname];
23
+
24
+ const dirStat = await fs.stat(dirFullpath);
25
+ if (dirStat.isDirectory() && currentDepth < depth) {
26
+ const childDirents = await fs.readdir(dirFullpath, { withFileTypes: true });
27
+
28
+ // Apply filter if provided
29
+ const filteredDirents = filter
30
+ ? childDirents.filter((dirent) => {
31
+ return filter({
32
+ ...dirent,
33
+ parentPath: dirFullpath,
34
+ name: dirent.name,
35
+ });
36
+ })
37
+ : childDirents;
38
+
39
+ filteredDirents.sort((a, b) => {
40
+ // orders directories before files
41
+ if (a.isDirectory() && b.isFile()) {
42
+ return -1;
43
+ }
44
+
45
+ if (a.isFile() && b.isDirectory()) {
46
+ return 1;
47
+ }
48
+
49
+ // orders by name because they are the same type
50
+ // either directory & directory
51
+ // or file & file
52
+ return b.name > a.name ? -1 : 1;
53
+ });
54
+
55
+ for (let i = 0; i < filteredDirents.length; i++) {
56
+ const dirent = filteredDirents[i];
57
+ const isLast = i === filteredDirents.length - 1;
58
+
59
+ const branchingSymbol = isLast ? SYMBOLS.LAST_BRANCH : SYMBOLS.BRANCH;
60
+ const verticalSymbol = isLast ? SYMBOLS.INDENT : SYMBOLS.VERTICAL;
61
+
62
+ if (dirent.isFile()) {
63
+ lines.push(`${branchingSymbol}${dirent.name}`);
64
+ } else {
65
+ const pathToDirectory = path.join(dirFullpath, dirent.name);
66
+ const treeLinesForSubDirectory = await getTreeLines(
67
+ pathToDirectory,
68
+ depth,
69
+ currentDepth + 1,
70
+ filter,
71
+ );
72
+ lines = lines.concat(
73
+ treeLinesForSubDirectory.map((line, index) =>
74
+ index === 0
75
+ ? `${branchingSymbol}${line}`
76
+ : `${verticalSymbol}${line}`,
77
+ ),
78
+ );
79
+ }
80
+ }
81
+ }
82
+
83
+ return lines;
84
+ };
85
+
86
+ export const tree = async (dirPath, depth, filter = null) => {
87
+ const lines = await getTreeLines(dirPath, depth, 0, filter);
88
+ return lines.join(os.EOL);
89
+ };
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "extends": "tsconfig/base.json",
3
- "include": ["**/*.ts", "**/*.tsx"],
3
+ "include": ["**/*.ts", "**/*.tsx", "**/*.js"],
4
4
  "exclude": ["dist", "build", "node_modules", ".test"],
5
5
  "compilerOptions": {
6
6
  "moduleResolution": "nodenext",