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.
@@ -1,13 +1,40 @@
1
1
  import { readFile, writeFile } from 'fs/promises';
2
2
  import dedent from 'dedent';
3
- import { inc, valid } from 'semver';
4
- import { createReadlineInterface, askQuestion, gitExec } from './utils.js';
3
+ import { askQuestion, createReadlineInterface, gitExec, ensureGitSync } from './utils.ts';
4
+
5
+ // Simple version increment functions to avoid semver compatibility issues
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('.');
26
+ }
27
+
28
+ function isValidVersion(version: string): boolean {
29
+ const versionRegex = /^\d+\.\d+\.\d+$/;
30
+ return versionRegex.test(version);
31
+ }
5
32
 
6
33
  const rl = createReadlineInterface();
7
34
 
8
35
  async function getTargetVersion(currentVersion: string): Promise<string> {
9
- const updateType = await askQuestion(
10
- dedent`
36
+ const updateType = await askQuestion(
37
+ dedent`
11
38
  Current version: ${currentVersion}
12
39
  Kind of update:
13
40
  patch(1.0.1) -> type 1 or p
@@ -15,100 +42,105 @@ async function getTargetVersion(currentVersion: string): Promise<string> {
15
42
  major(2.0.0) -> type 3 or maj
16
43
  or version number (e.g. 2.0.0)
17
44
  Enter choice: `,
18
- rl
19
- );
20
-
21
- switch (updateType.trim()) {
22
- case 'p':
23
- case '1':
24
- return inc(currentVersion, 'patch') || '';
25
- case 'min':
26
- case '2':
27
- return inc(currentVersion, 'minor') || '';
28
- case 'maj':
29
- case '3':
30
- return inc(currentVersion, 'major') || '';
31
- default:
32
- return valid(updateType.trim()) || '';
33
- }
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
+ }
34
63
  }
35
64
 
36
65
  async function updateJsonFile(
37
- filename: string,
38
- updateFn: (json: Record<string, unknown>) => void
66
+ filename: string,
67
+ updateFn: (json: Record<string, unknown>) => void
39
68
  ): Promise<void> {
40
- try {
41
- const content = JSON.parse(await readFile(filename, 'utf8'));
42
- updateFn(content);
43
- await writeFile(filename, JSON.stringify(content, null, ' '));
44
- } catch (error) {
45
- console.error(
46
- `Error updating ${filename}:`,
47
- error instanceof Error ? error.message : String(error)
48
- );
49
- throw error;
50
- }
69
+ try {
70
+ const content = JSON.parse(await readFile(filename, 'utf8'));
71
+ updateFn(content);
72
+ await writeFile(filename, JSON.stringify(content, null, ' '));
73
+ } catch (error) {
74
+ console.error(
75
+ `Error updating ${filename}:`,
76
+ error instanceof Error ? error.message : String(error)
77
+ );
78
+ throw error;
79
+ }
51
80
  }
52
81
 
53
- async function updateConfigVersions(targetVersion: string): Promise<void> {
54
- try {
55
- await updateJsonFile('package.json', (json) => (json.version = targetVersion));
56
- } catch (error) {
57
- console.error(
58
- 'Error updating config versions:',
59
- error instanceof Error ? error.message : String(error)
60
- );
61
- throw error;
62
- }
82
+ async function updatePackageVersion(targetVersion: string): Promise<void> {
83
+ try {
84
+ await updateJsonFile('package.json', (json) => (json.version = targetVersion));
85
+ } catch (error) {
86
+ console.error(
87
+ 'Error updating package.json version:',
88
+ error instanceof Error ? error.message : String(error)
89
+ );
90
+ throw error;
91
+ }
63
92
  }
64
93
 
65
94
  async function updateVersion(): Promise<void> {
66
- try {
67
- const currentVersion = process.env.npm_package_version || '1.0.0';
68
- const targetVersion = await getTargetVersion(currentVersion);
69
-
70
- if (!targetVersion) {
71
- console.log('Invalid version');
72
- return;
73
- }
74
-
75
- try {
76
- // Update all files first
77
- await updateConfigVersions(targetVersion);
78
- console.log(`Files updated to version ${targetVersion}`);
79
-
80
- // Add files to git
81
- gitExec('git add package.json');
82
- gitExec(`git commit -m "Updated to version ${targetVersion}"`);
83
- console.log('Changes committed');
84
- } catch (error) {
85
- console.error(
86
- 'Error during update or commit:',
87
- error instanceof Error ? error.message : String(error)
88
- );
89
- console.log('Operation failed.');
90
- return;
91
- }
92
-
93
- try {
94
- gitExec('git push');
95
- console.log(`Version successfully updated to ${targetVersion} and pushed.`);
96
- } catch (pushError) {
97
- console.error(
98
- 'Failed to push version update:',
99
- pushError instanceof Error ? pushError.message : String(pushError)
100
- );
101
- }
102
- } catch (error) {
103
- console.error('Error:', error instanceof Error ? error.message : String(error));
104
- } finally {
105
- rl.close();
106
- }
95
+ try {
96
+ const currentVersion = process.env.npm_package_version || '1.0.0';
97
+ const targetVersion = await getTargetVersion(currentVersion);
98
+
99
+ if (!targetVersion) {
100
+ console.log('Invalid version');
101
+ return;
102
+ }
103
+
104
+ try {
105
+ // Update package.json version
106
+ await updatePackageVersion(targetVersion);
107
+ console.log(`package.json updated to version ${targetVersion}`);
108
+
109
+ // Add files to git
110
+ gitExec('git add package.json');
111
+ gitExec(`git commit -m "Updated to version ${targetVersion}"`);
112
+ console.log('Changes committed');
113
+ } catch (error) {
114
+ console.error(
115
+ 'Error during update or commit:',
116
+ error instanceof Error ? error.message : String(error)
117
+ );
118
+ console.log('Operation failed.');
119
+ return;
120
+ }
121
+
122
+ try {
123
+ // Ensure Git is synchronized before pushing
124
+ await ensureGitSync();
125
+
126
+ gitExec('git push');
127
+ console.log(`Version successfully updated to ${targetVersion} and pushed.`);
128
+ } catch (pushError) {
129
+ console.error(
130
+ 'Failed to push version update:',
131
+ pushError instanceof Error ? pushError.message : String(pushError)
132
+ );
133
+ }
134
+ } catch (error) {
135
+ console.error('Error:', error instanceof Error ? error.message : String(error));
136
+ } finally {
137
+ rl.close();
138
+ }
107
139
  }
108
140
 
109
141
  updateVersion()
110
- .catch(console.error)
111
- .finally(() => {
112
- console.log('Exiting...');
113
- process.exit();
114
- });
142
+ .catch(console.error)
143
+ .finally(() => {
144
+ console.log('Exiting...');
145
+ process.exit();
146
+ });
package/scripts/utils.ts CHANGED
@@ -4,24 +4,24 @@ import * as readline from 'readline';
4
4
  import { execSync } from 'child_process';
5
5
 
6
6
  export function createReadlineInterface(): readline.Interface {
7
- return readline.createInterface({
8
- input: process.stdin as NodeJS.ReadableStream,
9
- output: process.stdout as NodeJS.WritableStream
10
- });
7
+ return readline.createInterface({
8
+ input: process.stdin as NodeJS.ReadableStream,
9
+ output: process.stdout as NodeJS.WritableStream
10
+ });
11
11
  }
12
12
 
13
13
  export const askQuestion = async (
14
- question: string,
15
- rl: readline.Interface
14
+ question: string,
15
+ rl: readline.Interface
16
16
  ): Promise<string> => {
17
- try {
18
- return await new Promise((resolve) =>
19
- rl.question(question, (input) => resolve(input.trim()))
20
- );
21
- } catch (error) {
22
- console.error('Error asking question:', error);
23
- throw error;
24
- }
17
+ try {
18
+ return await new Promise((resolve) =>
19
+ rl.question(question, (input) => resolve(input.trim()))
20
+ );
21
+ } catch (error) {
22
+ console.error('Error asking question:', error);
23
+ throw error;
24
+ }
25
25
  };
26
26
 
27
27
  /**
@@ -31,121 +31,121 @@ export const askQuestion = async (
31
31
  * Invalid input defaults to no for safety
32
32
  */
33
33
  export const askConfirmation = async (
34
- question: string,
35
- rl: readline.Interface
34
+ question: string,
35
+ rl: readline.Interface
36
36
  ): Promise<boolean> => {
37
- const answer = await askQuestion(`${question} [Y/n]: `, rl);
38
- const response = answer.toLowerCase();
39
-
40
- // Accept: y, yes, Y, YES, or empty (default to yes)
41
- // Reject: n, no, N, NO
42
- const isYes = response === '' || response === 'y' || response === 'yes';
43
- const isNo = response === 'n' || response === 'no';
44
-
45
- if (isNo) {
46
- return false;
47
- } else if (isYes) {
48
- return true;
49
- } else {
50
- console.log('Please answer Y (yes) or n (no). Defaulting to no for safety.');
51
- return false;
52
- }
37
+ const answer = await askQuestion(`${question} [Y/n]: `, rl);
38
+ const response = answer.toLowerCase();
39
+
40
+ // Accept: y, yes, Y, YES, or empty (default to yes)
41
+ // Reject: n, no, N, NO
42
+ const isYes = response === '' || response === 'y' || response === 'yes';
43
+ const isNo = response === 'n' || response === 'no';
44
+
45
+ if (isNo) {
46
+ return false;
47
+ } else if (isYes) {
48
+ return true;
49
+ } else {
50
+ console.log('Please answer Y (yes) or n (no). Defaulting to no for safety.');
51
+ return false;
52
+ }
53
53
  };
54
54
 
55
55
  export const cleanInput = (inputStr: string): string => {
56
- if (!inputStr) return '';
57
- return inputStr.trim().replace(/["`]/g, "'").replace(/\r\n/g, '\n');
56
+ if (!inputStr) return '';
57
+ return inputStr.trim().replace(/["`]/g, "'").replace(/\r\n/g, '\n');
58
58
  };
59
59
 
60
60
  export const isValidPath = async (pathToCheck: string): Promise<boolean> => {
61
- if (!pathToCheck) return false;
62
-
63
- try {
64
- // Using async fs.access is preferred over synchronous existsSync
65
- // as it doesn't block the main thread/event loop
66
- await access(pathToCheck.trim());
67
- return true;
68
- } catch {
69
- return false;
70
- }
61
+ if (!pathToCheck) return false;
62
+
63
+ try {
64
+ // Using async fs.access is preferred over synchronous existsSync
65
+ // as it doesn't block the main thread/event loop
66
+ await access(pathToCheck.trim());
67
+ return true;
68
+ } catch {
69
+ return false;
70
+ }
71
71
  };
72
72
 
73
73
  export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
74
- const pluginDir = process.cwd();
75
- const manifestSrc = path.join(pluginDir, 'manifest.json');
76
- const manifestDest = path.join(buildPath, 'manifest.json');
77
- const cssDest = path.join(buildPath, 'styles.css');
78
- const folderToRemove = path.join(buildPath, '_.._');
79
-
80
- try {
81
- await mkdir(buildPath, { recursive: true });
82
- } catch (error: unknown) {
83
- if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
84
- console.error(`Error creating directory: ${(error as Error).message}`);
85
- }
86
- }
87
-
88
- // Copy manifest
89
- try {
90
- await copyFile(manifestSrc, manifestDest);
91
- } catch (error: unknown) {
92
- console.error(`Error copying manifest: ${(error as Error).message}`);
93
- }
94
-
95
- // Copy CSS
96
- try {
97
- const srcStylesPath = path.join(pluginDir, 'src/styles.css');
98
- const rootStylesPath = path.join(pluginDir, 'styles.css');
99
-
100
- // First check if CSS exists in src/styles.css
101
- if (await isValidPath(srcStylesPath)) {
102
- await copyFile(srcStylesPath, cssDest);
103
- }
104
- // Otherwise, check if it exists in the root
105
- else if (await isValidPath(rootStylesPath)) {
106
- await copyFile(rootStylesPath, cssDest);
107
- if (await isValidPath(folderToRemove)) {
108
- await rm(folderToRemove, { recursive: true });
109
- }
110
- } else {
111
- return;
112
- }
113
- } catch (error: unknown) {
114
- console.error(`Error copying CSS: ${(error as Error).message}`);
115
- }
74
+ const pluginDir = process.cwd();
75
+ const manifestSrc = path.join(pluginDir, 'manifest.json');
76
+ const manifestDest = path.join(buildPath, 'manifest.json');
77
+ const cssDest = path.join(buildPath, 'styles.css');
78
+ const folderToRemove = path.join(buildPath, '_.._');
79
+
80
+ try {
81
+ await mkdir(buildPath, { recursive: true });
82
+ } catch (error: unknown) {
83
+ if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
84
+ console.error(`Error creating directory: ${(error as Error).message}`);
85
+ }
86
+ }
87
+
88
+ // Copy manifest
89
+ try {
90
+ await copyFile(manifestSrc, manifestDest);
91
+ } catch (error: unknown) {
92
+ console.error(`Error copying manifest: ${(error as Error).message}`);
93
+ }
94
+
95
+ // Copy CSS
96
+ try {
97
+ const srcStylesPath = path.join(pluginDir, 'src/styles.css');
98
+ const rootStylesPath = path.join(pluginDir, 'styles.css');
99
+
100
+ // First check if CSS exists in src/styles.css
101
+ if (await isValidPath(srcStylesPath)) {
102
+ await copyFile(srcStylesPath, cssDest);
103
+ }
104
+ // Otherwise, check if it exists in the root
105
+ else if (await isValidPath(rootStylesPath)) {
106
+ await copyFile(rootStylesPath, cssDest);
107
+ if (await isValidPath(folderToRemove)) {
108
+ await rm(folderToRemove, { recursive: true });
109
+ }
110
+ } else {
111
+ return;
112
+ }
113
+ } catch (error: unknown) {
114
+ console.error(`Error copying CSS: ${(error as Error).message}`);
115
+ }
116
116
  }
