obsidian-plugin-config 1.6.18 → 1.7.1
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/.editorconfig +9 -14
- package/.prettierrc +3 -12
- package/README.md +8 -12
- package/bin/obsidian-inject.js +2 -10
- package/docs/INTERACTIVE_INJECTION.md +55 -116
- package/docs/LLM-GUIDE.md +17 -8
- package/eslint.config.mts +63 -64
- package/package.json +3 -4
- package/scripts/acp.ts +53 -57
- package/scripts/build-npm.ts +180 -167
- package/scripts/help.ts +3 -6
- package/scripts/inject-core.ts +765 -829
- package/scripts/inject-path.ts +144 -160
- package/scripts/inject-prompt.ts +86 -91
- package/scripts/update-version-config.ts +121 -89
- package/scripts/utils.ts +112 -112
- package/templates/.editorconfig +11 -14
- package/templates/.prettierrc +3 -12
- package/templates/env.template +12 -9
- package/templates/eslint.config.mts +1 -1
- package/templates/package.json +2 -3
- package/templates/scripts/acp.ts +50 -74
- package/templates/scripts/constants.ts +26 -0
- package/templates/scripts/env.ts +94 -0
- package/templates/scripts/esbuild.config.ts +134 -287
- package/templates/scripts/release.ts +92 -87
- package/templates/scripts/reload.ts +46 -0
- package/templates/scripts/typingsPlugin.ts +26 -0
- package/templates/scripts/update-version.ts +120 -123
- package/templates/scripts/utils.ts +234 -134
- package/templates/tsconfig.json +2 -2
- package/tsconfig.json +1 -1
- package/templates/package-sass.json +0 -5
|
@@ -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.
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
|
|
65
|
+
filename: string,
|
|
66
|
+
updateFn: (json: Record<string, unknown>) => void
|
|
67
67
|
): Promise<void> {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
.catch(console.error)
|
|
150
|
+
.finally(() => {
|
|
151
|
+
console.log('Exiting...');
|
|
152
|
+
process.exit();
|
|
153
|
+
});
|