From accd195cb00e943fadea7caed08528cf4dd2ed02 Mon Sep 17 00:00:00 2001 From: Arthur Danjou Date: Fri, 18 Jun 2021 19:49:24 +0200 Subject: [PATCH] Working --- ace-manifest.json | 12 ++++++++++++ commands/UserCreate.ts | 40 ++++++++++++++++++++++++++++++++++++++++ package.json | 5 +++-- providers/AppProvider.ts | 8 -------- 4 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 commands/UserCreate.ts diff --git a/ace-manifest.json b/ace-manifest.json index 48f6f56..a77a38e 100644 --- a/ace-manifest.json +++ b/ace-manifest.json @@ -1,5 +1,17 @@ { "commands": { + "user:create": { + "settings": { + "loadApp": true, + "stayAlive": false + }, + "commandPath": "./commands/UserCreate", + "commandName": "user:create", + "description": "Create the default user", + "args": [], + "aliases": [], + "flags": [] + }, "dump:rcfile": { "settings": {}, "commandPath": "@adonisjs/core/build/commands/DumpRc", diff --git a/commands/UserCreate.ts b/commands/UserCreate.ts new file mode 100644 index 0000000..a2096a7 --- /dev/null +++ b/commands/UserCreate.ts @@ -0,0 +1,40 @@ +import { BaseCommand } from '@adonisjs/core/build/standalone' + +export default class UserCreate extends BaseCommand { + + /** + * Command name is used to run the command + */ + public static commandName = 'user:create' + + /** + * Command description is displayed in the "help" output + */ + public static description = 'Create the default user' + + public static settings = { + /** + * Set the following value to true, if you want to load the application + * before running the command + */ + loadApp: true, + + /** + * Set the following value to true, if you want this command to keep running until + * you manually decide to exit the process + */ + stayAlive: false, + } + + public async run () { + const { default: User } = await import('App/Models/User') + const { default: Env } = await import('@ioc:Adonis/Core/Env') + await User.firstOrCreate({ + email: Env.get('ADMIN_USER', 'admin@linkyjs.dev') + }, { + email: Env.get('ADMIN_USER', 'admin@linkyjs.dev'), + password: Env.get('ADMIN_PASSWORD', 'password') + }) + this.logger.info('User successfully created !') + } +} diff --git a/package.json b/package.json index 4d2dd9a..7cc1cf3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@linkyjs/core", - "version": "1.0.8", + "version": "1.0.9", "description": "URL Shortener for Developers 💻", "main": "start/kernel.ts", "repository": { @@ -18,7 +18,8 @@ "start": "node server.js", "seed": "node ace db:seed", "mig": "node ace migration:run", - "generate": "node ace generate:key" + "generate": "node ace generate:key", + "user": "node ace user:create" }, "devDependencies": { "@adonisjs/assembler": "^5.3.2", diff --git a/providers/AppProvider.ts b/providers/AppProvider.ts index 9d08669..1c8ec8e 100644 --- a/providers/AppProvider.ts +++ b/providers/AppProvider.ts @@ -1,6 +1,4 @@ import { ApplicationContract } from '@ioc:Adonis/Core/Application' -import User from "../app/Models/User"; -import Env from "@ioc:Adonis/Core/Env"; export default class AppProvider { public static needsApplication = true @@ -15,12 +13,6 @@ export default class AppProvider { } public async ready () { - await User.firstOrCreate({ - email: Env.get('ADMIN_USER', 'admin@linkyjs.dev') - }, { - email: Env.get('ADMIN_USER', 'admin@linkyjs.dev'), - password: Env.get('ADMIN_PASSWORD', 'password') - }) } public async shutdown () {