117
117
 
118
118
  export function gitExec(command: string): void {
119
- try {
120
- execSync(command, { stdio: 'inherit' });
121
- } catch (error: unknown) {
122
- console.error(`Error executing '${command}':`, (error as Error).message);
123
- throw error;
124
- }
119
+ try {
120
+ execSync(command, { stdio: 'inherit' });
121
+ } catch (error: unknown) {
122
+ console.error(`Error executing '${command}':`, (error as Error).message);
123
+ throw error;
124
+ }
125
125
  }
126
126
 
127
127
  /**
128
128
  * Ensure Git repository is synchronized with remote before pushing
129
129
  */
130
130
  export async function ensureGitSync(): Promise<void> {
131
- try {
132
- console.log('🔄 Checking Git synchronization...');
133
-
134
- // Fetch latest changes from remote
135
- execSync('git fetch origin', { stdio: 'pipe' });
136
-
137
- // Check if branch is behind remote
138
- const status = execSync('git status --porcelain -b', { encoding: 'utf8' });
139
-
140
- if (status.includes('behind')) {
141
- console.log('📥 Branch behind remote. Pulling changes...');
142
- execSync('git pull', { stdio: 'inherit' });
143
- console.log('✅ Successfully pulled remote changes');
144
- } else {
145
- console.log('✅ Repository is synchronized with remote');
146
- }
147
- } catch (error: unknown) {
148
- console.error(`❌ Git sync failed: ${(error as Error).message}`);
149
- throw error;
150
- }
131
+ try {
132
+ console.log('🔄 Checking Git synchronization...');
133
+
134
+ // Fetch latest changes from remote
135
+ execSync('git fetch origin', { stdio: 'pipe' });
136
+
137
+ // Check if branch is behind remote
138
+ const status = execSync('git status --porcelain -b', { encoding: 'utf8' });
139
+
140
+ if (status.includes('behind')) {
141
+ console.log('📥 Branch behind remote. Pulling changes...');
142
+ execSync('git pull', { stdio: 'inherit' });
143
+ console.log('✅ Successfully pulled remote changes');
144
+ } else {
145
+ console.log('✅ Repository is synchronized with remote');
146
+ }
147
+ } catch (error: unknown) {
148
+ console.error(`❌ Git sync failed: ${(error as Error).message}`);
149
+ throw error;
150
+ }
151
151
  }
