Skip to content

Commit d452303

Browse files
authored
chore: Flarum 2.0 compatibility (#1)
* chore(2.0): update dependencies Update dependencies to Flarum 2.0 compatible versions. * chore(2.0): update infrastructure Update the extension infrastructure * chore(2.0): remove compat API The compat API has been removed. Modules from extensions are now automatically accessible from other extensions using the format ext:vendor/extension/module-path. * chore(2.0): misc frontend changes Miscellaneous frontend changes * chore(2.0): misc backend changes Miscellaneous backend changes * chore(2.0): `LESS` code changes Many variables have been renamed to light/dark specific names and most are now used as CSS variables instead. * chore: 2.0 upgrade * chore: update README
1 parent b508444 commit d452303

File tree

21 files changed

+234
-190
lines changed

21 files changed

+234
-190
lines changed

.github/workflows/backend.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ on: [workflow_dispatch, push, pull_request]
44

55
jobs:
66
run:
7-
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
7+
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@2.x
88
with:
99
enable_backend_testing: false
1010
enable_phpstan: true
11-
php_versions: '["8.2", "8.3", "8.4", "8.5"]'
1211

1312
backend_directory: .

.github/workflows/frontend.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [workflow_dispatch, push, pull_request]
44

55
jobs:
66
run:
7-
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
7+
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@2.x
88
with:
99
enable_bundlewatch: false
1010
enable_prettier: true
@@ -13,7 +13,7 @@ jobs:
1313
frontend_directory: ./js
1414
backend_directory: .
1515
js_package_manager: yarn
16-
main_git_branch: 1.x
16+
main_git_branch: 2.x
1717

1818
secrets:
1919
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Extension developers wanting to create widgets with this small framework, the fo
5555
2. Create your widget's component in `common/components` by extending the base `Widget` component:
5656

5757
```jsx
58-
import Widget from 'flarum/extensions/fof-forum-widgets-core/common/components/Widget';
58+
import Widget from 'ext:fof/forum-widgets-core/common/components/Widget';
5959

6060
export default class MyWidget extends Widget {
6161
className() {
@@ -81,7 +81,7 @@ export default class MyWidget extends Widget {
8181
3. Register your widget in both frontends. Create `common/registerWidget.js`:
8282

8383
```js
84-
import Widgets from 'flarum/extensions/fof-forum-widgets-core/common/extend/Widgets';
84+
import Widgets from 'ext:fof/forum-widgets-core/common/extend/Widgets';
8585
import MyWidget from './components/MyWidget';
8686

8787
export default function (app) {
@@ -114,7 +114,7 @@ app.initializers.add('my-extension-id', () => {
114114
4. For TypeScript, add this to the `paths` key in your `tsconfig.json`:
115115

116116
```json
117-
"flarum/extensions/fof-forum-widgets-core/*": ["../vendor/fof/forum-widgets-core/js/dist-typings/*"]
117+
"ext:fof/forum-widgets-core/*": ["../vendor/fof/forum-widgets-core/js/dist-typings/*"]
118118
```
119119

120120
## Links

composer.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"name": "fof/forum-widgets-core",
33
"description": "Core Extension for Managing Forum Widgets",
44
"keywords": [
5-
"flarum", "widgets", "framework", "core"
5+
"flarum",
6+
"widgets",
7+
"framework",
8+
"core"
69
],
710
"type": "flarum-extension",
811
"license": "MIT",
@@ -28,21 +31,22 @@
2831
"afrux/forum-widgets-core": "*"
2932
},
3033
"require": {
31-
"php": "^8.2",
32-
"flarum/core": "^1.8"
34+
"flarum/core": "^2.0.0"
3335
},
3436
"require-dev": {
35-
"flarum/phpstan": "*"
37+
"flarum/phpstan": "^2.0.0"
3638
},
3739
"autoload": {
3840
"psr-4": {
3941
"FoF\\ForumWidgets\\": "src/"
4042
},
41-
"files": ["src/helpers.php"]
43+
"files": [
44+
"src/helpers.php"
45+
]
4246
},
4347
"extra": {
4448
"branch-alias": {
45-
"dev-1.x": "1.x-dev"
49+
"dev-2.x": "2.x-dev"
4650
},
4751
"flarum-extension": {
4852
"title": "FoF Widgets Core",
@@ -63,5 +67,7 @@
6367
},
6468
"scripts-descriptions": {
6569
"analyse:phpstan": "Run static analysis"
66-
}
70+
},
71+
"minimum-stability": "beta",
72+
"prefer-stable": true
6773
}

js/package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
"@flarum/prettier-config": "^1.0.0",
1111
"webpack": "^5.0",
1212
"webpack-cli": "^4.0",
13-
"flarum-webpack-config": "^2.0.0",
13+
"flarum-webpack-config": "^3.0.0",
1414
"@types/sortablejs": "^1.10.7",
1515
"bundlewatch": "^0.3.2",
1616
"prettier": "^3.0.3",
17-
"flarum-tsconfig": "^1.0.2",
17+
"flarum-tsconfig": "^2.0.0",
1818
"typescript": "^4.5.4",
1919
"typescript-coverage-report": "^0.6.1"
2020
},
2121
"scripts": {
22-
"dev": "webpack --mode development --watch",
23-
"build": "webpack --mode production",
24-
"analyze": "cross-env ANALYZER=true npm run build",
25-
"format": "prettier --write src",
26-
"format-check": "prettier --check src",
27-
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
28-
"build-typings": "npm run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && npm run post-build-typings",
29-
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' 's,../src/@types,@types,g'",
30-
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
31-
"check-typings-coverage": "typescript-coverage-report"
32-
}
22+
"dev": "webpack --mode development --watch",
23+
"build": "webpack --mode production",
24+
"analyze": "cross-env ANALYZER=true npm run build",
25+
"format": "prettier --write src",
26+
"format-check": "prettier --check src",
27+
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
28+
"build-typings": "npm run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && npm run post-build-typings",
29+
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' 's,../src/@types,@types,g'",
30+
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
31+
"check-typings-coverage": "typescript-coverage-report"
32+
}
3333
}

