Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call function to output DBStructure in cli package #88

Merged
merged 7 commits into from
Nov 21, 2024

Conversation

hoshinotsuyoshi
Copy link
Member

@hoshinotsuyoshi hoshinotsuyoshi commented Nov 18, 2024

Summary

The $ liam erd build --input command now parses the schema.rb format. This feature builds upon changes from PR #87 and PR #89.

Related Issue

N/A

Changes

acbb208 : chore(cli): update build process and adjust input file references

  • Change build script in frontend/package.json and include build step in the CI workflow
  • Refactor CLI documentation to reflect updated command usage
  • Update CLI scripts to use input.schema.rb instead of input.sql
  • Add a temporary workaround in App.tsx to set schema content

f5d2c05 : db-structure: update package to use ESM and streamline parser generation

  • Update package.json to specify ESM settings and adjust main/types entries
  • Add generateParser.sh script to simplify Peggy parser generation
  • Refactor imports in parser.js to use ES modules instead of CommonJS
  • Update TypeScript configuration for better ESM support and output
  • Adjust dependencies to use ESM versions of libraries like lodash-es and pluralize-esm
  • Add .gitignore to exclude dist directory from version control

cefb3e4 : chore(erd-core): add ESM support by specifying "type": "module" in package.json

  • "type": "module" applied to erd-core package

Testing

Setup:

[liam]$ cd frontend
[frontend]$ pnpm i
# Scope: all 7 workspace projects
# Lockfile is up to date, resolution step is skipped
# Already up to date
# Done in 539ms

Build the CLI:

[frontend]$ cd packages/cli
[cli]$ pnpm run build && pnpm link --global

> @liam/[email protected] prebuild
> pnpm --filter @liam/db-structure run build

> @liam/[email protected] build
> tsc

> @liam/[email protected] build
> tsc -p tsconfig.node.json

Run the build and preview commands:

[cli]$ liam erd build --input fixtures/input.schema.rb
# vite v5.4.10 building for production...
# ✓ 848 modules transformed.
# dist/index.html                   0.46 kB │ gzip:   0.30 kB
# dist/assets/index-DijVQA92.css   17.44 kB │ gzip:   3.38 kB
# dist/assets/index-D5tlKNA5.js   321.97 kB │ gzip: 103.79 kB
# ✓ built in 909ms

[cli]$ liam erd preview
# Preview server is running at http://localhost:4173

Open http://localhost:4173, and you'll see the users table node, which is defined in fixtures/input.schema.rb.

Screenshot 2024-11-20 9 21 37

Other Information

N/A

@hoshinotsuyoshi hoshinotsuyoshi self-assigned this Nov 18, 2024
@hoshinotsuyoshi hoshinotsuyoshi force-pushed the feat/runpreprocess-db-structure-parse branch 5 times, most recently from 7eef20d to 74345e4 Compare November 19, 2024 10:54
- Add a `build` script to `frontend/package.json` and include build step in the CI workflow
- Update CLI scripts to use `input.schema.rb` instead of `input.sql`
- Modify smoke tests to reference the new input file format
- Simplify `runPreprocess` function to use parsed schema input
- Add a temporary workaround in `App.tsx` to set schema content
- Refactor CLI documentation to reflect updated command usage
- Update `package.json` to specify ESM settings and adjust main/types entries
- Add `generateParser.sh` script to simplify Peggy parser generation
- Refactor imports in `parser.js` to use ES modules instead of CommonJS
- Update TypeScript configuration for better ESM support and output
- Adjust dependencies to use ESM versions of libraries like `lodash-es` and `pluralize-esm`
- Add `.gitignore` to exclude `dist` directory from version control
@hoshinotsuyoshi hoshinotsuyoshi force-pushed the feat/runpreprocess-db-structure-parse branch from 759d859 to cefb3e4 Compare November 19, 2024 13:02
@hoshinotsuyoshi hoshinotsuyoshi changed the title runpreprocess-db-structure-parse Call function to output DBStructure in cli package runPreprocess.ts Nov 19, 2024
@hoshinotsuyoshi hoshinotsuyoshi changed the title Call function to output DBStructure in cli package runPreprocess.ts Call function to output DBStructure in cli package Nov 19, 2024
@hoshinotsuyoshi hoshinotsuyoshi marked this pull request as ready for review November 20, 2024 00:48
@hoshinotsuyoshi hoshinotsuyoshi requested a review from a team as a code owner November 20, 2024 00:48
@hoshinotsuyoshi hoshinotsuyoshi requested review from FunamaYukina, junkisai, MH4GF and sasamuku and removed request for a team November 20, 2024 00:49
Comment on lines 10 to 14
"dev": "pnpm run build:cli && node ./dist-cli/bin/cli.js erd dev --input ./fixtures/input.sql",
"build": "pnpm run build:cli && node ./dist-cli/bin/cli.js erd build --input ./fixtures/input.sql",
"preview": "pnpm run build:cli && node ./dist-cli/bin/cli.js erd preview",
"build:cli": "tsc -p tsconfig.node.json",
"command:dev": "pnpm run build && node ./dist-cli/bin/cli.js erd dev --input ./fixtures/input.schema.rb",
"command:build": "pnpm run build && node ./dist-cli/bin/cli.js erd build --input ./fixtures/input.schema.rb",
"command:preview": "pnpm run build && node ./dist-cli/bin/cli.js erd preview",
"prebuild": "pnpm --filter @liam/db-structure run build",
"build": "tsc -p tsconfig.node.json",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scripts have been updated:

  • build now refers to building the CLI.
  • command:build now runs liam erd build --input ./fixtures/input.schema.rb. This is intended for our development purposes.

