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.
- package/.injection-info.json +5 -1
- package/.vscode/tasks.json +116 -116
- package/bin/obsidian-inject.js +1 -1
- package/package.json +3 -1
- package/scripts/acp.ts +64 -56
- package/scripts/build-npm.ts +152 -135
- package/scripts/esbuild.config.ts +221 -196
- package/scripts/inject-core.ts +613 -619
- package/scripts/inject-path.ts +144 -130
- package/scripts/inject-prompt.ts +85 -78
- package/scripts/sync-template-deps.ts +44 -44
- package/scripts/update-version-config.ts +117 -98
- package/scripts/utils.ts +121 -118
- package/templates/.vscode/settings.json +9 -9
- package/templates/.vscode/tasks.json +53 -53
- package/templates/package.json +3 -1
- package/templates/scripts/acp.ts +64 -56
- package/templates/scripts/esbuild.config.ts +268 -232
- package/templates/scripts/release.ts +78 -79
- package/templates/scripts/update-version.ts +129 -106
- package/templates/scripts/utils.ts +129 -126
- package/tsconfig.json +30 -41
- package/versions.json +3 -1
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|