obsidian-plugin-config 1.4.4 → 1.4.6

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.
@@ -1,140 +1,154 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import fs from "fs";
4
- import path from "path";
3
+ import fs from 'fs';
4
+ import path from 'path';
5
5
  import {
6
- analyzePlugin,
7
- ensurePluginConfigClean,
8
- findPluginConfigRoot,
9
- performInjection,
10
- readInjectionInfo,
11
- showInjectionPlan
12
- } from "./inject-core.js";
13
- import { createReadlineInterface, isValidPath } from "./utils.js";
6
+ analyzePlugin,
7
+ ensurePluginConfigClean,
8
+ findPluginConfigRoot,
9
+ performInjection,
10
+ readInjectionInfo,
11
+ showInjectionPlan
12
+ } from './inject-core.js';
13
+ import { createReadlineInterface, isValidPath } from './utils.js';
14
14
 
15
15
  const rl = createReadlineInterface();
16
16
 
17
17
  async function main(): Promise<void> {
18
- try {
19
- console.log(`šŸŽÆ Obsidian Plugin Config - Local Injection Tool`);
20
- console.log(`šŸ“„ Inject autonomous configuration from local files\n`);
21
-
22
- const args = process.argv.slice(2);
23
- const autoConfirm = args.includes("--yes") || args.includes("-y");
24
- const dryRun = args.includes("--dry-run") || args.includes("--check");
25
- const useSass = args.includes("--sass");
26
- const targetPath = args.find((arg) => !arg.startsWith("-"));
27
-
28
- if (!targetPath) {
29
- console.error(`āŒ Usage: yarn inject-path <plugin-directory> [options]`);
30
- console.error(` Example: yarn inject-path ../my-obsidian-plugin`);
31
- console.error(` Options:`);
32
- console.error(` --yes, -y Auto-confirm injection`);
33
- console.error(` --dry-run Check only (no injection)`);
34
- console.error(` --sass Add esbuild-sass-plugin dependency`);
35
- console.error(` Shortcuts:`);
36
- console.error(` yarn check-plugin ../plugin # Verification only`);
37
- process.exit(1);
38
- }
39
-
40
- const resolvedPath = path.resolve(targetPath);
41
-
42
- if (!await isValidPath(resolvedPath)) {
43
- console.error(`āŒ Directory not found: ${resolvedPath}`);
44
- process.exit(1);
45
- }
46
-
47
- console.log(`šŸ“ Target directory: ${resolvedPath}`);
48
- console.log(`\nšŸ” Analyzing plugin...`);
49
- const plan = await analyzePlugin(resolvedPath);
50
-
51
- if (dryRun) {
52
- console.log(`\nšŸŽÆ Injection Plan for: ${plan.targetPath}`);
53
- console.log(`šŸ“ Target: ${path.basename(plan.targetPath)}`);
54
- console.log(`šŸ“¦ Package.json: ${plan.hasPackageJson ? "āœ…" : "āŒ"}`);
55
- console.log(`šŸ“‹ Manifest.json: ${plan.hasManifest ? "āœ…" : "āŒ"}`);
56
- console.log(
57
- `šŸ“‚ Scripts folder: ${plan.hasScriptsFolder ? "āœ… (will be updated)" : "āŒ (will be created)"}`
58
- );
59
- console.log(`šŸ”Œ Obsidian plugin: ${plan.isObsidianPlugin ? "āœ…" : "āŒ"}`);
60
- console.log(`šŸŽØ SASS support: ${useSass ? "āœ… (esbuild-sass-plugin will be added)" : "āŒ"}`);
61
-
62
- if (!plan.isObsidianPlugin) {
63
- console.log(`\nāš ļø Warning: This doesn't appear to be a valid Obsidian plugin`);
64
- console.log(` Missing manifest.json or invalid structure`);
65
- }
66
-
67
- console.log(`\nšŸ“‹ Would inject:`);
68
- console.log(` āœ… Local scripts (utils.ts, esbuild.config.ts, acp.ts, etc.)`);
69
- console.log(` āœ… Updated package.json scripts`);
70
- console.log(` āœ… Required dependencies`);
71
- console.log(` šŸ” Analyze centralized imports (manual commenting may be needed)`);
72
-
73
- const injectionInfo = readInjectionInfo(resolvedPath);
74
-
75
- if (injectionInfo) {
76
- console.log(`\nāœ… Status: Plugin is already injected`);
77
- console.log(` šŸ“¦ Injector: ${injectionInfo.injectorName || "unknown"}`);
78
- console.log(` šŸ·ļø Version: ${injectionInfo.injectorVersion || "unknown"}`);
79
- console.log(
80
- ` šŸ“… Date: ${injectionInfo.injectionDate
81
- ? new Date(injectionInfo.injectionDate).toLocaleDateString()
82
- : "unknown"}`
83
- );
84
-
85
- const configRoot = findPluginConfigRoot();
86
- try {
87
- const configPackageJson = JSON.parse(
88
- fs.readFileSync(path.join(configRoot, "package.json"), "utf8")
89
- );
90
- const currentVersion = configPackageJson.version;
91
- if (
92
- currentVersion &&
93
- injectionInfo.injectorVersion &&
94
- currentVersion !== injectionInfo.injectorVersion
95
- ) {
96
- console.log(
97
- ` šŸ”„ Update available: ${injectionInfo.injectorVersion} → ${currentVersion}`
98
- );
99
- }
100
- } catch {
101
- // Ignore version comparison errors
102
- }
103
- } else {
104
- const hasInjectedScripts = fs.existsSync(
105
- path.join(resolvedPath, "scripts", "utils.ts")
106
- );
107
- if (hasInjectedScripts) {
108
- console.log(`\nāš ļø Status: Plugin appears to be injected (legacy)`);
109
- console.log(` Found: scripts/utils.ts but no .injection-info.json`);
110
- console.log(` šŸ’” Re-inject to add version tracking`);
111
- } else {
112
- console.log(`\nāŒ Status: Plugin not yet injected`);
113
- }
114
- }
115
-
116
- console.log(`\nšŸ” Dry-run completed - no changes made`);
117
- console.log(` To inject: yarn inject ${targetPath} --yes`);
118
- return;
119
- }
120
-
121
- console.log(`\nšŸ” Checking plugin-config repository status...`);
122
- await ensurePluginConfigClean();
123
-
124
- const confirmed = await showInjectionPlan(plan, autoConfirm, useSass);
125
-
126
- if (!confirmed) {
127
- console.log(`āŒ Injection cancelled by user`);
128
- process.exit(0);
129
- }
130
-
131
- await performInjection(resolvedPath, useSass);
132
- } catch (error) {
133
- console.error(`šŸ’„ Error: ${error instanceof Error ? error.message : String(error)}`);
134
- process.exit(1);
135
- } finally {
136
- rl.close();
137
- }
18
+ try {
19
+ console.log(`šŸŽÆ Obsidian Plugin Config - Local Injection Tool`);
20
+ console.log(`šŸ“„ Inject autonomous configuration from local files\n`);
21
+
22
+ const args = process.argv.slice(2);
23
+ const autoConfirm = args.includes('--yes') || args.includes('-y');
24
+ const dryRun = args.includes('--dry-run') || args.includes('--check');
25
+ const useSass = args.includes('--sass');
26
+ const targetPath = args.find((arg) => !arg.startsWith('-'));
27
+
28
+ if (!targetPath) {
29
+ console.error(`āŒ Usage: yarn inject-path <plugin-directory> [options]`);
30
+ console.error(` Example: yarn inject-path ../my-obsidian-plugin`);
31
+ console.error(` Options:`);
32
+ console.error(` --yes, -y Auto-confirm injection`);
33
+ console.error(` --dry-run Check only (no injection)`);
34
+ console.error(` --sass Add esbuild-sass-plugin dependency`);
35
+ console.error(` Shortcuts:`);
36
+ console.error(` yarn check-plugin ../plugin # Verification only`);
37
+ process.exit(1);
38
+ }
39
+
40
+ const resolvedPath = path.resolve(targetPath);
41
+
42
+ if (!(await isValidPath(resolvedPath))) {
43
+ console.error(`āŒ Directory not found: ${resolvedPath}`);
44
+ process.exit(1);
45
+ }
46
+
47
+ console.log(`šŸ“ Target directory: ${resolvedPath}`);
48
+ console.log(`\nšŸ” Analyzing plugin...`);
49
+ const plan = await analyzePlugin(resolvedPath);
50
+
51
+ if (dryRun) {
52
+ console.log(`\nšŸŽÆ Injection Plan for: ${plan.targetPath}`);
53
+ console.log(`šŸ“ Target: ${path.basename(plan.targetPath)}`);
54
+ console.log(`šŸ“¦ Package.json: ${plan.hasPackageJson ? 'āœ…' : 'āŒ'}`);
55
+ console.log(`šŸ“‹ Manifest.json: ${plan.hasManifest ? 'āœ…' : 'āŒ'}`);
56
+ console.log(
57
+ `šŸ“‚ Scripts folder: ${plan.hasScriptsFolder ? 'āœ… (will be updated)' : 'āŒ (will be created)'}`
58
+ );
59
+ console.log(`šŸ”Œ Obsidian plugin: ${plan.isObsidianPlugin ? 'āœ…' : 'āŒ'}`);
60
+ console.log(
61
+ `šŸŽØ SASS support: ${useSass ? 'āœ… (esbuild-sass-plugin will be added)' : 'āŒ'}`
62
+ );
63
+
64
+ if (!plan.isObsidianPlugin) {
65
+ console.log(
66
+ `\nāš ļø Warning: This doesn't appear to be a valid Obsidian plugin`
67
+ );
68
+ console.log(` Missing manifest.json or invalid structure`);
69
+ }
70
+
71
+ console.log(`\nšŸ“‹ Would inject:`);
72
+ console.log(
73
+ ` āœ… Local scripts (utils.ts, esbuild.config.ts, acp.ts, etc.)`
74
+ );
75
+ console.log(` āœ… Updated package.json scripts`);
76
+ console.log(` āœ… Required dependencies`);
77
+ console.log(
78
+ ` šŸ” Analyze centralized imports (manual commenting may be needed)`
79
+ );
80
+
81
+ const injectionInfo = readInjectionInfo(resolvedPath);
82
+
83
+ if (injectionInfo) {
84
+ console.log(`\nāœ… Status: Plugin is already injected`);
85
+ console.log(` šŸ“¦ Injector: ${injectionInfo.injectorName || 'unknown'}`);
86
+ console.log(
87
+ ` šŸ·ļø Version: ${injectionInfo.injectorVersion || 'unknown'}`
88
+ );
89
+ console.log(
90
+ ` šŸ“… Date: ${
91
+ injectionInfo.injectionDate
92
+ ? new Date(injectionInfo.injectionDate).toLocaleDateString()
93
+ : 'unknown'
94
+ }`
95
+ );
96
+
97
+ const configRoot = findPluginConfigRoot();
98
+ try {
99
+ const configPackageJson = JSON.parse(
100
+ fs.readFileSync(path.join(configRoot, 'package.json'), 'utf8')
101
+ );
102
+ const currentVersion = configPackageJson.version;
103
+ if (
104
+ currentVersion &&
105
+ injectionInfo.injectorVersion &&
106
+ currentVersion !== injectionInfo.injectorVersion
107
+ ) {
108
+ console.log(
109
+ ` šŸ”„ Update available: ${injectionInfo.injectorVersion} → ${currentVersion}`
110
+ );
111
+ }
112
+ } catch {
113
+ // Ignore version comparison errors
114
+ }
115
+ } else {
116
+ const hasInjectedScripts = fs.existsSync(
117
+ path.join(resolvedPath, 'scripts', 'utils.ts')
118
+ );
119
+ if (hasInjectedScripts) {
120
+ console.log(`\nāš ļø Status: Plugin appears to be injected (legacy)`);
121
+ console.log(` Found: scripts/utils.ts but no .injection-info.json`);
122
+ console.log(` šŸ’” Re-inject to add version tracking`);
123
+ } else {
124
+ console.log(`\nāŒ Status: Plugin not yet injected`);
125
+ }
126
+ }
127
+
128
+ console.log(`\nšŸ” Dry-run completed - no changes made`);
129
+ console.log(` To inject: yarn inject ${targetPath} --yes`);
130
+ return;
131
+ }
132
+
133
+ console.log(`\nšŸ” Checking plugin-config repository status...`);
134
+ await ensurePluginConfigClean();
135
+
136
+ const confirmed = await showInjectionPlan(plan, autoConfirm, useSass);
137
+
138
+ if (!confirmed) {
139
+ console.log(`āŒ Injection cancelled by user`);
140
+ process.exit(0);
141
+ }
142
+
143
+ await performInjection(resolvedPath, useSass);
144
+ } catch (error) {
145
+ console.error(
146
+ `šŸ’„ Error: ${error instanceof Error ? error.message : String(error)}`
147
+ );
148
+ process.exit(1);
149
+ } finally {
150
+ rl.close();
151
+ }
138
152
  }
