obsidian-plugin-config 1.4.4 → 1.4.7

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,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,121 +30,124 @@ 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: any) {
80
- if (error.code !== "EEXIST") {
81
- console.error(`Error creating directory: ${error.message}`);
82
- }
83
- }
84
-
85
- // Copy manifest
86
- try {
87
- await copyFile(manifestSrc, manifestDest);
88
- } catch (error: any) {
89
- console.error(`Error copying manifest: ${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: any) {
111
- console.error(`Error copying CSS: ${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: any) {
83
+ if (error.code !== 'EEXIST') {
84
+ console.error(`Error creating directory: ${error.message}`);
85
+ }
86
+ }
87
+
88
+ // Copy manifest
89
+ try {
90
+ await copyFile(manifestSrc, manifestDest);
91
+ } catch (error: any) {
92
+ console.error(`Error copying manifest: ${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: any) {
114
+ console.error(`Error copying CSS: ${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: any) {
119
- console.error(`Error executing '${command}':`, error.message);
120
- throw error;
121
- }
119
+ try {
120
+ execSync(command, { stdio: 'inherit' });
121
+ } catch (error: any) {
122
+ console.error(`Error executing '${command}':`, 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: any) {
145
- console.error(`❌ Git sync failed: ${error.message}`);
146
- throw error;
147
- }
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: any) {
148
+ console.error(`❌ Git sync failed: ${error.message}`);
149
+ throw error;
150
+ }
148
151
  }
149
152
 
150
153
  /**
@@ -152,12 +155,12 @@ export async function ensureGitSync(): Promise<void> {
152
155
  * This prevents the unwanted main.css from being included in the plugin
153
156
  */
154
157
  export async function removeMainCss(outdir: string): Promise<void> {
155
- const mainCssPath = path.join(outdir, 'main.css');
156
- try {
157
- await rm(mainCssPath);
158
- } catch (error: any) {
159
- if (error.code !== 'ENOENT') {
160
- console.warn(`Warning: Could not remove main.css: ${error.message}`);
161
- }
162
- }
163
- }
158
+ const mainCssPath = path.join(outdir, 'main.css');
159
+ try {
160
+ await rm(mainCssPath);
161
+ } catch (error: any) {
162
+ if (error.code !== 'ENOENT') {
163
+ console.warn(`Warning: Could not remove main.css: ${error.message}`);
164
+ }
165
+ }
166
+ }
package/tsconfig.json CHANGED
@@ -1,41 +1,30 @@
1
- {
2
- "compilerOptions": {
3
- "types": [
4
- "obsidian-typings"
5
- ],
6
- "paths": {
7
- "obsidian-typings/implementations": [
8
- "./node_modules/obsidian-typings/dist/cjs/implementations.d.cts",
9
- "./node_modules/obsidian-typings/dist/esm/implementations.mjs"
10
- ]
11
- },
12
- "inlineSourceMap": true,
13
- "inlineSources": true,
14
- "module": "NodeNext",
15
- "moduleResolution": "NodeNext",
16
- "target": "ES2021",
17
- "allowJs": true,
18
- "noImplicitAny": true,
19
- "importHelpers": true,
20
- "isolatedModules": true,
21
- "allowImportingTsExtensions": true,
22
- "noEmit": true,
23
- "allowSyntheticDefaultImports": true,
24
- "verbatimModuleSyntax": true,
25
- "forceConsistentCasingInFileNames": true,
26
- "strictNullChecks": true,
27
- "resolveJsonModule": true,
28
- "lib": [
29
- "DOM",
30
- "ES2021"
31
- ]
32
- },
33
- "include": [
34
- "./src/**/*.ts",
35
- "./scripts/**/*.ts"
36
- ],
37
- "exclude": [
38
- "node_modules",
39
- "eslint.config.ts"
40
- ]
41
- }
1
+ {
2
+ "compilerOptions": {
3
+ "types": ["obsidian-typings"],
4
+ "paths": {
5
+ "obsidian-typings/implementations": [
6
+ "./node_modules/obsidian-typings/dist/cjs/implementations.d.cts",
7
+ "./node_modules/obsidian-typings/dist/esm/implementations.mjs"
8
+ ]
9
+ },
10
+ "inlineSourceMap": true,
11
+ "inlineSources": true,
12
+ "module": "NodeNext",
13
+ "moduleResolution": "NodeNext",
14
+ "target": "ES2021",
15
+ "allowJs": true,
16
+ "noImplicitAny": true,
17
+ "importHelpers": true,
18
+ "isolatedModules": true,
19
+ "allowImportingTsExtensions": true,
20
+ "noEmit": true,
21
+ "allowSyntheticDefaultImports": true,
22
+ "verbatimModuleSyntax": true,
23
+ "forceConsistentCasingInFileNames": true,
24
+ "strictNullChecks": true,
25
+ "resolveJsonModule": true,
26
+ "lib": ["DOM", "ES2021"]
27
+ },
28
+ "include": ["./src/**/*.ts", "./scripts/**/*.ts"],
29
+ "exclude": ["node_modules", "eslint.config.ts"]
30
+ }
package/versions.json CHANGED
@@ -43,5 +43,8 @@
43
43
  "1.4.1": "1.8.9",
44
44
  "1.4.2": "1.8.9",
45
45
  "1.4.3": "1.8.9",
46
- "1.4.4": "1.8.9"
46
+ "1.4.4": "1.8.9",
47
+ "1.4.5": "1.8.9",
48
+ "1.4.6": "1.8.9",
49
+ "1.4.7": "1.8.9"
47
50
  }