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,98 +1,117 @@
1
- import { readFile, writeFile } from "fs/promises";
2
- import dedent from "dedent";
3
- import { inc, valid } from "semver";
4
- import { createReadlineInterface, askQuestion, gitExec } from "./utils.js";
5
-
6
-
7
- const rl = createReadlineInterface();
8
-
9
- async function getTargetVersion(currentVersion: string): Promise<string> {
10
- const updateType = await askQuestion(dedent`
11
- Current version: ${currentVersion}
12
- Kind of update:
13
- patch(1.0.1) -> type 1 or p
14
- minor(1.1.0) -> type 2 or min
15
- major(2.0.0) -> type 3 or maj
16
- or version number (e.g. 2.0.0)
17
- Enter choice: `, rl);
18
-
19
- switch (updateType.trim()) {
20
- case "p":
21
- case "1":
22
- return inc(currentVersion, "patch") || "";
23
- case "min":
24
- case "2":
25
- return inc(currentVersion, "minor") || "";
26
- case "maj":
27
- case "3":
28
- return inc(currentVersion, "major") || "";
29
- default:
30
- return valid(updateType.trim()) || "";
31
- }
32
- }
33
-
34
- async function updateJsonFile(filename: string, updateFn: (json: Record<string, unknown>) => void): Promise<void> {
35
- try {
36
- const content = JSON.parse(await readFile(filename, "utf8"));
37
- updateFn(content);
38
- await writeFile(filename, JSON.stringify(content, null, "\t"));
39
- } catch (error) {
40
- console.error(`Error updating ${filename}:`, error instanceof Error ? error.message : String(error));
41
- throw error;
42
- }
43
- }
44
-
45
- async function updateConfigVersions(targetVersion: string): Promise<void> {
46
- try {
47
- await Promise.all([
48
- updateJsonFile("package.json", json => json.version = targetVersion),
49
- updateJsonFile("versions.json", json => json[targetVersion] = "1.8.9")
50
- ]);
51
- } catch (error) {
52
- console.error("Error updating config versions:", error instanceof Error ? error.message : String(error));
53
- throw error;
54
- }
55
- }
56
-
57
- async function updateVersion(): Promise<void> {
58
- try {
59
- const currentVersion = process.env.npm_package_version || "1.0.0";
60
- const targetVersion = await getTargetVersion(currentVersion);
61
-
62
- if (!targetVersion) {
63
- console.log("Invalid version");
64
- return;
65
- }
66
-
67
- try {
68
- // Update all files first
69
- await updateConfigVersions(targetVersion);
70
- console.log(`Files updated to version ${targetVersion}`);
71
-
72
- // Add files to git
73
- gitExec("git add package.json versions.json");
74
- gitExec(`git commit -m "Updated to version ${targetVersion}"`);
75
- console.log("Changes committed");
76
- } catch (error) {
77
- console.error("Error during update or commit:", error instanceof Error ? error.message : String(error));
78
- console.log("Operation failed.");
79
- return;
80
- }
81
-
82
- try {
83
- gitExec("git push");
84
- console.log(`Version successfully updated to ${targetVersion} and pushed.`);
85
- } catch (pushError) {
86
- console.error("Failed to push version update:", pushError instanceof Error ? pushError.message : String(pushError));
87
- }
88
- } catch (error) {
89
- console.error("Error:", error instanceof Error ? error.message : String(error));
90
- } finally {
91
- rl.close();
92
- }
93
- }
94
-
95
- updateVersion().catch(console.error).finally(() => {
96
- console.log("Exiting...");
97
- process.exit();
98
- });
1
+ import { readFile, writeFile } from 'fs/promises';
2
+ import dedent from 'dedent';
3
+ import { inc, valid } from 'semver';
4
+ import { createReadlineInterface, askQuestion, gitExec } from './utils.js';
5
+
6
+ const rl = createReadlineInterface();
7
+
8
+ async function getTargetVersion(currentVersion: string): Promise<string> {
9
+ const updateType = await askQuestion(
10
+ dedent`
11
+ Current version: ${currentVersion}
12
+ Kind of update:
13
+ patch(1.0.1) -> type 1 or p
14
+ minor(1.1.0) -> type 2 or min
15
+ major(2.0.0) -> type 3 or maj
16
+ or version number (e.g. 2.0.0)
17
+ 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
+ }
34
+ }
35
+
36
+ async function updateJsonFile(
37
+ filename: string,
38
+ updateFn: (json: Record<string, unknown>) => void
39
+ ): Promise<void> {
40
+ try {
41
+ const content = JSON.parse(await readFile(filename, 'utf8'));
42
+ updateFn(content);
43
+ await writeFile(filename, JSON.stringify(content, null, '\t'));
44
+ } catch (error) {
45
+ console.error(
46
+ `Error updating ${filename}:`,
47
+ error instanceof Error ? error.message : String(error)
48
+ );
49
+ throw error;
50
+ }
51
+ }
52
+
53
+ async function updateConfigVersions(targetVersion: string): Promise<void> {
54
+ try {
55
+ await Promise.all([
56
+ updateJsonFile('package.json', (json) => (json.version = targetVersion)),
57
+ updateJsonFile('versions.json', (json) => (json[targetVersion] = '1.8.9'))
58
+ ]);
59
+ } catch (error) {
60
+ console.error(
61
+ 'Error updating config versions:',
62
+ error instanceof Error ? error.message : String(error)
63
+ );
64
+ throw error;
65
+ }
66
+ }
67
+
68
+ async function updateVersion(): Promise<void> {
69
+ try {
70
+ const currentVersion = process.env.npm_package_version || '1.0.0';
71
+ const targetVersion = await getTargetVersion(currentVersion);
72
+
73
+ if (!targetVersion) {
74
+ console.log('Invalid version');
75
+ return;
76
+ }
77
+
78
+ try {
79
+ // Update all files first
80
+ await updateConfigVersions(targetVersion);
81
+ console.log(`Files updated to version ${targetVersion}`);
82
+
83
+ // Add files to git
84
+ gitExec('git add package.json versions.json');
85
+ gitExec(`git commit -m "Updated to version ${targetVersion}"`);
86
+ console.log('Changes committed');
87
+ } catch (error) {
88
+ console.error(
89
+ 'Error during update or commit:',
90
+ error instanceof Error ? error.message : String(error)
91
+ );
92
+ console.log('Operation failed.');
93
+ return;
94
+ }
95
+
96
+ try {
97
+ gitExec('git push');
98
+ console.log(`Version successfully updated to ${targetVersion} and pushed.`);
99
+ } catch (pushError) {
100
+ console.error(
101
+ 'Failed to push version update:',
102
+ pushError instanceof Error ? pushError.message : String(pushError)
103
+ );
104
+ }
105
+ } catch (error) {
106
+ console.error('Error:', error instanceof Error ? error.message : String(error));
107
+ } finally {
108
+ rl.close();
109
+ }
110
+ }
111
+
112
+ updateVersion()
113
+ .catch(console.error)
114
+ .finally(() => {
115
+ console.log('Exiting...');
116
+ process.exit();
117
+ });
package/scripts/utils.ts CHANGED
@@ -1,27 +1,27 @@
1
- import {
2
- access,
3
- mkdir,
4
- copyFile,
5
- rm
6
- } from "fs/promises";
7
- import path from "path";
8
- import * as readline from "readline";
9
- import { execSync } from "child_process";
1
+ import { access, mkdir, copyFile, rm } from 'fs/promises';
2
+ import path from 'path';
3
+ import * as readline from 'readline';
4
+ import { execSync } from 'child_process';
10
5
 
11
6
  export function createReadlineInterface(): readline.Interface {
12
- return readline.createInterface({
13
- input: process.stdin as NodeJS.ReadableStream,
14
- output: process.stdout as NodeJS.WritableStream,
15
- });
7
+ return readline.createInterface({
8
+ input: process.stdin as NodeJS.ReadableStream,
9
+ output: process.stdout as NodeJS.WritableStream
10
+ });
16
11
  }
17
12
 
18
- export const askQuestion = async (question: string, rl: readline.Interface): Promise<string> => {
19
- try {
20
- return await new Promise(resolve => rl.question(question, input => resolve(input.trim())));
21
- } catch (error) {
22
- console.error("Error asking question:", error);
23
- throw error;
24
- }
13
+ export const askQuestion = async (
14
+ question: string,
15
+ rl: readline.Interface
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
+ }
25
25
  };
26
26
 
27
27
  /**
@@ -30,119 +30,122 @@ export const askQuestion = async (question: string, rl: readline.Interface): Pro
30
30
  * Rejects: n, no, N, NO
31
31
  * Invalid input defaults to no for safety
32
32
  */
33
- export const askConfirmation = async (question: string, rl: readline.Interface): Promise<boolean> => {
34
- const answer = await askQuestion(`${question} [Y/n]: `, rl);
35
- const response = answer.toLowerCase();
36
-
37
- // Accept: y, yes, Y, YES, or empty (default to yes)
38
- // Reject: n, no, N, NO
39
- const isYes = response === '' || response === 'y' || response === 'yes';
40
- const isNo = response === 'n' || response === 'no';
41
-
42
- if (isNo) {
43
- return false;
44
- } else if (isYes) {
45
- return true;
46
- } else {
47
- console.log("Please answer Y (yes) or n (no). Defaulting to no for safety.");
48
- return false;
49
- }
33
+ export const askConfirmation = async (
34
+ question: string,
35
+ rl: readline.Interface
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
+ }
50
53
  };
51
54
 
52
55
  export const cleanInput = (inputStr: string): string => {
53
- if (!inputStr) return "";
54
- 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');
55
58
  };
56
59
 
57
60
  export const isValidPath = async (pathToCheck: string): Promise<boolean> => {
58
- if (!pathToCheck) return false;
59
-
60
- try {
61
- // Using async fs.access is preferred over synchronous existsSync
62
- // as it doesn't block the main thread/event loop
63
- await access(pathToCheck.trim());
64
- return true;
65
- } catch {
66
- return false;
67
- }
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
+ }
68
71
  };
69
72
 
70
73
  export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
71
- const pluginDir = process.cwd();
72
- const manifestSrc = path.join(pluginDir, "manifest.json");
73
- const manifestDest = path.join(buildPath, "manifest.json");
74
- const cssDest = path.join(buildPath, "styles.css");
75
- const folderToRemove = path.join(buildPath, "_.._");
76
-
77
- try {
78
- await mkdir(buildPath, { recursive: true });
79
- } catch (error: unknown) {
80
- if ((error as NodeJS.ErrnoException).code !== "EEXIST") {
81
- console.error(`Error creating directory: ${(error as Error).message}`);
82
- }
83
- }
84
-
85
- // Copy manifest
86
- try {
87
- await copyFile(manifestSrc, manifestDest);
88
- } catch (error: unknown) {
89
- console.error(`Error copying manifest: ${(error as Error).message}`);
90
- }
91
-
92
- // Copy CSS
93
- try {
94
- const srcStylesPath = path.join(pluginDir, "src/styles.css");
95
- const rootStylesPath = path.join(pluginDir, "styles.css");
96
-
97
- // First check if CSS exists in src/styles.css
98
- if (await isValidPath(srcStylesPath)) {
99
- await copyFile(srcStylesPath, cssDest);
100
- }
101
- // Otherwise, check if it exists in the root
102
- else if (await isValidPath(rootStylesPath)) {
103
- await copyFile(rootStylesPath, cssDest);
104
- if (await isValidPath(folderToRemove)) {
105
- await rm(folderToRemove, { recursive: true });
106
- }
107
- } else {
108
- return;
109
- }
110
- } catch (error: unknown) {
111
- console.error(`Error copying CSS: ${(error as Error).message}`);
112
- }
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
+ }
113
116
  }
114
117
 
115
118
  export function gitExec(command: string): void {
116
- try {
117
- execSync(command, { stdio: "inherit" });
118
- } catch (error: unknown) {
119
- console.error(`Error executing '${command}':`, (error as Error).message);
120
- throw error;
121
- }
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
+ }
122
125
  }
123
126
 
124
127
  /**
125
128
  * Ensure Git repository is synchronized with remote before pushing
126
129
  */
127
130
  export async function ensureGitSync(): Promise<void> {
128
- try {
129
- console.log("🔄 Checking Git synchronization...");
130
-
131
- // Fetch latest changes from remote
132
- execSync('git fetch origin', { stdio: 'pipe' });
133
-
134
- // Check if branch is behind remote
135
- const status = execSync('git status --porcelain -b', { encoding: 'utf8' });
136
-
137
- if (status.includes('behind')) {
138
- console.log('📥 Branch behind remote. Pulling changes...');
139
- execSync('git pull', { stdio: 'inherit' });
140
- console.log('✅ Successfully pulled remote changes');
141
- } else {
142
- console.log('✅ Repository is synchronized with remote');
143
- }
144
- } catch (error: unknown) {
145
- console.error(`❌ Git sync failed: ${(error as Error).message}`);
146
- throw error;
147
- }
148
- }
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
+ }
@@ -1,11 +1,11 @@
1
1
  {
2
- "npm.packageManager": "yarn",
3
- // "js/ts.preferences.includePackageJsonAutoImports": "off",
4
- "[typescript]": {
5
- "editor.defaultFormatter": "esbenp.prettier-vscode"
6
- },
7
- "[markdown]": {
8
- "editor.defaultFormatter": "yzhang.markdown-all-in-one"
9
- },
10
- "editor.formatOnSave": true
2
+ "npm.packageManager": "yarn",
3
+ // "js/ts.preferences.includePackageJsonAutoImports": "off",
4
+ "[typescript]": {
5
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
6
+ },
7
+ "[markdown]": {
8
+ "editor.defaultFormatter": "yzhang.markdown-all-in-one"
9
+ },
10
+ "editor.formatOnSave": true
11
11
  }
@@ -1,53 +1,53 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "label": "Lint",
6
- "type": "shell",
7
- "command": "yarn lint",
8
- "group": "test",
9
- "presentation": { "reveal": "always", "panel": "shared" },
10
- "problemMatcher": ["$eslint-stylish"]
11
- },
12
- {
13
- "label": "Lint: Fix",
14
- "type": "shell",
15
- "command": "yarn lint:fix",
16
- "group": "test",
17
- "presentation": { "reveal": "always", "panel": "shared" },
18
- "problemMatcher": ["$eslint-stylish"]
19
- },
20
- {
21
- "label": "Prettier: Check",
22
- "type": "shell",
23
- "command": "npx prettier --check \"{src,scripts}/**/*.{ts,json}\"",
24
- "group": "test",
25
- "presentation": { "reveal": "always", "panel": "shared" },
26
- "problemMatcher": []
27
- },
28
- {
29
- "label": "Prettier: Fix",
30
- "type": "shell",
31
- "command": "npx prettier --write \"{src,scripts}/**/*.{ts,json}\"",
32
- "group": "test",
33
- "presentation": { "reveal": "always", "panel": "shared" },
34
- "problemMatcher": []
35
- },
36
- {
37
- "label": "Build",
38
- "type": "shell",
39
- "command": "yarn build",
40
- "group": { "kind": "build", "isDefault": true },
41
- "presentation": { "reveal": "always", "panel": "shared" },
42
- "problemMatcher": ["$tsc"]
43
- },
44
- {
45
- "label": "Cleanup: Lint + Prettier + Build",
46
- "dependsOrder": "sequence",
47
- "dependsOn": ["Lint: Fix", "Prettier: Fix", "Build"],
48
- "group": "build",
49
- "presentation": { "reveal": "always", "panel": "shared" },
50
- "problemMatcher": []
51
- }
52
- ]
53
- }
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "Lint",
6
+ "type": "shell",
7
+ "command": "yarn lint",
8
+ "group": "test",
9
+ "presentation": { "reveal": "always", "panel": "shared" },
10
+ "problemMatcher": ["$eslint-stylish"]
11
+ },
12
+ {
13
+ "label": "Lint: Fix",
14
+ "type": "shell",
15
+ "command": "yarn lint:fix",
16
+ "group": "test",
17
+ "presentation": { "reveal": "always", "panel": "shared" },
18
+ "problemMatcher": ["$eslint-stylish"]
19
+ },
20
+ {
21
+ "label": "Prettier: Check",
22
+ "type": "shell",
23
+ "command": "yarn prettier",
24
+ "group": "test",
25
+ "presentation": { "reveal": "always", "panel": "shared" },
26
+ "problemMatcher": []
27
+ },
28
+ {
29
+ "label": "Prettier: Fix",
30
+ "type": "shell",
31
+ "command": "yarn prettier:fix",
32
+ "group": "test",
33
+ "presentation": { "reveal": "always", "panel": "shared" },
34
+ "problemMatcher": []
35
+ },
36
+ {
37
+ "label": "Build",
38
+ "type": "shell",
39
+ "command": "yarn build",
40
+ "group": { "kind": "build", "isDefault": true },
41
+ "presentation": { "reveal": "always", "panel": "shared" },
42
+ "problemMatcher": ["$tsc"]
43
+ },
44
+ {
45
+ "label": "Cleanup: Lint + Prettier + Build",
46
+ "dependsOrder": "sequence",
47
+ "dependsOn": ["Lint: Fix", "Prettier: Fix", "Build"],
48
+ "group": "build",
49
+ "presentation": { "reveal": "always", "panel": "shared" },
50
+ "problemMatcher": []
51
+ }
52
+ ]
53
+ }
@@ -18,7 +18,9 @@
18
18
  "help": "tsx scripts/help.ts",
19
19
  "h": "tsx scripts/help.ts",
20
20
  "lint": "eslint . --ext .ts",
21
- "lint:fix": "eslint . --ext .ts --fix"
21
+ "lint:fix": "eslint . --ext .ts --fix",
22
+ "prettier": "npx prettier --check '**/*.{ts,json}'",
23
+ "prettier:fix": "npx prettier --write '**/*.{ts,json}'"
22
24
  },
23
25
  "devDependencies": {
24
26
  "@types/eslint": "latest",