Comment on lines 23 to 24
"test": "pnpm vitest"
"test": "pnpm prebuild && pnpm vitest --watch=false"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Added --watch=false to prevent the output from persisting in the terminal.
  • Calling prebuild to build the dependent packages beforehand for testing purposes.

I'm not entirely confident if this aligns perfectly with best practices for turbo or pnpm workspaces , but it seems to work well in my local environment.

Comment on lines -15 to +25
"lodash.isequal": "^4.5.0",
"lodash.sortby": "^4.7.0",
"pluralize": "^8.0.0",
"valibot": "^1.0.0-beta.5"
},
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@packages/configs": "workspace:*",
"lodash-es": "^4.17.21",
"peggy": "^4.1.1",
"pluralize-esm": "^9.0.5",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for ESM style.

Comment on lines +5 to +11
--format es \
--dependencies \
'{
"pluralize": "pluralize-esm",
"{ isEqual }": "lodash-es",
"{ sortBy }": "lodash-es"
}' \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settings for ESM style.
See --dependencies options. doc: https://peggyjs.org/documentation.html

Comment on lines -1 to +3
import schemaRbParser from './parser'
import * as parser from './parser.js'

export { schemaRbParser }
export { parser }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of change is needed across all packages, but unfortunately, it can't be verified through unit tests within each package. We might need to add a lint rule (perhaps using eslint-plugin-import?) to ensure this consistently.

Comment on lines -6 to +8
"use strict";
import pluralize from "pluralize-esm";
import { isEqual } from "lodash-es";
import { sortBy } from "lodash-es";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the effect of "gen:parser" script.

@MH4GF
Copy link
Member

MH4GF commented Nov 20, 2024

workaround

{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist", "dist-cli"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    },
    "gen": {
      "dependsOn": ["^gen"]
    },
    "lint": {
      "dependsOn": ["build", "gen", "^lint"]
    },
    "fmt": {},
    "test": {
      "outputs": []
    },
    "@liam/cli#test": {
      "dependsOn": ["^build"]
    }
  }
}

@MH4GF
Copy link
Member

MH4GF commented Nov 20, 2024

It worked in hand as well!

スクリーンショット 2024-11-20 15 33 57

Copy link
Member

@MH4GF MH4GF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

.github/workflows/frontend-ci.yml Outdated Show resolved Hide resolved
frontend/packages/cli/package.json Outdated Show resolved Hide resolved
MH4GF and others added 3 commits November 20, 2024 15:44
- Modified `.github/workflows/frontend-ci.yml` to run `pnpm lint` instead of `pnpm build && pnpm lint`
- Updated `frontend/turbo.json` to add `^build` as a dependency for the `lint` task and specified `dist` and `dist-cli` as outputs for the `build` task
@hoshinotsuyoshi hoshinotsuyoshi added this pull request to the merge queue Nov 21, 2024
Merged via the queue into main with commit 34722b4 Nov 21, 2024
8 checks passed
@hoshinotsuyoshi hoshinotsuyoshi deleted the feat/runpreprocess-db-structure-parse branch November 21, 2024 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants