Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kerwanp committed Sep 23, 2024
0 parents commit dd67a84
Show file tree
Hide file tree
Showing 53 changed files with 1,397 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# http://editorconfig.org

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
insert_final_newline = ignore

[**.min.js]
indent_style = ignore
insert_final_newline = ignore

[MakeFile]
indent_style = space

[*.md]
trim_trailing_whitespace = false
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ['@foa/eslint-config/adonis-package.js'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.lint.json',
tsconfigRootDir: __dirname,
},
}
26 changes: 26 additions & 0 deletions .github/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
ignoreUnless: {{ STALE_BOT }}
---
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app

# Number of days of inactivity before a closed issue or pull request is locked
daysUntilLock: 60

# Skip issues and pull requests created before a given timestamp. Timestamp must
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
skipCreatedBefore: false

# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
exemptLabels: ['Type: Security']

# Label to add before locking, such as `outdated`. Set to `false` to disable
lockLabel: false

# Comment to post before locking. Set to `false` to disable
lockComment: >
This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.
# Assign `resolved` as the reason for locking. Set to `false` to disable
setLockReason: false
24 changes: 24 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
ignoreUnless: {{ STALE_BOT }}
---
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60

# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7

# Issues with these labels will never be considered stale
exemptLabels:
- 'Type: Security'

# Label to use when marking an issue as stale
staleLabel: 'Status: Abandoned'

# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: test

on:
- push
- pull_request

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: npm install
- name: Run lint
run: npm run lint

typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: npm install
- name: Run typecheck
run: npm run typecheck

tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version:
- 20.10.0
- 21.x
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm install
- name: Run tests
run: npm test
windows:
runs-on: windows-latest
strategy:
matrix:
node-version:
- 20.10.0
- 21.x
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm install
- name: Run tests
run: npm test
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
coverage
.DS_STORE
.nyc_output
.idea
.vscode/
*.sublime-project
*.sublime-workspace
*.log
build
dist
yarn.lock
shrinkwrap.yaml
package-lock.json
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
docs
coverage
*.html
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# The MIT License

Copyright (c) 2023

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div align="center">
<br/>

## @foadonis/edgewire

### Build reactive interfaces without leaving Adonis.js

<br/>
</div>

<div align="center">

[![PRs Welcome](https://img.shields.io/badge/PRs-Are%20welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com) [![License](https://img.shields.io/github/license/FriendsOfAdonis/edgewire?label=License&style=flat-square)](LICENCE) [![@foadonis/edgewire](https://img.shields.io/npm/v/%40foadonis%2Fedgewire?style=flat-square)](https://www.npmjs.com/package/@foadonis/edgewire)

</div>

## Description

Edgewire allows you to build reactive interfaces without leaving your server using Adonis. It is heavily inspired by the PHP library [Livewire](https://livewire.laravel.com/docs/quickstart) and even share some code.

## Quickstart

[Installation & Getting Started](https://friendsofadonis.github.io/docs/edgewire/introduction)

## License

[MIT licensed](LICENSE.md).
93 changes: 93 additions & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
|--------------------------------------------------------------------------
| Test runner entrypoint
|--------------------------------------------------------------------------
|
| The "test.ts" file is the entrypoint for running tests using Japa.
|
| Either you can run this file directly or use the "test"
| command to run this file and monitor file changes.
|
*/

process.env.NODE_ENV = 'test'
process.env.PORT = '3332'

import 'reflect-metadata'
import { prettyPrintError } from '@adonisjs/core'
import { configure, processCLIArgs, run } from '@japa/runner'
import { IgnitorFactory } from '@adonisjs/core/factories'
import { HttpContext } from '@adonisjs/core/http'
import edge from 'edge.js'

/**
* URL to the application root. AdonisJS need it to resolve
* paths to file and directories for scaffolding commands
*/
const APP_ROOT = new URL('../tmp', import.meta.url)

/**
* The importer is used to import files in context of the
* application.
*/
const IMPORTER = (filePath: string) => {
if (filePath.startsWith('./') || filePath.startsWith('../')) {
return import(new URL(filePath, APP_ROOT).href)
}
return import(filePath)
}

new IgnitorFactory()
.merge({
rcFileContents: {
providers: [
() => import('../providers/edgewire_provider.js'),
() => import('@adonisjs/core/providers/edge_provider'),
],
},
})
.withCoreConfig()
.withCoreProviders()
.create(APP_ROOT, { importer: IMPORTER })
.tap((app) => {
app.booting(async () => {})
app.starting(async () => {
app.config.set('edgewire.viewPath', 'viewPath')

const router = await app.container.make('router')
router.get('/edgewire/test', ({ request }: HttpContext) => {
const { name, params } = request.qs()
return edge.renderRaw(`@!edgewire('${name}')`)
})
})
app.listen('SIGTERM', () => app.terminate())
app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate())
})
.testRunner()
.configure(async (app) => {
const { runnerHooks, ...config } = await import('../tests/bootstrap.js')

processCLIArgs(process.argv.splice(2))
configure({
suites: [
{
name: 'functional',
files: ['tests/functional/**/*.spec.(js|ts)'],
},
{
name: 'unit',
files: ['tests/unit/**/*.spec.(js|ts)'],
},
],
...config,
...{
setup: runnerHooks.setup,
teardown: runnerHooks.teardown.concat([() => app.terminate()]),
},
})
})
.run(() => run())
.catch((error) => {
process.exitCode = 1
prettyPrintError(error)
})
72 changes: 72 additions & 0 deletions commands/make_edgewire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { args, BaseCommand } from '@adonisjs/core/ace'
import { CommandOptions } from '@adonisjs/core/types/ace'
import { stubsRoot } from '../stubs/main.js'
import string from '@adonisjs/core/helpers/string'
import path from 'node:path'

export default class MakeEdgewire extends BaseCommand {
static commandName = 'make:edgewire'
static description = 'Make a new Edgewire component'
static options: CommandOptions = {
startApp: true,
allowUnknownFlags: true,
}

@args.string({ description: 'Name of the migration file' })
declare name: string

async run() {
const codemods = await this.createCodemods()

const component = this.createComponent()
const view = this.createView()

await codemods.makeUsingStub(stubsRoot, 'make/edgewire/component.stub', {
component,
view,
})

await codemods.makeUsingStub(stubsRoot, 'make/edgewire/view.stub', {
component,
view,
})

const morph = await codemods.getTsMorphProject()

if (!morph) {
this.logger.warning(
'An issue occured when retrieving ts-morph. start/view.ts has not been updated'
)
return
}

const startView = morph.getSourceFileOrThrow('start/view.ts')

startView.addImportDeclaration({
moduleSpecifier: component.importPath,
defaultImport: component.className,
})

startView.addStatements(`edgewire.component('${component.name}', ${component.className})`)

await startView.save()
}

createView() {
return {
path: 'edgewire',
fileName: string.create(this.name).snakeCase().ext('.edge').toString(),
templatePath: path.join('edgewire', string.create(this.name).snakeCase().toString()),
}
}

createComponent() {
return {
path: '',
name: string.create(this.name).snakeCase().toString(),
className: string.create(this.name).pascalCase().suffix('Component').toString(),
fileName: string.create(this.name).snakeCase().ext('.ts').toString(),
importPath: ['#components', string.create(this.name).snakeCase().toString()].join('/'),
}
}
}
Loading

0 comments on commit dd67a84

Please sign in to comment.