Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to Supercharge v4 and ESM #58

Merged
merged 19 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@typescript-eslint/comma-dangle": [
"error",
"only-multiline"
]
],
"@typescript-eslint/no-empty-interface": 0
}
}
31 changes: 23 additions & 8 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
name: Run tests

on: [push, pull_request]
on:
push:
paths-ignore:
- 'README.md'

concurrency:
# the group name is composed of two elements:
# 1. this workflow name "run-tests"
# 2. the branch name retrieved via the "github.ref" variable
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x]
bun-version: [1.0.x]

name: Node ${{ matrix.node-version }}
name: Bun ${{ matrix.bun-version }}

steps:
- name: Clone repository
Expand All @@ -36,15 +46,20 @@ jobs:
path: resources/docs/3.x
ref: 3.x

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v4
# with:
# node-version: ${{ matrix.node-version }}

- name: Use Bun ${{ matrix.bun-version }}
uses: oven-sh/setup-bun@v1
with:
node-version: ${{ matrix.node-version }}
bun-version: ${{ matrix.bun-version }}

- name: Install dependencies
run: npm install --legacy-peer-deps
run: bun install

- name: Run tests
run: npm test
run: bun test
env:
CI: true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ results
dist
node_modules
npm-debug.log
package-lock.json
.swc

# Docs
Expand Down
1 change: 0 additions & 1 deletion app/console/commands/inspire.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

import { Command } from '@supercharge/console'

Expand Down
3 changes: 1 addition & 2 deletions app/console/kernel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

import { ConsoleKernel as Kernel } from '@supercharge/core'

