diff --git a/package.json b/package.json index 2676c4f7..51383ce5 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,5 @@ { - "name": "truth-cli", - "version": "0.5.6", - "description": "A command-line tool for analyzing dependencies under node_moudles", "type": "module", - "main": "dist/index.js", - "bin": { - "truth-cli": "dist/index.js" - }, - "files": [ - "dist" - ], "scripts": { "dev": "pnpm -F web dev", "dev:test": "vitest", @@ -21,21 +11,7 @@ "commit": "git-cz", "ci:publish": "pnpm publish -r --no-git-checks" }, - "repository": { - "type": "git", - "url": "git+https://github.com/truthRestorer/truth-cli.git" - }, - "keywords": [ - "node_moudles", - "cli", - "node" - ], - "author": "truthRestorer", "license": "MIT", - "bugs": { - "url": "https://github.com/truthRestorer/truth-cli/issues" - }, - "homepage": "https://github.com/truthRestorer/truth-cli#readme", "devDependencies": { "@antfu/eslint-config": "^0.39.8", "@changesets/cli": "^2.26.2", @@ -46,11 +22,7 @@ "@rollup/plugin-terser": "^0.4.3", "@rollup/plugin-typescript": "^11.1.2", "@truth-cli/shared": "workspace:^", - "@types/koa": "^2.13.8", - "@types/koa-static": "^4.0.2", "@types/node": "^20.4.7", - "chalk": "^5.3.0", - "commander": "^11.0.0", "commitizen": "^4.3.0", "cz-git": "^1.7.0", "eslint": "^8.45.0", diff --git a/packages/cli/LICENSE b/packages/cli/LICENSE new file mode 100644 index 00000000..7133aa6f --- /dev/null +++ b/packages/cli/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 truthRestorer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bin/index.ts b/packages/cli/bin/index.ts similarity index 85% rename from bin/index.ts rename to packages/cli/bin/index.ts index e0c5d858..b887a9ae 100644 --- a/bin/index.ts +++ b/packages/cli/bin/index.ts @@ -1,8 +1,8 @@ import { Command } from 'commander' -import { genByCommand } from 'lib' -import { cleanFiles } from 'lib/cleanFile' -import { genJSONFile } from 'lib/genFile' -import { genPkgTree } from 'lib/genFile/pkgTree' +import { genByCommand } from '../lib' +import { cleanFiles } from '../lib/cleanFile' +import { genJSONFile } from '../lib/genFile' +import { genPkgTree } from '../lib/genFile/pkgTree' import { analyzeCommandWords, bothOptionWords, @@ -13,7 +13,7 @@ import { logDepthError, logLogo, version, -} from 'lib/utils/const.js' +} from '../lib/utils/const.js' const program = new Command() program diff --git a/lib/analyze.ts b/packages/cli/lib/analyze.ts similarity index 100% rename from lib/analyze.ts rename to packages/cli/lib/analyze.ts diff --git a/lib/cleanFile.ts b/packages/cli/lib/cleanFile.ts similarity index 100% rename from lib/cleanFile.ts rename to packages/cli/lib/cleanFile.ts diff --git a/lib/genFile/__test__/genGraph.test.ts b/packages/cli/lib/genFile/__test__/genGraph.test.ts similarity index 100% rename from lib/genFile/__test__/genGraph.test.ts rename to packages/cli/lib/genFile/__test__/genGraph.test.ts diff --git a/lib/genFile/__test__/genRelations.test.ts b/packages/cli/lib/genFile/__test__/genRelations.test.ts similarity index 100% rename from lib/genFile/__test__/genRelations.test.ts rename to packages/cli/lib/genFile/__test__/genRelations.test.ts diff --git a/lib/genFile/__test__/genTree.test.ts b/packages/cli/lib/genFile/__test__/genTree.test.ts similarity index 100% rename from lib/genFile/__test__/genTree.test.ts rename to packages/cli/lib/genFile/__test__/genTree.test.ts diff --git a/lib/genFile/__test__/vControl.test.ts b/packages/cli/lib/genFile/__test__/vControl.test.ts similarity index 100% rename from lib/genFile/__test__/vControl.test.ts rename to packages/cli/lib/genFile/__test__/vControl.test.ts diff --git a/lib/genFile/graph.ts b/packages/cli/lib/genFile/graph.ts similarity index 100% rename from lib/genFile/graph.ts rename to packages/cli/lib/genFile/graph.ts diff --git a/lib/genFile/index.ts b/packages/cli/lib/genFile/index.ts similarity index 100% rename from lib/genFile/index.ts rename to packages/cli/lib/genFile/index.ts diff --git a/lib/genFile/pkgTree.ts b/packages/cli/lib/genFile/pkgTree.ts similarity index 100% rename from lib/genFile/pkgTree.ts rename to packages/cli/lib/genFile/pkgTree.ts diff --git a/lib/genFile/pkgs.ts b/packages/cli/lib/genFile/pkgs.ts similarity index 100% rename from lib/genFile/pkgs.ts rename to packages/cli/lib/genFile/pkgs.ts diff --git a/lib/genFile/relations.ts b/packages/cli/lib/genFile/relations.ts similarity index 100% rename from lib/genFile/relations.ts rename to packages/cli/lib/genFile/relations.ts diff --git a/lib/genFile/tree.ts b/packages/cli/lib/genFile/tree.ts similarity index 100% rename from lib/genFile/tree.ts rename to packages/cli/lib/genFile/tree.ts diff --git a/lib/genFile/versions.ts b/packages/cli/lib/genFile/versions.ts similarity index 100% rename from lib/genFile/versions.ts rename to packages/cli/lib/genFile/versions.ts diff --git a/lib/index.ts b/packages/cli/lib/index.ts similarity index 100% rename from lib/index.ts rename to packages/cli/lib/index.ts diff --git a/lib/utils/__test__/readDir.test.ts b/packages/cli/lib/utils/__test__/readDir.test.ts similarity index 100% rename from lib/utils/__test__/readDir.test.ts rename to packages/cli/lib/utils/__test__/readDir.test.ts diff --git a/lib/utils/__test__/readFile.test.ts b/packages/cli/lib/utils/__test__/readFile.test.ts similarity index 100% rename from lib/utils/__test__/readFile.test.ts rename to packages/cli/lib/utils/__test__/readFile.test.ts diff --git a/lib/utils/const.ts b/packages/cli/lib/utils/const.ts similarity index 100% rename from lib/utils/const.ts rename to packages/cli/lib/utils/const.ts diff --git a/lib/utils/dependency.ts b/packages/cli/lib/utils/dependency.ts similarity index 100% rename from lib/utils/dependency.ts rename to packages/cli/lib/utils/dependency.ts diff --git a/lib/utils/tools.ts b/packages/cli/lib/utils/tools.ts similarity index 100% rename from lib/utils/tools.ts rename to packages/cli/lib/utils/tools.ts diff --git a/packages/cli/package.json b/packages/cli/package.json new file mode 100644 index 00000000..7fe20955 --- /dev/null +++ b/packages/cli/package.json @@ -0,0 +1,48 @@ +{ + "name": "truth-cli", + "version": "0.5.6", + "description": "A command-line tool for analyzing dependencies under node_moudles", + "type": "module", + "main": "dist/index.js", + "bin": { + "truth-cli": "dist/index.js" + }, + "files": [ + "dist" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/truthRestorer/truth-cli.git" + }, + "keywords": [ + "node_moudles", + "cli", + "node" + ], + "author": "truthRestorer", + "license": "MIT", + "bugs": { + "url": "https://github.com/truthRestorer/truth-cli/issues" + }, + "homepage": "https://github.com/truthRestorer/truth-cli#readme", + "devDependencies": { + "chalk": "^5.3.0", + "commander": "^11.0.0", + "local-pkg": "^0.4.3" + }, + "config": { + "commitizen": { + "path": "node_modules/cz-git", + "useEmoji": true + } + }, + "engines": { + "node": ">=14", + "pnpm": ">=6" + }, + "lint-staged": { + "*.{js,ts,vue}": [ + "eslint" + ] + } +} diff --git a/packages/docs/EN.md b/packages/docs/EN.md deleted file mode 100644 index 3387956f..00000000 --- a/packages/docs/EN.md +++ /dev/null @@ -1,102 +0,0 @@ -# Truth-cli🤩 - -> A command-line tool for analyzing dependencies under node_moudles. - -# feature - -- Simple API -- Visualization -- Friendly error message prompt - -# installing - -**Using npm:** - -```bash -npm install -g truth-cli -``` - -# usage - -**Start Web and Generate file:** - -```bash -truth-cli analyze -``` - -*The Content of web inluces:* - -- Tree -- Force Layout - -By default, you will see `pkgs.json` in the root of your project. - -Due to management style of npm's dependency , we have set the depth to 3 for the web and 2 for the `pkgs.json` by default, you can use `--dep` of `-d` to change it: - -```bash -truth-cli analyze -d 4 -``` - -We do not recommend setting the depth too large, if the `dep` is over 5, we will stop the operation, If you still want to continue, add `--force` or `-f`: - -> `dep` will influence the `pkgs.json` and `Tree` - -```bash -truth-cli analyze -d 7 -f -``` - -> **This will take a lot of time, and the file size can be very large(130 mb for truth-cli when the dep is 6), so please just not do this** - -**Only Generate file:** - -Use `--json` or `-j` option: - -```bash -truth-cli analyze --json [file-path] -``` - -By default, the `file-path` is `./`, which is the root of your project. - -You can use `--dep` or `-d` option: - -```bash -truth-cli analyze --json [file-path] --dep [depth] -``` - -**only start website:** - -Use `--web` or `-w` option: - -```bash -truth-cli analyze --web -``` - -**clean generate file:** - -> Truth-cli will generate files in npm's global file path, the files will very large if you set `dep` over 4 or 5. - -If you want to delete them, use `truth-cli clean`: - -```bash -truth-cli clean -``` - -**Get usage:** - -```bash -truth-cli -h -``` - -More command's help: - -**analyze:** - -```bash -truth-cli analyze -h -``` - -**clean:** - -```bash -truth-cli clean -h -``` \ No newline at end of file diff --git a/packages/docs/ZH.md b/packages/docs/ZH.md deleted file mode 100644 index 0f650d9b..00000000 --- a/packages/docs/ZH.md +++ /dev/null @@ -1,109 +0,0 @@ -# Truth-cli🤩 - -> 一个用于分析 npm 包结构的 cli 工具。 - -# 特点 - -- 使用简单 -- 可视化展示 -- 友好的提示 - -**关于构建速度:** - -由于 `turth-cli` 采用了生成文件的方式,加上 npm 包嵌套关系非常深,如果设置了太大的 `depth`,会导致构建速度变慢,生成的文件也会占用很大的硬盘空间,因此我们推荐将 `depth` 设置在 `<= 4` 的范围内,默认情况下,`tree` 图深度为 3, `pkgs.json` 文件深度为 2(速度控制在 `325ms` 左右)。 - -**另外需要注意的是,`depth` 设置太大对阅读也会产生很大影响,所以我们不建议设置太大的 `depth`。** - -**同时,`truth-cli` 采用深度优先遍历算法,在遍历过程中会记住各个根节点,便于后续的“剪枝”,即使设置了很大的 `depth`,对网页端 `tree` 图的影响也不大。** - -# 安装 - -```bash -npm install -g truth-cli -``` - -# 使用教程 - -**简单示例:** - -此命令默认只打开网页效果: - -```bash -truth-cli analyze -``` - -**网页的内容包括:** - -- tree 图:用树型结构展示 npm 依赖之间的关系,受参数 `dep` 影响 -- force 图:用引力布局的图结构展示 npm 依赖之间的关系,不受参数 `dep` 影响 - -## 指定深度 - -> 我们并不建议更改深度,如果有需要,请设置在 `<= 4` 范围内。 - -使用 `--dep` 或者 `-d` 参数: - -```bash -truth-cli analyze --dep 4 -``` - -> 需要额外注意的是,tree 图从根节点到尾节点,依次为 *"项目名(`packages.json 中 name 指定,没有默认为 __root__`)"* -> *"项目依赖"* -> *"项目依赖引用的依赖"*,而**深度指的是项目依赖引用的依赖的层数** - -如果设置了太大的深度,会报错,这时使用 `--force` 或者 `-f` 参数继续: - -```bash -truth-cli analyze --dep 8 --force -``` - -## 只生成文件 - -**使用 `--json` 或者 `-j` 参数:** - -```bash -truth-cli analyze --json -``` - -默认情况下,会在根目录下生成 `pkgs.json` 文件,如果需要更改生成目录,可以在参数之后加上路径 - -```bash -truth-cli analyze --json dist/ -``` - -> **注意:请不要在路径开头加上 `/`,这会被 nodejs 识别为根路径,导致生成失败** - -**结合 `dep` 参数:** - -```bash -truth-cli analyze --json --dep 3 -``` - -## 生成文件并打开页面 - -使用 `--both` 或者 `-b` 参数: - -```bash -truth-cli analyze --both -``` - -`--both` 参数的优先级是比 `--json` 大的,也就是说两者同时使用,优先考虑 `--both`,例如以下会生成文件并打开网页: - -```bash -truth-cli analyze --both --json -``` - -**也可以指定 dep 参数** - -```bash -truth-cli analyze --both --dep 4 -``` - -> **dep 参数在 tree 图和 `pkgs.json` 文件共享**,两者之间的关系为: -> **tree 深度 = dep = `pkgs.json` 深度 + 1*,也就是说 tree 比 `pkgs.json` 深度大 1。 - -## 清理缓存 - -前文提到过,`truth-cli` 生成文件达到分析目的,但是有时候生成的文件太大会影响到硬盘空间,此时可以使用 `clean` 命令进行删除: - -```bash -truth-cli clean -``` \ No newline at end of file diff --git a/packages/shared/LICENSE b/packages/shared/LICENSE new file mode 100644 index 00000000..7133aa6f --- /dev/null +++ b/packages/shared/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 truthRestorer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/web/.eslintrc.cjs b/packages/web/.eslintrc.cjs deleted file mode 100644 index 060b9dd1..00000000 --- a/packages/web/.eslintrc.cjs +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - extends: '@antfu', -} diff --git a/packages/web/LICENSE b/packages/web/LICENSE new file mode 100644 index 00000000..7133aa6f --- /dev/null +++ b/packages/web/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 truthRestorer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/web/tsconfig.json b/packages/web/tsconfig.json deleted file mode 100644 index da1cbb8c..00000000 --- a/packages/web/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "useDefineForClassFields": true, - "module": "ESNext", - "lib": ["ES2020", "DOM", "DOM.Iterable"], - "skipLibCheck": true, - - /* Bundler mode */ - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "preserve", - - /* Linting */ - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true - }, - "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/vite-env.d.ts"], - "references": [{ "path": "./tsconfig.node.json" }] -} diff --git a/scripts/build.ts b/scripts/build.ts index 2f41a083..1b203cab 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -7,13 +7,12 @@ import commonjs from '@rollup/plugin-commonjs' import terser from '@rollup/plugin-terser' import { nodeResolve } from '@rollup/plugin-node-resolve' import { rollup } from 'rollup' -import { logBuildFinished } from '../lib/utils/const.js' const __dirname = fileURLToPath(new URL('.', import.meta.url)) async function buildCli() { const inputOptions = { - input: ['bin/index.ts'], + input: path.resolve(__dirname, '../packages/cli/bin/index.ts'), plugins: [ nodeResolve({ preferBuiltins: true, @@ -27,7 +26,7 @@ async function buildCli() { ], } const outputOptions = { - dir: 'dist', + dir: path.resolve(__dirname, '../packages/cli/dist'), format: 'es' as ModuleFormat, banner: '#! /usr/bin/env node', } @@ -40,7 +39,7 @@ async function buildWeb() { root: path.resolve(__dirname, '../packages/web'), base: './', build: { - outDir: path.resolve(__dirname, '../dist'), + outDir: path.resolve(__dirname, '../packages/cli/dist'), copyPublicDir: false, emptyOutDir: true, }, @@ -48,11 +47,8 @@ async function buildWeb() { } async function resolveBuild() { - const begin = Date.now() await buildWeb() await buildCli() - const end = Date.now() - logBuildFinished(end - begin) } resolveBuild() diff --git a/scripts/dev-cli.ts b/scripts/dev-cli.ts index 5685f527..53245bb8 100644 --- a/scripts/dev-cli.ts +++ b/scripts/dev-cli.ts @@ -1,6 +1,3 @@ -import { logLogo } from '../lib/utils/const.js' -import { genByCommand } from '../lib/index.js' - -logLogo() +import { genByCommand } from 'packages/cli/lib/index' genByCommand(3, true, true) diff --git a/tsconfig.json b/tsconfig.json index c80bdf3a..9dd4fdaf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,6 @@ { "compilerOptions": { "baseUrl": ".", - "outDir": "dist", "sourceMap": false, "target": "ES2020", "newLine": "crlf", @@ -27,8 +26,5 @@ "include": [ "packages/**/*.ts", "scripts/*.ts", - "bin/*.ts", - "lib/**/*.ts", - "packages/shared/index.ts" ] }