139
153
 
140
154
  main().catch(console.error);
@@ -1,91 +1,98 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import path from "path";
3
+ import path from 'path';
4
4
  import {
5
- analyzePlugin,
6
- ensurePluginConfigClean,
7
- performInjection,
8
- showInjectionPlan
9
- } from "./inject-core.js";
10
- import { askConfirmation, askQuestion, createReadlineInterface, isValidPath } from "./utils.js";
5
+ analyzePlugin,
6
+ ensurePluginConfigClean,
7
+ performInjection,
8
+ showInjectionPlan
9
+ } from './inject-core.js';
10
+ import {
11
+ askConfirmation,
12
+ askQuestion,
13
+ createReadlineInterface,
14
+ isValidPath
15
+ } from './utils.js';
11
16
 
12
17
  const rl = createReadlineInterface();
13
18
 
14
19
  async function promptForTargetPath(): Promise<string> {
15
- console.log(`\nšŸ“ Select target plugin directory:`);
16
- console.log(` Common paths (copy-paste ready):`);
17
- console.log(` - ../test-sample-plugin`);
18
- console.log(` - ../sample-plugin-modif`);
19
- console.log(` - ../my-obsidian-plugin`);
20
- console.log(` šŸ’” Tip: You can paste paths with or without quotes`);
21
-
22
- while (true) {
23
- const rawInput = await askQuestion(`\nEnter plugin directory path: `, rl);
24
-
25
- if (!rawInput.trim()) {
26
- console.log(`āŒ Please enter a valid path`);
27
- continue;
28
- }
29
-
30
- const cleanPath = rawInput.trim().replace(/^["']|["']$/g, "");
31
- const resolvedPath = path.resolve(cleanPath);
32
-
33
- if (!await isValidPath(resolvedPath)) {
34
- console.log(`āŒ Directory not found: ${resolvedPath}`);
35
- const retry = await askConfirmation(`Try again?`, rl);
36
- if (!retry) throw new Error("User cancelled");
37
- continue;
38
- }
39
-
40
- console.log(`šŸ“ Target directory: ${resolvedPath}`);
41
- return resolvedPath;
42
- }
20
+ console.log(`\nšŸ“ Select target plugin directory:`);
21
+ console.log(` Common paths (copy-paste ready):`);
22
+ console.log(` - ../test-sample-plugin`);
23
+ console.log(` - ../sample-plugin-modif`);
24
+ console.log(` - ../my-obsidian-plugin`);
25
+ console.log(` šŸ’” Tip: You can paste paths with or without quotes`);
26
+
27
+ while (true) {
28
+ const rawInput = await askQuestion(`\nEnter plugin directory path: `, rl);
29
+
30
+ if (!rawInput.trim()) {
31
+ console.log(`āŒ Please enter a valid path`);
32
+ continue;
33
+ }
34
+
35
+ const cleanPath = rawInput.trim().replace(/^["']|["']$/g, '');
36
+ const resolvedPath = path.resolve(cleanPath);
37
+
38
+ if (!(await isValidPath(resolvedPath))) {
39
+ console.log(`āŒ Directory not found: ${resolvedPath}`);
40
+ const retry = await askConfirmation(`Try again?`, rl);
41
+ if (!retry) throw new Error('User cancelled');
42
+ continue;
43
+ }
44
+
45
+ console.log(`šŸ“ Target directory: ${resolvedPath}`);
46
+ return resolvedPath;
47
+ }
43
48
  }
44
49
 
45
50
  async function main(): Promise<void> {
46
- try {
47
- console.log(`šŸŽÆ Obsidian Plugin Config - Interactive Injection Tool`);
48
- console.log(`šŸ“„ Inject autonomous configuration with prompts\n`);
49
-
50
- const args = process.argv.slice(2);
51
- const useSass = args.includes("--sass");
52
- let targetPath: string;
53
-
54
- const pathArg = args.find((arg) => !arg.startsWith("-"));
55
- if (pathArg) {
56
- const cleanPath = pathArg.trim().replace(/^["']|["']$/g, "");
57
- targetPath = path.resolve(cleanPath);
58
-
59
- if (!await isValidPath(targetPath)) {
60
- console.error(`āŒ Directory not found: ${targetPath}`);
61
- process.exit(1);
62
- }
63
-
64
- console.log(`šŸ“ Using provided path: ${targetPath}`);
65
- } else {
66
- targetPath = await promptForTargetPath();
67
- }
68
-
69
- console.log(`\nšŸ” Checking plugin-config repository status...`);
70
- await ensurePluginConfigClean();
71
-
72
- console.log(`\nšŸ” Analyzing plugin...`);
73
- const plan = await analyzePlugin(targetPath);
74
-
75
- const confirmed = await showInjectionPlan(plan, false, useSass);
76
-
77
- if (!confirmed) {
78
- console.log(`āŒ Injection cancelled by user`);
79
- process.exit(0);
80
- }
81
-
82
- await performInjection(targetPath, useSass);
83
- } catch (error) {
84
- console.error(`šŸ’„ Error: ${error instanceof Error ? error.message : String(error)}`);
85
- process.exit(1);
86
- } finally {
87
- rl.close();
88
- }
51
+ try {
52
+ console.log(`šŸŽÆ Obsidian Plugin Config - Interactive Injection Tool`);
53
+ console.log(`šŸ“„ Inject autonomous configuration with prompts\n`);
54
+
55
+ const args = process.argv.slice(2);
56
+ const useSass = args.includes('--sass');
57
+ let targetPath: string;
58
+
59
+ const pathArg = args.find((arg) => !arg.startsWith('-'));
60
+ if (pathArg) {
61
+ const cleanPath = pathArg.trim().replace(/^["']|["']$/g, '');
62
+ targetPath = path.resolve(cleanPath);
63
+
64
+ if (!(await isValidPath(targetPath))) {
65
+ console.error(`āŒ Directory not found: ${targetPath}`);
66
+ process.exit(1);
67
+ }
68
+
69
+ console.log(`šŸ“ Using provided path: ${targetPath}`);
70
+ } else {
71
+ targetPath = await promptForTargetPath();
72
+ }
73
+
74
+ console.log(`\nšŸ” Checking plugin-config repository status...`);
75
+ await ensurePluginConfigClean();
76
+
77
+ console.log(`\nšŸ” Analyzing plugin...`);
78
+ const plan = await analyzePlugin(targetPath);
79
+
80
+ const confirmed = await showInjectionPlan(plan, false, useSass);
81
+
82
+ if (!confirmed) {
83
+ console.log(`āŒ Injection cancelled by user`);
84
+ process.exit(0);
85
+ }
86
+
87
+ await performInjection(targetPath, useSass);
88
+ } catch (error) {
89
+ console.error(
90
+ `šŸ’„ Error: ${error instanceof Error ? error.message : String(error)}`
91
+ );
92
+ process.exit(1);
93
+ } finally {
94
+ rl.close();
95
+ }
89
96
  }
90
97
 
91
98
  main().catch(console.error);
@@ -1,59 +1,59 @@
1
1
  #!/usr/bin/env tsx
2
2
 
3
- import fs from "fs";
4
- import path from "path";
3
+ import fs from 'fs';
4
+ import path from 'path';
5
5
 
6
- const TEMPLATES_PKG = "templates/package.json";
7
- const TEMPLATES_SASS = "templates/package-sass.json";
6
+ const TEMPLATES_PKG = 'templates/package.json';
7
+ const TEMPLATES_SASS = 'templates/package-sass.json';
8
8
 
9
9
  function resolvedVersion(dep: string): string | null {
10
- const pkgPath = path.join("node_modules", dep, "package.json");
11
- if (!fs.existsSync(pkgPath)) return null;
12
- try {
13
- return JSON.parse(fs.readFileSync(pkgPath, "utf8")).version as string;
14
- } catch {
15
- return null;
16
- }
10
+ const pkgPath = path.join('node_modules', dep, 'package.json');
11
+ if (!fs.existsSync(pkgPath)) return null;
12
+ try {
13
+ return JSON.parse(fs.readFileSync(pkgPath, 'utf8')).version as string;
14
+ } catch {
15
+ return null;
16
+ }
17
17
  }
18
18
 
19
19
  function updateDeps(deps: Record<string, string>): { updated: string[] } {
20
- const updated: string[] = [];
21
-
22
- for (const dep of Object.keys(deps)) {
23
- const current = deps[dep];
24
- // Skip wildcards like "*"
25
- if (current === "*") continue;
26
-
27
- const resolved = resolvedVersion(dep);
28
- if (!resolved) continue;
29
-
30
- // Keep "latest" as-is, update pinned/range versions
31
- if (current !== "latest") {
32
- const newVersion = `^${resolved}`;
33
- if (deps[dep] !== newVersion) {
34
- deps[dep] = newVersion;
35
- updated.push(`${dep}: ${current} → ${newVersion}`);
36
- }
37
- }
38
- }
39
-
40
- return { updated };
20
+ const updated: string[] = [];
21
+
22
+ for (const dep of Object.keys(deps)) {
23
+ const current = deps[dep];
24
+ // Skip wildcards like "*"
25
+ if (current === '*') continue;
26
+
27
+ const resolved = resolvedVersion(dep);
28
+ if (!resolved) continue;
29
+
30
+ // Keep "latest" as-is, update pinned/range versions
31
+ if (current !== 'latest') {
32
+ const newVersion = `^${resolved}`;
33
+ if (deps[dep] !== newVersion) {
34
+ deps[dep] = newVersion;
35
+ updated.push(`${dep}: ${current} → ${newVersion}`);
36
+ }
37
+ }
38
+ }
39
+
40
+ return { updated };
41
41
  }
42
42
 
43
43
  function syncFile(filePath: string): void {
44
- const pkg = JSON.parse(fs.readFileSync(filePath, "utf8"));
45
- const { updated } = updateDeps(pkg.devDependencies ?? {});
46
-
47
- if (updated.length) {
48
- fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
49
- console.log(`\nāœ… ${filePath}`);
50
- for (const u of updated) console.log(` ${u}`);
51
- } else {
52
- console.log(`\nāœ… ${filePath} — already up to date`);
53
- }
44
+ const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8'));
45
+ const { updated } = updateDeps(pkg.devDependencies ?? {});
46
+
47
+ if (updated.length) {
48
+ fs.writeFileSync(filePath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
49
+ console.log(`\nāœ… ${filePath}`);
50
+ for (const u of updated) console.log(` ${u}`);
51
+ } else {
52
+ console.log(`\nāœ… ${filePath} — already up to date`);
53
+ }
54
54
  }
55
55
 
56
- console.log("šŸ”„ Syncing template deps from node_modules...");
56
+ console.log('šŸ”„ Syncing template deps from node_modules...');
57
57
  syncFile(TEMPLATES_PKG);
58
58
  syncFile(TEMPLATES_SASS);
59
- console.log("\nāœ… Done.");
59
+ console.log('\nāœ… Done.');