mirror of
https://github.com/flarum/framework.git
synced 2024-11-23 11:24:37 +08:00
Webpack (#14)
See https://github.com/flarum/core/pull/1367 * Replace gulp with webpack and npm scripts for JS compilation * Set up Travis CI to commit compiled JS * Restructure `js` directory; only one instance of npm, forum/admin are "submodules" * Restructure `less` directory
This commit is contained in:
parent
d8a8c34503
commit
990cae94cb
BIN
extensions/lock/.deploy.enc
Normal file
BIN
extensions/lock/.deploy.enc
Normal file
Binary file not shown.
2
extensions/lock/.gitattributes
vendored
2
extensions/lock/.gitattributes
vendored
|
@ -2,4 +2,4 @@
|
|||
.gitignore export-ignore
|
||||
.travis.yml export-ignore
|
||||
|
||||
js/*/dist/*.js -diff
|
||||
js/dist/* -diff
|
||||
|
|
4
extensions/lock/.gitignore
vendored
4
extensions/lock/.gitignore
vendored
|
@ -2,5 +2,5 @@
|
|||
composer.phar
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
bower_components
|
||||
node_modules
|
||||
node_modules
|
||||
js/dist/*
|
||||
|
|
15
extensions/lock/.travis.yml
Normal file
15
extensions/lock/.travis.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
language: minimal
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.npm
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: build
|
||||
if: branch = master AND type = push
|
||||
script: curl -s https://raw.githubusercontent.com/flarum/core/master/.travis/build.sh | bash -s -
|
||||
-k $encrypted_1f8bf19c48b3_key
|
||||
-i $encrypted_1f8bf19c48b3_iv
|
|
@ -16,12 +16,12 @@ use Illuminate\Contracts\Events\Dispatcher;
|
|||
|
||||
return [
|
||||
(new Extend\Assets('forum'))
|
||||
->asset(__DIR__.'/js/forum/dist/extension.js')
|
||||
->asset(__DIR__.'/less/forum/extension.less')
|
||||
->bootstrapper('flarum/lock/main'),
|
||||
->js(__DIR__.'/js/dist/forum.js')
|
||||
->asset(__DIR__.'/less/forum.less'),
|
||||
|
||||
(new Extend\Assets('admin'))
|
||||
->asset(__DIR__.'/js/admin/dist/extension.js')
|
||||
->bootstrapper('flarum/lock/main'),
|
||||
->js(__DIR__.'/js/dist/admin.js'),
|
||||
|
||||
function (Dispatcher $events) {
|
||||
$events->subscribe(Listener\AddDiscussionLockedAttributes::class);
|
||||
$events->subscribe(Listener\AddLockedGambit::class);
|
||||
|
|
10
extensions/lock/js/admin.js
Normal file
10
extensions/lock/js/admin.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
export * from './src/admin';
|
|
@ -1,7 +0,0 @@
|
|||
var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'flarum/lock': 'src/**/*.js'
|
||||
}
|
||||
});
|
28
extensions/lock/js/admin/dist/extension.js
vendored
28
extensions/lock/js/admin/dist/extension.js
vendored
|
@ -1,28 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
System.register('flarum/lock/main', ['flarum/extend', 'flarum/app', 'flarum/components/PermissionGrid'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, app, PermissionGrid;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp.default;
|
||||
}, function (_flarumComponentsPermissionGrid) {
|
||||
PermissionGrid = _flarumComponentsPermissionGrid.default;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('lock', function () {
|
||||
extend(PermissionGrid.prototype, 'moderateItems', function (items) {
|
||||
items.add('lock', {
|
||||
icon: 'lock',
|
||||
label: app.translator.trans('flarum-lock.admin.permissions.lock_discussions_label'),
|
||||
permission: 'discussion.lock'
|
||||
}, 95);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.1",
|
||||
"flarum-gulp": "^0.2.0"
|
||||
}
|
||||
}
|
10
extensions/lock/js/forum.js
Normal file
10
extensions/lock/js/forum.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
export * from './src/forum';
|
|
@ -1,7 +0,0 @@
|
|||
var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'flarum/lock': 'src/**/*.js'
|
||||
}
|
||||
});
|
204
extensions/lock/js/forum/dist/extension.js
vendored
204
extensions/lock/js/forum/dist/extension.js
vendored
|
@ -1,204 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
System.register('flarum/lock/addLockBadge', ['flarum/extend', 'flarum/models/Discussion', 'flarum/components/Badge'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, Discussion, Badge;
|
||||
function addLockBadge() {
|
||||
extend(Discussion.prototype, 'badges', function (badges) {
|
||||
if (this.isLocked()) {
|
||||
badges.add('locked', Badge.component({
|
||||
type: 'locked',
|
||||
label: app.translator.trans('flarum-lock.forum.badge.locked_tooltip'),
|
||||
icon: 'lock'
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_export('default', addLockBadge);
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumModelsDiscussion) {
|
||||
Discussion = _flarumModelsDiscussion.default;
|
||||
}, function (_flarumComponentsBadge) {
|
||||
Badge = _flarumComponentsBadge.default;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/lock/addLockControl', ['flarum/extend', 'flarum/utils/DiscussionControls', 'flarum/components/DiscussionPage', 'flarum/components/Button'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, DiscussionControls, DiscussionPage, Button;
|
||||
function addLockControl() {
|
||||
extend(DiscussionControls, 'moderationControls', function (items, discussion) {
|
||||
if (discussion.canLock()) {
|
||||
items.add('lock', Button.component({
|
||||
children: app.translator.trans(discussion.isLocked() ? 'flarum-lock.forum.discussion_controls.unlock_button' : 'flarum-lock.forum.discussion_controls.lock_button'),
|
||||
icon: 'lock',
|
||||
onclick: this.lockAction.bind(discussion)
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
DiscussionControls.lockAction = function () {
|
||||
this.save({ isLocked: !this.isLocked() }).then(function () {
|
||||
if (app.current instanceof DiscussionPage) {
|
||||
app.current.stream.update();
|
||||
}
|
||||
|
||||
m.redraw();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
_export('default', addLockControl);
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumUtilsDiscussionControls) {
|
||||
DiscussionControls = _flarumUtilsDiscussionControls.default;
|
||||
}, function (_flarumComponentsDiscussionPage) {
|
||||
DiscussionPage = _flarumComponentsDiscussionPage.default;
|
||||
}, function (_flarumComponentsButton) {
|
||||
Button = _flarumComponentsButton.default;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/lock/components/DiscussionLockedNotification', ['flarum/components/Notification'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var Notification, DiscussionLockedNotification;
|
||||
return {
|
||||
setters: [function (_flarumComponentsNotification) {
|
||||
Notification = _flarumComponentsNotification.default;
|
||||
}],
|
||||
execute: function () {
|
||||
DiscussionLockedNotification = function (_Notification) {
|
||||
babelHelpers.inherits(DiscussionLockedNotification, _Notification);
|
||||
|
||||
function DiscussionLockedNotification() {
|
||||
babelHelpers.classCallCheck(this, DiscussionLockedNotification);
|
||||
return babelHelpers.possibleConstructorReturn(this, (DiscussionLockedNotification.__proto__ || Object.getPrototypeOf(DiscussionLockedNotification)).apply(this, arguments));
|
||||
}
|
||||
|
||||
babelHelpers.createClass(DiscussionLockedNotification, [{
|
||||
key: 'icon',
|
||||
value: function icon() {
|
||||
return 'lock';
|
||||
}
|
||||
}, {
|
||||
key: 'href',
|
||||
value: function href() {
|
||||
var notification = this.props.notification;
|
||||
|
||||
return app.route.discussion(notification.subject(), notification.content().postNumber);
|
||||
}
|
||||
}, {
|
||||
key: 'content',
|
||||
value: function content() {
|
||||
return app.translator.trans('flarum-lock.forum.notifications.discussion_locked_text', { user: this.props.notification.sender() });
|
||||
}
|
||||
}]);
|
||||
return DiscussionLockedNotification;
|
||||
}(Notification);
|
||||
|
||||
_export('default', DiscussionLockedNotification);
|
||||
}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/lock/components/DiscussionLockedPost', ['flarum/components/EventPost'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var EventPost, DiscussionLockedPost;
|
||||
return {
|
||||
setters: [function (_flarumComponentsEventPost) {
|
||||
EventPost = _flarumComponentsEventPost.default;
|
||||
}],
|
||||
execute: function () {
|
||||
DiscussionLockedPost = function (_EventPost) {
|
||||
babelHelpers.inherits(DiscussionLockedPost, _EventPost);
|
||||
|
||||
function DiscussionLockedPost() {
|
||||
babelHelpers.classCallCheck(this, DiscussionLockedPost);
|
||||
return babelHelpers.possibleConstructorReturn(this, (DiscussionLockedPost.__proto__ || Object.getPrototypeOf(DiscussionLockedPost)).apply(this, arguments));
|
||||
}
|
||||
|
||||
babelHelpers.createClass(DiscussionLockedPost, [{
|
||||
key: 'icon',
|
||||
value: function icon() {
|
||||
return this.props.post.content().locked ? 'lock' : 'unlock';
|
||||
}
|
||||
}, {
|
||||
key: 'descriptionKey',
|
||||
value: function descriptionKey() {
|
||||
return this.props.post.content().locked ? 'flarum-lock.forum.post_stream.discussion_locked_text' : 'flarum-lock.forum.post_stream.discussion_unlocked_text';
|
||||
}
|
||||
}]);
|
||||
return DiscussionLockedPost;
|
||||
}(EventPost);
|
||||
|
||||
_export('default', DiscussionLockedPost);
|
||||
}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/lock/main', ['flarum/extend', 'flarum/app', 'flarum/Model', 'flarum/models/Discussion', 'flarum/components/NotificationGrid', 'flarum/lock/components/DiscussionLockedPost', 'flarum/lock/components/DiscussionLockedNotification', 'flarum/lock/addLockBadge', 'flarum/lock/addLockControl'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, app, Model, Discussion, NotificationGrid, DiscussionLockedPost, DiscussionLockedNotification, addLockBadge, addLockControl;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp.default;
|
||||
}, function (_flarumModel) {
|
||||
Model = _flarumModel.default;
|
||||
}, function (_flarumModelsDiscussion) {
|
||||
Discussion = _flarumModelsDiscussion.default;
|
||||
}, function (_flarumComponentsNotificationGrid) {
|
||||
NotificationGrid = _flarumComponentsNotificationGrid.default;
|
||||
}, function (_flarumLockComponentsDiscussionLockedPost) {
|
||||
DiscussionLockedPost = _flarumLockComponentsDiscussionLockedPost.default;
|
||||
}, function (_flarumLockComponentsDiscussionLockedNotification) {
|
||||
DiscussionLockedNotification = _flarumLockComponentsDiscussionLockedNotification.default;
|
||||
}, function (_flarumLockAddLockBadge) {
|
||||
addLockBadge = _flarumLockAddLockBadge.default;
|
||||
}, function (_flarumLockAddLockControl) {
|
||||
addLockControl = _flarumLockAddLockControl.default;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('flarum-lock', function () {
|
||||
app.postComponents.discussionLocked = DiscussionLockedPost;
|
||||
app.notificationComponents.discussionLocked = DiscussionLockedNotification;
|
||||
|
||||
Discussion.prototype.isLocked = Model.attribute('isLocked');
|
||||
Discussion.prototype.canLock = Model.attribute('canLock');
|
||||
|
||||
addLockBadge();
|
||||
addLockControl();
|
||||
|
||||
extend(NotificationGrid.prototype, 'notificationTypes', function (items) {
|
||||
items.add('discussionLocked', {
|
||||
name: 'discussionLocked',
|
||||
icon: 'lock',
|
||||
label: app.translator.trans('flarum-lock.forum.settings.notify_discussion_locked_label')
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.1",
|
||||
"flarum-gulp": "^0.2.0"
|
||||
}
|
||||
}
|
4695
extensions/lock/js/package-lock.json
generated
Normal file
4695
extensions/lock/js/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
extensions/lock/js/package.json
Normal file
13
extensions/lock/js/package.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@flarum/flarum-ext-lock",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"flarum-webpack-config": "^0.1.0-beta.8",
|
||||
"webpack": "^4.0.0",
|
||||
"webpack-cli": "^3.0.7"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "webpack --mode production --progress",
|
||||
"watch": "webpack --mode development --watch"
|
||||
}
|
||||
}
|
|
@ -4,10 +4,10 @@ import Model from 'flarum/Model';
|
|||
import Discussion from 'flarum/models/Discussion';
|
||||
import NotificationGrid from 'flarum/components/NotificationGrid';
|
||||
|
||||
import DiscussionLockedPost from 'flarum/lock/components/DiscussionLockedPost';
|
||||
import DiscussionLockedNotification from 'flarum/lock/components/DiscussionLockedNotification';
|
||||
import addLockBadge from 'flarum/lock/addLockBadge';
|
||||
import addLockControl from 'flarum/lock/addLockControl';
|
||||
import DiscussionLockedPost from './components/DiscussionLockedPost';
|
||||
import DiscussionLockedNotification from './components/DiscussionLockedNotification';
|
||||
import addLockBadge from './addLockBadge';
|
||||
import addLockControl from './addLockControl';
|
||||
|
||||
app.initializers.add('flarum-lock', () => {
|
||||
app.postComponents.discussionLocked = DiscussionLockedPost;
|
3
extensions/lock/js/webpack.config.js
Normal file
3
extensions/lock/js/webpack.config.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
const config = require('flarum-webpack-config');
|
||||
|
||||
module.exports = config();
|
|
@ -1,6 +1,3 @@
|
|||
.Badge--locked {
|
||||
background: #888;
|
||||
}
|
||||
.DiscussionLockedPost {
|
||||
.EventPost-icon,
|
||||
.EventPost-info,
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script compiles the extension so that it can be used in a Flarum
|
||||
# installation. It should be run from the root directory of the extension.
|
||||
|
||||
base=$PWD
|
||||
|
||||
cd "${base}/js"
|
||||
|
||||
if [ -f bower.json ]; then
|
||||
bower install
|
||||
fi
|
||||
|
||||
for app in forum admin; do
|
||||
cd "${base}/js"
|
||||
|
||||
if [ -d $app ]; then
|
||||
cd $app
|
||||
|
||||
if [ -f bower.json ]; then
|
||||
bower install
|
||||
fi
|
||||
|
||||
npm install
|
||||
gulp --production
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user