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,83 +1,59 @@
1
1
  import { execSync } from 'child_process';
2
- import fs from 'fs';
3
- import path from 'path';
4
2
  import {
5
- askQuestion,
6
- cleanInput,
7
- createReadlineInterface,
8
- gitExec,
9
- ensureGitSync
10
- } from './utils.js';
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
- try {
25
- if (process.argv.includes('-b')) {
26
- console.log('Building...');
27
- gitExec('yarn build');
28
- console.log('Build successful.');
29
- }
30
-
31
- // Only update exports if we're in the centralized repo and not explicitly disabled
32
- if (
33
- !process.argv.includes('-ne') &&
34
- !process.argv.includes('--no-exports') &&
35
- isInCentralizedRepo()
36
- ) {
37
- console.log('Updating exports...');
38
- gitExec('yarn run update-exports');
39
- console.log('Exports updated.');
40
- }
41
-
42
- const input: string = await askQuestion('Enter commit message: ', rl);
43
-
44
- const cleanedInput = cleanInput(input);
45
-
46
- try {
47
- gitExec('git add -A');
48
- gitExec(`git commit -m "${cleanedInput}"`);
49
- } catch {
50
- console.log('Commit already exists or failed.');
51
- return;
52
- }
53
-
54
- // get current branch name
55
- const currentBranch = execSync('git rev-parse --abbrev-ref HEAD')
56
- .toString()
57
- .trim();
58
-
59
- // Ensure Git is synchronized before pushing
60
- await ensureGitSync();
61
-
62
- try {
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
- .catch(console.error)
80
- .finally(() => {
81
- console.log('Exiting...');
82
- process.exit();
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
+ }