-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit - converting test command into package
- Loading branch information
0 parents
commit b6224f6
Showing
26 changed files
with
605 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# http://editorconfig.org | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.json] | ||
insert_final_newline = ignore | ||
|
||
[**.min.js] | ||
indent_style = ignore | ||
insert_final_newline = ignore | ||
|
||
[MakeFile] | ||
indent_style = space | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,26 @@ | ||
--- | ||
ignoreUnless: {{ STALE_BOT }} | ||
--- | ||
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app | ||
|
||
# Number of days of inactivity before a closed issue or pull request is locked | ||
daysUntilLock: 60 | ||
|
||
# Skip issues and pull requests created before a given timestamp. Timestamp must | ||
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable | ||
skipCreatedBefore: false | ||
|
||
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable | ||
exemptLabels: ['Type: Security'] | ||
|
||
# Label to add before locking, such as `outdated`. Set to `false` to disable | ||
lockLabel: false | ||
|
||
# Comment to post before locking. Set to `false` to disable | ||
lockComment: > | ||
This thread has been automatically locked since there has not been | ||
any recent activity after it was closed. Please open a new issue for | ||
related bugs. | ||
# Assign `resolved` as the reason for locking. Set to `false` to disable | ||
setLockReason: false |
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,24 @@ | ||
--- | ||
ignoreUnless: {{ STALE_BOT }} | ||
--- | ||
# Number of days of inactivity before an issue becomes stale | ||
daysUntilStale: 60 | ||
|
||
# Number of days of inactivity before a stale issue is closed | ||
daysUntilClose: 7 | ||
|
||
# Issues with these labels will never be considered stale | ||
exemptLabels: | ||
- 'Type: Security' | ||
|
||
# Label to use when marking an issue as stale | ||
staleLabel: 'Status: Abandoned' | ||
|
||
# Comment to post when marking an issue as stale. Set to `false` to disable | ||
markComment: > | ||
This issue has been automatically marked as stale because it has not had | ||
recent activity. It will be closed if no further activity occurs. Thank you | ||
for your contributions. | ||
# Comment to post when closing a stale issue. Set to `false` to disable | ||
closeComment: false |
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,60 @@ | ||
name: test | ||
|
||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install | ||
run: npm install | ||
- name: Run lint | ||
run: npm run lint | ||
|
||
typecheck: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install | ||
run: npm install | ||
- name: Run typecheck | ||
run: npm run typecheck | ||
|
||
tests: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
node-version: | ||
- 20.10.0 | ||
- 21.x | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install | ||
run: npm install | ||
- name: Run tests | ||
run: npm test | ||
windows: | ||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- 20.10.0 | ||
- 21.x | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install | ||
run: npm install | ||
- name: Run tests | ||
run: npm test |
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,14 @@ | ||
node_modules | ||
coverage | ||
.DS_STORE | ||
.nyc_output | ||
.idea | ||
.vscode/ | ||
*.sublime-project | ||
*.sublime-workspace | ||
*.log | ||
build | ||
dist | ||
yarn.lock | ||
shrinkwrap.yaml | ||
package-lock.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
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,4 @@ | ||
build | ||
docs | ||
coverage | ||
*.html |
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,9 @@ | ||
# The MIT License | ||
|
||
Copyright (c) 2023 | ||
|
||
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. |
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 @@ | ||
# @adocasts.com/generate-models | ||
|
||
> Generate Lucid Models from an existing database schema | ||
👋 Hey there! This is still a work in progress |
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,11 @@ | ||
import { assert } from '@japa/assert' | ||
import { configure, processCLIArgs, run } from '@japa/runner' | ||
|
||
processCLIArgs(process.argv.splice(2)) | ||
|
||
configure({ | ||
files: ['tests/**/*.spec.ts'], | ||
plugins: [assert()], | ||
}) | ||
|
||
run() |
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,22 @@ | ||
import { inject } from '@adonisjs/core' | ||
import { BaseCommand } from '@adonisjs/core/ace' | ||
import type { CommandOptions } from '@adonisjs/core/types/ace' | ||
import Schema from '../src/db/schema.js' | ||
import Model from '../src/model/index.js' | ||
|
||
export default class GenerateModels extends BaseCommand { | ||
static commandName = 'generate:models' | ||
static description = 'Generate model files from an existing database' | ||
|
||
static options: CommandOptions = { | ||
startApp: true, | ||
} | ||
|
||
@inject() | ||
async run(schema: Schema) { | ||
const tables = await schema.getTables() | ||
const models = Model.build(tables) | ||
|
||
console.log({ models }) | ||
} | ||
} |
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,17 @@ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Configure hook | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The configure hook is called when someone runs "node ace configure <package>" | ||
| command. You are free to perform any operations inside this function to | ||
| configure the package. | ||
| | ||
| To make things easier, you have access to the underlying "ConfigureCommand" | ||
| instance and you can use codemods to modify the source files. | ||
| | ||
*/ | ||
|
||
import ConfigureCommand from '@adonisjs/core/commands/configure' | ||
|
||
export async function configure(_command: ConfigureCommand) {} |
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,10 @@ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Package entrypoint | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Export values from the package entrypoint as you see fit. | ||
| | ||
*/ | ||
|
||
export { configure } from './configure.js' |
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,92 @@ | ||
{ | ||
"name": "generate-models", | ||
"description": "Generate Lucid Models from an existing database schema", | ||
"version": "0.0.0", | ||
"engines": { | ||
"node": ">=20.6.0" | ||
}, | ||
"type": "module", | ||
"files": [ | ||
"build/src", | ||
"build/providers", | ||
"build/stubs", | ||
"build/index.d.ts", | ||
"build/index.js" | ||
], | ||
"exports": { | ||
".": "./build/index.js", | ||
"./types": "./build/src/types.js" | ||
}, | ||
"scripts": { | ||
"clean": "del-cli build", | ||
"copy:templates": "copyfiles \"stubs/**/*.stub\" build", | ||
"typecheck": "tsc --noEmit", | ||
"lint": "eslint . --ext=.ts", | ||
"format": "prettier --write .", | ||
"quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts", | ||
"pretest": "npm run lint", | ||
"test": "c8 npm run quick:test", | ||
"prebuild": "npm run lint && npm run clean", | ||
"build": "tsc", | ||
"postbuild": "npm run copy:templates", | ||
"release": "np", | ||
"version": "npm run build", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"devDependencies": { | ||
"@adonisjs/assembler": "^7.7.0", | ||
"@adonisjs/core": "^6.12.0", | ||
"@adonisjs/eslint-config": "^1.3.0", | ||
"@adonisjs/lucid": "^21.2.0", | ||
"@adonisjs/prettier-config": "^1.3.0", | ||
"@adonisjs/tsconfig": "^1.3.0", | ||
"@japa/assert": "^3.0.0", | ||
"@japa/runner": "^3.1.4", | ||
"@swc/core": "^1.6.3", | ||
"@types/node": "^20.14.5", | ||
"c8": "^10.1.2", | ||
"copyfiles": "^2.4.1", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.57.0", | ||
"knex-schema-inspector": "^3.1.0", | ||
"np": "^10.0.6", | ||
"prettier": "^3.3.2", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5" | ||
}, | ||
"peerDependencies": { | ||
"@adonisjs/core": "^6.2.0", | ||
"@adonisjs/lucid": "^21.2.0" | ||
}, | ||
"author": "tomgobich,adocasts.com", | ||
"license": "MIT", | ||
"keywords": [ | ||
"adonisjs", | ||
"lucid", | ||
"model", | ||
"generate" | ||
], | ||
"eslintConfig": { | ||
"extends": "@adonisjs/eslint-config/package" | ||
}, | ||
"prettier": "@adonisjs/prettier-config", | ||
"publishConfig": { | ||
"access": "public", | ||
"tag": "latest" | ||
}, | ||
"np": { | ||
"message": "chore(release): %s", | ||
"tag": "latest", | ||
"branch": "main", | ||
"anyBranch": false | ||
}, | ||
"c8": { | ||
"reporter": [ | ||
"text", | ||
"html" | ||
], | ||
"exclude": [ | ||
"tests/**" | ||
] | ||
} | ||
} |
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 @@ | ||
# The providers directory | ||
|
||
The `providers` directory contains the service providers exported by your application. Make sure to register these providers within the `exports` collection (aka package entrypoints) defined within the `package.json` file. | ||
|
||
Learn more about [package entrypoints](https://nodejs.org/api/packages.html#package-entry-points). |
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,3 @@ | ||
# The src directory | ||
|
||
The `src` directory is where you organize your package code. Feel free to create additional sub-directories as you see fit. |
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,29 @@ | ||
import db from '@adonisjs/lucid/services/db' | ||
import { default as schemaInspectorImport } from 'knex-schema-inspector' | ||
import type { Column } from 'knex-schema-inspector/dist/types/column.js' | ||
import type { SchemaInspector } from 'knex-schema-inspector/dist/types/schema-inspector.js' | ||
const schemaInspector = schemaInspectorImport.default | ||
|
||
export type TableSchema = { | ||
name: string | ||
columns: Column[] | ||
} | ||
|
||
export default class Schema { | ||
declare inspector: SchemaInspector | ||
|
||
constructor() { | ||
const knex = db.connection().getWriteClient() | ||
this.inspector = schemaInspector(knex) | ||
} | ||
|
||
async getTables(): Promise<TableSchema[]> { | ||
const tableNames = await this.inspector.tables() | ||
const promises = tableNames.map(async (name) => ({ | ||
name, | ||
columns: await this.inspector.columnInfo(name), | ||
})) | ||
|
||
return Promise.all(promises) | ||
} | ||
} |
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,8 @@ | ||
enum RelationshipTypes { | ||
BELONGS_TO = 'belongsTo', | ||
HAS_ONE = 'hasOne', | ||
HAS_MANY = 'hasMany', | ||
MANY_TO_MANY = 'manyToMany', | ||
} | ||
|
||
export default RelationshipTypes |
Oops, something went wrong.