Expand All @@ -7,7 +6,7 @@ export class ConsoleKernel extends Kernel {
* Register the console commands to the application.
*/
override async commands (): Promise<void> {
await this.loadFrom(
await this.loadCommandsFromPaths(
this.app().resolveFromBasePath('app/console/commands'),
)
}
Expand Down
5 changes: 4 additions & 1 deletion app/errors/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

import { ErrorHandler as Handler } from '@supercharge/core'

Expand All @@ -8,6 +7,10 @@ export class ErrorHandler extends Handler {
* upstream to an error tracking service, like Sentry or Bugsnag.
*/
override register (): void {
this.reportable(async (error) => {
this.logger().error('Received error -->', error)
})

// this.reportable(async (ctx, error) => {
// await this.sendToIssueTracker(error)
// })
Expand Down
1 change: 0 additions & 1 deletion app/http/controllers/ShowDocs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

import { Controller } from '@supercharge/http'
import { HttpContext, HttpRedirect } from '@supercharge/contracts'
Expand Down
18 changes: 5 additions & 13 deletions app/http/controllers/ShowDocsVersion.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'

import Str from '@supercharge/strings'
import { Str } from '@supercharge/strings'
import { Controller } from '@supercharge/http'
import { Documentation } from '../../models/documentation'
import { Documentation } from '../../models/documentation.js'
import { Application, HttpContext, HttpResponse } from '@supercharge/contracts'

export class ShowDocsVersion extends Controller {
Expand All @@ -24,8 +23,6 @@ export class ShowDocsVersion extends Controller {

/**
* Returns the documentation instance.
*
* @returns {Documentation}
*/
docs (): Documentation {
if (this.meta.docs) {
Expand All @@ -39,8 +36,8 @@ export class ShowDocsVersion extends Controller {
* Handle the given request.
*/
async handle ({ request, response }: HttpContext): Promise<any> {
const page = request.params().get('page', 'installation') as string
const version = request.params().get('version') as string
const page = request.params<{ page?: string }>().get('page', 'installation')
const version = request.params<{ version: string }>().get('version')

this.meta.docs = new Documentation(this.app, version)

Expand All @@ -62,18 +59,13 @@ export class ShowDocsVersion extends Controller {
currentPage: page,
docsContent: content,
versions: this.docs().versions(),
navigation: this.docs().navigation(),
navigation: await this.docs().navigation(),
currentVersion: this.docs().versions()[version],
})
}

/**
* Redirect to the docs default version.
*
* @param response
* @param page
*
* @returns
*/
private redirectToDefaultVersion (response: HttpResponse, page: string): any {
return response.redirect().to(`/docs/${this.docs().defaultVersion()}/${page}`)
Expand Down
7 changes: 1 addition & 6 deletions app/http/controllers/ShowNews.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

import Fs from '@supercharge/fs'
import { Post } from '../../models/post'
import { Post } from '../../models/post.js'
import { Controller } from '@supercharge/http'
import { Collect } from '@supercharge/collections'
import { HttpContext, HttpResponse } from '@supercharge/contracts'
Expand All @@ -18,8 +17,6 @@ export class ShowNews extends Controller {

/**
* Returns the list of published posts, ordered DESC by publishedAt date.
*
* @returns {Object[]}
*/
async publishedPosts (): Promise<object[]> {
const posts = await this.loadPosts()
Expand All @@ -35,8 +32,6 @@ export class ShowNews extends Controller {

/**
* Load all news posts.
*
* @returns {Post[]}
*/
async loadPosts (): Promise<Post[]> {
return await Collect(
Expand Down
1 change: 0 additions & 1 deletion app/http/controllers/ShowPodcast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

import { HttpContext } from '@supercharge/contracts'

Expand Down
1 change: 0 additions & 1 deletion app/http/controllers/ShowStartpage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict'

import { HttpContext } from '@supercharge/contracts'

Expand Down
7 changes: 1 addition & 6 deletions app/http/kernel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict'

import { MiddlewareCtor } from '@supercharge/contracts'
import { HttpKernel as Kernel } from '@supercharge/core'
import { ServeStaticAssets } from './middleware/serve-static-assets'
import { HandleCorsMiddleware as HandleCors } from '@supercharge/http'
import { ServeStaticAssets } from './middleware/serve-static-assets.js'

export class HttpKernel extends Kernel {
/**
Expand Down Expand Up @@ -31,8 +30,6 @@ export class HttpKernel extends Kernel {
/**
* Returns the application’s global middleware stack. Every middleware
* listed here runs on every request to the application.
*
* @returns {MiddlewareCtor[]}
*/
override middleware (): MiddlewareCtor[] {
return [
Expand All @@ -54,8 +51,6 @@ export class HttpKernel extends Kernel {
* Route.get('/profile', …)
* })
* ```
*
* @returns {Object}
*/
override routeMiddleware (): { [name: string]: MiddlewareCtor} {
return {
Expand Down
3 changes: 0 additions & 3 deletions app/http/middleware/serve-static-assets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict'

import { ServeStaticAssetsMiddleware as Middleware } from '@supercharge/http'

export class ServeStaticAssets extends Middleware {
/**
* Returns the path to the asset files.
*
* @returns {String}
*/
override assetsLocation (): string {
return this.app.publicPath()
Expand Down
3 changes: 0 additions & 3 deletions app/http/middleware/verify-csrf-token.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict'

// import Middleware from '@supercharge/http-server/middleware/verify-csrf-token'

export default class VerifyCsrfToken {
/**
* Returns an array of URIs that should be excluded from CSRF verfication.
*
* @returns {Array}
*/
exclude (): string[] {
return [
Expand Down
44 changes: 6 additions & 38 deletions app/models/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

import Fs from '@supercharge/fs'
import Str from '@supercharge/strings'
import { Str } from '@supercharge/strings'
import { Application } from '@supercharge/contracts'
import { MarkdownRenderer } from '../modules/markdown/markdown-renderer'
import { resolveDefaultImport } from '@supercharge/goodies'
import { MarkdownRenderer } from '../modules/markdown/markdown-renderer.js'

export class Documentation {
private readonly app: Application
Expand All @@ -19,30 +19,22 @@ export class Documentation {

/**
* Returns the navigation.
*
* @returns {String}
*/
navigation (): string {
return require(
this.app.resourcePath(`docs/${this.version}/navigation`)
async navigation (): Promise<string> {
return await resolveDefaultImport(
this.app.resourcePath(`docs/${this.version}/navigation.js`)
)
}

/**
* Returns the markdown renderer instance.
*
* @returns {MarkdownRenderer}
*/
markdownRenderer (): MarkdownRenderer {
return this.app.make(MarkdownRenderer.name)
}

/**
* Returns the rendered HTML content for the given docs `page`.
*
* @param {String} page
*
* @returns {String}
*/
async get (page: string): Promise<string> {
try {
Expand All @@ -54,10 +46,6 @@ export class Documentation {

/**
* Returns the parsed and prepared HTML page for the given docs `file`.
*
* @param {String} file
*
* @returns {String}
*/
async readAndParseFile (file: string): Promise<string> {
return this.createHtmlFromMarkdown(
Expand All @@ -68,10 +56,6 @@ export class Documentation {
/**
* Returns the resolved file path to the given docs `file`. Throws an error
* if the given docs page does not exist for the requested `file`.
*
* @param {String} file
*
* @returns {Strin}
*/
private async resolveDocsPathFor (file: string): Promise<string> {
const resourcePath = this.app.resourcePath(`docs/${this.version}/${file}`)
Expand All @@ -91,10 +75,6 @@ export class Documentation {

/**
* Returns the rendered HTML string for the given markdown `file`.
*
* @param file
*
* @returns {String}
*/
async createHtmlFromMarkdown (file: string): Promise<string> {
const markdown = await this.markdownRenderer().renderWithToc(
Expand All @@ -107,10 +87,6 @@ export class Documentation {
/**
* Replaces the {{version}} placeholders in the docs markdown files with the
* actual version so that all links in the docs work nicely together.
*
* @param {String} content
*
* @returns {String}
*/
replaceLinks (content: string): string {
const pattern = encodeURIComponent('{{version}}')
Expand All @@ -120,17 +96,13 @@ export class Documentation {

/**
* Determine whether the given version is valid.
*
* @returns {Boolean}
*/
isValidVersion (): boolean {
return !!this.versions()[this.version]
}

/**
* Determine whether the given version is not valid.
*
* @returns {Boolean}
*/
isInvalidVersion (): boolean {
return !this.isValidVersion()
Expand All @@ -139,17 +111,13 @@ export class Documentation {
/**
* Returns all configured docs version mappings. The mapping keys are the
* folder names and the values represent the name that is shown in the web.
*
* @returns {Object}
*/
versions (): { [key: string]: string } {
return this.app.config().get('docs.versions')
}

/**
* Returns the configured default docs version.
*
* @returns {String}
*/
defaultVersion (): string {
return this.app.config().get('docs.default')
Expand Down
Loading
Loading