Skip to content

Commit

Permalink
feat: add instructions file
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 2, 2019
1 parent e094a0a commit 9ed0bcd
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 9 deletions.
91 changes: 91 additions & 0 deletions config/database.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Config source: https://git.io/fjS7M
*
* Feel free to let us know via PR, if you find something broken in this config
* file.
*/

import Env from '@ioc:Adonis/Core/Env'
import Application from '@ioc:Adonis/Core/Application'
import { DatabaseConfigContract } from '@ioc:Adonis/Lucid/Database'

const databaseConfig: DatabaseConfigContract = {
/*
|--------------------------------------------------------------------------
| Connection
|--------------------------------------------------------------------------
|
| The primary connection for making database queries across the application
| You can use any key from the `connections` object defined in this same
| file.
|
*/
connection: Env.get('DB_CONNECTION', 'sqlite'),

connections: {
/*
|--------------------------------------------------------------------------
| Sqlite
|--------------------------------------------------------------------------
|
| Configuration for the Sqlite database. Make sure to install the driver
| from npm when using this connection
|
| npm i sqlite3
|
*/
sqlite: {
client: 'sqlite',
connection: {
filename: Application.tmpPath('db.sqlite3'),
},
useNullAsDefault: true
},

/*
|--------------------------------------------------------------------------
| Mysql config
|--------------------------------------------------------------------------
|
| Configuration for Mysql database. Make sure to install the driver
| from npm when using this connection
|
| npm i mysql
|
*/
mysql: {
client: 'mysql',
connection: {
host?: Env.get('DB_HOST', '127.0.0.1'),
port?: Env.get('DB_PORT', 3306) as number,
user?: Env.get('DB_USER', 'lucid'),
password?: Env.get('DB_PASSWORD', 'lucid'),
database?: Env.get('DB_NAME', 'lucid'),
},
},

/*
|--------------------------------------------------------------------------
| PostreSQL config
|--------------------------------------------------------------------------
|
| Configuration for postgreSQL database. Make sure to install the driver
| from npm when using this connection
|
| npm i pg
|
*/
pg: {
client: 'pg',
connection: {
host?: Env.get('DB_HOST', '127.0.0.1'),
port?: Env.get('DB_PORT', 5432) as number,
user?: Env.get('DB_USER', 'lucid'),
password?: Env.get('DB_PASSWORD', 'lucid'),
database?: Env.get('DB_NAME', 'lucid'),
},
}
}
}

export default databaseConfig
39 changes: 39 additions & 0 deletions instructions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* @adonisjs/lucid
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { join } from 'path'
import sinkStatic from '@adonisjs/sink'
import { ApplicationContract } from '@poppinss/application'

export function instructions (
projectRoot: string,
application: ApplicationContract,
{ TemplateFile, EnvFile, kleur }: typeof sinkStatic,
) {
const dest = `${application.directoriesMap.get('config')}/database.ts`
const src = join(__dirname, 'config', 'database.txt')

new TemplateFile(projectRoot, dest, src)
.apply({})
.commit()

console.log(` create ${kleur.green(dest)}`)

const env = new EnvFile('.env')

env.set('DB_CONNECTION', 'sqlite')
env.set('DB_HOST', '127.0.0.1')
env.set('DB_USER', 'lucid')
env.set('DB_PASSWORD', 'lucid')
env.set('DB_NAME', 'lucid')

env.commit()

console.log(` update ${kleur.green('.env')}`)
}
28 changes: 19 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
"name": "@adonisjs/lucid",
"version": "6.1.3",
"description": "SQL ORM built on top of Active Record pattern",
"main": "build/index.js",
"files": [
"build/src",
"build/adonis-typings",
"build/providers",
"build/config",
"build/instructions.js"
],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
Expand All @@ -28,17 +36,22 @@
},
"homepage": "https://github.com/adonisjs/adonis-lucid#readme",
"dependencies": {
"@poppinss/logger": "^1.1.3",
"@poppinss/profiler": "^1.1.1",
"@poppinss/traits": "^1.0.0",
"@poppinss/utils": "^1.0.5",
"knex": "^0.19.3",
"knex-dynamic-connection": "^1.0.0",
"ts-essentials": "^3.0.2"
},
"peerDependencies": {
"@adonisjs/core": "2.x.x"
},
"devDependencies": {
"@adonisjs/mrm-preset": "^2.1.0",
"@adonisjs/sink": "^2.1.5",
"@poppinss/application": "^1.0.10",
"@poppinss/dev-utils": "^1.0.1",
"@poppinss/logger": "^1.1.3",
"@poppinss/profiler": "^1.1.1",
"@types/dotenv": "^6.1.1",
"@types/node": "^12.7.3",
"clone": "^2.1.2",
Expand Down Expand Up @@ -71,12 +84,6 @@
".ts"
]
},
"main": "build/index.js",
"files": [
"build/src",
"build/index.d.ts",
"build/index.js"
],
"husky": {
"hooks": {
"pre-commit": "doctoc README.md --title='## Table of contents' && git add README.md",
Expand All @@ -91,5 +98,8 @@
"directories": {
"test": "test"
},
"keywords": []
"keywords": [],
"adonisjs": {
"instructions": "./build/instructions.js"
}
}

0 comments on commit 9ed0bcd

Please sign in to comment.