mirror of
https://github.com/flarum/framework.git
synced 2025-01-31 17:26:16 +08:00
Webpack (#10)
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
27ea2f82f8
commit
70f2b63bf5
BIN
extensions/sticky/.deploy.enc
Normal file
BIN
extensions/sticky/.deploy.enc
Normal file
Binary file not shown.
2
extensions/sticky/.gitattributes
vendored
2
extensions/sticky/.gitattributes
vendored
|
@ -2,4 +2,4 @@
|
|||
.gitignore export-ignore
|
||||
.travis.yml export-ignore
|
||||
|
||||
js/*/dist/*.js -diff
|
||||
js/dist/* -diff
|
||||
|
|
2
extensions/sticky/.gitignore
vendored
2
extensions/sticky/.gitignore
vendored
|
@ -3,4 +3,4 @@ composer.phar
|
|||
.DS_Store
|
||||
Thumbs.db
|
||||
node_modules
|
||||
bower_components
|
||||
js/dist/*
|
||||
|
|
15
extensions/sticky/.travis.yml
Normal file
15
extensions/sticky/.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_1695d3919056_key
|
||||
-i $encrypted_1695d3919056_iv
|
|
@ -15,12 +15,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/sticky/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/sticky/main'),
|
||||
->js(__DIR__.'/js/dist/admin.js'),
|
||||
|
||||
function (Dispatcher $events) {
|
||||
$events->subscribe(Listener\AddApiAttributes::class);
|
||||
$events->subscribe(Listener\CreatePostWhenDiscussionIsStickied::class);
|
||||
|
|
10
extensions/sticky/js/admin.js
Normal file
10
extensions/sticky/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/sticky': 'src/**/*.js'
|
||||
}
|
||||
});
|
28
extensions/sticky/js/admin/dist/extension.js
vendored
28
extensions/sticky/js/admin/dist/extension.js
vendored
|
@ -1,28 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
System.register('flarum/sticky/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('flarum-sticky', function () {
|
||||
extend(PermissionGrid.prototype, 'moderateItems', function (items) {
|
||||
items.add('sticky', {
|
||||
icon: 'thumb-tack',
|
||||
label: app.translator.trans('flarum-sticky.admin.permissions.sticky_discussions_label'),
|
||||
permission: 'discussion.sticky'
|
||||
}, 95);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.1",
|
||||
"flarum-gulp": "^0.2.0"
|
||||
}
|
||||
}
|
10
extensions/sticky/js/forum.js
Normal file
10
extensions/sticky/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/sticky': 'src/**/*.js'
|
||||
}
|
||||
});
|
189
extensions/sticky/js/forum/dist/extension.js
vendored
189
extensions/sticky/js/forum/dist/extension.js
vendored
|
@ -1,189 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
System.register('flarum/sticky/addStickyBadge', ['flarum/extend', 'flarum/models/Discussion', 'flarum/components/Badge'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, Discussion, Badge;
|
||||
function addStickyBadge() {
|
||||
extend(Discussion.prototype, 'badges', function (badges) {
|
||||
if (this.isSticky()) {
|
||||
badges.add('sticky', Badge.component({
|
||||
type: 'sticky',
|
||||
label: app.translator.trans('flarum-sticky.forum.badge.sticky_tooltip'),
|
||||
icon: 'thumb-tack'
|
||||
}), 10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_export('default', addStickyBadge);
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumModelsDiscussion) {
|
||||
Discussion = _flarumModelsDiscussion.default;
|
||||
}, function (_flarumComponentsBadge) {
|
||||
Badge = _flarumComponentsBadge.default;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/sticky/addStickyControl', ['flarum/extend', 'flarum/utils/DiscussionControls', 'flarum/components/DiscussionPage', 'flarum/components/Button'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, DiscussionControls, DiscussionPage, Button;
|
||||
function addStickyControl() {
|
||||
extend(DiscussionControls, 'moderationControls', function (items, discussion) {
|
||||
if (discussion.canSticky()) {
|
||||
items.add('sticky', Button.component({
|
||||
children: app.translator.trans(discussion.isSticky() ? 'flarum-sticky.forum.discussion_controls.unsticky_button' : 'flarum-sticky.forum.discussion_controls.sticky_button'),
|
||||
icon: 'thumb-tack',
|
||||
onclick: this.stickyAction.bind(discussion)
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
DiscussionControls.stickyAction = function () {
|
||||
this.save({ isSticky: !this.isSticky() }).then(function () {
|
||||
if (app.current instanceof DiscussionPage) {
|
||||
app.current.stream.update();
|
||||
}
|
||||
|
||||
m.redraw();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
_export('default', addStickyControl);
|
||||
|
||||
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/sticky/addStickyExcerpt', ['flarum/extend', 'flarum/components/DiscussionList', 'flarum/components/DiscussionListItem', 'flarum/utils/string'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var extend, DiscussionList, DiscussionListItem, truncate;
|
||||
function addStickyControl() {
|
||||
extend(DiscussionList.prototype, 'requestParams', function (params) {
|
||||
params.include.push('startPost');
|
||||
});
|
||||
|
||||
extend(DiscussionListItem.prototype, 'infoItems', function (items) {
|
||||
var discussion = this.props.discussion;
|
||||
|
||||
if (discussion.isSticky() && !this.props.params.q) {
|
||||
var startPost = discussion.startPost();
|
||||
|
||||
if (startPost) {
|
||||
var excerpt = truncate(startPost.contentPlain(), 175);
|
||||
|
||||
items.add('excerpt', excerpt, -100);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_export('default', addStickyControl);
|
||||
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
}, function (_flarumComponentsDiscussionList) {
|
||||
DiscussionList = _flarumComponentsDiscussionList.default;
|
||||
}, function (_flarumComponentsDiscussionListItem) {
|
||||
DiscussionListItem = _flarumComponentsDiscussionListItem.default;
|
||||
}, function (_flarumUtilsString) {
|
||||
truncate = _flarumUtilsString.truncate;
|
||||
}],
|
||||
execute: function () {}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/sticky/components/DiscussionStickiedPost', ['flarum/components/EventPost'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var EventPost, DiscussionStickiedPost;
|
||||
return {
|
||||
setters: [function (_flarumComponentsEventPost) {
|
||||
EventPost = _flarumComponentsEventPost.default;
|
||||
}],
|
||||
execute: function () {
|
||||
DiscussionStickiedPost = function (_EventPost) {
|
||||
babelHelpers.inherits(DiscussionStickiedPost, _EventPost);
|
||||
|
||||
function DiscussionStickiedPost() {
|
||||
babelHelpers.classCallCheck(this, DiscussionStickiedPost);
|
||||
return babelHelpers.possibleConstructorReturn(this, (DiscussionStickiedPost.__proto__ || Object.getPrototypeOf(DiscussionStickiedPost)).apply(this, arguments));
|
||||
}
|
||||
|
||||
babelHelpers.createClass(DiscussionStickiedPost, [{
|
||||
key: 'icon',
|
||||
value: function icon() {
|
||||
return 'thumb-tack';
|
||||
}
|
||||
}, {
|
||||
key: 'descriptionKey',
|
||||
value: function descriptionKey() {
|
||||
return this.props.post.content().sticky ? 'flarum-sticky.forum.post_stream.discussion_stickied_text' : 'flarum-sticky.forum.post_stream.discussion_unstickied_text';
|
||||
}
|
||||
}]);
|
||||
return DiscussionStickiedPost;
|
||||
}(EventPost);
|
||||
|
||||
_export('default', DiscussionStickiedPost);
|
||||
}
|
||||
};
|
||||
});;
|
||||
'use strict';
|
||||
|
||||
System.register('flarum/sticky/main', ['flarum/app', 'flarum/Model', 'flarum/models/Discussion', 'flarum/sticky/components/DiscussionStickiedPost', 'flarum/sticky/addStickyBadge', 'flarum/sticky/addStickyControl', 'flarum/sticky/addStickyExcerpt'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var app, Model, Discussion, DiscussionStickiedPost, addStickyBadge, addStickyControl, addStickyExcerpt;
|
||||
return {
|
||||
setters: [function (_flarumApp) {
|
||||
app = _flarumApp.default;
|
||||
}, function (_flarumModel) {
|
||||
Model = _flarumModel.default;
|
||||
}, function (_flarumModelsDiscussion) {
|
||||
Discussion = _flarumModelsDiscussion.default;
|
||||
}, function (_flarumStickyComponentsDiscussionStickiedPost) {
|
||||
DiscussionStickiedPost = _flarumStickyComponentsDiscussionStickiedPost.default;
|
||||
}, function (_flarumStickyAddStickyBadge) {
|
||||
addStickyBadge = _flarumStickyAddStickyBadge.default;
|
||||
}, function (_flarumStickyAddStickyControl) {
|
||||
addStickyControl = _flarumStickyAddStickyControl.default;
|
||||
}, function (_flarumStickyAddStickyExcerpt) {
|
||||
addStickyExcerpt = _flarumStickyAddStickyExcerpt.default;
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('flarum-sticky', function () {
|
||||
app.postComponents.discussionStickied = DiscussionStickiedPost;
|
||||
|
||||
Discussion.prototype.isSticky = Model.attribute('isSticky');
|
||||
Discussion.prototype.canSticky = Model.attribute('canSticky');
|
||||
|
||||
addStickyBadge();
|
||||
addStickyControl();
|
||||
addStickyExcerpt();
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"gulp": "^3.9.1",
|
||||
"flarum-gulp": "^0.2.0"
|
||||
}
|
||||
}
|
4695
extensions/sticky/js/package-lock.json
generated
Normal file
4695
extensions/sticky/js/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
extensions/sticky/js/package.json
Normal file
13
extensions/sticky/js/package.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@flarum/flarum-ext-sticky",
|
||||
"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"
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@ import app from 'flarum/app';
|
|||
import Model from 'flarum/Model';
|
||||
import Discussion from 'flarum/models/Discussion';
|
||||
|
||||
import DiscussionStickiedPost from 'flarum/sticky/components/DiscussionStickiedPost';
|
||||
import addStickyBadge from 'flarum/sticky/addStickyBadge';
|
||||
import addStickyControl from 'flarum/sticky/addStickyControl';
|
||||
import addStickyExcerpt from 'flarum/sticky/addStickyExcerpt';
|
||||
import DiscussionStickiedPost from './components/DiscussionStickiedPost';
|
||||
import addStickyBadge from './addStickyBadge';
|
||||
import addStickyControl from './addStickyControl';
|
||||
import addStickyExcerpt from './addStickyExcerpt';
|
||||
|
||||
app.initializers.add('flarum-sticky', () => {
|
||||
app.postComponents.discussionStickied = DiscussionStickiedPost;
|
||||
|
@ -17,3 +17,4 @@ app.initializers.add('flarum-sticky', () => {
|
|||
addStickyControl();
|
||||
addStickyExcerpt();
|
||||
});
|
||||
|
3
extensions/sticky/js/webpack.config.js
Normal file
3
extensions/sticky/js/webpack.config.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
const config = require('flarum-webpack-config');
|
||||
|
||||
module.exports = config();
|
|
@ -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