Skip to content

Commit a4087c8

Browse files
committed
cleanup and stats
1 parent 2b801df commit a4087c8

File tree

152 files changed

+939
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+939
-532
lines changed

.eslintrc.cjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ const config = {
4242
'@typescript-eslint/explicit-function-return-type': ['warn'],
4343
'@typescript-eslint/require-await': 'off',
4444
},
45+
overrides: [
46+
{
47+
files: ['packages/core/src/**/*.ts'],
48+
rules: {
49+
'no-restricted-imports': [
50+
'error',
51+
{
52+
patterns: [
53+
{
54+
group: ['packages/obsidian/*'],
55+
message: 'Core should not import from the Obsidian Adapter.',
56+
},
57+
{
58+
group: ['packages/publish/*'],
59+
message: 'Core should not import from the Obsidian Publish Adapter.',
60+
},
61+
],
62+
},
63+
],
64+
},
65+
},
66+
],
4567
};
4668

4769
module.exports = config;

automation/release.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { $seq, Verboseness, $input, $choise as $choice, $confirm, CMD_FMT } from './shellUtils';
2-
import config from './config.json';
3-
import { CanaryVersion, Version, getIncrementOptions, parseVersion, stringifyVersion } from 'versionUtils';
41
import { UserError } from 'utils';
2+
import { CanaryVersion, Version, getIncrementOptions, parseVersion, stringifyVersion } from 'versionUtils';
3+
import config from './config.json';
4+
import { $choise as $choice, $confirm, $seq, CMD_FMT, Verboseness } from './shellUtils';
55