@@ -1,14 +1,11 @@
1
- # top-most EditorConfig file
2
- root = true
3
-
4
- [*]
5
- charset = utf-8
6
- end_of_line = lf
7
- insert_final_newline = true
8
- indent_style = tab
9
- indent_size = 4
10
- tab_width = 4
11
-
12
- [*.json]
13
- indent_style = space
14
- indent_size = 2
1
+ # top-most EditorConfig file
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ end_of_line = lf
7
+ indent_style = space
8
+ indent_size = 2
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+
@@ -1,19 +1,10 @@
1
1
  {
2
- "useTabs": true,
3
- "tabWidth": 4,
2
+ "useTabs": false,
3
+ "tabWidth": 2,
4
4
  "printWidth": 90,
5
5
  "endOfLine": "lf",
6
6
  "trailingComma": "none",
7
7
  "semi": true,
8
8
  "singleQuote": true,
9
- "arrowParens": "always",
10
- "overrides": [
11
- {
12
- "files": ["*.json"],
13
- "options": {
14
- "useTabs": false,
15
- "tabWidth": 2
16
- }
17
- }
18
- ]
9
+ "arrowParens": "always"
19
10
  }
@@ -1,10 +1,13 @@
1
1
  # Environment variables for plugin development
2
- # Update these paths to match your setup
3
-
4
- # Path to test vault (for development)
5
- TEST_VAULT=
6
-
7
- # Path to real vault (for production testing)
8
- REAL_VAULT=
9
-
10
- # Note: Run 'yarn version' to update these paths interactively
2
+ #
3
+ # Vault paths
4
+ # TEST_VAULT: path to your test/development vault (used with yarn dev)
5
+ # REAL_VAULT: path to your production vault (used with yarn real)
6
+ TEST_VAULT=/path/to/your/test/vault
7
+ REAL_VAULT=/path/to/your/real/vault
8
+ #
9
+ # Obsidian Local REST API (for automatic reload after yarn real)
10
+ # 1. Install the "Local REST API" plugin in Obsidian
11
+ # 2. Enable "Enable Non-encrypted (HTTP) Server" in plugin settings
12
+ # 3. Copy the API Key from plugin settings and paste it below
13
+ OBSIDIAN_REST_API_KEY=your_api_key_here
@@ -7,7 +7,7 @@ import type {
7
7
 
8
8
  const configs: Linter.Config[] = [
9
9
  {
10
- ignores: ["eslint.config.mts"]
10
+ ignores: ["eslint.config.mts", "scripts/**"]
11
11
  },
12
12
  {
13
13
  files: ["**/*.ts"],
@@ -2,7 +2,8 @@
2
2
  "type": "module",
3
3
  "engines": {
4
4
  "npm": "please-use-yarn",
5
- "yarn": ">=1.22.0"
5
+ "yarn": ">=1.22.0",
6
+ "node": ">=16.0.0"
6
7
  },
7
8
  "scripts": {
8
9
  "start": "yarn install && yarn dev",
@@ -25,7 +26,6 @@
25
26
  "devDependencies": {
26
27
  "@types/eslint": "latest",
27
28
  "@types/node": "latest",
28
- "@types/semver": "latest",
29
29
  "@typescript-eslint/eslint-plugin": "latest",
30
30
  "@typescript-eslint/parser": "latest",
31
31
  "builtin-modules": "latest",
@@ -39,7 +39,6 @@
39
39
  "obsidian-typings": "latest",
40
40
  "prettier": "latest",
41
41
  "tslib": "2.4.0",
42
- "semver": "latest",
43
42
  "tsx": "^4.21.0",
44
43
  "typescript": "^5.8.2"
45
44
  }