-
Notifications
You must be signed in to change notification settings - Fork 1
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
new cli #79
Merged
Merged
new cli #79
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7a6aa44
$ pnpm add commander
hoshinotsuyoshi 5270bee
Update dependencies
hoshinotsuyoshi 27ba010
Add 'incremental' option to avoid TS5111 error
hoshinotsuyoshi f9c2de6
Update tsconfig files to specify output directories
hoshinotsuyoshi a6d8b88
Implement initial CLI functionality and update package configuration
hoshinotsuyoshi 2ccf588
Display file content in a <pre> tag for demo purposes in App.tsx
hoshinotsuyoshi 7bcd8d2
Update README
hoshinotsuyoshi 8ccc65a
Rename command name: `liam-cli` -> `liam`
hoshinotsuyoshi 52e18ad
Change to subcommand `liam erd`
hoshinotsuyoshi d10fbcc
Merge branch 'main' into setup-erd-generator-cli
hoshinotsuyoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
dist-cli | ||
public/schema.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,62 @@ | ||
# @liam/cli | ||
|
||
`liam-cli` is a command-line tool designed to generate a web application that displays ER diagrams. | ||
MH4GF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```bash | ||
$ liam-cli build --input {your .sql} | ||
# Outputs the web application to the ./public and ./dist directories | ||
|
||
$ liam-cli preview | ||
# Launches the web application for preview | ||
``` | ||
|
||
## Building and Installing the Standalone CLI for Development | ||
|
||
To build the CLI for development purposes, run: | ||
|
||
```bash | ||
pnpm run build:cli | ||
# The executable will be output to dist-cli/bin/cli.js. | ||
``` | ||
|
||
After building, you can invoke it locally with: | ||
|
||
```bash | ||
node ./dist-cli/bin/cli.js build --input ./fixtures/input.sql | ||
``` | ||
|
||
To make it globally accessible as `liam-cli`, use: | ||
|
||
```bash | ||
pnpm link --global | ||
``` | ||
|
||
## Explanation of npm Scripts for Development | ||
|
||
### Commands | ||
|
||
1. **Build** | ||
```bash | ||
pnpm run build | ||
``` | ||
- Internally, `./fixtures/input.sql` is passed as the `build --input` argument. | ||
- Runs Vite's build process. | ||
|
||
2. **Dev** | ||
```bash | ||
pnpm run dev | ||
``` | ||
- Internally, `./fixtures/input.sql` is passed as the `dev --input` argument. | ||
- Starts the Vite development server. | ||
|
||
3. **Preview** | ||
```bash | ||
pnpm run preview | ||
``` | ||
- Previews the production build using Vite's built-in preview functionality. | ||
|
||
## File Structure | ||
|
||
- **bin/cli.ts**: The main CLI script. | ||
- **fixtures/input.sql**: A sample `.sql` file for testing purposes. | ||
- **src/**: The web application that displays ER diagrams. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { Command } from 'commander' | ||
import { build, createServer, preview } from 'vite' | ||
|
||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
const root = path.resolve(__dirname, '../..') | ||
const publicDir = path.join(process.cwd(), 'public') | ||
const outDir = path.join(process.cwd(), 'dist') | ||
|
||
function runPreprocess(inputPath: string | null) { | ||
if (inputPath && !fs.existsSync(inputPath)) { | ||
throw new Error('Invalid input path. Please provide a valid .sql file.') | ||
} | ||
FunamaYukina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const sqlContent = inputPath ? fs.readFileSync(inputPath, 'utf8') : '{}' | ||
const filePath = path.join(publicDir, 'schema.json') | ||
|
||
if (!fs.existsSync(publicDir)) { | ||
fs.mkdirSync(publicDir, { recursive: true }) | ||
} | ||
|
||
try { | ||
const jsonContent = JSON.stringify({ sql: sqlContent }, null, 2) | ||
fs.writeFileSync(filePath, jsonContent, 'utf8') | ||
return filePath | ||
} catch (error) { | ||
console.error( | ||
`Error during preprocessing: ${error instanceof Error ? error.message : 'Unknown error'}`, | ||
) | ||
return null | ||
} | ||
} | ||
|
||
const program = new Command() | ||
|
||
program | ||
.name('liam-cli') | ||
.description('CLI for running build and dev commands') | ||
.version('0.0.0') | ||
|
||
program | ||
.command('build') | ||
.description('Run Vite build') | ||
.option('--input <path>', 'Path to the .sql file') | ||
.action(async (options) => { | ||
try { | ||
const inputPath = options.input | ||
runPreprocess(inputPath) | ||
await build({ | ||
publicDir, | ||
root, | ||
build: { | ||
outDir, | ||
emptyOutDir: false, | ||
}, | ||
}) | ||
} catch (error) { | ||
console.error('Build failed:', error) | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
program | ||
.command('dev') | ||
.description('Run Vite dev server') | ||
.option('--input <path>', 'Path to the .sql file') | ||
.action(async (options) => { | ||
try { | ||
const inputPath = options.input | ||
runPreprocess(inputPath) | ||
const server = await createServer({ publicDir, root }) | ||
const address = server.httpServer?.address() | ||
const port = typeof address === 'object' && address ? address.port : 5173 | ||
console.info(`Dev server is running at http://localhost:${port}`) | ||
await server.listen() | ||
} catch (error) { | ||
console.error('Failed to start dev server:', error) | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
program | ||
.command('preview') | ||
.description('Preview the production build') | ||
.action(async () => { | ||
try { | ||
const previewServer = await preview({ | ||
publicDir, | ||
root, | ||
build: { | ||
outDir, | ||
emptyOutDir: false, | ||
}, | ||
}) | ||
const address = previewServer.httpServer?.address() | ||
const port = typeof address === 'object' && address ? address.port : 4173 | ||
console.info(`Preview server is running at http://localhost:${port}`) | ||
} catch (error) { | ||
console.error('Failed to start preview server:', error) | ||
process.exit(1) | ||
} | ||
}) | ||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE products ( | ||
brand VARCHAR(255), | ||
model VARCHAR(255), | ||
year INT | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
import { ERDRenderer } from '@liam/erd-core' | ||
import { useEffect, useState } from 'react' | ||
|
||
function App() { | ||
return <ERDRenderer /> | ||
const [fileContent, setFileContent] = useState<string | null>(null) | ||
|
||
useEffect(() => { | ||
async function loadSchemaContent() { | ||
const response = await fetch('/schema.json') | ||
const data = (await response.json()) || 'No file content available' | ||
setFileContent(JSON.stringify(data, null, 2)) | ||
} | ||
|
||
loadSchemaContent() | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<ERDRenderer /> | ||
|
||
{/* TODO: Remove this */} | ||
{/* Display the file content in a pre tag for demo purposes */} | ||
<pre | ||
style={{ | ||
backgroundColor: '#f5f5f5', | ||
padding: '10px', | ||
borderRadius: '4px', | ||
whiteSpace: 'pre-wrap', | ||
}} | ||
> | ||
{fileContent || 'Loading...'} | ||
</pre> | ||
</> | ||
) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo", | ||
"incremental": true, | ||
"target": "ES2022", | ||
"lib": ["ES2023"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
"moduleResolution": "Bundler", | ||
"allowImportingTsExtensions": true, | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
"noEmit": false, | ||
"strict": true, | ||
"outDir": "dist-cli", | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUncheckedSideEffectImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
"include": ["vite.config.ts", "bin"] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice README! 😄