Skip to content

Commit

Permalink
feat: 隐藏依赖视图优化&添加代码预览&全局样式优化
Browse files Browse the repository at this point in the history
  • Loading branch information
chennlang committed Jan 31, 2024
1 parent ffa6af8 commit 36d248c
Show file tree
Hide file tree
Showing 49 changed files with 9,929 additions and 3,355 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll.eslint": false
"source.fixAll": "never",
"source.fixAll.eslint": "never"
}
}
8 changes: 7 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
"version": "independent",
"npmClient": "pnpm",
"useWorkspaces": true,
"packages": [
"packages/core",
"packages/server",
"packages/shared",
"packages/web"
],
"command": {
"publish": {
"ignoreChanges": [".gitignore", "*.md", ".log", "public"],
"message": "chore(release): publish",
"registry": "https://npm.pkg.github.com"
"registry": "https://registry.npmjs.org/"
}
}
}
Empty file added nx.json
Empty file.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"name": "root",
"author": "Alang",
"private": true,
"workspaces": ["packages/*"],
"workspaces": [
"packages/core",
"packages/server",
"packages/web",
"packages/shared"
],
"scripts": {
"dev": "lerna run --scope '@js-analyzer/core' --scope @js-analyzer/server dev"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@js-analyzer/core",
"version": "1.0.11",
"version": "1.0.12",
"main": "dist/js-analyzer-core.cjs.js",
"types": "dist/js-analyzer-core.d.ts",
"author": "chennlang",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function injectFileDeps(
source: source,
vars: vars,
fullPath: file,
loc: {}
loc,
})
} else {
unknownQuote[depName] = {
Expand All @@ -281,7 +281,7 @@ function injectFileDeps(
source: source,
vars: vars,
fullPath: file,
loc: {}
loc,
}]
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/server/.yarnrc

This file was deleted.

34 changes: 18 additions & 16 deletions packages/server/config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

module.exports = {
root: '/Users/ll/Desktop/work/deepexi/dxp-cdp-data-ui',
extensions: ['.js', '.ts','.tsx','.vue', '.json', '.jsx'],
ignore: ['**/node_modules/**', '**/dist/**', '**/static/**'],
server: {
port: 8088,
},
alias: {
'@@/': '/',
'~~/': '/',
'@/': '/examples/',
'~/': '/examples/',
'@p/': '/packages/',
},
plugins: []
}
// root: "/Users/ll/Desktop/work/deepexi/fastdataforflink_frontend",
root: "/Users/ll/Desktop/work/deepexi/dxp-cdp-data-ui",
// root: '/Users/ll/Desktop/work/deepexi/dxp-cdp-data-ui/packages/page-components/scene-module/daw-scene-detail.vue',
extensions: [".js", ".ts", ".tsx", ".vue", ".json", ".jsx"],
ignore: ["**/node_modules/**", "**/dist/**", "**/static/**"],
server: {
port: 8088,
},
alias: {
"@@/": "/",
"~~/": "/",
"@/": "/examples/",
"~/": "/examples/",
"@p/": "/packages/",
"~@p/": "/packages/",
},
plugins: [],
};
7 changes: 4 additions & 3 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@js-analyzer/server",
"version": "1.0.26",
"version": "2.0.12",
"main": "src/index.js",
"author": "chennlang",
"description": "一个可视化可交互的 Web 文件依赖分析工具",
Expand All @@ -15,7 +15,7 @@
"dev": "node ./bin/service.js --config ./config.js",
"rm": "rm -rf ./pubblic/data/",
"login": "npm login --registry=https://registry.npmjs.org/",
"publish": "npm publish --registry=https://registry.npmjs.org/ --tag beta"
"publish": "npm publish --registry=https://registry.npmjs.org/"
},
"bugs": {
"url": "https://github.com/chennlang/js-analyzer/issues"
Expand Down Expand Up @@ -45,6 +45,7 @@
"koa-static": "^5.0.0",
"koa2-cors": "^2.0.6",
"launch-editor": "^2.3.0",
"open": "^8.4.0"
"open": "^8.4.0",
"portfinder": "^1.0.32"
}
}
152 changes: 83 additions & 69 deletions packages/server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,111 @@
const path = require('path')
const Koa = require('koa')
const router = require("koa-router")()
const koaStatic = require("koa-static")
const cors = require('koa2-cors')
const { koaBody } = require('koa-body')
const launch = require('launch-editor')
const open = require('open')
const template = require('art-template')
const fs = require('fs')
const { JsAnalyzer } = require('@js-analyzer/core')
// const { Analy } = require('../../core/dist/js-analyzer-core.cjs')
const fs = require("fs");
const path = require("path");
const Koa = require("koa");
const router = require("koa-router")();
const open = require("open");
const koaStatic = require("koa-static");
const cors = require("koa2-cors");
const launch = require("launch-editor");
const template = require("art-template");
const portfinder = require("portfinder");
const { koaBody } = require("koa-body");
const { JsAnalyzer } = require("@js-analyzer/core");

const app = new Koa();
app.use(cors())
app.use(koaBody())
app.use(koaStatic(
path.join( __dirname, '../public/')
));
app.use(cors());
app.use(koaBody());
app.use(koaStatic(path.join(__dirname, "../public/")));

