obsidian-plugin-config 1.6.18 → 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.
@@ -0,0 +1,46 @@
1
+ import { OBSIDIAN_REST_PORT } from './constants.ts';
2
+
3
+ /**
4
+ * Attempts to trigger "Reload app without saving" in Obsidian
5
+ * via the Local REST API plugin (community plugin by coddingtonbear).
6
+ * Silently does nothing if Obsidian is not running or the plugin is unreachable.
7
+ *
8
+ * @see https://github.com/coddingtonbear/obsidian-local-rest-api
9
+ */
10
+ export async function reloadObsidian(): Promise<void> {
11
+ try {
12
+ const apiKey = process.env.OBSIDIAN_REST_API_KEY;
13
+
14
+ if (!apiKey || apiKey === 'your_api_key_here') {
15
+ console.warn('⚠ Obsidian REST API: API key not configured in .env file');
16
+ return;
17
+ }
18
+
19
+ const res = await fetch(
20
+ `http://localhost:${OBSIDIAN_REST_PORT}/commands/app:reload`,
21
+ {
22
+ method: 'POST',
23
+ headers: { Authorization: `Bearer ${apiKey}` }
24
+ }
25
+ );
26
+
27
+ if (res.ok) {
28
+ console.log('Obsidian reloaded via Local REST API.');
29
+ } else {
30
+ console.warn(
31
+ `⚠ Obsidian REST API responded with status ${res.status} for command app:reload`
32
+ );
33
+ }
34
+ } catch (e) {
35
+ const isConnRefused =
36
+ e instanceof Error &&
37
+ (e.message.includes('ECONNREFUSED') || e.message.includes('fetch failed'));
38
+ if (isConnRefused) {
39
+ console.warn(
40
+ '⚠ Obsidian REST API unreachable: Obsidian is not running or the Local REST API plugin is disabled'
41
+ );
42
+ } else {
43
+ console.warn('⚠ Obsidian REST API error:', e);
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,26 @@
1
+ import esbuild from 'esbuild';
2
+ import path from 'path';
3
+
4
+ export function obsidianTypingsPlugin(pluginDir: string): esbuild.Plugin {
5
+ return {
6
+ name: 'obsidian-typings-implementations',
7
+ setup(build: esbuild.PluginBuild): void {
8
+ // Bare import: types only, erased at runtime
9
+ build.onResolve({ filter: /^obsidian-typings$/ }, () => ({
10
+ path: 'obsidian-typings',
11
+ namespace: 'empty-module'
12
+ }));
13
+ build.onLoad({ filter: /.*/, namespace: 'empty-module' }, () => ({
14
+ contents: '',
15
+ loader: 'js'
16
+ }));
17
+ // Implementations: redirect to CJS file
18
+ build.onResolve({ filter: /^obsidian-typings\/implementations$/ }, () => ({
19
+ path: path.resolve(
20
+ pluginDir,
21
+ 'node_modules/obsidian-typings/dist/cjs/implementations.cjs'
22
+ )
23
+ }));
24
+ }
25
+ };
26
+ }
@@ -1,40 +1,40 @@
1
1
  import { readFile, writeFile } from 'fs/promises';
2
2
  import dedent from 'dedent';
3
- import { askQuestion, createReadlineInterface, gitExec, ensureGitSync } from './utils.js';
3
+ import { askQuestion, createReadlineInterface, gitExec, ensureGitSync } from './utils.ts';
4
4
 
5
5
  // Simple version increment functions to avoid semver compatibility issues
6
6
  function incrementVersion(version: string, type: 'patch' | 'minor' | 'major'): string {
7
- const parts = version.split('.').map(Number);
8
- if (parts.length !== 3) return '';
9
-
10
- switch (type) {
11
- case 'patch':
12
- parts[2]++;
13
- break;
14
- case 'minor':
15
- parts[1]++;
16
- parts[2] = 0;
17
- break;
18
- case 'major':
19
- parts[0]++;
20
- parts[1] = 0;
21
- parts[2] = 0;
22
- break;
23
- }
24
-
25
- return parts.join('.');
7
+ const parts = version.split('.').map(Number);
8
+ if (parts.length !== 3) return '';
9
+
10
+ switch (type) {
11
+ case 'patch':
12
+ parts[2]++;
13
+ break;
14
+ case 'minor':
15
+ parts[1]++;
16
+ parts[2] = 0;
17
+ break;
18
+ case 'major':
19
+ parts[0]++;
20
+ parts[1] = 0;
21
+ parts[2] = 0;
22
+ break;
23
+ }
24
+
25
+ return parts.join('.');
26
26
  }
27
27
 
28
28
  function isValidVersion(version: string): boolean {
29
- const versionRegex = /^\d+\.\d+\.\d+$/;
30
- return versionRegex.test(version);
29
+ const versionRegex = /^\d+\.\d+\.\d+$/;
30
+ return versionRegex.test(version);
31
31
  }
32
32
 
33
33
  const rl = createReadlineInterface();
34
34
 
35
35
  async function getTargetVersion(currentVersion: string): Promise<string> {
36
- const updateType = await askQuestion(
37
- dedent`
36
+ const updateType = await askQuestion(
37
+ dedent`
38
38
  Current version: ${currentVersion}
39
39
  Kind of update:
40
40
  patch(1.0.1) -> type 1 or p
@@ -42,115 +42,112 @@ async function getTargetVersion(currentVersion: string): Promise<string> {
42
42
  major(2.0.0) -> type 3 or maj
43
43
  or version number (e.g. 2.0.0)
44
44
  Enter choice: `,
45
- rl
46
- );
47
-
48
- switch (updateType.trim()) {
49
- case 'p':
50
- case '1':
51
- return incrementVersion(currentVersion, 'patch');
52
- case 'min':
53
- case '2':
54
- return incrementVersion(currentVersion, 'minor');
55
- case 'maj':
56
- case '3':
57
- return incrementVersion(currentVersion, 'major');
58
- default:
59
- const trimmed = updateType.trim();
60
- return isValidVersion(trimmed) ? trimmed : '';
61
- }
45
+ rl
46
+ );
47
+
48
+ switch (updateType.trim()) {
49
+ case 'p':
50
+ case '1':
51
+ return incrementVersion(currentVersion, 'patch');
52
+ case 'min':
53
+ case '2':
54
+ return incrementVersion(currentVersion, 'minor');
55
+ case 'maj':
56
+ case '3':
57
+ return incrementVersion(currentVersion, 'major');
58
+ default:
59
+ const trimmed = updateType.trim();
60
+ return isValidVersion(trimmed) ? trimmed : '';
61
+ }
62
62
  }
63
63
 
64
64
  async function updateJsonFile(
65
- filename: string,
66
- updateFn: (json: Record<string, unknown>) => void
65
+ filename: string,
66
+ updateFn: (json: Record<string, unknown>) => void
67
67
  ): Promise<void> {
68
- try {
69
- const content = JSON.parse(await readFile(filename, 'utf8'));
70
- updateFn(content);
71
- await writeFile(filename, JSON.stringify(content, null, ' '));
72
- } catch (error) {
73
- console.error(
74
- `Error updating ${filename}:`,
75
- error instanceof Error ? error.message : String(error)
76
- );
77
- throw error;
78
- }
68
+ try {
69
+ const content = JSON.parse(await readFile(filename, 'utf8'));
70
+ updateFn(content);
71
+ await writeFile(filename, JSON.stringify(content, null, ' '));
72
+ } catch (error) {
73
+ console.error(
74
+ `Error updating ${filename}:`,
75
+ error instanceof Error ? error.message : String(error)
76
+ );
77
+ throw error;
78
+ }
79
79
  }
80
80
 
81
81
  async function updateManifestVersions(targetVersion: string): Promise<void> {
82
- try {
83
- const manifest = JSON.parse(await readFile('manifest.json', 'utf8'));
84
- const { minAppVersion } = manifest;
85
-
86
- await Promise.all([
87
- updateJsonFile('manifest.json', (json) => (json.version = targetVersion)),
88
- updateJsonFile(
89
- 'versions.json',
90
- (json) => (json[targetVersion] = minAppVersion)
91
- ),
92
- updateJsonFile('package.json', (json) => (json.version = targetVersion))
93
- // updateJsonFile("package-lock.json", json => json.version = targetVersion)
94
- ]);
95
- } catch (error) {
96
- console.error(
97
- 'Error updating manifest versions:',
98
- error instanceof Error ? error.message : String(error)
99
- );
100
- throw error;
101
- }
82
+ try {
83
+ const manifest = JSON.parse(await readFile('manifest.json', 'utf8'));
84
+ const { minAppVersion } = manifest;
85
+
86
+ await Promise.all([
87
+ updateJsonFile('manifest.json', (json) => (json.version = targetVersion)),
88
+ updateJsonFile('versions.json', (json) => (json[targetVersion] = minAppVersion)),
89
+ updateJsonFile('package.json', (json) => (json.version = targetVersion))
90
+ // updateJsonFile("package-lock.json", json => json.version = targetVersion)
91
+ ]);
92
+ } catch (error) {
93
+ console.error(
94
+ 'Error updating manifest versions:',
95
+ error instanceof Error ? error.message : String(error)
96
+ );
97
+ throw error;
98
+ }
102
99
  }
103
100
 
104
101
  async function updateVersion(): Promise<void> {
105
- try {
106
- const currentVersion = process.env.npm_package_version || '1.0.0';
107
- const targetVersion = await getTargetVersion(currentVersion);
108
-
109
- if (!targetVersion) {
110
- console.log('Invalid version');
111
- return;
112
- }
113
-
114
- try {
115
- // Update all files first
116
- await updateManifestVersions(targetVersion);
117
- console.log(`Files updated to version ${targetVersion}`);
118
-
119
- // Add files to git
120
- gitExec('git add manifest.json package.json versions.json');
121
- gitExec(`git commit -m "Updated to version ${targetVersion}"`);
122
- console.log('Changes committed');
123
- } catch (error) {
124
- console.error(
125
- 'Error during update or commit:',
126
- error instanceof Error ? error.message : String(error)
127
- );
128
- console.log('Operation failed.');
129
- return;
130
- }
131
-
132
- try {
133
- // Ensure Git is synchronized before pushing
134
- await ensureGitSync();
135
-
136
- gitExec('git push');
137
- console.log(`Version successfully updated to ${targetVersion} and pushed.`);
138
- } catch (pushError) {
139
- console.error(
140
- 'Failed to push version update:',
141
- pushError instanceof Error ? pushError.message : String(pushError)
142
- );
143
- }
144
- } catch (error) {
145
- console.error('Error:', error instanceof Error ? error.message : String(error));
146
- } finally {
147
- rl.close();
148
- }
102
+ try {
103
+ const currentVersion = process.env.npm_package_version || '1.0.0';
104
+ const targetVersion = await getTargetVersion(currentVersion);
105
+
106
+ if (!targetVersion) {
107
+ console.log('Invalid version');
108
+ return;
109
+ }
110
+
111
+ try {
112
+ // Update all files first
113
+ await updateManifestVersions(targetVersion);
114
+ console.log(`Files updated to version ${targetVersion}`);
115
+
116
+ // Add files to git
117
+ gitExec('git add manifest.json package.json versions.json');
118
+ gitExec(`git commit -m "Updated to version ${targetVersion}"`);
119
+ console.log('Changes committed');
120
+ } catch (error) {
121
+ console.error(
122
+ 'Error during update or commit:',
123
+ error instanceof Error ? error.message : String(error)
124
+ );
125
+ console.log('Operation failed.');
126
+ return;
127
+ }
128
+
129
+ try {
130
+ // Ensure Git is synchronized before pushing
131
+ await ensureGitSync();
132
+
133
+ gitExec('git push');
134
+ console.log(`Version successfully updated to ${targetVersion} and pushed.`);
135
+ } catch (pushError) {
136
+ console.error(
137
+ 'Failed to push version update:',
138
+ pushError instanceof Error ? pushError.message : String(pushError)
139
+ );
140
+ }
141
+ } catch (error) {
142
+ console.error('Error:', error instanceof Error ? error.message : String(error));
143
+ } finally {
144
+ rl.close();
145
+ }
149
146
  }
150
147
 
151
148
  updateVersion()
152
- .catch(console.error)
153
- .finally(() => {
154
- console.log('Exiting...');
155
- process.exit();
156
- });
149
+ .catch(console.error)
150
+ .finally(() => {
151
+ console.log('Exiting...');
152
+ process.exit();
153
+ });