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