diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a61a3ab --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 2 + +[*.{diff,md}] +trim_trailing_whitespace = false + +[*.{php,xml,json}] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..71b028f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,20 @@ +**/.gitattributes export-ignore +**/.gitignore export-ignore +**/.gitmodules export-ignore +**/.github export-ignore +**/.travis export-ignore +**/.travis.yml export-ignore +**/.editorconfig export-ignore +**/.styleci.yml export-ignore + +**/phpunit.xml export-ignore +**/tests export-ignore + +**/js/dist/**/* -diff +**/js/dist/**/* linguist-generated +**/js/dist-typings/**/* -diff +**/js/dist-typings/**/* linguist-generated +**/js/yarn.lock -diff +**/js/package-lock.json -diff + +* text=auto eol=lf diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..b0d3c20 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,11 @@ +name: OAuth Center PHP + +on: [workflow_dispatch, push, pull_request] + +jobs: + run: + uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main + with: + enable_backend_testing: true + + backend_directory: . diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..e3e40f5 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,18 @@ +name: OAuth Center JS + +on: [workflow_dispatch, push, pull_request] + +jobs: + run: + uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main + with: + enable_bundlewatch: false + enable_prettier: true + enable_typescript: true + + frontend_directory: ./js + backend_directory: . + js_package_manager: npm + main_git_branch: main + secrets: + bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ebb168 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +/vendor +composer.lock +composer.phar + +.DS_Store +Thumbs.db +tests/.phpunit.result.cache +/tests/integration/tmp +.vagrant +.idea/* +.vscode +js/coverage-ts diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..8806a54 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,14 @@ +preset: recommended + +enabled: + - logical_not_operators_with_successor_space + +disabled: + - align_double_arrow + - blank_line_after_opening_tag + - multiline_array_trailing_comma + - new_with_braces + - phpdoc_align + - phpdoc_order + - phpdoc_separation + - phpdoc_types diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a0296d --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# OAuth Center + +![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/foskym/flarum-oauth-center.svg)](https://packagist.org/packages/foskym/flarum-oauth-center) [![Total Downloads](https://img.shields.io/packagist/dt/foskym/flarum-oauth-center.svg)](https://packagist.org/packages/foskym/flarum-oauth-center) + +A [Flarum](http://flarum.org) extension. Allow user to authorize the third clients + +## Installation + +Install with composer: + +```sh +composer require foskym/flarum-oauth-center:"*" +``` + +## Updating + +```sh +composer update foskym/flarum-oauth-center:"*" +php flarum migrate +php flarum cache:clear +``` + +## Links + +- [Packagist](https://packagist.org/packages/foskym/flarum-oauth-center) +- [GitHub](https://github.com/foskym/flarum-oauth-center) +- [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..11c5858 --- /dev/null +++ b/composer.json @@ -0,0 +1,82 @@ +{ + "name": "foskym/flarum-oauth-center", + "description": "Allow user to authorize the third clients", + "keywords": [ + "flarum", + "user", + "oauth", + "center" + ], + "type": "flarum-extension", + "license": "MIT", + "require": { + "flarum/core": "^1.2.0" + }, + "authors": [ + { + "name": "FoskyM", + "email": "i@fosky.top", + "role": "Developer", + "homepage": "https://fosky.top" + } + ], + "autoload": { + "psr-4": { + "FoskyM\\OAuthCenter\\": "src/" + } + }, + "extra": { + "flarum-extension": { + "title": "OAuth Center", + "category": "", + "icon": { + "name": "fas fa-user-friends", + "color": "#fff", + "backgroundColor": "#c12c1f" + } + }, + "flarum-cli": { + "modules": { + "admin": true, + "forum": true, + "js": true, + "jsCommon": true, + "css": true, + "locale": true, + "gitConf": true, + "githubActions": true, + "prettier": true, + "typescript": true, + "bundlewatch": false, + "backendTesting": true, + "editorConfig": true, + "styleci": true + } + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "autoload-dev": { + "psr-4": { + "FoskyM\\OAuthCenter\\Tests\\": "tests/" + } + }, + "scripts": { + "test": [ + "@test:unit", + "@test:integration" + ], + "test:unit": "phpunit -c tests/phpunit.unit.xml", + "test:integration": "phpunit -c tests/phpunit.integration.xml", + "test:setup": "@php tests/integration/setup.php" + }, + "scripts-descriptions": { + "test": "Runs all tests.", + "test:unit": "Runs all unit tests.", + "test:integration": "Runs all integration tests.", + "test:setup": "Sets up a database for use with integration tests. Execute this only once." + }, + "require-dev": { + "flarum/testing": "^1.0.0" + } +} diff --git a/extend.php b/extend.php new file mode 100644 index 0000000..d2e6144 --- /dev/null +++ b/extend.php @@ -0,0 +1,24 @@ +js(__DIR__.'/js/dist/forum.js') + ->css(__DIR__.'/less/forum.less'), + (new Extend\Frontend('admin')) + ->js(__DIR__.'/js/dist/admin.js') + ->css(__DIR__.'/less/admin.less'), + new Extend\Locales(__DIR__.'/locale'), +]; diff --git a/js/.gitignore b/js/.gitignore new file mode 100644 index 0000000..adc90f3 --- /dev/null +++ b/js/.gitignore @@ -0,0 +1,9 @@ +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions + +node_modules diff --git a/js/admin.ts b/js/admin.ts new file mode 100644 index 0000000..1f9e14a --- /dev/null +++ b/js/admin.ts @@ -0,0 +1,2 @@ +export * from './src/common'; +export * from './src/admin'; diff --git a/js/forum.ts b/js/forum.ts new file mode 100644 index 0000000..f49b871 --- /dev/null +++ b/js/forum.ts @@ -0,0 +1,2 @@ +export * from './src/common'; +export * from './src/forum'; diff --git a/js/package.json b/js/package.json new file mode 100644 index 0000000..bda04ef --- /dev/null +++ b/js/package.json @@ -0,0 +1,28 @@ +{ + "name": "@foskym/flarum-oauth-center", + "private": true, + "version": "0.0.0", + "devDependencies": { + "flarum-webpack-config": "^2.0.0", + "webpack": "^5.65.0", + "webpack-cli": "^4.9.1", + "prettier": "^2.5.1", + "@flarum/prettier-config": "^1.0.0", + "flarum-tsconfig": "^1.0.2", + "typescript": "^4.5.4", + "typescript-coverage-report": "^0.6.1" + }, + "scripts": { + "dev": "webpack --mode development --watch", + "build": "webpack --mode production", + "analyze": "cross-env ANALYZER=true npm run build", + "format": "prettier --write src", + "format-check": "prettier --check src", + "clean-typings": "npx rimraf dist-typings && mkdir dist-typings", + "build-typings": "npm run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && npm run post-build-typings", + "post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'", + "check-typings": "tsc --noEmit --emitDeclarationOnly false", + "check-typings-coverage": "typescript-coverage-report" + }, + "prettier": "@flarum/prettier-config" +} diff --git a/js/src/admin/index.ts b/js/src/admin/index.ts new file mode 100644 index 0000000..e0cf37b --- /dev/null +++ b/js/src/admin/index.ts @@ -0,0 +1,5 @@ +import app from 'flarum/admin/app'; + +app.initializers.add('foskym/flarum-oauth-center', () => { + console.log('[foskym/flarum-oauth-center] Hello, admin!'); +}); diff --git a/js/src/common/index.ts b/js/src/common/index.ts new file mode 100644 index 0000000..6e6e9c1 --- /dev/null +++ b/js/src/common/index.ts @@ -0,0 +1,5 @@ +import app from 'flarum/common/app'; + +app.initializers.add('foskym/flarum-oauth-center', () => { + console.log('[foskym/flarum-oauth-center] Hello, forum and admin!'); +}); diff --git a/js/src/forum/index.ts b/js/src/forum/index.ts new file mode 100644 index 0000000..9cc94df --- /dev/null +++ b/js/src/forum/index.ts @@ -0,0 +1,5 @@ +import app from 'flarum/forum/app'; + +app.initializers.add('foskym/flarum-oauth-center', () => { + console.log('[foskym/flarum-oauth-center] Hello, forum!'); +}); diff --git a/js/tsconfig.json b/js/tsconfig.json new file mode 100644 index 0000000..504f800 --- /dev/null +++ b/js/tsconfig.json @@ -0,0 +1,24 @@ +{ + // Use Flarum's tsconfig as a starting point + "extends": "flarum-tsconfig", + // This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder + // and also tells your Typescript server to read core's global typings for + // access to `dayjs` and `$` in the global namespace. + "include": [ + "src/**/*", + "../vendor/*/*/js/dist-typings/@types/**/*", +// +// + "@types/**/*" +], + "compilerOptions": { + // This will output typings to `dist-typings` + "declarationDir": "./dist-typings", + "baseUrl": ".", + "paths": { + "flarum/*": ["../vendor/flarum/core/js/dist-typings/*"], +// +// + } + } +} diff --git a/js/webpack.config.js b/js/webpack.config.js new file mode 100644 index 0000000..ef35ea0 --- /dev/null +++ b/js/webpack.config.js @@ -0,0 +1 @@ +module.exports = require('flarum-webpack-config')(); diff --git a/less/admin.less b/less/admin.less new file mode 100644 index 0000000..e69de29 diff --git a/less/forum.less b/less/forum.less new file mode 100644 index 0000000..e69de29 diff --git a/locale/en.yml b/locale/en.yml new file mode 100644 index 0000000..438e1c2 --- /dev/null +++ b/locale/en.yml @@ -0,0 +1,7 @@ +foskym-oauth-center: + # For more details on the format + # Checkout https://docs.flarum.org/extend/i18n/#appendix-a-standard-key-format + admin: + my_cool_key: My Cool Key + + forum: diff --git a/tests/fixtures/.gitkeep b/tests/fixtures/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/setup.php b/tests/integration/setup.php new file mode 100644 index 0000000..67039c0 --- /dev/null +++ b/tests/integration/setup.php @@ -0,0 +1,16 @@ +run(); diff --git a/tests/phpunit.integration.xml b/tests/phpunit.integration.xml new file mode 100644 index 0000000..90fbbff --- /dev/null +++ b/tests/phpunit.integration.xml @@ -0,0 +1,25 @@ + + + + + ../src/ + + + + + ./integration + ./integration/tmp + + + diff --git a/tests/phpunit.unit.xml b/tests/phpunit.unit.xml new file mode 100644 index 0000000..d3a4a3e --- /dev/null +++ b/tests/phpunit.unit.xml @@ -0,0 +1,27 @@ + + + + + ../src/ + + + + + ./unit + + + + + + diff --git a/tests/unit/.gitkeep b/tests/unit/.gitkeep new file mode 100644 index 0000000..e69de29