Skip to content

Commit

Permalink
refactor: tighten up things for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Aug 10, 2024
1 parent fb80e6a commit dc319d0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
export * from 'flydrive'
export * as errors from './src/errors.js'
export { configure } from './configure.js'
export { stubsRoot } from './stubs/main.js'
export { defineConfig, services } from './src/define_config.js'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"scripts": {
"clean": "del-cli build",
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
"copy:templates": "copyfiles --up=1 \"stubs/**/**/*.stub\" build",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext=.ts",
"format": "prettier --write .",
Expand Down
10 changes: 9 additions & 1 deletion providers/drive_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { ApplicationService } from '@adonisjs/core/types'

import { createFileServer } from '../src/file_server.js'
import type { DriveService, ServiceWithLocalServer, SignedURLOptions } from '../src/types.js'
import debug from '../src/debug.js'

/**
* Extending the container with a custom service
Expand Down Expand Up @@ -45,6 +46,8 @@ export default class DriveProvider {
protected async registerViewHelpers(drive: DriveManager<any>) {
if (this.app.usingEdgeJS) {
const edge = await import('edge.js')
debug('detected edge installation. Registering drive global helpers')

edge.default.global('driveUrl', function (key: string, diskName?: string) {
const disk = diskName ? drive.use(diskName) : drive.use()
return disk.getUrl(key)
Expand Down Expand Up @@ -109,7 +112,7 @@ export default class DriveProvider {
}

/**
* The boot method early resolves drive and router to register
* The boot method resolves drive and router to register
* the routes for the locally served services.
*
* The routes must be defined before the application has
Expand All @@ -120,6 +123,11 @@ export default class DriveProvider {
const router = await this.app.container.make('router')

this.#locallyServedServices.forEach((service) => {
debug(
'configuring drive local file server for "%s", route "%s"',
service.service,
service.routePattern
)
router
.get(service.routePattern, createFileServer(drive.use(service.service)))
.as(service.routeName)
Expand Down
5 changes: 5 additions & 0 deletions src/define_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
ServiceConfigProvider,
ServiceWithLocalServer,
} from './types.js'
import debug from './debug.js'

/**
* Helper to remap known drive services to factory functions
Expand Down Expand Up @@ -115,6 +116,8 @@ export const services: {
return {
type: 'provider',
async resolver(name, app, locallyServed) {
debug('configuring fs service')

/**
* Ensure route base path is provided when serving files
*/
Expand Down Expand Up @@ -152,6 +155,7 @@ export const services: {
return {
type: 'provider',
async resolver() {
debug('configuring s3 service')
const { S3Driver } = await import('flydrive/drivers/s3')
return () => new S3Driver(config)
},
Expand All @@ -161,6 +165,7 @@ export const services: {
return {
type: 'provider',
async resolver() {
debug('configuring gcs service')
const { GCSDriver } = await import('flydrive/drivers/gcs')
return () => new GCSDriver(config)
},
Expand Down
2 changes: 1 addition & 1 deletion tests/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ test.group('Configure', (group) => {
])
})

test('print error when trying to configure an unknown service', async ({ fs, assert }) => {
test('print error when trying to configure an unknown service', async ({ fs }) => {
const ignitor = new IgnitorFactory()
.withCoreProviders()
.withCoreConfig()
Expand Down

0 comments on commit dc319d0

Please sign in to comment.