Skip to content

Commit

Permalink
Merge pull request #30 from verful/development
Browse files Browse the repository at this point in the history
fix: types and package setup
  • Loading branch information
arthur-er authored Dec 28, 2023
2 parents 9aca34a + 8a86c48 commit cf22c73
Show file tree
Hide file tree
Showing 12 changed files with 558 additions and 467 deletions.
12 changes: 9 additions & 3 deletions adonis-typings/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ declare module '@ioc:Verful/Notification' {
}

export interface RoutesNotificationsMixin {
<T extends NormalizeConstructor<LucidModel>>(superclass: T): T & {
<T extends NormalizeConstructor<LucidModel>>(
superclass: T
): T & {
new (...args: any[]): LucidRow & RoutesNotificationsModel
}
}
Expand All @@ -77,7 +79,9 @@ declare module '@ioc:Verful/Notification' {
}

export interface HasDatabaseNotificationsMixin {
<T extends NormalizeConstructor<LucidModel>>(superclass: T): T & {
<T extends NormalizeConstructor<LucidModel>>(
superclass: T
): T & {
new (...args: any[]): LucidRow & HasDatabaseNotificationsModel
}
}
Expand All @@ -87,7 +91,9 @@ declare module '@ioc:Verful/Notification' {
HasDatabaseNotificationsModel {}

export interface NotifiableMixin {
<T extends NormalizeConstructor<LucidModel>>(superclass: T): T & {
<T extends NormalizeConstructor<LucidModel>>(
superclass: T
): T & {
new (...args: any[]): LucidRow & NotifiableModel
}
}
Expand Down
47 changes: 16 additions & 31 deletions instructions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import * as sinkStatic from '@adonisjs/sink'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
import pluralize from 'pluralize'
import { join } from 'path'

type InstructionsState = {
notificationsTableName: string
notificationsSchemaName: string

notifiableTableName: string

mailer: string

channels: ('database' | 'mail')[]

hasChannel: {
database: boolean
mail: boolean
Expand Down Expand Up @@ -129,15 +125,18 @@ async function getChannels(sink: typeof sinkStatic) {
)
}

async function getMigrationConsent(sink: typeof sinkStatic, tableName: string): Promise<boolean> {
return sink
.getPrompt()
.confirm(`Create migration for the ${sink.logger.colors.underline(tableName)} table?`)
async function getMigrationConsent(sink: typeof sinkStatic): Promise<boolean> {
return sink.getPrompt().confirm(`You want to create a notifications table?`)
}

async function getNotificationTableName(sink: typeof sinkStatic): Promise<string> {
async function getNotificationTableName(
sink: typeof sinkStatic,
notifiableTableName: string
): Promise<string> {
const singularNotifiableTableName = pluralize.singular(notifiableTableName)

return sink.getPrompt().ask('Enter the notifications table name', {
default: 'notifications',
default: `${singularNotifiableTableName}_notifications`,
validate(value) {
return !!value.trim().length
},
Expand All @@ -153,14 +152,6 @@ async function getNotifiableTableName(sink: typeof sinkStatic): Promise<string>
})
}

async function getMailerName(sink: typeof sinkStatic): Promise<string> {
return sink.getPrompt().ask('Enter the mailer you want to use for mail notifications', {
validate(value) {
return !!value.trim().length
},
})
}

export default async function instructions(
projectRoot: string,
app: ApplicationContract,
Expand All @@ -170,7 +161,6 @@ export default async function instructions(
notificationsSchemaName: 'Notifications',
notificationsTableName: '',
notifiableTableName: '',
mailer: '',
channels: [],
hasChannel: {
database: false,
Expand All @@ -182,18 +172,13 @@ export default async function instructions(
state.channels.forEach((channel) => (state.hasChannel[channel] = true))

if (state.hasChannel.database) {
state.notifiableTableName = await getNotifiableTableName(sink)
state.notificationsTableName = await getNotificationTableName(sink)
}

const notificationMigrationConsent = await getMigrationConsent(sink, state.notificationsTableName)

if (state.hasChannel.mail) {
state.mailer = await getMailerName(sink)
}
const notificationMigrationConsent = await getMigrationConsent(sink)

if (notificationMigrationConsent) {
makeNotificationsMigration(projectRoot, app, sink, state)
if (notificationMigrationConsent) {
state.notifiableTableName = await getNotifiableTableName(sink)
state.notificationsTableName = await getNotificationTableName(sink, state.notifiableTableName)
makeNotificationsMigration(projectRoot, app, sink, state)
}
}

makeContract(projectRoot, app, sink, state)
Expand Down
35 changes: 19 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
"license": "MIT",
"dependencies": {
"@poppinss/manager": "^5.0.2",
"@poppinss/utils": "^4.0.4",
"fastq": "^1.13.0",
"luxon": "^3.4.4"
"@poppinss/utils": "^5.0.0",
"fastq": "^1.16.0",
"luxon": "^3.4.4",
"pluralize": "^8.0.0"
},
"devDependencies": {
"@adonisjs/assembler": "^5.7.0",
"@adonisjs/assembler": "^5.9.6",
"@adonisjs/core": "^5.8.3",
"@adonisjs/lucid": "^18.0.0",
"@adonisjs/lucid": "^18.4.2",
"@adonisjs/mail": "^8.1.2",
"@adonisjs/mrm-preset": "^5.0.3",
"@adonisjs/require-ts": "^2.0.12",
Expand All @@ -38,24 +39,26 @@
"@japa/runner": "^2.0.8",
"@japa/spec-reporter": "^1.1.12",
"@poppinss/dev-utils": "^2.0.3",
"@types/luxon": "3.3.5",
"@types/node": "^17.0.38",
"@types/pluralize": "^0.0.33",
"commitizen": "^4.2.4",
"copyfiles": "^2.4.1",
"cz-conventional-changelog": "^3.3.0",
"del-cli": "^4.0.1",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-adonis": "^2.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.1.2",
"github-label-sync": "^2.2.0",
"husky": "^8.0.1",
"mrm": "^4.0.0",
"np": "^9.0.0",
"np": "^9.2.0",
"nyc": "^15.1.0",
"prettier": "^2.6.2",
"prettier": "^3.1.1",
"reflect-metadata": "^0.2.1",
"sqlite3": "^5.0.8",
"typescript": "^4.7.2"
"typescript": "^5.3.3"
},
"peerDependencies": {
"@adonisjs/core": "^5.8.3",
Expand All @@ -73,17 +76,17 @@
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"test": "node -r @adonisjs/assembler/build/register bin/test/index.ts",
"coverage": "nyc yarn test",
"coverage": "nyc pnpm test",
"clean": "del build",
"copyfiles": "copyfiles \"templates/**/*.txt\" \"instructions.md\" build",
"compile": "yarn lint && yarn clean && tsc",
"build": "yarn compile && yarn copyfiles",
"prepublishOnly": "yarn build",
"compile": "pnpm lint && pnpm clean && tsc",
"build": "pnpm compile && pnpm copyfiles",
"prepublishOnly": "pnpm build",
"lint": "eslint . --ext=.ts",
"format": "prettier --write .",
"commit": "git-cz",
"release": "np --message=\"chore(release): %s\"",
"version": "yarn build",
"version": "pnpm build",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json verful/notifications"
},
"engines": {
Expand Down
Loading

0 comments on commit cf22c73

Please sign in to comment.