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,97 @@
1
+ import {
2
+ writeFile,
3
+ stat
4
+ } from "fs/promises";
5
+ import { execSync } from "child_process";
6
+ import dedent from "dedent";
7
+ import {
8
+ askQuestion,
9
+ askConfirmation,
10
+ createReadlineInterface
11
+ } from "./utils.ts";
12
+
13
+ const rl = createReadlineInterface();
14
+
15
+ const body = ".github/workflows/release-body.md";
16
+
17
+ async function checkOrCreateFile(filename: string): Promise<void> {
18
+ try {
19
+ await stat(filename);
20
+ } catch {
21
+ console.log(`Creating ${filename} because it doesn't exist. Avoid deleting it.`);
22
+ await writeFile(filename, "");
23
+ }
24
+ }
25
+
26
+ async function createReleaseNotesFile(tagMessage: string, tag: string): Promise<void> {
27
+ await writeFile(body, tagMessage);
28
+ console.log(`Release notes for tag ${tag} have been written to release-body.md`);
29
+ }
30
+
31
+ async function handleExistingTag(tag: string): Promise<boolean> {
32
+ const confirmed = await askConfirmation(`Tag ${tag} already exists. Do you want to replace it?`, rl);
33
+
34
+ if (!confirmed) {
35
+ console.log("Operation aborted");
36
+ return false;
37
+ }
38
+
39
+ execSync(`git tag -d ${tag}`);
40
+ execSync(`git push origin :refs/tags/${tag}`);
41
+ console.log(`Deleted existing tag ${tag} locally and remotely.`);
42
+ return true;
43
+ }
44
+
45
+ async function createTag(): Promise<void> {
46
+ const currentVersion = process.env.npm_package_version;
47
+ const tag = `${currentVersion}`;
48
+
49
+ await checkOrCreateFile(body);
50
+ const exists = execSync("git ls-remote --tags origin").toString().includes(`refs/tags/${tag}`);
51
+
52
+ if (exists && !(await handleExistingTag(tag))) {
53
+ rl.close();
54
+ return;
55
+ }
56
+ await doCommit(currentVersion, tag);
57
+ }
58
+
59
+
60
+
61
+ async function doCommit(currentVersion: string | undefined, tag: string): Promise<void> {
62
+ rl.question(`Enter the commit message for version ${currentVersion}: `, async (message) => {
63
+ doNextSteps(message, tag);
64
+ rl.close();
65
+ });
66
+ }
67
+
68
+ async function doNextSteps(message: string, tag: string): Promise<void> {
69
+ const messages = message.split("\\n");
70
+ const toShow = message.replace(/\\n/g, "\n");
71
+ await createReleaseNotesFile(toShow, tag);
72
+ const tagMessage = messages.map(m => `-m "${m}"`).join(" ");
73
+
74
+ try {
75
+ execSync("git add -A");
76
+ execSync("git commit -m \"update tag description\"");
77
+ execSync("git push");
78
+ } catch (error: any) {
79
+ console.error("Error:", error.message);
80
+ }
81
+ try {
82
+ execSync(`git tag -a ${tag} ${tagMessage}`);
83
+ } catch {
84
+ execSync(`git tag -d ${tag}`);
85
+ execSync(`git push origin :refs/tags/${tag}`);
86
+ console.log("Fixed");
87
+ execSync(`git tag -a ${tag} ${tagMessage}`);
88
+ }
89
+ execSync(`git push origin ${tag}`);
90
+ console.log(`Release ${tag} pushed to repo.`);
91
+ console.log(dedent`
92
+ with message:
93
+ ${toShow}
94
+ `);
95
+ }
96
+
97
+ createTag().catch(console.error);
@@ -0,0 +1,102 @@
1
+ import { readFile, writeFile } from "fs/promises";
2
+ import dedent from "dedent";
3
+ import { inc, valid } from "semver";
4
+ import { askQuestion, createReadlineInterface, gitExec } from "./utils.ts";
5
+
6
+ const rl = createReadlineInterface();
7
+
8
+ async function getTargetVersion(currentVersion: string): Promise<string> {
9
+ const updateType = await askQuestion(dedent`
10
+ Current version: ${currentVersion}
11
+ Kind of update:
12
+ patch(1.0.1) -> type 1 or p
13
+ minor(1.1.0) -> type 2 or min
14
+ major(2.0.0) -> type 3 or maj
15
+ or version number (e.g. 2.0.0)
16
+ Enter choice: `, rl);
17
+
18
+ switch (updateType.trim()) {
19
+ case "p":
20
+ case "1":
21
+ return inc(currentVersion, "patch") || "";
22
+ case "min":
23
+ case "2":
24
+ return inc(currentVersion, "minor") || "";
25
+ case "maj":
26
+ case "3":
27
+ return inc(currentVersion, "major") || "";
28
+ default:
29
+ return valid(updateType.trim()) || "";
30
+ }
31
+ }
32
+
33
+ async function updateJsonFile(filename: string, updateFn: (json: any) => void): Promise<void> {
34
+ try {
35
+ const content = JSON.parse(await readFile(filename, "utf8"));
36
+ updateFn(content);
37
+ await writeFile(filename, JSON.stringify(content, null, "\t"));
38
+ } catch (error) {
39
+ console.error(`Error updating ${filename}:`, error instanceof Error ? error.message : String(error));
40
+ throw error;
41
+ }
42
+ }
43
+
44
+ async function updateManifestVersions(targetVersion: string): Promise<void> {
45
+ try {
46
+ const manifest = JSON.parse(await readFile("manifest.json", "utf8"));
47
+ const { minAppVersion } = manifest;
48
+
49
+ await Promise.all([
50
+ updateJsonFile("manifest.json", json => json.version = targetVersion),
51
+ updateJsonFile("versions.json", json => json[targetVersion] = minAppVersion),
52
+ updateJsonFile("package.json", json => json.version = targetVersion),
53
+ // updateJsonFile("package-lock.json", json => json.version = targetVersion)
54
+ ]);
55
+ } catch (error) {
56
+ console.error("Error updating manifest versions:", error instanceof Error ? error.message : String(error));
57
+ throw error;
58
+ }
59
+ }
60
+
61
+ async function updateVersion(): Promise<void> {
62
+ try {
63
+ const currentVersion = process.env.npm_package_version || "1.0.0";
64
+ const targetVersion = await getTargetVersion(currentVersion);
65
+
66
+ if (!targetVersion) {
67
+ console.log("Invalid version");
68
+ return;
69
+ }
70
+
71
+ try {
72
+ // Update all files first
73
+ await updateManifestVersions(targetVersion);
74
+ console.log(`Files updated to version ${targetVersion}`);
75
+
76
+ // Add files to git
77
+ gitExec("git add manifest.json package.json versions.json");
78
+ gitExec(`git commit -m "Updated to version ${targetVersion}"`);
79
+ console.log("Changes committed");
80
+ } catch (error) {
81
+ console.error("Error during update or commit:", error instanceof Error ? error.message : String(error));
82
+ console.log("Operation failed.");
83
+ return;
84
+ }
85
+
86
+ try {
87
+ gitExec("git push");
88
+ console.log(`Version successfully updated to ${targetVersion} and pushed.`);
89
+ } catch (pushError) {
90
+ console.error("Failed to push version update:", pushError instanceof Error ? pushError.message : String(pushError));
91
+ }
92
+ } catch (error) {
93
+ console.error("Error:", error instanceof Error ? error.message : String(error));
94
+ } finally {
95
+ rl.close();
96
+ }
97
+ }
98
+
99
+ updateVersion().catch(console.error).finally(() => {
100
+ console.log("Exiting...");
101
+ process.exit();
102
+ });
@@ -0,0 +1,117 @@
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";
10
+
11
+ export function createReadlineInterface(): readline.Interface {
12
+ return readline.createInterface({
13
+ input: process.stdin as NodeJS.ReadableStream,
14
+ output: process.stdout as NodeJS.WritableStream,
15
+ });
16
+ }
17
+
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
+ }
25
+ };
26
+
27
+ /**
28
+ * Ask a yes/no confirmation question with standardized logic
29
+ * Accepts: y, yes, Y, YES, or empty (default to yes)
30
+ * Rejects: n, no, N, NO
31
+ * Invalid input defaults to no for safety
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
+ }
50
+ };
51
+
52
+ export const cleanInput = (inputStr: string): string => {
53
+ if (!inputStr) return "";
54
+ return inputStr.trim().replace(/["`]/g, "'").replace(/\r\n/g, "\n");
55
+ };
56
+
57
+ 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
+ }
68
+ };
69
+
70
+ export async function copyFilesToTargetDir(buildPath: string): Promise<void> {
71
+ const manifestDest = path.join(buildPath, "manifest.json");
72
+ const cssDest = path.join(buildPath, "styles.css");
73
+ const folderToRemove = path.join(buildPath, "_.._");
74
+
75
+ try {
76
+ await mkdir(buildPath);
77
+ } catch (error: any) {
78
+ if (error.code !== "EEXIST") {
79
+ console.error(`Error creating directory: ${error.message}`);
80
+ }
81
+ }
82
+
83
+ // Copy manifest
84
+ try {
85
+ await copyFile("./manifest.json", manifestDest);
86
+ } catch (error: any) {
87
+ console.error(`Error copying manifest: ${error.message}`);
88
+ }
89
+
90
+ // Copy CSS
91
+ try {
92
+ // First check if CSS exists in src/styles.css
93
+ if (await isValidPath("./src/styles.css")) {
94
+ await copyFile("./src/styles.css", cssDest);
95
+ }
96
+ // Otherwise, check if it exists in the root
97
+ else if (await isValidPath("./styles.css")) {
98
+ await copyFile("./styles.css", cssDest);
99
+ if (await isValidPath(folderToRemove)) {
100
+ await rm(folderToRemove, { recursive: true });
101
+ }
102
+ } else {
103
+ return;
104
+ }
105
+ } catch (error: any) {
106
+ console.error(`Error copying CSS: ${error.message}`);
107
+ }
108
+ }
109
+
110
+ export function gitExec(command: string): void {
111
+ try {
112
+ execSync(command, { stdio: "inherit" });
113
+ } catch (error: any) {
114
+ console.error(`Error executing '${command}':`, error.message);
115
+ throw error;
116
+ }
117
+ }
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'obsidian';
2
+
3
+ export default class TestPlugin extends Plugin {
4
+ async onload() {
5
+ console.log('Test Plugin loaded');
6
+ }
7
+
8
+ onunload() {
9
+ console.log('Test Plugin unloaded');
10
+ }
11
+ }