obsidian-plugin-config 1.0.2

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.
Files changed (55) hide show
  1. package/.vscode/settings.json +4 -0
  2. package/README.md +45 -0
  3. package/bin/obsidian-inject.js +98 -0
  4. package/obsidian-plugin-config-1.0.2.tgz +0 -0
  5. package/package.json +88 -0
  6. package/scripts/acp.ts +71 -0
  7. package/scripts/build-npm.ts +137 -0
  8. package/scripts/esbuild.config.ts +311 -0
  9. package/scripts/help.ts +46 -0
  10. package/scripts/inject-path.ts +487 -0
  11. package/scripts/inject-prompt.ts +399 -0
  12. package/scripts/open-editor.mjs +18 -0
  13. package/scripts/release.ts +97 -0
  14. package/scripts/update-exports.js +91 -0
  15. package/scripts/update-version-config.ts +98 -0
  16. package/scripts/update-version.ts +102 -0
  17. package/scripts/utils.ts +117 -0
  18. package/src/index.ts +6 -0
  19. package/src/main_test.ts +106 -0
  20. package/src/modals/GenericConfirmModal.ts +67 -0
  21. package/src/modals/index.ts +3 -0
  22. package/src/test-centralized-utils.ts +23 -0
  23. package/src/tools/index.ts +9 -0
  24. package/src/utils/NoticeHelper.ts +102 -0
  25. package/src/utils/SettingsHelper.ts +180 -0
  26. package/src/utils/index.ts +3 -0
  27. package/templates/.vscode/settings.json +4 -0
  28. package/templates/eslint.config.ts +48 -0
  29. package/templates/help-plugin.ts +39 -0
  30. package/templates/package-versions.json +28 -0
  31. package/templates/tsconfig.json +37 -0
  32. package/test-plugin/manifest.json +10 -0
  33. package/test-plugin/package.json +38 -0
  34. package/test-plugin/scripts/acp.ts +71 -0
  35. package/test-plugin/scripts/esbuild.config.ts +165 -0
  36. package/test-plugin/scripts/help.ts +29 -0
  37. package/test-plugin/scripts/release.ts +97 -0
  38. package/test-plugin/scripts/update-version.ts +102 -0
  39. package/test-plugin/scripts/utils.ts +117 -0
  40. package/test-plugin/src/main.ts +11 -0
  41. package/test-plugin/yarn.lock +386 -0
  42. package/test-plugin-v2/main.js +5 -0
  43. package/test-plugin-v2/manifest.json +10 -0
  44. package/test-plugin-v2/package.json +40 -0
  45. package/test-plugin-v2/scripts/acp.ts +71 -0
  46. package/test-plugin-v2/scripts/esbuild.config.ts +165 -0
  47. package/test-plugin-v2/scripts/help.ts +29 -0
  48. package/test-plugin-v2/scripts/release.ts +97 -0
  49. package/test-plugin-v2/scripts/update-version.ts +102 -0
  50. package/test-plugin-v2/scripts/utils.ts +117 -0
  51. package/test-plugin-v2/src/main.ts +11 -0
  52. package/test-plugin-v2/tsconfig.json +31 -0
  53. package/test-plugin-v2/yarn.lock +1986 -0
  54. package/tsconfig.json +38 -0
  55. package/versions.json +5 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "npm.packageManager": "yarn",
