obsidian-plugin-config 1.6.18 → 1.7.0
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/bin/obsidian-inject.js +1 -1
- package/docs/INTERACTIVE_INJECTION.md +4 -4
- package/docs/LLM-GUIDE.md +12 -2
- package/eslint.config.mts +63 -64
- package/package.json +3 -3
- package/scripts/acp.ts +52 -56
- package/scripts/build-npm.ts +161 -157
- package/scripts/inject-core.ts +835 -823
- package/scripts/inject-path.ts +150 -160
- package/scripts/inject-prompt.ts +89 -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/scripts/acp.ts
CHANGED
|
@@ -1,83 +1,59 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
2
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from './utils.
|
|
3
|
+
askQuestion,
|
|
4
|
+
cleanInput,
|
|
5
|
+
createReadlineInterface,
|
|
6
|
+
gitExec,
|
|
7
|
+
ensureGitSync
|
|
8
|
+
} from './utils.ts';
|
|
11
9
|
|
|
12
10
|
const rl = createReadlineInterface();
|
|
13
11
|
|
|
14
|
-
// Check if we're in the centralized config repo
|
|
15
|
-
function isInCentralizedRepo(): boolean {
|
|
16
|
-
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
17
|
-
if (!fs.existsSync(packageJsonPath)) return false;
|
|
18
|
-
|
|
19
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
20
|
-
return packageJson.name === 'obsidian-plugin-config';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
12
|
async function main(): Promise<void> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
gitExec(`git push origin ${currentBranch}`);
|
|
64
|
-
console.log('Commit and push successful.');
|
|
65
|
-
} catch {
|
|
66
|
-
// new branch
|
|
67
|
-
console.log(`New branch detected. Setting upstream for ${currentBranch}...`);
|
|
68
|
-
gitExec(`git push --set-upstream origin ${currentBranch}`);
|
|
69
|
-
console.log('Upstream branch set and push successful.');
|
|
70
|
-
}
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.error('Error:', error instanceof Error ? error.message : String(error));
|
|
73
|
-
} finally {
|
|
74
|
-
rl.close();
|
|
75
|
-
}
|
|
13
|
+
try {
|
|
14
|
+
if (process.argv.includes('-b')) {
|
|
15
|
+
console.log('Building...');
|
|
16
|
+
gitExec('yarn build');
|
|
17
|
+
console.log('Build successful.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const input: string = await askQuestion('Enter commit message: ', rl);
|
|
21
|
+
|
|
22
|
+
const cleanedInput = cleanInput(input);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
gitExec('git add -A');
|
|
26
|
+
gitExec(`git commit -m "${cleanedInput}"`);
|
|
27
|
+
} catch {
|
|
28
|
+
console.log('Commit already exists or failed.');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// get current branch name
|
|
33
|
+
const currentBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
|
|
34
|
+
|
|
35
|
+
// Ensure Git is synchronized before pushing
|
|
36
|
+
await ensureGitSync();
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
gitExec(`git push origin ${currentBranch}`);
|
|
40
|
+
console.log('Commit and push successful.');
|
|
41
|
+
} catch {
|
|
42
|
+
// new branch
|
|
43
|
+
console.log(`New branch detected. Setting upstream for ${currentBranch}...`);
|
|
44
|
+
gitExec(`git push --set-upstream origin ${currentBranch}`);
|
|
45
|
+
console.log('Upstream branch set and push successful.');
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Error:', error instanceof Error ? error.message : String(error));
|
|
49
|
+
} finally {
|
|
50
|
+
rl.close();
|
|
51
|
+
}
|
|
76
52
|
}
|
|
77
53
|
|
|
78
54
|
main()
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
55
|
+
.catch(console.error)
|
|
56
|
+
.finally(() => {
|
|
57
|
+
console.log('Exiting...');
|
|
58
|
+
process.exit();
|
|
59
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import builtins from 'builtin-modules';
|
|
2
|
+
|
|
3
|
+
export const EXTERNAL_DEPS = [
|
|
4
|
+
'obsidian',
|
|
5
|
+
'electron',
|
|
6
|
+
'@codemirror/autocomplete',
|
|
7
|
+
'@codemirror/collab',
|
|
8
|
+
'@codemirror/commands',
|
|
9
|
+
'@codemirror/language',
|
|
10
|
+
'@codemirror/lint',
|
|
11
|
+
'@codemirror/search',
|
|
12
|
+
'@codemirror/state',
|
|
13
|
+
'@codemirror/view',
|
|
14
|
+
'@lezer/common',
|
|
15
|
+
'@lezer/highlight',
|
|
16
|
+
'@lezer/lr',
|
|
17
|
+
...builtins
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const BANNER = `/*
|
|
21
|
+
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
22
|
+
if you want to view the source, please visit the github repository of this plugin
|
|
23
|
+
*/`;
|
|
24
|
+
|
|
25
|
+
/** The default port used by the Obsidian Local REST API plugin for HTTP. */
|
|
26
|
+
export const OBSIDIAN_REST_PORT = 27123;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { type Interface } from 'readline';
|
|
5
|
+
import {
|
|
6
|
+
isValidPath,
|
|
7
|
+
isInPluginsFolder,
|
|
8
|
+
getVaultPath,
|
|
9
|
+
updateEnvFile,
|
|
10
|
+
ensureEnvFile,
|
|
11
|
+
promptForVaultPath
|
|
12
|
+
} from './utils.ts';
|
|
13
|
+
import { config } from 'dotenv';
|
|
14
|
+
|
|
15
|
+
interface Manifest {
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { Manifest };
|
|
20
|
+
|
|
21
|
+
export function checkManifest(pluginDir: string): Manifest {
|
|
22
|
+
const manifestPath = path.join(pluginDir, 'manifest.json');
|
|
23
|
+
|
|
24
|
+
// Check if manifest exists (for plugin-config itself, it might not exist)
|
|
25
|
+
if (!fs.existsSync(manifestPath)) {
|
|
26
|
+
console.log(
|
|
27
|
+
'⚠️ No manifest.json found - this script is designed for Obsidian plugins'
|
|
28
|
+
);
|
|
29
|
+
console.log(" If you're building plugin-config itself, use 'tsc' instead");
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check that the environment is valid
|
|
38
|
+
* - main.ts exists in src/
|
|
39
|
+
* - manifest.json exists and is valid JSON
|
|
40
|
+
*/
|
|
41
|
+
export async function validateEnvironment(pluginDir: string): Promise<void> {
|
|
42
|
+
const srcMainPath = path.join(pluginDir, 'src/main.ts');
|
|
43
|
+
if (!(await isValidPath(srcMainPath))) {
|
|
44
|
+
throw new Error('Invalid path for src/main.ts. main.ts must be in the src directory');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the build path based on the environment and user input
|
|
50
|
+
*
|
|
51
|
+
* @Param pluginDir The plugin directory
|
|
52
|
+
* @Param manifest The manifest object
|
|
53
|
+
* @Param _isProd Whether this is a production build (true for 'production' arg, false for 'watch'/'dev')
|
|
54
|
+
* @Param rl The readline interface
|
|
55
|
+
* @return The path to build the plugin to (either the vault plugins folder or the initial folder for in-place development)
|
|
56
|
+
*/
|
|
57
|
+
export async function getBuildPath(
|
|
58
|
+
pluginDir: string,
|
|
59
|
+
manifest: Manifest,
|
|
60
|
+
isProd: boolean,
|
|
61
|
+
rl: Interface
|
|
62
|
+
): Promise<string> {
|
|
63
|
+
// In-place development: already inside a plugins folder
|
|
64
|
+
if (isInPluginsFolder(pluginDir)) {
|
|
65
|
+
console.log('ℹ️ Building in Obsidian plugins folder (in-place development)');
|
|
66
|
+
return pluginDir;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// External development
|
|
70
|
+
const useRealVault = process.argv.includes('-r') || process.argv.includes('real');
|
|
71
|
+
|
|
72
|
+
// Production build without vault copy: build in place, no vault resolution needed
|
|
73
|
+
if (isProd && !useRealVault) {
|
|
74
|
+
return pluginDir;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const envKey = useRealVault ? 'REAL_VAULT' : 'TEST_VAULT';
|
|
78
|
+
const envPath = path.join(pluginDir, '.env');
|
|
79
|
+
|
|
80
|
+
await ensureEnvFile(envPath);
|
|
81
|
+
config(); // reload after potential creation
|
|
82
|
+
|
|
83
|
+
const vaultPath = process.env[envKey]?.trim();
|
|
84
|
+
|
|
85
|
+
// Prompt if missing or still a placeholder
|
|
86
|
+
if (!vaultPath || vaultPath.startsWith('/path/to/your/')) {
|
|
87
|
+
const newPath = await promptForVaultPath(envKey, rl);
|
|
88
|
+
await updateEnvFile(envKey, newPath, envPath);
|
|
89
|
+
config();
|
|
90
|
+
return getVaultPath(newPath, manifest.id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return getVaultPath(vaultPath, manifest.id);
|
|
94
|
+
}
|