@mnaoumov/create-obsidian-plugin 0.0.0-stage → 1.0.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.
- package/LICENSE +19 -0
- package/README.md +341 -2
- package/dist/main.js +4184 -0
- package/package.json +83 -4
- package/src/main.ts +650 -0
- package/templates/default/.depcheckrc.json.ejs +19 -0
- package/templates/default/.editorconfig.ejs +11 -0
- package/templates/default/.env.ejs +1 -0
- package/templates/default/.env@vault_has-vault-false.ejs +2 -0
- package/templates/default/.env@vault_has-vault-true.ejs +1 -0
- package/templates/default/.gitattributes.ejs +7 -0
- package/templates/default/.github/FUNDING.yml.ejs +3 -0
- package/templates/default/.github/ISSUE_TEMPLATE/bug_report.yml.ejs +71 -0
- package/templates/default/.github/ISSUE_TEMPLATE/config.yml.ejs +1 -0
- package/templates/default/.github/ISSUE_TEMPLATE/feature_request.yml.ejs +61 -0
- package/templates/default/.github/workflows/attest-release-assets.yml.ejs +24 -0
- package/templates/default/.github/workflows/ci.yml.ejs +20 -0
- package/templates/default/.github/workflows/ci.yml@steps_biome-linter.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_cspell.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_dprint.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_eslint.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_jest.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_markdownlint.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_prettier.ejs +1 -0
- package/templates/default/.github/workflows/ci.yml@steps_vitest.ejs +1 -0
- package/templates/default/.github/workflows/release.yml.ejs +27 -0
- package/templates/default/.github/workflows/update-license-year.yml.ejs +38 -0
- package/templates/default/.gitignore_common.ejs +27 -0
- package/templates/default/.gitignore_scss.ejs +1 -0
- package/templates/default/.gitignore_tailwind.ejs +3 -0
- package/templates/default/.husky/commit-msg.ejs +1 -0
- package/templates/default/.husky/pre-commit.ejs +1 -0
- package/templates/default/.markdownlint-cli2.mjs.ejs +4 -0
- package/templates/default/.nano-staged.mjs.ejs +5 -0
- package/templates/default/.npmrc.ejs +1 -0
- package/templates/default/.parcelrc.ejs +9 -0
- package/templates/default/.parcelrc@transformers_svelte.ejs +1 -0
- package/templates/default/.prettierignore.ejs +10 -0
- package/templates/default/.typesafe-i18n.json.ejs +5 -0
- package/templates/default/CONTRIBUTING.md.ejs +49 -0
- package/templates/default/CONTRIBUTING.md@demo-vault_dev-utils.ejs +15 -0
- package/templates/default/CONTRIBUTING.md@scripts_biome-formatter.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_biome-linter.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_conventional-commits.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_cspell.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_dev-utils.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_dprint.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_eslint.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_jest.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_markdownlint.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_prettier.ejs +1 -0
- package/templates/default/CONTRIBUTING.md@scripts_vitest.ejs +1 -0
- package/templates/default/LICENSE.ejs +21 -0
- package/templates/default/README.md.ejs +28 -0
- package/templates/default/README.md@demo-vault_dev-utils.ejs +12 -0
- package/templates/default/README.md@preset_dev-utils.ejs +12 -0
- package/templates/default/README.md@support_has-funding.ejs +8 -0
- package/templates/default/babel.config.json.ejs +8 -0
- package/templates/default/babel.config.mjs.ejs +5 -0
- package/templates/default/biome.jsonc.ejs +47 -0
- package/templates/default/commitlint.config.ts.ejs +1 -0
- package/templates/default/cspell.json.ejs +67 -0
- package/templates/default/demo-vault/.gitignore.ejs +15 -0
- package/templates/default/demo-vault/.obsidian/app.json.ejs +4 -0
- package/templates/default/demo-vault/.obsidian/community-plugins.json.ejs +4 -0
- package/templates/default/demo-vault/00 Start.md.ejs +32 -0
- package/templates/default/demo-vault/00 Start.md@features_wasm.ejs +1 -0
- package/templates/default/demo-vault/01 Sample commands.md.ejs +38 -0
- package/templates/default/demo-vault/01 Sample commands.md@commands_wasm.ejs +4 -0
- package/templates/default/demo-vault/02 Settings.md.ejs +40 -0
- package/templates/default/demo-vault/03 WebAssembly.md.ejs +34 -0
- package/templates/default/demo-vault/Materials/01 Sample commands/Scratch note.md.ejs +5 -0
- package/templates/default/demo-vault/README.md.ejs +10 -0
- package/templates/default/demo-vault/_assets/CodeScriptToolkit/demoSetup.ts.ejs +88 -0
- package/templates/default/demo-vault/_assets/CodeScriptToolkit/demoSetup.ts@commands_wasm.ejs +10 -0
- package/templates/default/demo-vault/_assets/CodeScriptToolkit/startup.ts.ejs +17 -0
- package/templates/default/dprint.json_dev-utils.ejs +10 -0
- package/templates/default/dprint.json_standalone.ejs +26 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test.ejs +16 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test@lint-no-void-disable_dev-utils.ejs +3 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test@lint-no-void-enable_dev-utils.ejs +1 -0
- package/templates/default/e2e/sample.spec.ts_obsidian-test@unofficial_with-unofficial.ejs +13 -0
- package/templates/default/e2e/sample.spec.ts_wdio-obsidian.ejs +7 -0
- package/templates/default/e2e/sample.spec.ts_wdio-obsidian@unofficial_with-unofficial.ejs +15 -0
- package/templates/default/eslint.config.mts_dev-utils.ejs +1 -0
- package/templates/default/eslint.config.mts_standalone.ejs +119 -0
- package/templates/default/eslint.config.mts_standalone@extra-files_has-e2e.ejs +2 -0
- package/templates/default/jest.config.ts.ejs +57 -0
- package/templates/default/jest.config.ts@lint-root-dir_dev-utils.ejs +1 -0
- package/templates/default/jest.config.ts@ts-jest-tsconfig_solid.ejs +8 -0
- package/templates/default/linkinator.config.json.ejs +11 -0
- package/templates/default/manifest.json.ejs +11 -0
- package/templates/default/manifest.json@funding_has-funding.ejs +1 -0
- package/templates/default/manifest.json@platform_desktop-and-mobile.ejs +1 -0
- package/templates/default/manifest.json@platform_desktop-only.ejs +1 -0
- package/templates/default/package.json.ejs +32 -0
- package/templates/default/package.json@targets_parcel.ejs +36 -0
- package/templates/default/parcel-namer-obsidian.cjs.ejs +26 -0
- package/templates/default/parcel-resolver-obsidian.cjs.ejs +37 -0
- package/templates/default/parcel-transformer-inline-imports.cjs.ejs +39 -0
- package/templates/default/parcel-transformer-svelte.cjs.ejs +67 -0
- package/templates/default/pinned-versions.json.ejs +1 -0
- package/templates/default/pnpm-workspace.yaml.ejs +19 -0
- package/templates/default/postcss.config.cjs.ejs +12 -0
- package/templates/default/prettier.config.mjs.ejs +5 -0
- package/templates/default/rollup.config.mjs.ejs +7 -0
- package/templates/default/scripts/babel.config.ts_rollup.ejs +16 -0
- package/templates/default/scripts/babel.config.ts_rollup@babel-plugin_preact.ejs +1 -0
- package/templates/default/scripts/babel.config.ts_rollup@babel-preset_react.ejs +1 -0
- package/templates/default/scripts/babel.config.ts_rollup@babel-preset_solid.ejs +1 -0
- package/templates/default/scripts/build-clean.ts.ejs +4 -0
- package/templates/default/scripts/build-compile.ts.ejs +4 -0
- package/templates/default/scripts/build-styles.ts.ejs +12 -0
- package/templates/default/scripts/build.ts.ejs +6 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler.ejs +63 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@compile_svelte.ejs +4 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@fs-import_hot-reload-plugin.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@hot-reload_hot-reload-plugin.ejs +3 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@import_tailwind.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@lint-build-styles_dev-utils.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@reload_obsidian-cli.ejs +5 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_parcel.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_rollup.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_vite.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_cli-bundler@run_webpack.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild.ejs +3 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@compile_svelte.ejs +4 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@dev-utils-pre-build_tailwind.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@fs-import_hot-reload-plugin.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@hot-reload_hot-reload-plugin.ejs +4 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_postcss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_scss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_solid.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_svelte.ejs +10 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_tailwind.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@import_vue.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@lint-build-styles_dev-utils.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@options_preact.ejs +2 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@options_react.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@options_wasm.ejs +5 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_postcss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_scss.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_solid.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_svelte.ejs +5 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@plugin_vue.ejs +1 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@preset_standalone.ejs +138 -0
- package/templates/default/scripts/build.ts@bundler_esbuild@reload_obsidian-cli.ejs +6 -0
- package/templates/default/scripts/commit.ts_dev-utils.ejs +3 -0
- package/templates/default/scripts/commit.ts_standalone.ejs +3 -0
- package/templates/default/scripts/commitlint-config.ts.ejs +5 -0
- package/templates/default/scripts/demo-vault-global-setup.ts.ejs +43 -0
- package/templates/default/scripts/dev.ts.ejs +6 -0
- package/templates/default/scripts/dev.ts@bundler_cli-bundler.ejs +8 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild.ejs +3 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@dev-utils-pre-build_tailwind.ejs +2 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@lint-build-styles_dev-utils.ejs +1 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/dev.ts@bundler_esbuild@preset_standalone.ejs +3 -0
- package/templates/default/scripts/esbuild-plugins.ts.ejs +20 -0
- package/templates/default/scripts/esbuild-plugins.ts@dev-utils-import_vue.ejs +2 -0
- package/templates/default/scripts/esbuild-plugins.ts@dev-utils-plugin_vue.ejs +1 -0
- package/templates/default/scripts/esbuild-plugins.ts@dev-utils-plugin_wasm.ejs +13 -0
- package/templates/default/scripts/eslint-config.ts.ejs +113 -0
- package/templates/default/scripts/eslint-config.ts@extra-files_has-e2e.ejs +7 -0
- package/templates/default/scripts/find-overexposed-fix.ts.ejs +26 -0
- package/templates/default/scripts/find-overexposed.ts.ejs +15 -0
- package/templates/default/scripts/format-check.ts.ejs +4 -0
- package/templates/default/scripts/format-check.ts@tool_biome-formatter.ejs +8 -0
- package/templates/default/scripts/format-check.ts@tool_dprint.ejs +3 -0
- package/templates/default/scripts/format-check.ts@tool_dprint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/format-check.ts@tool_dprint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/format-check.ts@tool_prettier.ejs +8 -0
- package/templates/default/scripts/format.ts.ejs +4 -0
- package/templates/default/scripts/format.ts@tool_biome-formatter.ejs +8 -0
- package/templates/default/scripts/format.ts@tool_dprint.ejs +3 -0
- package/templates/default/scripts/format.ts@tool_dprint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/format.ts@tool_dprint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/format.ts@tool_prettier.ejs +8 -0
- package/templates/default/scripts/framework-component-stub.ts.ejs +46 -0
- package/templates/default/scripts/gate.ts.ejs +10 -0
- package/templates/default/scripts/lint-fix.ts.ejs +6 -0
- package/templates/default/scripts/lint-fix.ts@tool_biome-linter.ejs +8 -0
- package/templates/default/scripts/lint-fix.ts@tool_eslint.ejs +3 -0
- package/templates/default/scripts/lint-fix.ts@tool_eslint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint-fix.ts@tool_eslint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/lint-md-fix.ts_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint-md-fix.ts_standalone.ejs +37 -0
- package/templates/default/scripts/lint-md.ts_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint-md.ts_standalone.ejs +37 -0
- package/templates/default/scripts/lint.ts.ejs +6 -0
- package/templates/default/scripts/lint.ts@tool_biome-linter.ejs +8 -0
- package/templates/default/scripts/lint.ts@tool_eslint.ejs +3 -0
- package/templates/default/scripts/lint.ts@tool_eslint@preset_dev-utils.ejs +7 -0
- package/templates/default/scripts/lint.ts@tool_eslint@preset_standalone.ejs +8 -0
- package/templates/default/scripts/markdownlint-cli2-config.ts_dev-utils.ejs +14 -0
- package/templates/default/scripts/markdownlint-cli2-config.ts_standalone.ejs +36 -0
- package/templates/default/scripts/nano-staged-config.ts.ejs +9 -0
- package/templates/default/scripts/postcss.config.ts.ejs +1 -0
- package/templates/default/scripts/postcss.config.ts@plugins_postcss.ejs +7 -0
- package/templates/default/scripts/prepare.ts_dev-utils.ejs +3 -0
- package/templates/default/scripts/prepare.ts_standalone.ejs +3 -0
- package/templates/default/scripts/prettier.config.ts.ejs +12 -0
- package/templates/default/scripts/rollup.config.ts.ejs +129 -0
- package/templates/default/scripts/rollup.config.ts@import_rollup-babel.ejs +5 -0
- package/templates/default/scripts/rollup.config.ts@import_rollup-json.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@import_rollup-postcss.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@import_scss.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@import_svelte.ejs +2 -0
- package/templates/default/scripts/rollup.config.ts@import_vue.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@import_wasm.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@lint-out-dir_dev-utils.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_preact.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_react.ejs +5 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_rollup-json.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_rollup-postcss.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_scss.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_solid.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@post-plugin_wasm.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@pre-plugin_svelte.ejs +4 -0
- package/templates/default/scripts/rollup.config.ts@pre-plugin_vue.ejs +13 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_rollup-babel.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_rollup-json.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_rollup-postcss.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_scss.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_svelte.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_vue.ejs +1 -0
- package/templates/default/scripts/rollup.config.ts@unwrap_wasm.ejs +1 -0
- package/templates/default/scripts/spellcheck.ts_dev-utils.ejs +7 -0
- package/templates/default/scripts/spellcheck.ts_standalone.ejs +8 -0
- package/templates/default/scripts/stylesheet-stub.ts.ejs +17 -0
- package/templates/default/scripts/test-coverage.ts.ejs +8 -0
- package/templates/default/scripts/test-e2e.ts.ejs +1 -0
- package/templates/default/scripts/test-e2e.ts@tool_obsidian-test.ejs +8 -0
- package/templates/default/scripts/test-e2e.ts@tool_wdio-obsidian.ejs +8 -0
- package/templates/default/scripts/test-integration-android.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-demo-vault.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-desktop-performance.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-desktop.ts.ejs +8 -0
- package/templates/default/scripts/test-integration-no-app.ts.ejs +8 -0
- package/templates/default/scripts/test-integration.ts.ejs +22 -0
- package/templates/default/scripts/test-watch.ts_dev-utils.ejs +1 -0
- package/templates/default/scripts/test-watch.ts_dev-utils@tool_jest.ejs +13 -0
- package/templates/default/scripts/test-watch.ts_dev-utils@tool_vitest.ejs +8 -0
- package/templates/default/scripts/test-watch.ts_standalone.ejs +1 -0
- package/templates/default/scripts/test-watch.ts_standalone@tool_jest.ejs +13 -0
- package/templates/default/scripts/test-watch.ts_standalone@tool_vitest.ejs +8 -0
- package/templates/default/scripts/test.ts_dev-utils.ejs +1 -0
- package/templates/default/scripts/test.ts_dev-utils@tool_jest.ejs +13 -0
- package/templates/default/scripts/test.ts_dev-utils@tool_vitest.ejs +8 -0
- package/templates/default/scripts/test.ts_standalone.ejs +1 -0
- package/templates/default/scripts/test.ts_standalone@tool_jest.ejs +13 -0
- package/templates/default/scripts/test.ts_standalone@tool_vitest.ejs +8 -0
- package/templates/default/scripts/version.ts_dev-utils.ejs +10 -0
- package/templates/default/scripts/version.ts_standalone.ejs +317 -0
- package/templates/default/scripts/vite.config.ts.ejs +76 -0
- package/templates/default/scripts/vite.config.ts@import_preact.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_react.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_solid.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_svelte.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@import_vue.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@lint-empty-out-dir_dev-utils.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@lint-out-dir_dev-utils.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_preact.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_react.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_solid.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_svelte.ejs +1 -0
- package/templates/default/scripts/vite.config.ts@plugin_vue.ejs +1 -0
- package/templates/default/scripts/vitest-config.ts.ejs +75 -0
- package/templates/default/scripts/vitest-config.ts@post-config_solid.ejs +67 -0
- package/templates/default/scripts/wasm-module-stub.ts.ejs +21 -0
- package/templates/default/scripts/webpack.config.ts.ejs +124 -0
- package/templates/default/scripts/webpack.config.ts@import_svelte.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@import_vue.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@import_webpack-css-extract.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@lint-webpack-default_dev-utils.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@plugin_vue.ejs +1 -0
- package/templates/default/scripts/webpack.config.ts@plugin_webpack-css-extract.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_css-modules.ejs +7 -0
- package/templates/default/scripts/webpack.config.ts@rule_css.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_postcss.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_scss.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_solid.ejs +17 -0
- package/templates/default/scripts/webpack.config.ts@rule_svelte.ejs +7 -0
- package/templates/default/scripts/webpack.config.ts@rule_tailwind.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_vue.ejs +4 -0
- package/templates/default/scripts/webpack.config.ts@rule_wasm.ejs +8 -0
- package/templates/default/scripts/webpack.config.ts@ts-loader-compiler-options_vue.ejs +5 -0
- package/templates/default/scripts/webpack.config.ts@ts-loader-options_vue.ejs +5 -0
- package/templates/default/src/demo-vault-buttons.demo-vault.integration.test.ts.ejs +12 -0
- package/templates/default/src/demo-vault.no-app.integration.test.ts.ejs +18 -0
- package/templates/default/src/editor-extensions/sample-state-field.ts_dev-utils.ejs +56 -0
- package/templates/default/src/editor-extensions/sample-state-field.ts_standalone.ejs +60 -0
- package/templates/default/src/editor-extensions/sample-view-plugin.ts.ejs +66 -0
- package/templates/default/src/editor-extensions/sample-widget.ts.ejs +22 -0
- package/templates/default/src/editor-suggests/sample-editor-suggest.ts.ejs +42 -0
- package/templates/default/src/i18n/en/index.ts.ejs +10 -0
- package/templates/default/src/i18n/index.ts_i18next.ejs +21 -0
- package/templates/default/src/i18n/index.ts_typesafe-i18n.ejs +14 -0
- package/templates/default/src/i18n/locales/en.json.ejs +3 -0
- package/templates/default/src/lit-elements/sample-lit-element.ts.ejs +54 -0
- package/templates/default/src/main.test.ts.ejs +11 -0
- package/templates/default/src/main.test.ts@test-imports_vitest.ejs +6 -0
- package/templates/default/src/main.ts.ejs +4 -0
- package/templates/default/src/main.ts@import_css-modules.ejs +1 -0
- package/templates/default/src/main.ts@import_css.ejs +1 -0
- package/templates/default/src/main.ts@import_postcss.ejs +1 -0
- package/templates/default/src/main.ts@import_scss.ejs +1 -0
- package/templates/default/src/main.ts@import_tailwind.ejs +1 -0
- package/templates/default/src/modals/sample-form-modal.ts.ejs +35 -0
- package/templates/default/src/modals/sample-suggest-modal.ts.ejs +37 -0
- package/templates/default/src/plugin-settings-component.test.ts_demo.ejs +49 -0
- package/templates/default/src/plugin-settings-component.test.ts_demo@test-imports_vitest.ejs +5 -0
- package/templates/default/src/plugin-settings-component.test.ts_enhanced.ejs +41 -0
- package/templates/default/src/plugin-settings-component.test.ts_enhanced@test-imports_vitest.ejs +5 -0
- package/templates/default/src/plugin-settings-component.ts_demo.ejs +87 -0
- package/templates/default/src/plugin-settings-component.ts_enhanced.ejs +27 -0
- package/templates/default/src/plugin-settings-tab.ts_demo.ejs +286 -0
- package/templates/default/src/plugin-settings-tab.ts_enhanced.ejs +26 -0
- package/templates/default/src/plugin-settings.test.ts_demo.ejs +14 -0
- package/templates/default/src/plugin-settings.test.ts_demo@test-imports_vitest.ejs +6 -0
- package/templates/default/src/plugin-settings.ts_demo.ejs +64 -0
- package/templates/default/src/plugin-settings.ts_enhanced.ejs +3 -0
- package/templates/default/src/plugin.test.ts_jest.ejs +9 -0
- package/templates/default/src/plugin.test.ts_vitest.ejs +14 -0
- package/templates/default/src/plugin.ts_demo.ejs +316 -0
- package/templates/default/src/plugin.ts_demo@import_i18next.ejs +1 -0
- package/templates/default/src/plugin.ts_demo@import_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_react.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_typesafe-i18n.ejs +1 -0
- package/templates/default/src/plugin.ts_demo@import_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@import_wasm.ejs +1 -0
- package/templates/default/src/plugin.ts_demo@method_ui-view.ejs +7 -0
- package/templates/default/src/plugin.ts_demo@onload_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_demo@onload_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_react.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_typesafe-i18n.ejs +8 -0
- package/templates/default/src/plugin.ts_demo@onload_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_demo@onload_wasm.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced.ejs +72 -0
- package/templates/default/src/plugin.ts_enhanced@import2_codemirror.ejs +3 -0
- package/templates/default/src/plugin.ts_enhanced@import2_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced@import2_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_react.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_typesafe-i18n.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced@import2_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@import2_wasm.ejs +1 -0
- package/templates/default/src/plugin.ts_enhanced@method_ui-view.ejs +7 -0
- package/templates/default/src/plugin.ts_enhanced@onload_codemirror.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_enhanced@onload_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_react.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_typesafe-i18n.ejs +8 -0
- package/templates/default/src/plugin.ts_enhanced@onload_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_enhanced@onload_wasm.ejs +2 -0
- package/templates/default/src/plugin.ts_standalone.ejs +56 -0
- package/templates/default/src/plugin.ts_standalone@import_codemirror.ejs +3 -0
- package/templates/default/src/plugin.ts_standalone@import_i18next.ejs +1 -0
- package/templates/default/src/plugin.ts_standalone@import_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_react.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_typesafe-i18n.ejs +1 -0
- package/templates/default/src/plugin.ts_standalone@import_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@import_wasm.ejs +1 -0
- package/templates/default/src/plugin.ts_standalone@method_ui-view.ejs +7 -0
- package/templates/default/src/plugin.ts_standalone@onload_codemirror.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_i18next.ejs +2 -0
- package/templates/default/src/plugin.ts_standalone@onload_lit.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_preact.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_react.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_solid.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_svelte.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_typesafe-i18n.ejs +8 -0
- package/templates/default/src/plugin.ts_standalone@onload_vue.ejs +4 -0
- package/templates/default/src/plugin.ts_standalone@onload_wasm.ejs +2 -0
- package/templates/default/src/preact-components/sample-preact-component.tsx_dev-utils.ejs +47 -0
- package/templates/default/src/preact-components/sample-preact-component.tsx_standalone.ejs +47 -0
- package/templates/default/src/react-components/sample-react-component.tsx_dev-utils.ejs +35 -0
- package/templates/default/src/react-components/sample-react-component.tsx_standalone.ejs +47 -0
- package/templates/default/src/settings.ts.ejs +32 -0
- package/templates/default/src/solid-components/sample-solid-component.tsx_dev-utils.ejs +47 -0
- package/templates/default/src/solid-components/sample-solid-component.tsx_standalone.ejs +47 -0
- package/templates/default/src/styles/css-modules.d.ts.ejs +4 -0
- package/templates/default/src/styles/main.css_dev-utils.ejs +17 -0
- package/templates/default/src/styles/main.css_dev-utils@content_tailwind.ejs +1 -0
- package/templates/default/src/styles/main.css_standalone.ejs +11 -0
- package/templates/default/src/styles/main.css_standalone@content_tailwind.ejs +1 -0
- package/templates/default/src/styles/main.module.css.ejs +3 -0
- package/templates/default/src/styles/main.scss_dev-utils.ejs +16 -0
- package/templates/default/src/styles/main.scss_standalone.ejs +10 -0
- package/templates/default/src/styles/styles.d.ts.ejs +4 -0
- package/templates/default/src/svelte-components/sample-svelte-component.d.ts.ejs +7 -0
- package/templates/default/src/svelte-components/sample-svelte-component.svelte.ejs +24 -0
- package/templates/default/src/views/sample-lit-view.ts.ejs +30 -0
- package/templates/default/src/views/sample-lit-view.ts@lint-register-element_dev-utils.ejs +1 -0
- package/templates/default/src/views/sample-preact-view.tsx_dev-utils.ejs +45 -0
- package/templates/default/src/views/sample-preact-view.tsx_standalone.ejs +42 -0
- package/templates/default/src/views/sample-react-view.tsx_dev-utils.ejs +47 -0
- package/templates/default/src/views/sample-react-view.tsx_standalone.ejs +49 -0
- package/templates/default/src/views/sample-solid-view.tsx_dev-utils.ejs +46 -0
- package/templates/default/src/views/sample-solid-view.tsx_standalone.ejs +46 -0
- package/templates/default/src/views/sample-svelte-view.ts.ejs +47 -0
- package/templates/default/src/views/sample-view.ts.ejs +37 -0
- package/templates/default/src/views/sample-vue-view.ts.ejs +34 -0
- package/templates/default/src/vue-components/sample-vue-component.d.ts.ejs +6 -0
- package/templates/default/src/vue-components/sample-vue-component.vue.ejs +25 -0
- package/templates/default/src/wasm/README.md.ejs +29 -0
- package/templates/default/src/wasm/answer.ts_esbuild.ejs +23 -0
- package/templates/default/src/wasm/answer.ts_parcel.ejs +29 -0
- package/templates/default/src/wasm/answer.ts_rollup.ejs +19 -0
- package/templates/default/src/wasm/answer.ts_vite.ejs +29 -0
- package/templates/default/src/wasm/answer.ts_webpack.ejs +29 -0
- package/templates/default/src/wasm/module.wasm +0 -0
- package/templates/default/src/wasm/module.wat.ejs +12 -0
- package/templates/default/src/wasm/sample-command.ts.ejs +33 -0
- package/templates/default/src/wasm.d.ts_esbuild.ejs +12 -0
- package/templates/default/src/wasm.d.ts_parcel.ejs +7 -0
- package/templates/default/src/wasm.d.ts_rollup.ejs +8 -0
- package/templates/default/src/wasm.d.ts_vite.ejs +8 -0
- package/templates/default/src/wasm.d.ts_webpack.ejs +7 -0
- package/templates/default/tsconfig.json_dev-utils.ejs +34 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_i18next.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_lit.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_preact.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_react.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@compiler-options_solid.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@include_has-e2e.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@include_svelte.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@include_vue.ejs +1 -0
- package/templates/default/tsconfig.json_dev-utils@types_jest.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@types_svelte.ejs +2 -0
- package/templates/default/tsconfig.json_dev-utils@types_wdio-obsidian.ejs +5 -0
- package/templates/default/tsconfig.json_dev-utils@types_with-unofficial.ejs +2 -0
- package/templates/default/tsconfig.json_standalone.ejs +47 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_i18next.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_lit.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_preact.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_react.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@compiler-options_solid.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include-extra_preact.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include-extra_react.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include-extra_solid.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@include_has-e2e.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@include_svelte.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@include_vue.ejs +1 -0
- package/templates/default/tsconfig.json_standalone@types_jest.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@types_svelte.ejs +2 -0
- package/templates/default/tsconfig.json_standalone@types_wdio-obsidian.ejs +5 -0
- package/templates/default/tsconfig.json_standalone@types_with-unofficial.ejs +2 -0
- package/templates/default/versions.json.ejs +3 -0
- package/templates/default/vite.config.ts.ejs +3 -0
- package/templates/default/vitest.config.ts_dev-utils.ejs +1 -0
- package/templates/default/vitest.config.ts_standalone.ejs +55 -0
- package/templates/default/vitest.config.ts_standalone@jsx_solid.ejs +11 -0
- package/templates/default/wdio.conf.ts.ejs +21 -0
- package/templates/default/webpack.config.ts.ejs +3 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ObsidianPluginVitestConfigContext } from 'obsidian-dev-utils/script-utils/test-runners/vitest-config';
|
|
2
|
+
import type { TestProjectConfiguration } from 'vitest/config';
|
|
3
|
+
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { defineObsidianPluginVitestConfig } from 'obsidian-dev-utils/script-utils/test-runners/vitest-config';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The demo-vault button suite. It drives a real desktop Obsidian like the desktop project, but opens a
|
|
9
|
+
* copy of the in-repo `demo-vault/` rather than an empty vault — hence its own `globalSetup` — and needs
|
|
10
|
+
* its own file suffix so the desktop project does not also collect it and open it against a vault with no
|
|
11
|
+
* notes in it.
|
|
12
|
+
*/
|
|
13
|
+
const DEMO_VAULT_TEST_FILES = 'src/**/*.demo-vault.integration.test.ts';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* One `it` per note runs every button in that note, and each button re-opens the note, walks the preview
|
|
17
|
+
* to find itself and then waits for a result. A note with several buttons blows past the desktop
|
|
18
|
+
* project's 30s default — which fails the whole note with a bare vitest timeout instead of naming the
|
|
19
|
+
* button that actually misbehaved.
|
|
20
|
+
*/
|
|
21
|
+
const DEMO_VAULT_TIMEOUT_IN_MILLISECONDS = 600_000;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Where every `.svelte` / `.vue` import in a unit test's module graph is sent. Compiling a single-file
|
|
25
|
+
* component is the bundler's job, and the plugin that does it is a dependency only of the bundler that
|
|
26
|
+
* was chosen — so a unit test that imports the plugin's own code would otherwise fail on a file vitest
|
|
27
|
+
* cannot transform. Absolute, because a vite alias replacement is resolved from the project root rather
|
|
28
|
+
* than from this file.
|
|
29
|
+
*/
|
|
30
|
+
const FRAMEWORK_COMPONENT_STUB_PATH = fileURLToPath(new URL('framework-component-stub.ts', import.meta.url));
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Where every `.wasm` import in a unit test's module graph is sent, for the same reason as the component
|
|
34
|
+
* stub above. Vitest resolves a `.wasm` through vite's own WebAssembly helper, which fetches it from a
|
|
35
|
+
* URL that exists only under a dev server — so a unit test that imports the plugin's own code fails on
|
|
36
|
+
* `Failed to parse URL` before it runs a single assertion.
|
|
37
|
+
*/
|
|
38
|
+
const WASM_MODULE_STUB_PATH = fileURLToPath(new URL('wasm-module-stub.ts', import.meta.url));
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Where every stylesheet import in a unit test's module graph is sent. `src/main.ts` imports one for its
|
|
42
|
+
* side effect, and on the `tailwind` styling the file it names is generated by the first build — so a
|
|
43
|
+
* unit test run on a fresh clone would otherwise fail to resolve it.
|
|
44
|
+
*/
|
|
45
|
+
const STYLESHEET_STUB_PATH = fileURLToPath(new URL('stylesheet-stub.ts', import.meta.url));
|
|
46
|
+
|
|
47
|
+
export const config = defineObsidianPluginVitestConfig({
|
|
48
|
+
customProjects(context: ObsidianPluginVitestConfigContext): TestProjectConfiguration[] {
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
test: {
|
|
52
|
+
...context.desktop,
|
|
53
|
+
globalSetup: ['./scripts/demo-vault-global-setup.ts'],
|
|
54
|
+
include: [DEMO_VAULT_TEST_FILES],
|
|
55
|
+
name: 'integration-tests:demo-vault',
|
|
56
|
+
testTimeout: DEMO_VAULT_TIMEOUT_IN_MILLISECONDS
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
},
|
|
61
|
+
// `^.+` is load-bearing, not decoration: a vite alias built from a RegExp replaces only the part the
|
|
62
|
+
// Pattern MATCHED, so `/\.svelte$/` rewrites the extension and leaves the rest of the specifier glued
|
|
63
|
+
// To the front of the stub path. The pattern has to cover the whole id.
|
|
64
|
+
editContext(context: ObsidianPluginVitestConfigContext): void {
|
|
65
|
+
context.unitTests.alias = [
|
|
66
|
+
{ find: /^.+\.(?:svelte|vue)$/u, replacement: FRAMEWORK_COMPONENT_STUB_PATH },
|
|
67
|
+
{ find: /^.+\.(?:css|scss)$/u, replacement: STYLESHEET_STUB_PATH },
|
|
68
|
+
// Two patterns because two bundlers do not write the import plainly: vite asks for the asset's URL
|
|
69
|
+
// (`./module.wasm?url`) and parcel uses a scheme (`data-url:./module.wasm`).
|
|
70
|
+
{ find: /^.+\.wasm(?:\?.*)?$/u, replacement: WASM_MODULE_STUB_PATH },
|
|
71
|
+
{ find: /^data-url:.+$/u, replacement: WASM_MODULE_STUB_PATH }
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
<%- render('post-config') -%>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* The config above, narrowed to the one field this file writes through.
|
|
4
|
+
*/
|
|
5
|
+
interface ConfigWithProjects {
|
|
6
|
+
test: ProjectsSection;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The shape of a project entry this file reaches into, which vitest's own union type does not narrow to.
|
|
11
|
+
*/
|
|
12
|
+
interface JsxProject {
|
|
13
|
+
oxc?: OxcSection;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The JSX transform a test project is given.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately not named `…Options`: the shared lint config requires every member of a `Params` /
|
|
20
|
+
* `Options` / `Result` interface to be `readonly`, and this one is assigned to.
|
|
21
|
+
*/
|
|
22
|
+
interface JsxRuntimeSpec {
|
|
23
|
+
importSource: string;
|
|
24
|
+
runtime: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The `oxc` section of a project entry.
|
|
29
|
+
*/
|
|
30
|
+
interface OxcSection {
|
|
31
|
+
jsx: JsxRuntimeSpec;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The `test` section of the config above.
|
|
36
|
+
*/
|
|
37
|
+
interface ProjectsSection {
|
|
38
|
+
projects: JsxProject[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* Solid compiles its JSX with `babel-preset-solid`, so the project's `tsconfig.json` sets
|
|
43
|
+
* `jsx: 'preserve'` and leaves the JSX in place for the bundler. Vite refuses to parse a file in that
|
|
44
|
+
* state at all -- "make sure to not set jsx to preserve" -- so every suite whose module graph reaches a
|
|
45
|
+
* `.tsx` file fails before it runs. The test projects transform JSX with the automatic runtime instead,
|
|
46
|
+
* from `solid-js/h`, which is the entry point that publishes a `jsx-runtime`; plain `solid-js` does not.
|
|
47
|
+
* Reactivity is not compiled in, which unit tests do not need -- rendering a Solid component is an
|
|
48
|
+
* integration-test job.
|
|
49
|
+
*
|
|
50
|
+
* Applied here rather than through `editContext`, which reaches a project's `test` section only, while
|
|
51
|
+
* `oxc` is a vite-level option on the project itself.
|
|
52
|
+
*
|
|
53
|
+
* Widened through a separate `unknown` binding rather than asserted twice in one expression: the
|
|
54
|
+
* returned type does not overlap `ConfigWithProjects`, so a direct assertion is TS2352, and
|
|
55
|
+
* `as unknown as` in one expression is what the shared lint config bans.
|
|
56
|
+
*/
|
|
57
|
+
const untypedConfig: unknown = config;
|
|
58
|
+
const configWithProjects = untypedConfig as ConfigWithProjects;
|
|
59
|
+
|
|
60
|
+
for (const project of configWithProjects.test.projects) {
|
|
61
|
+
project.oxc = {
|
|
62
|
+
jsx: {
|
|
63
|
+
importSource: 'solid-js/h',
|
|
64
|
+
runtime: 'automatic'
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The unit runners' stand-in for a `.wasm` import.
|
|
3
|
+
*
|
|
4
|
+
* Neither runner can load one the way the bundler does, and each fails differently: vitest resolves a
|
|
5
|
+
* `.wasm` through vite's own WebAssembly helper, which tries to `fetch` it from a URL that does not
|
|
6
|
+
* exist outside a dev server, and jest has no transform for the extension at all. Meanwhile the emitted
|
|
7
|
+
* `src/plugin.ts` reaches the module through `src/wasm/sample-command.ts`, so ANY unit test that imports
|
|
8
|
+
* the plugin -- which the sample one does, deliberately -- pulls the `.wasm` into its module graph.
|
|
9
|
+
*
|
|
10
|
+
* So both runners send every `.wasm` import here, exactly as they send every `.svelte` / `.vue` import
|
|
11
|
+
* to `framework-component-stub.ts`, and for the same reason: loading the real thing is the bundler's
|
|
12
|
+
* job, and no unit test needs it.
|
|
13
|
+
*
|
|
14
|
+
* It throws rather than returning inert bytes. A unit test that really does want to run WebAssembly
|
|
15
|
+
* should instantiate the module itself from `readFileSync`, and this sentence is what tells it so.
|
|
16
|
+
*
|
|
17
|
+
* @throws Always.
|
|
18
|
+
*/
|
|
19
|
+
export default function wasmModuleStub(): never {
|
|
20
|
+
throw new Error('A `.wasm` import is not loaded in unit tests. Read the file and instantiate it directly if a test needs the real module.');
|
|
21
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Configuration } from 'webpack';
|
|
2
|
+
|
|
3
|
+
<%# Sorted as one group: the per-answer partials contribute imports in question-registration order, -%>
|
|
4
|
+
<%# which is not the order an import-sorting lint rule wants. See `sortImports` in `src/templates.ts`. -%>
|
|
5
|
+
<%- sortImports(`import { builtinModules } from 'node:module';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import process from 'node:process';
|
|
8
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
9
|
+
${render('lint-webpack-default')}import webpack from 'webpack';
|
|
10
|
+
${render('import')}`) -%>
|
|
11
|
+
|
|
12
|
+
const isProduction = process.env['BUILD'] === 'production';
|
|
13
|
+
const distFolder = process.env['DIST_FOLDER'] ?? (isProduction ? 'dist/build' : 'dist/dev');
|
|
14
|
+
|
|
15
|
+
const EXTERNAL = [
|
|
16
|
+
'obsidian',
|
|
17
|
+
'electron',
|
|
18
|
+
'@codemirror/autocomplete',
|
|
19
|
+
'@codemirror/collab',
|
|
20
|
+
'@codemirror/commands',
|
|
21
|
+
'@codemirror/language',
|
|
22
|
+
'@codemirror/lint',
|
|
23
|
+
'@codemirror/search',
|
|
24
|
+
'@codemirror/state',
|
|
25
|
+
'@codemirror/view',
|
|
26
|
+
'@lezer/common',
|
|
27
|
+
'@lezer/highlight',
|
|
28
|
+
'@lezer/lr',
|
|
29
|
+
'esbuild',
|
|
30
|
+
'eslint',
|
|
31
|
+
...builtinModules
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
<%# Each per-answer partial ends its entry with a comma so two of them concatenate into a valid list; -%>
|
|
35
|
+
<%# the last entry of each array must not carry one. Stripped here rather than by making every partial -%>
|
|
36
|
+
<%# know whether it is last. -%>
|
|
37
|
+
<%
|
|
38
|
+
const rules = ` {
|
|
39
|
+
// The emitted \`tsconfig.json\` declares \`noEmit: true\` and allows \`.ts\` import specifiers, both
|
|
40
|
+
// Right for the file itself -- more than tsc reads it. ts-loader compiles WITH emit, so it needs
|
|
41
|
+
// Both overridden, and the overrides belong here, in the one tool that needs them, exactly as
|
|
42
|
+
// \`jest.config.ts\` overrides \`rootDir\` for the same reason.
|
|
43
|
+
//
|
|
44
|
+
// \`rewriteRelativeImportExtensions\` rather than turning \`allowImportingTsExtensions\` off: the
|
|
45
|
+
// Emitted \`src/\` really does import \`./plugin.ts\` by that name, so switching it off trades
|
|
46
|
+
// TS5096 for an error on every one of those. This is the option TypeScript added for emitting
|
|
47
|
+
// From exactly such sources. \`onlyCompileBundledFiles\` keeps ts-loader to the graph webpack
|
|
48
|
+
// Actually pulls in, instead of every file the tsconfig's \`include\` lists -- it was reaching
|
|
49
|
+
// \`webpack.config.ts\` and \`scripts/dev.ts\`, which are no business of the bundle.
|
|
50
|
+
exclude: /node_modules/,
|
|
51
|
+
test: /\\.tsx?$/,
|
|
52
|
+
use: {
|
|
53
|
+
loader: 'ts-loader',
|
|
54
|
+
options: {
|
|
55
|
+
${render('ts-loader-options')} compilerOptions: {
|
|
56
|
+
noEmit: false,
|
|
57
|
+
${render('ts-loader-compiler-options')} rewriteRelativeImportExtensions: true
|
|
58
|
+
},
|
|
59
|
+
onlyCompileBundledFiles: true
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
${render('rule')}`;
|
|
64
|
+
const plugins = ` new webpack.BannerPlugin({
|
|
65
|
+
banner: \`/*
|
|
66
|
+
THIS IS A GENERATED/BUNDLED FILE BY WEBPACK
|
|
67
|
+
if you want to view the source, please visit the github repository of this plugin
|
|
68
|
+
*/\`,
|
|
69
|
+
raw: true
|
|
70
|
+
}),
|
|
71
|
+
${render('plugin')}`;
|
|
72
|
+
-%>
|
|
73
|
+
export const config: Configuration = {
|
|
74
|
+
devtool: isProduction ? false : 'inline-source-map',
|
|
75
|
+
entry: './src/main.ts',
|
|
76
|
+
externals: Object.fromEntries(
|
|
77
|
+
EXTERNAL.map((moduleName) => [moduleName, `commonjs2 ${moduleName}`])
|
|
78
|
+
),
|
|
79
|
+
mode: isProduction ? 'production' : 'development',
|
|
80
|
+
module: {
|
|
81
|
+
rules: [
|
|
82
|
+
<%- rules.replace(/,(?<Trailing>\s*)$/, '$<Trailing>') -%>
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
optimization: {
|
|
86
|
+
// Terser's default `extractComments` cuts every bundled dependency's `/*! ... */` and `@license`
|
|
87
|
+
// Comment out of `main.js` into a `main.js.LICENSE.txt` beside it -- which no Obsidian release ships,
|
|
88
|
+
// So the installed plugin would carry the code without the notices it is licensed under. Kept inline
|
|
89
|
+
// Instead, as esbuild's `legalComments` default keeps them.
|
|
90
|
+
minimizer: [new TerserPlugin({ extractComments: false })]
|
|
91
|
+
},
|
|
92
|
+
output: {
|
|
93
|
+
// An Obsidian release ships `main.js` and nothing beside it, so a dynamic import -- obsidian-dev-utils
|
|
94
|
+
// Has several -- must not become a sibling chunk that `main.js` then loads by name at runtime. This is
|
|
95
|
+
// Webpack's twin of rollup's `inlineDynamicImports`.
|
|
96
|
+
asyncChunks: false,
|
|
97
|
+
filename: 'main.js',
|
|
98
|
+
libraryExport: 'default',
|
|
99
|
+
libraryTarget: 'commonjs2',
|
|
100
|
+
path: join(process.cwd(), distFolder)
|
|
101
|
+
},
|
|
102
|
+
plugins: [
|
|
103
|
+
<%- plugins.replace(/,(?<Trailing>\s*)$/, '$<Trailing>') -%>
|
|
104
|
+
],
|
|
105
|
+
resolve: {
|
|
106
|
+
// A plugin runs in Obsidian's renderer, not in Node, but `target: 'node'` resolves only the `node`
|
|
107
|
+
// Export condition -- which hands Solid and Svelte their SERVER builds, where `render` / `mount` do
|
|
108
|
+
// Nothing a view can use, with the build green. `browser` is what esbuild's `conditions` and rollup's
|
|
109
|
+
// `nodeResolve({ browser: true })` already ask for; `'...'` keeps webpack's own defaults beside it.
|
|
110
|
+
conditionNames: ['browser', '...'],
|
|
111
|
+
// The loader above rewrites `./plugin.ts` to `./plugin.js` on emit, but only `./plugin.ts` exists on
|
|
112
|
+
// Disk, and webpack's `extensions` list only appends a suffix to a request that has no extension --
|
|
113
|
+
// It does not map one extension to another. Without this the bundle fails to resolve "./plugin.js".
|
|
114
|
+
//
|
|
115
|
+
// Under `jsx: preserve` (the Solid answer) it rewrites `./view.tsx` to `./view.jsx` instead, so that
|
|
116
|
+
// Name is mapped back the same way. Nothing else emits a `.jsx` specifier, so elsewhere it is inert.
|
|
117
|
+
extensionAlias: {
|
|
118
|
+
'.js': ['.ts', '.tsx', '.js'],
|
|
119
|
+
'.jsx': ['.tsx', '.jsx']
|
|
120
|
+
},
|
|
121
|
+
extensions: ['.ts', '.tsx', '.js']
|
|
122
|
+
},
|
|
123
|
+
target: 'node'
|
|
124
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { sveltePreprocess } from 'svelte-preprocess';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { VueLoaderPlugin } from 'vue-loader';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<%# Shared by EVERY styling answer that extracts CSS, rather than one identical copy per answer. -%>
|
|
2
|
+
<%# Partials are a Set, so a preset forcing a second styling answer on top of the chosen one -- which -%>
|
|
3
|
+
<%# `demo` does, with `scss` -- renders this once instead of emitting a duplicate `import` (TS2300). -%>
|
|
4
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// eslint-disable-next-line import-x/no-named-as-default -- The default export IS the `webpack` namespace; the same name is the point.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
new VueLoaderPlugin(),
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<%# One instance, for the reason its import partial gives: two plugins both writing `styles.css` is -%>
|
|
2
|
+
<%# what five per-answer copies produced. The per-answer `rule` partials stay per-answer -- they test -%>
|
|
3
|
+
<%# different extensions and are meant to coexist. -%>
|
|
4
|
+
new MiniCssExtractPlugin({ filename: 'styles.css' }),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<%# Solid's JSX is not React's, so ts-loader leaves it alone: the Solid answer sets `jsx: preserve` for -%>
|
|
2
|
+
<%# `babel-preset-solid`, and ts-loader emits every `.tsx` with its JSX intact. This rule compiles it. -%>
|
|
3
|
+
<%# `enforce: 'post'` runs it AFTER ts-loader, which still type-checks and strips the types, so babel -%>
|
|
4
|
+
<%# needs only the Solid preset. `configFile: false` keeps a babel config another answer emits away from it. -%>
|
|
5
|
+
{
|
|
6
|
+
enforce: 'post',
|
|
7
|
+
exclude: /node_modules/,
|
|
8
|
+
test: /\.tsx$/,
|
|
9
|
+
use: {
|
|
10
|
+
loader: 'babel-loader',
|
|
11
|
+
options: {
|
|
12
|
+
babelrc: false,
|
|
13
|
+
configFile: false,
|
|
14
|
+
presets: ['babel-preset-solid']
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
// NOT `experiments.asyncWebAssembly`, which is what this used to be. That emits the module as a
|
|
3
|
+
// Separate `.wasm` chunk the bundle fetches at runtime -- and an Obsidian release ships `main.js`
|
|
4
|
+
// And `styles.css` and nothing else, so the chunk is simply absent wherever the plugin is
|
|
5
|
+
// Installed. `asset/inline` carries the module inside `main.js` as a `data:` URL instead.
|
|
6
|
+
test: /\.wasm$/,
|
|
7
|
+
type: 'asset/inline'
|
|
8
|
+
},
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<%# Only for this compile, not in `tsconfig.json`. `appendTsSuffixTo` hands ts-loader the component's -%>
|
|
2
|
+
<%# `<script>` block as a standalone module, WITHOUT the template that uses its bindings, so every -%>
|
|
3
|
+
<%# handler the template calls reads as unused: TS6133 "'increment' is declared but its value is never -%>
|
|
4
|
+
<%# read". The gate's own `tsc --noEmit`, and the editor, still enforce it on real `.ts` files. -%>
|
|
5
|
+
noUnusedLocals: false,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<%# Without this, ts-loader does not recognize vue-loader's `?vue&type=script&lang=ts` request as -%>
|
|
2
|
+
<%# TypeScript, and TypeScript resolves the block against the WRONG file: the build failed with -%>
|
|
3
|
+
<%# "Can't resolve './styles/main.module.css' in src/vue-components" -- which is `src/main.ts`'s import, -%>
|
|
4
|
+
<%# reported from the component's directory. -%>
|
|
5
|
+
appendTsSuffixTo: [/\.vue$/u],
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { registerDemoVaultButtonSuite } from 'obsidian-dev-utils/script-utils/demo-vault-buttons';
|
|
2
|
+
|
|
3
|
+
// Clicks every `code-button` in `demo-vault/` against a real Obsidian. A button fails at CLICK time -- a
|
|
4
|
+
// Wrong `require('/demoSetup.ts')` path, or an API that changed shape under it -- so no other gate can
|
|
5
|
+
// Catch it: `lint:md` reads the markdown and the coverage suite checks the authoring conventions, and
|
|
6
|
+
// Neither executes anything.
|
|
7
|
+
//
|
|
8
|
+
// It needs the CodeScript Toolkit binary seeded into `demo-vault/.obsidian/plugins/`, which happens the
|
|
9
|
+
// First time you open `demo-vault/` in Obsidian. See CONTRIBUTING.md.
|
|
10
|
+
//
|
|
11
|
+
// Isolation: `npx vitest run --project integration-tests:demo-vault`.
|
|
12
|
+
registerDemoVaultButtonSuite();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { registerDemoVaultCoverageSuite } from 'obsidian-dev-utils/script-utils/demo-vault-coverage';
|
|
3
|
+
import { getRootFolder } from 'obsidian-dev-utils/script-utils/root';
|
|
4
|
+
|
|
5
|
+
// Keeps the in-repo `demo-vault/` honest WITHOUT launching Obsidian. It enforces the authoring convention
|
|
6
|
+
// Every vault owes its readers: an `# H1` and a prose opener on every note, Markdown links rather than
|
|
7
|
+
// Wikilinks (which do not render on GitHub), no `[Docs]` line, every note reachable from `00 Start.md`,
|
|
8
|
+
// And an `.obsidian/app.json` that commits none of the settings obsidian-dev-utils injects at release time.
|
|
9
|
+
//
|
|
10
|
+
// `rootFolder` alone is enough for those. Once your settings surface settles, add a reflection spec so the
|
|
11
|
+
// Suite also fails when a setting is documented nowhere in the vault, or when a note names one that no
|
|
12
|
+
// Longer exists:
|
|
13
|
+
//
|
|
14
|
+
// registerDemoVaultCoverageSuite({
|
|
15
|
+
// configInterfaces: [{ interfaceName: 'PluginSettings', sourcePath: 'src/plugin-settings.ts' }],
|
|
16
|
+
// rootFolder: getRootFolder() ?? process.cwd()
|
|
17
|
+
// });
|
|
18
|
+
registerDemoVaultCoverageSuite({ rootFolder: getRootFolder() ?? process.cwd() });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Extension,
|
|
3
|
+
Transaction
|
|
4
|
+
} from '@codemirror/state';
|
|
5
|
+
import type { DecorationSet } from '@codemirror/view';
|
|
6
|
+
import type { StateFieldSpec } from 'obsidian-dev-utils/codemirror/state-field-spec';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
RangeSetBuilder,
|
|
10
|
+
StateField
|
|
11
|
+
} from '@codemirror/state';
|
|
12
|
+
import {
|
|
13
|
+
Decoration,
|
|
14
|
+
EditorView
|
|
15
|
+
} from '@codemirror/view';
|
|
16
|
+
|
|
17
|
+
import { SampleWidget } from './sample-widget.ts';
|
|
18
|
+
|
|
19
|
+
class SampleStateField implements StateFieldSpec<DecorationSet> {
|
|
20
|
+
public create(state: Transaction['state']): DecorationSet {
|
|
21
|
+
return buildDecorations(state);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public provide(field: StateField<DecorationSet>): Extension {
|
|
25
|
+
return EditorView.decorations.from(field);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public update(oldState: DecorationSet, transaction: Transaction): DecorationSet {
|
|
29
|
+
return transaction.docChanged ? buildDecorations(transaction.state) : oldState;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function buildDecorations(state: Transaction['state']): DecorationSet {
|
|
34
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
35
|
+
const doc = state.doc;
|
|
36
|
+
|
|
37
|
+
for (let index = 1; index <= doc.lines; index++) {
|
|
38
|
+
const line = doc.line(index);
|
|
39
|
+
const words = line.text.trim().split(/\s+/).filter((w) => w.length > 0);
|
|
40
|
+
|
|
41
|
+
if (words.length > 0) {
|
|
42
|
+
builder.add(
|
|
43
|
+
line.to,
|
|
44
|
+
line.to,
|
|
45
|
+
Decoration.widget({
|
|
46
|
+
side: 1,
|
|
47
|
+
widget: new SampleWidget(words.length)
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return builder.finish();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const sampleStateField = StateField.define<DecorationSet>(new SampleStateField());
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Extension,
|
|
3
|
+
Transaction
|
|
4
|
+
} from '@codemirror/state';
|
|
5
|
+
import type { DecorationSet } from '@codemirror/view';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
RangeSetBuilder,
|
|
9
|
+
StateField
|
|
10
|
+
} from '@codemirror/state';
|
|
11
|
+
import {
|
|
12
|
+
Decoration,
|
|
13
|
+
EditorView
|
|
14
|
+
} from '@codemirror/view';
|
|
15
|
+
|
|
16
|
+
import { SampleWidget } from './sample-widget.ts';
|
|
17
|
+
|
|
18
|
+
function buildDecorations(state: Transaction['state']): DecorationSet {
|
|
19
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
20
|
+
const doc = state.doc;
|
|
21
|
+
|
|
22
|
+
for (let i = 1; i <= doc.lines; i++) {
|
|
23
|
+
const line = doc.line(i);
|
|
24
|
+
const words = line.text.trim().split(/\s+/).filter((w) => w.length > 0);
|
|
25
|
+
|
|
26
|
+
if (words.length > 0) {
|
|
27
|
+
builder.add(
|
|
28
|
+
line.to,
|
|
29
|
+
line.to,
|
|
30
|
+
Decoration.widget({
|
|
31
|
+
side: 1,
|
|
32
|
+
widget: new SampleWidget(words.length)
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return builder.finish();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createSampleStateField(): StateField<DecorationSet> {
|
|
42
|
+
return StateField.define<DecorationSet>({
|
|
43
|
+
create(state): DecorationSet {
|
|
44
|
+
return buildDecorations(state);
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
provide(field: StateField<DecorationSet>): Extension {
|
|
48
|
+
return EditorView.decorations.from(field);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
update(oldState: DecorationSet, transaction: Transaction): DecorationSet {
|
|
52
|
+
if (transaction.docChanged) {
|
|
53
|
+
return buildDecorations(transaction.state);
|
|
54
|
+
}
|
|
55
|
+
return oldState;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const sampleStateField = createSampleStateField();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DecorationSet,
|
|
3
|
+
EditorView,
|
|
4
|
+
PluginSpec,
|
|
5
|
+
PluginValue,
|
|
6
|
+
ViewUpdate
|
|
7
|
+
} from '@codemirror/view';
|
|
8
|
+
|
|
9
|
+
import { RangeSetBuilder } from '@codemirror/state';
|
|
10
|
+
import {
|
|
11
|
+
Decoration,
|
|
12
|
+
ViewPlugin
|
|
13
|
+
} from '@codemirror/view';
|
|
14
|
+
|
|
15
|
+
import { SampleWidget } from './sample-widget.ts';
|
|
16
|
+
|
|
17
|
+
class SampleViewPlugin implements PluginValue {
|
|
18
|
+
public decorations: DecorationSet;
|
|
19
|
+
|
|
20
|
+
public constructor(view: EditorView) {
|
|
21
|
+
this.decorations = this.buildDecorations(view);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public update(update: ViewUpdate): void {
|
|
25
|
+
if (update.docChanged || update.viewportChanged) {
|
|
26
|
+
this.decorations = this.buildDecorations(update.view);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private buildDecorations(view: EditorView): DecorationSet {
|
|
31
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
32
|
+
|
|
33
|
+
for (const { from, to } of view.visibleRanges) {
|
|
34
|
+
const doc = view.state.doc;
|
|
35
|
+
const startLine = doc.lineAt(from).number;
|
|
36
|
+
const endLine = doc.lineAt(to).number;
|
|
37
|
+
|
|
38
|
+
for (let index = startLine; index <= endLine; index++) {
|
|
39
|
+
const line = doc.line(index);
|
|
40
|
+
const words = line.text.trim().split(/\s+/).filter((w) => w.length > 0);
|
|
41
|
+
|
|
42
|
+
if (words.length > 0) {
|
|
43
|
+
builder.add(
|
|
44
|
+
line.to,
|
|
45
|
+
line.to,
|
|
46
|
+
Decoration.widget({
|
|
47
|
+
side: 1,
|
|
48
|
+
widget: new SampleWidget(words.length)
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return builder.finish();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const pluginSpec: PluginSpec<SampleViewPlugin> = {
|
|
60
|
+
decorations: (value: SampleViewPlugin) => value.decorations
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const sampleViewPlugin = ViewPlugin.fromClass(
|
|
64
|
+
SampleViewPlugin,
|
|
65
|
+
pluginSpec
|
|
66
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WidgetType } from '@codemirror/view';
|
|
2
|
+
|
|
3
|
+
export class SampleWidget extends WidgetType {
|
|
4
|
+
private readonly count: number;
|
|
5
|
+
|
|
6
|
+
public constructor(count: number) {
|
|
7
|
+
super();
|
|
8
|
+
this.count = count;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public override eq(other: SampleWidget): boolean {
|
|
12
|
+
return this.count === other.count;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public toDOM(): HTMLElement {
|
|
16
|
+
const span = createSpan({
|
|
17
|
+
cls: 'cm-sample-word-count',
|
|
18
|
+
text: ` [${String(this.count)} words]`
|
|
19
|
+
});
|
|
20
|
+
return span;
|
|
21
|
+
}
|
|
22
|
+
}
|