3
+ "typescript.preferences.includePackageJsonAutoImports": "off"
4
+ }
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Obsidian Plugin Config
2
+
3
+ Système d'injection pour plugins Obsidian autonomes.
4
+
5
+ ## Installation Globale
6
+
7
+ ```bash
8
+ npm install -g obsidian-plugin-config
9
+ ```
10
+
11
+ ## Utilisation
12
+
13
+ ### Injection dans un plugin existant
14
+
15
+ ```bash
16
+ cd votre-plugin-obsidian
17
+ obsidian-inject
18
+ ```
19
+
20
+ ### Injection par chemin
21
+
22
+ ```bash
23
+ obsidian-inject /chemin/vers/plugin
24
+ ```
25
+
26
+ ## Ce qui est injecté
27
+
28
+ - **Scripts locaux** : esbuild.config.ts, acp.ts, update-version.ts, utils.ts
29
+ - **Configuration package.json** : scripts, dépendances, protection yarn
30
+ - **Dossiers requis** : .github/workflows
31
+ - **Installation automatique** des dépendances
32
+
33
+ ## Commandes disponibles
34
+
35
+ ```bash
36
+ yarn inject-path <chemin> # Injection par chemin
37
+ yarn inject <chemin> # Alias
38
+ yarn migrate <chemin> # Migration de plugins (développement)
39
+ yarn acp # Add-commit-push
40
+ yarn h # Aide
41
+ ```
42
+
43
+ ## Architecture
44
+
45
+ Système d'injection qui transforme n'importe quel plugin en version autonome avec scripts locaux intégrés.
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Obsidian Plugin Config - CLI Entry Point
5
+ * Global command: obsidian-inject
6
+ */
7
+
8
+ import { execSync } from 'child_process';
9
+ import { fileURLToPath } from 'url';
10
+ import { dirname, join, isAbsolute, resolve } from 'path';
11
+ import fs from 'fs';
12
+
13
+ // Get the directory of this script
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = dirname(__filename);
16
+ const packageRoot = dirname(__dirname);
17
+
18
+ // Path to the injection script
19
+ const injectScriptPath = join(packageRoot, 'scripts', 'inject-path.ts');
20
+
21
+ function showHelp() {
22
+ console.log(`
23
+ Obsidian Plugin Config - Global CLI
24
+ Système d'injection pour plugins Obsidian autonomes
25
+
26
+ UTILISATION:
27
+ obsidian-inject # Injection dans le répertoire courant
28
+ obsidian-inject <chemin> # Injection par chemin
29
+ obsidian-inject --help, -h # Afficher cette aide
30
+
31
+ EXEMPLES:
32
+ cd mon-plugin && obsidian-inject
33
+ obsidian-inject ../mon-autre-plugin
34
+ obsidian-inject "C:\\Users\\dev\\plugins\\mon-plugin"
35
+
36
+ CE QUI EST INJECTÉ:
37
+ ✅ Scripts locaux (esbuild.config.ts, acp.ts, utils.ts, etc.)
38
+ ✅ Configuration package.json (scripts, dépendances)
39
+ ✅ Protection yarn obligatoire
40
+ ✅ Installation automatique des dépendances
41
+
42
+ ARCHITECTURE:
43
+ - Plugin devient AUTONOME avec scripts locaux
44
+ - Aucune dépendance externe requise après injection
45
+ - Mise à jour possible via re-injection
46
+
47
+ Pour plus d'informations: https://github.com/3C0D/obsidian-plugin-config
48
+ `);
49
+ }
50
+
51
+ function main() {
52
+ const args = process.argv.slice(2);
53
+
54
+ // Handle help flags
55
+ if (args.includes('--help') || args.includes('-h')) {
56
+ showHelp();
57
+ process.exit(0);
58
+ }
59
+
60
+ // Check if injection script exists
61
+ if (!fs.existsSync(injectScriptPath)) {
62
+ console.error(`❌ Erreur: Script d'injection non trouvé à ${injectScriptPath}`);
63
+ console.error(` Vérifiez que obsidian-plugin-config est correctement installé.`);
64
+ process.exit(1);
65
+ }
66
+
67
+ // Determine target path (resolve relative to user's current directory)
68
+ const userCwd = process.cwd();
69
+ let targetPath = args[0] || userCwd;
70
+
71
+ // If relative path, resolve from user's current directory
72
+ if (args[0] && !isAbsolute(args[0])) {
73
+ targetPath = resolve(userCwd, args[0]);
74
+ }
75
+
76
+ console.log(`🎯 Obsidian Plugin Config - Injection Globale`);
77
+ console.log(`📁 Cible: ${targetPath}`);
78
+ console.log(`📦 Depuis: ${packageRoot}\n`);
79
+
80
+ try {
81
+ // Execute the injection script with tsx
82
+ const command = `npx tsx "${injectScriptPath}" "${targetPath}"`;
83
+
84
+ execSync(command, {
85
+ stdio: 'inherit',
86
+ cwd: userCwd // Use user's current directory, not package directory
87
+ });
88
+
89
+ console.log(`\n✅ Injection terminée avec succès !`);
90
+
91
+ } catch (error) {
92
+ console.error(`\n❌ Erreur lors de l'injection:`, error.message);
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ // Run the CLI
98
+ main();
Binary file
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "obsidian-plugin-config",
3
+ "version": "1.0.2",
4
+ "description": "Système d'injection pour plugins Obsidian autonomes",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "bin": {
8
+ "obsidian-inject": "./bin/obsidian-inject.js"
9
+ },
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "obsidian",
13
+ "obsidian-plugin",
14
+ "typescript",
15
+ "injection",
16
+ "autonomous",
17
+ "cli",
18
+ "development-tools",
19
+ "plugin-utilities"
20
+ ],
21
+ "scripts": {
22
+ "start": "yarn install && yarn run update-exports",
23
+ "update-exports": "node scripts/update-exports.js",
24
+ "acp": "tsx scripts/acp.ts",
25
+ "update-version": "tsx scripts/update-version-config.ts",
26
+ "v": "tsx scripts/update-version-config.ts",
27
+ "inject-path": "tsx scripts/inject-path.ts",
28
+ "inject": "tsx scripts/inject-path.ts",
29
+ "inject-prompt": "tsx scripts/inject-prompt.ts",
30
+ "build-npm": "tsx scripts/build-npm.ts",
31
+ "publish-npm": "tsx scripts/build-npm.ts",
32
+ "help": "tsx scripts/help.ts",
33
+ "h": "tsx scripts/help.ts",
34
+ "dev": "tsx scripts/esbuild.config.ts",
35
+ "build": "tsc -noEmit -skipLibCheck && tsx scripts/esbuild.config.ts production",
36
+ "real": "tsx scripts/esbuild.config.ts production real",
37
+ "bacp": "tsx scripts/acp.ts -b",
38
+ "release": "tsx scripts/release.ts",
39
+ "r": "tsx scripts/release.ts"
40
+ },
41
+ "exports": {
42
+ ".": "./src/index.ts",
43
+ "./scripts/*": "./scripts/*",
44
+ "./modals": "./src/modals/index.ts",
45
+ "./tools": "./src/tools/index.ts",
46
+ "./utils": "./src/utils/index.ts"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^22.15.26",
50
+ "@types/semver": "^7.7.0",
51
+ "builtin-modules": "3.3.0",
52
+ "dedent": "^1.6.0",
53
+ "dotenv": "^16.4.5",
54
+ "esbuild": "latest",
55
+ "fs-extra": "^11.2.0",
56
+ "obsidian": "*",
57
+ "obsidian-typings": "^3.9.5",
58
+ "semver": "^7.7.2",
59
+ "tsx": "^4.19.4",
60
+ "typescript": "^5.8.2"
61
+ },
62
+ "dependencies": {
63
+ "@types/lodash": "^4.17.17",
64
+ "@types/node": "^22.15.26",
65
+ "@types/semver": "^7.7.0",
66
+ "builtin-modules": "3.3.0",
67
+ "dedent": "^1.6.0",
68
+ "dotenv": "^16.4.5",
69
+ "esbuild": "latest",
70
+ "fs-extra": "^11.2.0",
71
+ "lodash": "^4.17.21",
72
+ "obsidian": "*",
73
+ "obsidian-typings": "^3.9.5",
74
+ "semver": "^7.7.2",
75
+ "tsx": "^4.19.4",
76
+ "typescript": "^5.8.2"
77
+ },
78
+ "engines": {
79
+ "npm": "please-use-yarn",
80
+ "yarn": ">=1.22.0",
81
+ "node": ">=16.0.0"
82
+ },
83
+ "repository": {
84
+ "type": "git",
85
+ "url": "https://github.com/3C0D/obsidian-plugin-config.git"
86
+ },
87
+ "author": "3C0D"
88
+ }
package/scripts/acp.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { execSync } from "child_process";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import {
5
+ askQuestion,
6
+ cleanInput,
7
+ createReadlineInterface,
8
+ gitExec
9
+ } from "./utils.js";
10
+
11
+ const rl = createReadlineInterface();
12
+
13
+ // Check if we're in the centralized config repo
14
+ function isInCentralizedRepo(): boolean {
15
+ const packageJsonPath = path.join(process.cwd(), "package.json");
16
+ if (!fs.existsSync(packageJsonPath)) return false;
17
+
18
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
19
+ return packageJson.name === "obsidian-plugin-config";
20
+ }
21
+
22
+ async function main(): Promise<void> {
23
+ try {
24
+ if (process.argv.includes("-b")) {
25
+ console.log("Building...");
26
+ gitExec("yarn build");
27
+ console.log("Build successful.");
28
+ }
29
+
30
+ // Only update exports if we're in the centralized repo and not explicitly disabled
31
+ if (!process.argv.includes("-ne") && !process.argv.includes("--no-exports") && isInCentralizedRepo()) {
32
+ console.log("Updating exports...");
33
+ gitExec("yarn run update-exports");
34
+ console.log("Exports updated.");
35
+ }
36
+
37
+ const input: string = await askQuestion("Enter commit message: ", rl);
38
+
39
+ const cleanedInput = cleanInput(input);
40
+
41
+ try {
42
+ gitExec("git add -A");
43
+ gitExec(`git commit -m "${cleanedInput}"`);
44
+ } catch {
45
+ console.log("Commit already exists or failed.");
46
+ return;
47
+ }
48
+
49
+ // get current branch name
50
+ const currentBranch = execSync("git rev-parse --abbrev-ref HEAD").toString().trim();
51
+
52
+ try {
53
+ gitExec(`git push origin ${currentBranch}`);
54
+ console.log("Commit and push successful.");
55
+ } catch {
56
+ // new branch
57
+ console.log(`New branch detected. Setting upstream for ${currentBranch}...`);
58
+ gitExec(`git push --set-upstream origin ${currentBranch}`);
59
+ console.log("Upstream branch set and push successful.");
60
+ }
61
+ } catch (error) {
62
+ console.error("Error:", error instanceof Error ? error.message : String(error));
63
+ } finally {
64
+ rl.close();
65
+ }
66
+ }
67
+
68
+ main().catch(console.error).finally(() => {
69
+ console.log("Exiting...");
70
+ process.exit();
71
+ });
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env tsx
2
+
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { execSync } from "child_process";
6
+ import {
7
+ askQuestion,
8
+ askConfirmation,
9
+ createReadlineInterface
10
+ } from "./utils.js";
11
+
12
+ const rl = createReadlineInterface();
13
+
14
+ /**
15
+ * Build NPM package from local development
16
+ */
17
+ async function buildNpmPackage(): Promise<void> {
18
+ console.log(`🏗️ Building NPM package from local development...`);
19
+
20
+ try {
21
+ // Step 1: Verify all scripts are ready
22
+ console.log(`\n📋 Verifying scripts...`);
23
+
24
+ const requiredScripts = [
25
+ "scripts/inject-path.ts",
26
+ "scripts/inject-prompt.ts",
27
+ "scripts/utils.ts",
28
+ "scripts/esbuild.config.ts",
29
+ "scripts/acp.ts",
30
+ "scripts/update-version.ts",
31
+ "scripts/release.ts",
32
+ "scripts/help.ts"
33
+ ];
34
+
35
+ for (const script of requiredScripts) {
36
+ if (!fs.existsSync(script)) {
37
+ throw new Error(`Missing required script: ${script}`);
38
+ }
39
+ console.log(` ✅ ${script}`);
40
+ }
41
+
42
+ // Step 2: Update bin/obsidian-inject.js if needed
43
+ console.log(`\n📦 Checking bin/obsidian-inject.js...`);
44
+ const binPath = "bin/obsidian-inject.js";
45
+
46
+ if (fs.existsSync(binPath)) {
47
+ console.log(` ✅ ${binPath} exists`);
48
+ } else {
49
+ throw new Error(`Missing bin file: ${binPath}`);
50
+ }
51
+
52
+ // Step 3: Verify package.json is ready for NPM
53
+ console.log(`\n📄 Verifying package.json for NPM...`);
54
+ const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
55
+
56
+ const requiredFields = {
57
+ name: packageJson.name,
58
+ version: packageJson.version,
59
+ description: packageJson.description,
60
+ bin: packageJson.bin,
61
+ repository: packageJson.repository,
62
+ author: packageJson.author
63
+ };
64
+
65
+ for (const [field, value] of Object.entries(requiredFields)) {
66
+ if (!value) {
67
+ throw new Error(`Missing required package.json field: ${field}`);
68
+ }
69
+ console.log(` ✅ ${field}: ${typeof value === 'object' ? JSON.stringify(value) : value}`);
70
+ }
71
+
72
+ // Step 4: Check if we're logged into NPM
73
+ console.log(`\n🔐 Checking NPM authentication...`);
74
+ try {
75
+ const whoami = execSync('npm whoami', { encoding: 'utf8' }).trim();
76
+ console.log(` ✅ Logged in as: ${whoami}`);
77
+ } catch (error) {
78
+ console.log(` ❌ Not logged into NPM`);
79
+ console.log(` 💡 Run: npm login`);
80
+ throw new Error("NPM authentication required");
81
+ }
82
+
83
+ // Step 5: Run tests to ensure everything works
84
+ console.log(`\n🧪 Running quick test...`);
85
+ try {
86
+ execSync('yarn build', { stdio: 'inherit' });
87
+ console.log(` ✅ Build test passed`);
88
+ } catch (error) {
89
+ throw new Error("Build test failed");
90
+ }
91
+
92
+ console.log(`\n✅ Package is ready for NPM publication!`);
93
+
94
+ // Step 6: Ask for confirmation
95
+ const shouldPublish = await askConfirmation(`\nProceed with NPM publication?`, rl);
96
+
97
+ if (!shouldPublish) {
98
+ console.log(`❌ Publication cancelled`);
99
+ return;
100
+ }
101
+
102
+ // Step 7: Publish to NPM
103
+ console.log(`\n📤 Publishing to NPM...`);
104
+ execSync('npm publish', { stdio: 'inherit' });
105
+
106
+ console.log(`\n🎉 Package published successfully!`);
107
+ console.log(`\n📋 Next steps:`);
108
+ console.log(` 1. npm install -g ${packageJson.name}`);
109
+ console.log(` 2. cd any-obsidian-plugin && obsidian-inject`);
110
+ console.log(` 3. Test the global installation`);
111
+
112
+ } catch (error) {
113
+ console.error(`\n❌ Build failed: ${error instanceof Error ? error.message : String(error)}`);
114
+ throw error;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Main function
120
+ */
121
+ async function main(): Promise<void> {
122
+ try {
123
+ console.log(`🎯 Obsidian Plugin Config - NPM Package Builder`);
124
+ console.log(`📦 Prepare and publish NPM package\n`);
125
+
126
+ await buildNpmPackage();
127
+
128
+ } catch (error) {
129
+ console.error(`💥 Error: ${error instanceof Error ? error.message : String(error)}`);
130
+ process.exit(1);
131
+ } finally {
132
+ rl.close();
133
+ }
134
+ }
135
+
136
+ // Run the script
137
+ main().catch(console.error);