66
async function runPreconditions(): Promise<void> {
77
// run preconditions

automation/stats.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import * as fs from 'fs';
2+
3+
interface Stat {
4+
fileType: string;
5+
count: number;
6+
lines: number;
7+
}
8+
9+
abstract class StatsBase {
10+
parent: StatsBase | undefined;
11+
path: string;
12+
name: string;
13+
stats: Stat[];
14+
15+
constructor(parent: StatsBase | undefined, path: string, name: string, stats: Stat[]) {
16+
this.parent = parent;
17+
18+
this.path = path;
19+
this.name = name;
20+
this.stats = stats;
21+
}
22+
23+
abstract addChild(child: StatsBase): void;
24+
25+
abstract mergeStats(stats: Stat[]): void;
26+
27+
abstract print(depth: number, lastChildArr: boolean[]): void;
28+
29+
abstract sort(): void;
30+
31+
getPrefix(depth: number, lastChildArr: boolean[]): string {
32+
let prefix = '';
33+
for (let i = 0; i < depth; i++) {
34+
prefix += lastChildArr[i] ? ' ' : '│ ';
35+
}
36+
37+
if (lastChildArr.at(-1)) {
38+
prefix += '└─ ';
39+
} else {
40+
prefix += '├─ ';
41+
}
42+
43+
return prefix;
44+
}
45+
}
46+
47+
class FolderStats extends StatsBase {
48+
children: StatsBase[];
49+
50+
constructor(parent: StatsBase | undefined, path: string, name: string) {
51+
super(parent, path, name, []);
52+
53+
this.children = [];
54+
}
55+
56+
addChild(child: StatsBase) {
57+
this.children.push(child);
58+
this.mergeStats(child.stats);
59+
}
60+
61+
mergeStats(stats: Stat[]): void {
62+
// console.log(this, stats);
63+
for (const stat of stats) {
64+
const existingStat = this.stats.find(s => s.fileType === stat.fileType);
65+
if (existingStat) {
66+
existingStat.count += stat.count;
67+
existingStat.lines += stat.lines;
68+
} else {
69+
this.stats.push(structuredClone(stat));
70+
}
71+
}
72+
73+
this.parent?.mergeStats(stats);
74+
}
75+
76+
print(depth: number, lastChildArr: boolean[]): void {
77+
console.log(
78+
`${this.getPrefix(depth, lastChildArr)}${this.name} | ${this.stats.reduce((acc, s) => acc + s.count, 0)} files | ${this.stats.reduce((acc, s) => acc + s.lines, 0)} lines`,
79+
);
80+
for (let i = 0; i < this.children.length; i++) {
81+
const child = this.children[i];
82+
child.print(depth + 1, [...lastChildArr, i === this.children.length - 1]);
83+
}
84+
}
85+
86+
sort(): void {
87+
this.children.sort((a, b) => {
88+
if (a instanceof FolderStats && b instanceof FileStats) {
89+
return 1;
90+
} else if (a instanceof FileStats && b instanceof FolderStats) {
91+
return -1;
92+
} else {
93+
return a.name.localeCompare(b.name);
94+
}
95+
});
96+
this.children.forEach(c => c.sort());
97+
}
98+
}
99+
100+
class FileStats extends StatsBase {
101+
constructor(parent: StatsBase, path: string, name: string, stats: Stat[]) {
102+
super(parent, path, name, stats);
103+
}
104+
105+
addChild(_child: StatsBase): void {
106+
throw new Error('Cannot add child to file');
107+
}
108+
109+
mergeStats(_stats: Stat[]): void {
110+
throw new Error('Cannot merge stats to file');
111+
}
112+
113+
print(depth: number, lastChildArr: boolean[]): void {
114+
console.log(`${this.getPrefix(depth, lastChildArr)}${this.name} | ${this.stats[0].lines} lines`);
115+
}
116+
117+
sort(): void {}
118+
}
119+
120+
function collectStats() {
121+
const root = new FolderStats(undefined, './packages', 'packages');
122+
const ignore = ['node_modules', 'extraTypes', 'bun.lockb'];
123+
124+
const todo: FolderStats[] = [root];
125+
126+
while (todo.length > 0) {
127+
const current = todo.pop()!;
128+
const children = fs.readdirSync(current.path, { withFileTypes: true });
129+
130+
for (const child of children) {
131+
if (ignore.includes(child.name)) {
132+
continue;
133+
}
134+
135+
if (child.isDirectory()) {
136+
const folder = new FolderStats(current, `${current.path}/${child.name}`, child.name);
137+
current.addChild(folder);
138+
139+
todo.push(folder);
140+
} else {
141+
const content = fs.readFileSync(`${current.path}/${child.name}`, 'utf-8');
142+
143+
const file = new FileStats(current, `${current.path}/${child.name}`, child.name, [
144+
{
145+
fileType: child.name.split('.').splice(1).join('.'),
146+
count: 1,
147+
lines: content.split('\n').length,
148+
},
149+
]);
150+
current.addChild(file);
151+
}
152+
}
153+
}
154+
155+
root.sort();
156+
157+
root.print(0, [true]);
158+
}
159+
160+
collectStats();

automation/versionUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { P } from '@lemons_dev/parsinom/lib/ParsiNOM';
2-
import { P_UTILS } from '@lemons_dev/parsinom/lib/ParserUtils';
31
import { Parser } from '@lemons_dev/parsinom/lib/Parser';
4-
import { UserError } from 'utils';
2+
import { P_UTILS } from '@lemons_dev/parsinom/lib/ParserUtils';
3+
import { P } from '@lemons_dev/parsinom/lib/ParsiNOM';
54
import Moment from 'moment';
5+
import { UserError } from 'utils';
66

77
export class Version {
88
major: number;

bun.lockb

0 Bytes
Binary file not shown.

esbuild.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import esbuild, { analyzeMetafile } from 'esbuild';
21
import builtins from 'builtin-modules';
2+
import esbuild from 'esbuild';
33
import esbuildSvelte from 'esbuild-svelte';
44
import sveltePreprocess from 'svelte-preprocess';
55
import manifest from './manifest.json' assert { type: 'json' };

esbuild.publish.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import esbuild from 'esbuild';
2-
import process from 'process';
31
import builtins from 'builtin-modules';
2+
import esbuild from 'esbuild';
43
import esbuildSvelte from 'esbuild-svelte';
4+
import process from 'process';
55
import sveltePreprocess from 'svelte-preprocess';
66
import manifest from './manifest.json' assert { type: 'json' };
77

esbuild.publish.dev.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import esbuild from 'esbuild';
2-
import process from 'process';
31
import builtins from 'builtin-modules';
2+
import esbuild from 'esbuild';
43
import esbuildSvelte from 'esbuild-svelte';
4+
import process from 'process';
55
import sveltePreprocess from 'svelte-preprocess';
66
import manifest from './manifest.json' assert { type: 'json' };
77

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
"test": "LOG_TESTS=false bun test",
1313
"test:log": "LOG_TESTS=true bun test",
1414
"format": "prettier --write --plugin prettier-plugin-svelte .",
15-
"format:check": "prettier --check --plugin prettier-plugin-svelte .",
15+
"format:check": "prettier --check --plugin prettier-plugin-svelte.",
1616
"lint": "eslint --max-warnings=0 packages/**",
1717
"lint:fix": "eslint --max-warnings=0 --fix packages/**",
1818
"types": "tsc -p \"./tsconfig.types.json\"",
1919
"check": "bun run format:check && bun run lint && bun run tsc && bun run test",
2020
"check:fix": "bun run format && bun run lint:fix && bun run tsc && bun run test",
2121
"release": "bun run automation/release.ts",
22-
"serve-publish": "bun --watch automation/publishServer.ts"
22+
"serve-publish": "bun --watch automation/publishServer.ts",
23+
"stats": "bun run automation/stats.ts"
2324
},
2425
"keywords": [],
2526
"author": "Moritz Jung",

packages/core/src/IPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { type API } from 'packages/core/src/api/API';
21
import { type MetaBindPluginSettings } from 'packages/core/src/Settings';
3-
import { type MetadataManager } from 'packages/core/src/metadata/MetadataManager';
2+
import { type API } from 'packages/core/src/api/API';
43
import { type IInternalAPI } from 'packages/core/src/api/IInternalAPI';
4+
import { type MetadataManager } from 'packages/core/src/metadata/MetadataManager';
55

66
export interface IPlugin {
77
readonly api: API<IPlugin>;

0 commit comments

Comments
 (0)