// index.html
router.get("/", async ctx => {
ctx.set('Content-Type', 'text/html;charset=UTF-8')
const content = template(path.resolve(__dirname, '../public/index.html'), {
TITLE: 'JsAnalyzer | 依赖分析工具',
router.get("/", async (ctx) => {
ctx.set("Content-Type", "text/html;charset=UTF-8");
const content = template(path.resolve(__dirname, "../public/index.html"), {
TITLE: "JsAnalyzer | 依赖分析工具",
ROOT: ctx.config.root,
})
ctx.body = content
});
ctx.body = content;
});

router.get('/config', ctx => {
ctx.body = ctx.config
})
router.get("/config", (ctx) => {
ctx.body = ctx.config;
});

router.put('/config', async ctx => {
router.put("/config", async (ctx) => {
if (!ctx.request.body) {
ctx.status = 500
ctx.body = 'config error or null'
return
ctx.status = 500;
ctx.body = "config error or null";
return;
}

app.context.config = ctx.request.body
const instance = new JsAnalyzer(ctx.request.body)
await instance.init().then(() => {
ctx.body = 'ok'
}).catch(error => {
console.log(error)
ctx.status = 500
ctx.body = error.toString()
})
})
app.context.config = ctx.request.body;
const instance = new JsAnalyzer(ctx.request.body);
await instance
.init()
.then(() => {
ctx.body = "ok";
})
.catch((error) => {
console.log(error);
ctx.status = 500;
ctx.body = error.toString();
});
});

// open file in editor
router.get("/launch", async ctx => {
const file = ctx.query.file
launch(file, 'code', (name, error) => {
ctx.body = error
})
ctx.body = 'ok'
router.get("/launch", async (ctx) => {
const file = ctx.query.file;
launch(file, "code", (name, error) => {
ctx.body = error;
});
ctx.body = "ok";
});

router.get("/code", async ctx => {
ctx.set('Content-Type', 'text/text;charset=UTF-8')
const file = ctx.query.file
router.get("/code", async (ctx) => {
ctx.set("Content-Type", "text/text;charset=UTF-8");
const file = ctx.query.file;
try {
const data = fs.readFileSync(file, 'utf-8')
ctx.body = data
const data = fs.readFileSync(file, "utf-8");
ctx.body = data;
} catch (error) {
ctx.body = error
ctx.body = error;
}
});

app.use(router.routes()).use(router.allowedMethods());

function startServer (config) {
const serverOpts = config.server = Object.assign({
function startListen(config) {
portfinder.setBasePort(config.server.port);
portfinder.getPort({ port: 8000, stopPort: 9000 }, function (err, port) {
if (err) {
console.log(err);
} else {
app.listen(port);
const url = `http://${config.server.host}:${port}`;
config.server.openBrowser && open(url);
console.log("\033[32m Service started: \033[0m" + url);
}
});
}

function startServer(c) {
const config = {
...c,
server: {
port: 8666,
host: 'localhost',
host: "localhost",
openBrowser: true,
}, config.server || {})

app.context.config = config

const instance = new JsAnalyzer(config)
...(c.server || {}),
},
};

instance.init().then(() => {
app.listen(serverOpts.port, () => {
const url = `http://${serverOpts.host}:${serverOpts.port}`
serverOpts.openBrowser && open(url)
console.log('\033[32m Service started: \033[0m' + url)
})
})
app.context.config = config;
const instance = new JsAnalyzer(config);
console.log("\033[32m Generating dependency information... \033[0m");
instance.init().then(() => {
startListen(config);
});
}

module.exports = {
start: startServer
}
start: startServer,
};
18 changes: 9 additions & 9 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
"serve": "vite preview"
},
"dependencies": {
"@types/jquery": "^3.5.6",
"@types/wordcloud": "^1.2.0",
"@vitejs/plugin-vue-jsx": "^1.1.8",
"autoprefixer": "^10.3.4",
"dagre-esm": "^0.8.5",
"@highlightjs/vue-plugin": "^2.1.0",
"echarts": "^5.2.0",
"ignore": "^5.1.8",
"highlight.js": "^11.9.0",
"jquery": "^3.6.0",
"less": "^4.1.1",
"mitt": "^3.0.0",
"postcss": "^8.3.6",
"tailwindcss": "^2.2.15",
"vue": "3.2.31",
"vue-json-pretty": "^2.1.0",
"vue-router": "4",
"wordcloud": "^1.2.2"
},
"devDependencies": {
"@js-analyzer/core": "*",
"@types/jquery": "^3.5.6",
"@types/wordcloud": "^1.2.0",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue-jsx": "^1.1.8",
"@vue/compiler-sfc": "^3.2.6",
"autoprefixer": "^10.3.4",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.6.0",
"less": "^4.1.1",
"postcss": "^8.3.6",
"prettier": "^2.6.2",
"tailwindcss": "^2.2.15",
"typescript": "^4.3.2",
"vite": "^4.4.2",
"vue-tsc": "^1.4.4"
Expand Down
Loading

0 comments on commit 36d248c

Please sign in to comment.