js/src/admin/admin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../common/common';

js/src/admin/compat.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

js/src/admin/components/WidgetEditor.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import Form from 'flarum/common/components/Form';
12
import app from 'flarum/admin/app';
23
import sortable from 'sortablejs';
34
import type Mithril from 'mithril';
45
import ExtensionPage, { ExtensionPageAttrs } from 'flarum/admin/components/ExtensionPage';
5-
import icon from 'flarum/common/helpers/icon';
6+
import Icon from 'flarum/common/components/Icon';
67

78
import sortWidgets from '../../common/utils/sortWidgets';
89
import type { Widget } from '../../common/extend/Widgets';
@@ -30,19 +31,19 @@ export default class WidgetEditor extends ExtensionPage<WidgetEditorAttrs> {
3031
}
3132

3233
content() {
33-
const settings = app.extensionData.getSettings(this.extension.id);
34+
const settings = app.registry.getSettings(this.extension.id);
3435

3536
return (
3637
<div className="ExtensionPage-settings">
3738
<div className="container">
3839
{!app.data['fof-forum-widgets-core.cache_store_writable'] ? (
3940
<Alert type="error">{app.translator.trans('fof-forum-widgets-core.admin.cache_not_writable_warning')}</Alert>
4041
) : null}
41-
<div className="Form">
42+
<Form>
4243
<div className="Form-group">{this.editor()}</div>
4344
{settings ? settings.map(this.buildSettingComponent.bind(this)) : null}
4445
<div className="Form-group">{this.submitButton()}</div>
45-
</div>
46+
</Form>
4647
</div>
4748
</div>
4849
);
@@ -206,7 +207,7 @@ export default class WidgetEditor extends ExtensionPage<WidgetEditorAttrs> {
206207
<div className="FoF-ForumWidgets-Widget-container">
207208
<div className="FoF-ForumWidgets-Widget">
208209
<span className="FoF-ForumWidgets-Widget-icon ExtensionIcon" style={extension.icon}>
209-
{extension.icon ? icon(extension.icon.name) : ''}
210+
{extension.icon ? <Icon name={extension.icon.name} /> : ''}
210211
</span>
211212
<span className="FoF-ForumWidgets-Widget-title">{extension.extra['flarum-extension'].title}</span>
212213
</div>

js/src/admin/extend.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import app from 'flarum/admin/app';
2+
import Extend from 'flarum/common/extenders';
3+
import WidgetEditor from './components/WidgetEditor';
4+
5+
export default [
6+
new Extend.Admin() //
7+
.page(WidgetEditor)
8+
.setting(() => ({
9+
setting: 'fof-forum-widgets-core.prefer_data_with_initial_load',
10+
label: app.translator.trans('fof-forum-widgets-core.admin.settings.prefer_data_with_initial_load'),
11+
help: app.translator.trans('fof-forum-widgets-core.admin.settings.prefer_data_with_initial_load_help'),
12+
type: 'boolean',
13+
})),
14+
];

js/src/admin/index.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
import app from 'flarum/admin/app';
22
import WidgetManager from '../common/WidgetManager';
3-
import WidgetEditor from './components/WidgetEditor';
3+
4+
export { default as extend } from './extend';
45

56
app.widgets = new WidgetManager();
67

78
app.initializers.add('fof/forum-widgets-core', () => {
8-
app.extensionData
9-
.for('fof-forum-widgets-core')
10-
.registerSetting({
11-
setting: 'fof-forum-widgets-core.prefer_data_with_initial_load',
12-
label: app.translator.trans('fof-forum-widgets-core.admin.settings.prefer_data_with_initial_load'),
13-
help: app.translator.trans('fof-forum-widgets-core.admin.settings.prefer_data_with_initial_load_help'),
14-
type: 'boolean',
15-
})
16-
.registerPage(WidgetEditor);
9+
// Nothing to do here yet.
1710
});
1811

19-
// Expose compat API
20-
import customCompat from './compat';
12+
// Allow flarum to discover modules
13+
import './admin';
2114
// @ts-ignore
22-
import { compat } from '@flarum/core/admin';
23-
24-
Object.assign(compat, customCompat);

0 commit comments

Comments
 (0)