@linyjs/plugin-docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/docs/api-reference/index.md +341 -0
- package/docs/best-practices/error-handling.md +462 -0
- package/docs/best-practices/naming-conventions.md +495 -0
- package/docs/best-practices/performance.md +532 -0
- package/docs/best-practices/security.md +620 -0
- package/docs/faq.md +323 -0
- package/docs/getting-started/first-plugin.md +358 -0
- package/docs/getting-started/installation.md +244 -0
- package/docs/getting-started/quick-start.md +174 -0
- package/docs/guides/client-module.md +598 -0
- package/docs/guides/data-persistence.md +536 -0
- package/docs/guides/permissions.md +440 -0
- package/docs/guides/server-module.md +371 -0
- package/docs/guides/ui-slots.md +475 -0
- package/docs/migration/v0-to-v1.md +354 -0
- package/examples/analytics-plugin/README.md +416 -0
- package/examples/analytics-plugin/dist/client/index.d.ts +36 -0
- package/examples/analytics-plugin/dist/client/index.js +173 -0
- package/examples/analytics-plugin/dist/index.d.ts +64 -0
- package/examples/analytics-plugin/dist/index.js +72 -0
- package/examples/analytics-plugin/dist/server/index.d.ts +119 -0
- package/examples/analytics-plugin/dist/server/index.js +313 -0
- package/examples/analytics-plugin/package.json +28 -0
- package/examples/analytics-plugin/src/client/index.tsx +410 -0
- package/examples/analytics-plugin/src/index.ts +71 -0
- package/examples/analytics-plugin/src/server/index.ts +348 -0
- package/examples/analytics-plugin/tsconfig.json +21 -0
- package/examples/blog-plugin/README.md +316 -0
- package/examples/blog-plugin/dist/client/index.d.ts +22 -0
- package/examples/blog-plugin/dist/client/index.js +197 -0
- package/examples/blog-plugin/dist/server/index.d.ts +5 -0
- package/examples/blog-plugin/dist/server/index.js +220 -0
- package/examples/blog-plugin/package.json +24 -0
- package/examples/blog-plugin/src/client/index.tsx +405 -0
- package/examples/blog-plugin/src/server/index.ts +240 -0
- package/examples/blog-plugin/tsconfig.json +16 -0
- package/examples/hello-world/README.md +101 -0
- package/examples/hello-world/dist/client/index.d.ts +5 -0
- package/examples/hello-world/dist/client/index.js +80 -0
- package/examples/hello-world/dist/server/index.d.ts +5 -0
- package/examples/hello-world/dist/server/index.js +38 -0
- package/examples/hello-world/node_modules/.package-lock.json +61 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/HOOKS_USAGE.md +281 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/IMPLEMENTATION_SUMMARY.md +166 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/QUICK_REFERENCE.md +130 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/README.md +214 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/package.json +26 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/application.ts +50 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/comparison-example.tsx +229 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/di.ts +127 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/domain.ts +52 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks-example.tsx +275 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/hooks.ts +175 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/index.ts +87 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/interfaces.ts +117 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/src/router.ts +49 -0
- package/examples/hello-world/node_modules/@linyjs/client-module-interface/tsconfig.json +10 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/package.json +21 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/application.ts +21 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/di.ts +127 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/domain.ts +75 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/index.ts +55 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/src/interfaces.ts +58 -0
- package/examples/hello-world/node_modules/@linyjs/server-module-interface/tsconfig.json +8 -0
- package/examples/hello-world/node_modules/@types/react/LICENSE +21 -0
- package/examples/hello-world/node_modules/@types/react/README.md +15 -0
- package/examples/hello-world/node_modules/@types/react/canary.d.ts +129 -0
- package/examples/hello-world/node_modules/@types/react/compiler-runtime.d.ts +4 -0
- package/examples/hello-world/node_modules/@types/react/experimental.d.ts +184 -0
- package/examples/hello-world/node_modules/@types/react/global.d.ts +166 -0
- package/examples/hello-world/node_modules/@types/react/index.d.ts +4369 -0
- package/examples/hello-world/node_modules/@types/react/jsx-dev-runtime.d.ts +33 -0
- package/examples/hello-world/node_modules/@types/react/jsx-runtime.d.ts +24 -0
- package/examples/hello-world/node_modules/@types/react/package.json +210 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/canary.d.ts +129 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/experimental.d.ts +184 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/global.d.ts +166 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/index.d.ts +4356 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +33 -0
- package/examples/hello-world/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +24 -0
- package/examples/hello-world/node_modules/csstype/LICENSE +19 -0
- package/examples/hello-world/node_modules/csstype/README.md +291 -0
- package/examples/hello-world/node_modules/csstype/index.d.ts +22569 -0
- package/examples/hello-world/node_modules/csstype/index.js.flow +6863 -0
- package/examples/hello-world/node_modules/csstype/package.json +70 -0
- package/examples/hello-world/node_modules/react/LICENSE +21 -0
- package/examples/hello-world/node_modules/react/README.md +37 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.development.js +24 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.production.js +16 -0
- package/examples/hello-world/node_modules/react/cjs/react-compiler-runtime.profiling.js +16 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.development.js +338 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.production.js +14 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.profiling.js +14 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.development.js +370 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-dev-runtime.react-server.production.js +40 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.development.js +352 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.production.js +34 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.profiling.js +34 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.development.js +370 -0
- package/examples/hello-world/node_modules/react/cjs/react-jsx-runtime.react-server.production.js +40 -0
- package/examples/hello-world/node_modules/react/cjs/react.development.js +1284 -0
- package/examples/hello-world/node_modules/react/cjs/react.production.js +542 -0
- package/examples/hello-world/node_modules/react/cjs/react.react-server.development.js +848 -0
- package/examples/hello-world/node_modules/react/cjs/react.react-server.production.js +423 -0
- package/examples/hello-world/node_modules/react/compiler-runtime.js +14 -0
- package/examples/hello-world/node_modules/react/index.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-dev-runtime.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-dev-runtime.react-server.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-runtime.js +7 -0
- package/examples/hello-world/node_modules/react/jsx-runtime.react-server.js +7 -0
- package/examples/hello-world/node_modules/react/package.json +51 -0
- package/examples/hello-world/node_modules/react/react.react-server.js +7 -0
- package/examples/hello-world/node_modules/typescript/LICENSE.txt +55 -0
- package/examples/hello-world/node_modules/typescript/README.md +50 -0
- package/examples/hello-world/node_modules/typescript/SECURITY.md +41 -0
- package/examples/hello-world/node_modules/typescript/ThirdPartyNoticeText.txt +193 -0
- package/examples/hello-world/node_modules/typescript/bin/tsc +2 -0
- package/examples/hello-world/node_modules/typescript/bin/tsserver +2 -0
- package/examples/hello-world/node_modules/typescript/lib/_tsc.js +133818 -0
- package/examples/hello-world/node_modules/typescript/lib/_tsserver.js +659 -0
- package/examples/hello-world/node_modules/typescript/lib/_typingsInstaller.js +222 -0
- package/examples/hello-world/node_modules/typescript/lib/cs/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/de/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/es/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/fr/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/it/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ja/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ko/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.decorators.d.ts +384 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.decorators.legacy.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.asynciterable.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.d.ts +39429 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.dom.iterable.d.ts +571 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.collection.d.ts +147 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.core.d.ts +597 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.generator.d.ts +77 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.iterable.d.ts +605 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.promise.d.ts +81 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.proxy.d.ts +128 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.reflect.d.ts +144 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.d.ts +46 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts +326 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.array.include.d.ts +116 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.full.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2016.intl.d.ts +31 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.date.d.ts +31 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.full.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.intl.d.ts +44 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.object.d.ts +49 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts +135 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.string.d.ts +45 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts +53 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts +77 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts +53 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.intl.d.ts +83 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.promise.d.ts +30 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2018.regexp.d.ts +37 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.array.d.ts +79 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.intl.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.object.d.ts +33 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.string.d.ts +37 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2019.symbol.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.bigint.d.ts +765 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.d.ts +27 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.date.d.ts +42 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.intl.d.ts +474 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.number.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.promise.d.ts +47 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts +99 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.string.d.ts +44 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.intl.d.ts +166 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.promise.d.ts +48 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.string.d.ts +33 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2021.weakref.d.ts +78 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.array.d.ts +121 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.error.d.ts +75 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.intl.d.ts +145 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.object.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.regexp.d.ts +39 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2022.string.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.array.d.ts +924 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.collection.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.d.ts +22 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2023.intl.d.ts +56 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts +65 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.collection.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.d.ts +26 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.object.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.promise.d.ts +35 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.regexp.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts +68 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es2024.string.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es5.d.ts +4601 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.es6.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.array.d.ts +35 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.collection.d.ts +96 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.d.ts +29 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.decorators.d.ts +28 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.disposable.d.ts +193 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.error.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.float16.d.ts +445 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.full.d.ts +24 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.intl.d.ts +21 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.iterator.d.ts +148 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.promise.d.ts +34 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.esnext.sharedmemory.d.ts +25 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.scripthost.d.ts +322 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.asynciterable.d.ts +41 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.d.ts +13150 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.importscripts.d.ts +23 -0
- package/examples/hello-world/node_modules/typescript/lib/lib.webworker.iterable.d.ts +340 -0
- package/examples/hello-world/node_modules/typescript/lib/pl/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/ru/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/tr/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/tsc.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserver.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.d.ts +17 -0
- package/examples/hello-world/node_modules/typescript/lib/tsserverlibrary.js +21 -0
- package/examples/hello-world/node_modules/typescript/lib/typesMap.json +497 -0
- package/examples/hello-world/node_modules/typescript/lib/typescript.d.ts +11437 -0
- package/examples/hello-world/node_modules/typescript/lib/typescript.js +200276 -0
- package/examples/hello-world/node_modules/typescript/lib/typingsInstaller.js +8 -0
- package/examples/hello-world/node_modules/typescript/lib/watchGuard.js +53 -0
- package/examples/hello-world/node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json +2122 -0
- package/examples/hello-world/node_modules/typescript/package.json +120 -0
- package/examples/hello-world/package-lock.json +74 -0
- package/examples/hello-world/package.json +23 -0
- package/examples/hello-world/src/client/index.tsx +110 -0
- package/examples/hello-world/src/server/index.ts +42 -0
- package/examples/hello-world/tsconfig.json +16 -0
- package/package.json +42 -0
- package/src/cli.ts +321 -0
package/src/cli.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @linyjs/plugin-docs CLI 工具
|
|
5
|
+
*
|
|
6
|
+
* 提供快速访问文档和示例项目的功能
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
import { readFileSync, existsSync, readdirSync, copyFileSync, mkdirSync } from 'fs';
|
|
11
|
+
import { join, resolve, dirname } from 'path';
|
|
12
|
+
import { execSync } from 'child_process';
|
|
13
|
+
|
|
14
|
+
const program = new Command();
|
|
15
|
+
|
|
16
|
+
// 获取插件根目录
|
|
17
|
+
function getPluginRoot(): string {
|
|
18
|
+
return resolve(__dirname, '..');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 获取文档目录
|
|
22
|
+
function getDocsDir(): string {
|
|
23
|
+
return join(getPluginRoot(), 'docs');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 获取示例目录
|
|
27
|
+
function getExamplesDir(): string {
|
|
28
|
+
return join(getPluginRoot(), 'examples');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 打开URL(跨平台)
|
|
32
|
+
function openUrl(url: string): void {
|
|
33
|
+
const command = process.platform === 'win32'
|
|
34
|
+
? `start "" "${url}"`
|
|
35
|
+
: process.platform === 'darwin'
|
|
36
|
+
? `open "${url}"`
|
|
37
|
+
: `xdg-open "${url}"`;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
execSync(command, { stdio: 'inherit' });
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error(`Failed to open URL: ${url}`);
|
|
43
|
+
console.error('Please open it manually.');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 显示文档列表
|
|
48
|
+
function displayDocsList(): void {
|
|
49
|
+
const docsDir = getDocsDir();
|
|
50
|
+
|
|
51
|
+
console.log('📚 linyjs Plugin Documentation\n');
|
|
52
|
+
console.log('Available documentation sections:\n');
|
|
53
|
+
|
|
54
|
+
const sections = [
|
|
55
|
+
{ name: '入门教程', path: 'getting-started', description: '从零开始的插件开发教程' },
|
|
56
|
+
{ name: '进阶指南', path: 'guides', description: '深入理解各种开发细节' },
|
|
57
|
+
{ name: 'API参考', path: 'api-reference', description: '完整的接口文档' },
|
|
58
|
+
{ name: '最佳实践', path: 'best-practices', description: '开发规范和推荐做法' },
|
|
59
|
+
{ name: '常见问题', path: 'faq.md', description: 'FAQ 和故障排除' }
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
sections.forEach((section, index) => {
|
|
63
|
+
console.log(`${index + 1}. ${section.name.padEnd(8)} - ${section.description}`);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log('\n💡 使用命令:');
|
|
67
|
+
console.log(' docs --open 在浏览器中打开在线文档');
|
|
68
|
+
console.log(' docs search <keyword> 搜索文档');
|
|
69
|
+
console.log(' docs list-examples 列出所有示例项目');
|
|
70
|
+
console.log(' docs help 显示详细帮助');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 搜索文档
|
|
74
|
+
function searchDocs(keyword: string): void {
|
|
75
|
+
const docsDir = getDocsDir();
|
|
76
|
+
const results: Array<{ file: string; line: number; content: string }> = [];
|
|
77
|
+
|
|
78
|
+
function searchInDirectory(dir: string, basePath: string = '') {
|
|
79
|
+
try {
|
|
80
|
+
const items = readdirSync(dir, { withFileTypes: true });
|
|
81
|
+
|
|
82
|
+
for (const item of items) {
|
|
83
|
+
const fullPath = join(dir, item.name);
|
|
84
|
+
const relativePath = join(basePath, item.name);
|
|
85
|
+
|
|
86
|
+
if (item.isDirectory()) {
|
|
87
|
+
searchInDirectory(fullPath, relativePath);
|
|
88
|
+
} else if (item.isFile() && item.name.endsWith('.md')) {
|
|
89
|
+
try {
|
|
90
|
+
const content = readFileSync(fullPath, 'utf-8');
|
|
91
|
+
const lines = content.split('\n');
|
|
92
|
+
|
|
93
|
+
lines.forEach((line, index) => {
|
|
94
|
+
if (line.toLowerCase().includes(keyword.toLowerCase())) {
|
|
95
|
+
results.push({
|
|
96
|
+
file: relativePath,
|
|
97
|
+
line: index + 1,
|
|
98
|
+
content: line.trim()
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
// 忽略读取错误的文件
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(`Error searching in directory ${dir}:`, error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
searchInDirectory(docsDir);
|
|
113
|
+
|
|
114
|
+
if (results.length === 0) {
|
|
115
|
+
console.log(`❌ 未找到包含 "${keyword}" 的文档`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log(`\n🔍 找到 ${results.length} 个包含 "${keyword}" 的结果:\n`);
|
|
120
|
+
|
|
121
|
+
results.forEach(result => {
|
|
122
|
+
const preview = result.content.length > 100
|
|
123
|
+
? result.content.substring(0, 97) + '...'
|
|
124
|
+
: result.content;
|
|
125
|
+
|
|
126
|
+
console.log(`📄 ${result.file}:${result.line}`);
|
|
127
|
+
console.log(` ${preview}`);
|
|
128
|
+
console.log('');
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 列出示例项目
|
|
133
|
+
function listExamples(): void {
|
|
134
|
+
const examplesDir = getExamplesDir();
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const examples = readdirSync(examplesDir, { withFileTypes: true })
|
|
138
|
+
.filter(dirent => dirent.isDirectory())
|
|
139
|
+
.map(dirent => dirent.name);
|
|
140
|
+
|
|
141
|
+
if (examples.length === 0) {
|
|
142
|
+
console.log('❌ 暂无可用的示例项目');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('📂 可用的示例项目:\n');
|
|
147
|
+
|
|
148
|
+
examples.forEach((example, index) => {
|
|
149
|
+
const examplePath = join(examplesDir, example);
|
|
150
|
+
const packageJsonPath = join(examplePath, 'package.json');
|
|
151
|
+
|
|
152
|
+
let description = '示例项目';
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
if (existsSync(packageJsonPath)) {
|
|
156
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
157
|
+
description = packageJson.description || description;
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
// 忽略解析错误
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
console.log(`${index + 1}. ${example}`);
|
|
164
|
+
console.log(` ${description}`);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
console.log('\n💡 使用命令:');
|
|
168
|
+
console.log(' example <name> 生成示例到当前目录');
|
|
169
|
+
console.log(' example <name> -o <dir> 生成示例到指定目录');
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error('❌ 读取示例列表失败:', error.message);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 生成示例项目
|
|
176
|
+
async function generateExample(name: string, outputDir?: string): Promise<void> {
|
|
177
|
+
const examplesDir = getExamplesDir();
|
|
178
|
+
const examplePath = join(examplesDir, name);
|
|
179
|
+
|
|
180
|
+
// 检查示例是否存在
|
|
181
|
+
if (!existsSync(examplePath)) {
|
|
182
|
+
console.error(`❌ 示例 "${name}" 不存在`);
|
|
183
|
+
listExamples();
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 确定输出目录
|
|
188
|
+
const targetDir = outputDir ? resolve(process.cwd(), outputDir) : resolve(process.cwd(), name);
|
|
189
|
+
|
|
190
|
+
// 创建目标目录
|
|
191
|
+
mkdirSync(targetDir, { recursive: true });
|
|
192
|
+
|
|
193
|
+
console.log(`📦 正在生成示例 "${name}" 到 ${targetDir}...`);
|
|
194
|
+
|
|
195
|
+
// 复制示例文件
|
|
196
|
+
await copyDirectory(examplePath, targetDir);
|
|
197
|
+
|
|
198
|
+
// 安装依赖
|
|
199
|
+
console.log('📦 正在安装依赖...');
|
|
200
|
+
try {
|
|
201
|
+
execSync('npm install', { cwd: targetDir, stdio: 'inherit' });
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.log('⚠️ 自动安装依赖失败,请手动运行:');
|
|
204
|
+
console.log(` cd ${targetDir} && npm install`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
console.log(`✅ 示例 "${name}" 生成成功!`);
|
|
208
|
+
console.log('');
|
|
209
|
+
console.log('🚀 下一步:');
|
|
210
|
+
console.log(` cd ${name}`);
|
|
211
|
+
console.log(' npm run dev # 启动开发服务器');
|
|
212
|
+
console.log(' npm run build # 构建插件');
|
|
213
|
+
console.log('');
|
|
214
|
+
console.log('📖 查看详细说明:');
|
|
215
|
+
console.log(` ${join(targetDir, 'README.md')}`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 复制目录递归函数
|
|
219
|
+
async function copyDirectory(source: string, target: string): Promise<void> {
|
|
220
|
+
mkdirSync(target, { recursive: true });
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
const items = readdirSync(source, { withFileTypes: true });
|
|
224
|
+
|
|
225
|
+
for (const item of items) {
|
|
226
|
+
const sourcePath = join(source, item.name);
|
|
227
|
+
const targetPath = join(target, item.name);
|
|
228
|
+
|
|
229
|
+
if (item.isDirectory()) {
|
|
230
|
+
await copyDirectory(sourcePath, targetPath);
|
|
231
|
+
} else {
|
|
232
|
+
// 过滤掉不需要的文件
|
|
233
|
+
if (!['.DS_Store', 'Thumbs.db'].includes(item.name)) {
|
|
234
|
+
copyFileSync(sourcePath, targetPath);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
} catch (error) {
|
|
239
|
+
throw new Error(`复制目录失败: ${error.message}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 设置CLI命令
|
|
244
|
+
program
|
|
245
|
+
.name('@linyjs/plugin-docs')
|
|
246
|
+
.description('linyjs 插件文档和示例CLI工具')
|
|
247
|
+
.version('0.1.0');
|
|
248
|
+
|
|
249
|
+
// docs 命令
|
|
250
|
+
program
|
|
251
|
+
.command('docs')
|
|
252
|
+
.description('访问插件开发文档')
|
|
253
|
+
.option('--open', '在浏览器中打开在线文档')
|
|
254
|
+
.option('--list', '列出所有文档分类')
|
|
255
|
+
.argument('[keyword]', '搜索关键词')
|
|
256
|
+
.action((keyword, options) => {
|
|
257
|
+
if (options.open) {
|
|
258
|
+
console.log('🌐 正在打开在线文档...');
|
|
259
|
+
const docsUrl = 'https://github.com/linyjs/linyjs/tree/main/packages/plugin-docs/docs';
|
|
260
|
+
openUrl(docsUrl);
|
|
261
|
+
} else if (keyword) {
|
|
262
|
+
searchDocs(keyword);
|
|
263
|
+
} else {
|
|
264
|
+
displayDocsList();
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// example 命令
|
|
269
|
+
program
|
|
270
|
+
.command('example <name>')
|
|
271
|
+
.description('生成示例项目')
|
|
272
|
+
.option('-o, --output <directory>', '指定输出目录')
|
|
273
|
+
.action(async (name, options) => {
|
|
274
|
+
try {
|
|
275
|
+
await generateExample(name, options.output);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error('❌ 生成示例失败:', error.message);
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// list-examples 命令
|
|
283
|
+
program
|
|
284
|
+
.command('list-examples')
|
|
285
|
+
.description('列出所有可用示例')
|
|
286
|
+
.action(() => {
|
|
287
|
+
listExamples();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// 显示帮助信息
|
|
291
|
+
program
|
|
292
|
+
.command('help')
|
|
293
|
+
.description('显示详细帮助信息')
|
|
294
|
+
.action(() => {
|
|
295
|
+
console.log('\n📖 @linyjs/plugin-docs CLI 工具\n');
|
|
296
|
+
console.log('使用方法:');
|
|
297
|
+
console.log(' npx @linyjs/plugin-docs <command> [options]\n');
|
|
298
|
+
console.log('命令:');
|
|
299
|
+
console.log(' docs [keyword] 显示文档列表或搜索文档');
|
|
300
|
+
console.log(' docs --open 在浏览器中打开在线文档');
|
|
301
|
+
console.log(' example <name> 生成指定示例项目');
|
|
302
|
+
console.log(' example <name> -o <dir> 生成示例到指定目录');
|
|
303
|
+
console.log(' list-examples 列出所有可用示例');
|
|
304
|
+
console.log(' help 显示详细帮助\n');
|
|
305
|
+
console.log('示例:');
|
|
306
|
+
console.log(' npx @linyjs/plugin-docs docs');
|
|
307
|
+
console.log(' npx @linyjs/plugin-docs docs --open');
|
|
308
|
+
console.log(' npx @linyjs/plugin-docs docs "权限管理"');
|
|
309
|
+
console.log(' npx @linyjs/plugin-docs example hello-world');
|
|
310
|
+
console.log(' npx @linyjs/plugin-docs example blog-plugin -o ./my-blog');
|
|
311
|
+
console.log(' npx @linyjs/plugin-docs list-examples\n');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
// 如果没有提供命令,显示主帮助
|
|
315
|
+
if (process.argv.length === 2) {
|
|
316
|
+
program.outputHelp();
|
|
317
|
+
console.log('');
|
|
318
|
+
console.log('💡 获取更多信息: npx @linyjs/plugin-docs help');
|
|
319
|
+
} else {
|
|
320
|
+
program.parse();
|
|
321
|
+
}
|