Skip to content

Commit

Permalink
build: 📦️ 完善cli的dev脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
Plumbiu committed Aug 12, 2023
1 parent d81ac7e commit 77b0351
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 17 deletions.
4 changes: 2 additions & 2 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"watch": [
"packages/cli/**",
"packages/core/**"
"packages/cli/",
"packages/core/"
],
"ext": "ts,json",
"ignore": [
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"scripts": {
"dev:test": "vitest",
"dev:cli": "pnpm build && nodemon",
"dev:cli": "nodemon",
"dev:web": "pnpm -F web dev",
"build": "ts-node scripts/build.ts",
"build:cli": "ts-node scripts/build.ts --cli",
Expand Down Expand Up @@ -33,6 +33,7 @@
"commitizen": "^4.3.0",
"cz-git": "^1.7.0",
"eslint": "^8.45.0",
"fs-extra": "^11.1.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.3",
"minimist": "^1.2.8",
Expand Down
13 changes: 6 additions & 7 deletions packages/cli/src/genFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { devDistPath, distPath, logFileWirteError, logFileWirteFinished } from '
/**
* 生成网页所需要的数据(tree 图和 graph 图)
*/
async function genData(treeDep: number) {
function genData(treeDep: number) {
// relaitons 是一切 json 数据生成的基础,所以应该放在最前面
const relations = await genRelations()
const relations = genRelations()
const graph = genGraph()
const tree = genTree(treeDep)
const versions = genVersions()
Expand All @@ -26,7 +26,7 @@ async function genData(treeDep: number) {
export async function genWebFile(options: IOptions) {
const begin = Date.now()
const { dep, isBoth, isDev } = options
const { relations, graph, tree, versions } = await genData(dep)
const { relations, graph, tree, versions } = genData(dep)
const writePath = isDev ? devDistPath : distPath
await writeFile(`${writePath}/relations.json`, JSON.stringify(relations))
await writeFile(`${writePath}/graph.json`, JSON.stringify(graph))
Expand All @@ -35,7 +35,7 @@ export async function genWebFile(options: IOptions) {
if (isBoth) {
const pkgs = genPkgs(dep)
await writeFile('./pkgs.json', JSON.stringify(pkgs))
logFileWirteFinished(Date.now() - begin, './')
isDev || logFileWirteFinished(Date.now() - begin, './')
}
}

Expand All @@ -47,11 +47,10 @@ export async function genJSONFile(pkgDep: number, p?: string | boolean) {
if (!p || typeof p === 'boolean')
p = './'
try {
await genRelations()
genRelations()
const pkgs = genPkgs(pkgDep)
await writeFile(path.resolve(p, './pkgs.json'), JSON.stringify(pkgs))
const end = Date.now()
logFileWirteFinished(end - begin, p)
logFileWirteFinished(Date.now() - begin, p)
}
catch (err: any) {
logFileWirteError(err.message)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const server = function (webPath: string) {
* 启动服务器
*/
function startWeb(begin: number, isDev?: boolean) {
logWebStart(Date.now() - begin)
isDev || logWebStart(Date.now() - begin)
const webStartPath = isDev ? devDistPath : distPath
server(webStartPath).listen(3002)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ export function logBuildFinished(duration: number) {
}

export const distPath = resolve(__dirname, './')
export const devDistPath = resolve(__dirname, '../../cli/dist/')
export const devDistPath = resolve(__dirname, '../../web/public/')
2 changes: 1 addition & 1 deletion packages/web/public/graph.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"nodes":[{"name":"@antfu/eslint-config","category":1,"value":"^0.39.8"},{"name":"@changesets/cli","category":1,"value":"^2.26.2"},{"name":"@commitlint/cli","category":1,"value":"^17.6.7"},{"name":"@commitlint/config-conventional","category":1,"value":"^17.6.7"},{"name":"@rollup/plugin-commonjs","category":1,"value":"^25.0.3"},{"name":"@rollup/plugin-node-resolve","category":1,"value":"^15.1.0"},{"name":"@rollup/plugin-terser","category":1,"value":"^0.4.3"},{"name":"@rollup/plugin-typescript","category":1,"value":"^11.1.2"},{"name":"@truth-cli/shared","category":1,"value":"workspace:^"},{"name":"@types/minimist","category":1,"value":"^1.2.2"},{"name":"@types/node","category":1,"value":"^20.4.7"},{"name":"commitizen","category":1,"value":"^4.3.0"},{"name":"cz-git","category":1,"value":"^1.7.0"},{"name":"eslint","category":1,"value":"^8.45.0"},{"name":"husky","category":1,"value":"^8.0.3"},{"name":"lint-staged","category":1,"value":"^13.2.3"},{"name":"minimist","category":1,"value":"^1.2.8"},{"name":"prettier","category":1,"value":"^3.0.1"},{"name":"rollup","category":1,"value":"^3.26.3"},{"name":"ts-node","category":1,"value":"^10.9.1"},{"name":"typescript","category":1,"value":"^5.1.6"},{"name":"vite","category":1,"value":"^4.4.5"},{"name":"vitest","category":1,"value":"^0.34.1"},{"name":"_root_","category":2,"value":"1.0.0"}],"links":[{"source":"@antfu/eslint-config","target":"_root_","v":"^0.39.8"},{"source":"@changesets/cli","target":"_root_","v":"^2.26.2"},{"source":"@commitlint/cli","target":"_root_","v":"^17.6.7"},{"source":"@commitlint/config-conventional","target":"_root_","v":"^17.6.7"},{"source":"@rollup/plugin-commonjs","target":"_root_","v":"^25.0.3"},{"source":"@rollup/plugin-node-resolve","target":"_root_","v":"^15.1.0"},{"source":"@rollup/plugin-terser","target":"_root_","v":"^0.4.3"},{"source":"@rollup/plugin-typescript","target":"_root_","v":"^11.1.2"},{"source":"@truth-cli/shared","target":"_root_","v":"workspace:^"},{"source":"@types/minimist","target":"_root_","v":"^1.2.2"},{"source":"@types/node","target":"_root_","v":"^20.4.7"},{"source":"commitizen","target":"_root_","v":"^4.3.0"},{"source":"cz-git","target":"_root_","v":"^1.7.0"},{"source":"eslint","target":"_root_","v":"^8.45.0"},{"source":"husky","target":"_root_","v":"^8.0.3"},{"source":"lint-staged","target":"_root_","v":"^13.2.3"},{"source":"minimist","target":"_root_","v":"^1.2.8"},{"source":"prettier","target":"_root_","v":"^3.0.1"},{"source":"rollup","target":"_root_","v":"^3.26.3"},{"source":"ts-node","target":"_root_","v":"^10.9.1"},{"source":"typescript","target":"_root_","v":"^5.1.6"},{"source":"vite","target":"_root_","v":"^4.4.5"},{"source":"vitest","target":"_root_","v":"^0.34.1"}]}
{"nodes":[{"name":"@antfu/eslint-config","category":1,"value":"^0.39.8"},{"name":"@changesets/cli","category":1,"value":"^2.26.2"},{"name":"@commitlint/cli","category":1,"value":"^17.6.7"},{"name":"@commitlint/config-conventional","category":1,"value":"^17.6.7"},{"name":"@rollup/plugin-commonjs","category":1,"value":"^25.0.3"},{"name":"@rollup/plugin-node-resolve","category":1,"value":"^15.1.0"},{"name":"@rollup/plugin-terser","category":1,"value":"^0.4.3"},{"name":"@rollup/plugin-typescript","category":1,"value":"^11.1.2"},{"name":"@truth-cli/core","category":1,"value":"workspace:^"},{"name":"@truth-cli/shared","category":1,"value":"workspace:^"},{"name":"@types/minimist","category":1,"value":"^1.2.2"},{"name":"@types/node","category":1,"value":"^20.4.7"},{"name":"commitizen","category":1,"value":"^4.3.0"},{"name":"cz-git","category":1,"value":"^1.7.0"},{"name":"eslint","category":1,"value":"^8.45.0"},{"name":"fs-extra","category":1,"value":"^11.1.1"},{"name":"husky","category":1,"value":"^8.0.3"},{"name":"lint-staged","category":1,"value":"^13.2.3"},{"name":"minimist","category":1,"value":"^1.2.8"},{"name":"prettier","category":1,"value":"^3.0.1"},{"name":"rollup","category":1,"value":"^3.26.3"},{"name":"ts-node","category":1,"value":"^10.9.1"},{"name":"typescript","category":1,"value":"^5.1.6"},{"name":"vite","category":1,"value":"^4.4.5"},{"name":"vitepress","category":1,"value":"1.0.0-rc.4"},{"name":"vitest","category":1,"value":"^0.34.1"},{"name":"_root_","category":2,"value":"1.0.0"}],"links":[{"source":"@antfu/eslint-config","target":"_root_","v":"^0.39.8"},{"source":"@changesets/cli","target":"_root_","v":"^2.26.2"},{"source":"@commitlint/cli","target":"_root_","v":"^17.6.7"},{"source":"@commitlint/config-conventional","target":"_root_","v":"^17.6.7"},{"source":"@rollup/plugin-commonjs","target":"_root_","v":"^25.0.3"},{"source":"@rollup/plugin-node-resolve","target":"_root_","v":"^15.1.0"},{"source":"@rollup/plugin-terser","target":"_root_","v":"^0.4.3"},{"source":"@rollup/plugin-typescript","target":"_root_","v":"^11.1.2"},{"source":"@truth-cli/core","target":"_root_","v":"workspace:^"},{"source":"@truth-cli/shared","target":"_root_","v":"workspace:^"},{"source":"@types/minimist","target":"_root_","v":"^1.2.2"},{"source":"@types/node","target":"_root_","v":"^20.4.7"},{"source":"commitizen","target":"_root_","v":"^4.3.0"},{"source":"cz-git","target":"_root_","v":"^1.7.0"},{"source":"eslint","target":"_root_","v":"^8.45.0"},{"source":"fs-extra","target":"_root_","v":"^11.1.1"},{"source":"husky","target":"_root_","v":"^8.0.3"},{"source":"lint-staged","target":"_root_","v":"^13.2.3"},{"source":"minimist","target":"_root_","v":"^1.2.8"},{"source":"prettier","target":"_root_","v":"^3.0.1"},{"source":"rollup","target":"_root_","v":"^3.26.3"},{"source":"ts-node","target":"_root_","v":"^10.9.1"},{"source":"typescript","target":"_root_","v":"^5.1.6"},{"source":"vite","target":"_root_","v":"^4.4.5"},{"source":"vitepress","target":"_root_","v":"1.0.0-rc.4"},{"source":"vitest","target":"_root_","v":"^0.34.1"}]}
2 changes: 1 addition & 1 deletion packages/web/public/relations.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/web/public/tree.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/web/public/versions.json

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion scripts/dev-cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import { createServer } from 'vite'
import { genByCommand } from '../packages/cli/src/index.js'

genByCommand({ dep: 3, isDev: true, isBoth: true })
const __dirname = fileURLToPath(new URL('.', import.meta.url))

async function createCliServer() {
await genByCommand({ dep: 3, isDev: true, isBoth: true })
const server = await createServer({
// 任何合法的用户配置选项,加上 `mode` 和 `configFile`
configFile: path.resolve(__dirname, '../packages/web/vite.config.ts'),
root: path.resolve(__dirname, '../packages/web'),
server: {
port: 1337,
},
})
await server.listen()

server.printUrls()
}

createCliServer()

0 comments on commit 77b0351

Please sign in to comment.