Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
v1.1.0; add spinners, add some more validation, more info to README
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Apr 22, 2018
0 parents commit d85dd6b
Show file tree
Hide file tree
Showing 20 changed files with 1,439 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.DS_Store
test
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Create Flarum Extension by ReFlar

Create a Flarum extension from a boilerplate in minutes!

[![asciicast](https://asciinema.org/a/177728.png)](https://asciinema.org/a/177728)

## Quick Overview

Using `npx` (npx comes with npm 5.2+ and higher):
```sh
npx @reflar/create-flarum-extension [dir]
```

Normally:
```sh
npm install -g @reflar/create-flarum-extension
create-flarum-extension [dir]
```


## Creating an Extension


**You’ll need to have Node >= 8 on your local development machine (but it’s not required on the server).** You can use [n](https://www.npmjs.com/package/n) to interactively manager your node versions.

To create a new app, run a single command:

```
npx @reflar/create-flarum-extension my-extension
```
*([npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) comes with npm 5.2+ and higher, see [quick overview for older npm versions](#quick-overview))*

It will create a directory called `my-extension` inside the current folder.
Inside that directory, it will generate the initial project structure:

```
my-extension
├── .gitignore
├── bootstrap.php
├── composer.json
├── README.md
├── LICENSE.md
├── js
│ ├── admin
│ │ ├── Gulpfile.js
│ │ ├── package.json
│ │ └── src
│ │ └── main.js
│ └── forum
│ ├── Gulpfile.js
│ ├── package.json
│ └── src
│ └── main.js
├── less
│ ├── admin.less
│ └── app.less
├── locale
│ └── en.yml
└── src
└── Listeners
└── AddClientAssets.php
```

## Flarum Resources

- [Unofficial Flarum API Docs](https://discuss.flarum.org/d/4421-flarum-php-api-docs) - @datitisev
- [Extension development - first read](https://discuss.flarum.org/d/1662-extension-developer-first-read) - @luceos
- [Extension development - using composer](https://discuss.flarum.org/d/1608-extension-development-using-composer-repositories-path) - @luceos
- [Extension development - different workflows](https://discuss.flarum.org/d/6320-extension-developers-show-us-your-workflow)
- [Extension development - namespace tips](https://discuss.flarum.org/d/9625-flarum-extension-namespacing-tips)
19 changes: 19 additions & 0 deletions boilerplate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# <%= extensionName %>

---

![License](https://img.shields.io/badge/license-<%= license %>-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/<%= packageName %>.svg)](https://packagist.org/packages/<%= packageName %>)

A [Flarum](http://flarum.org) extension. <%= packageDescription %>

### Installation

Install it with composer:

```sh
composer require <%= packageName %>
```

### Links

- [Packagist](https://packagist.org/packages/<%= packageName %>)
19 changes: 19 additions & 0 deletions boilerplate/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* This file is part of <%= packageName %>.
*
* Copyright (c) 2018 <% authorName %>.
*
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace <%= namespace %>;

use Illuminate\Contracts\Events\Dispatcher;

return function (Dispatcher $events) {
$events->subscribe(Listeners\AddClientAssets::class);
};
37 changes: 37 additions & 0 deletions boilerplate/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "<%= packageName %>",
"description": "<%= packageDescription %>",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "<%= license %>",
"require": {
"flarum/core": "^0.1.0-beta-7"
},
"authors": [
{
"name": "<%= authorName %>",
"email": "<%= authorEmail %>",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"<%= packageNamespace %>": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "<%= extensionName %>",
"icon": {
"name": "",
"backgroundColor": "",
"color": ""
}
},
"flagrow": {
"discuss": ""
}
}
}
3 changes: 3 additions & 0 deletions boilerplate/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
vendor
composer.lock
9 changes: 9 additions & 0 deletions boilerplate/js/admin/Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var gulp = require('flarum-gulp');

gulp({
modules: {
'<%= packageName %>': [
'src/**/*.js',
]
}
});
8 changes: 8 additions & 0 deletions boilerplate/js/admin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1",
"flarum-gulp": "^0.2.0"
},
"dependencies": {}
}
5 changes: 5 additions & 0 deletions boilerplate/js/admin/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import app from 'flarum/app';

app.initializers.add('<%= packageName %>', () => {
console.log('Hello, admin!');
});
9 changes: 9 additions & 0 deletions boilerplate/js/forum/Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var gulp = require('flarum-gulp');

gulp({
modules: {
'<%= packageName %>': [
'src/**/*.js',
]
}
});
8 changes: 8 additions & 0 deletions boilerplate/js/forum/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1",
"flarum-gulp": "^0.2.0"
},
"dependencies": {}
}
5 changes: 5 additions & 0 deletions boilerplate/js/forum/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import app from 'flarum/app';

app.initializers.add('<%= packageName %>', () => {
console.log('Hello, forum!');
});
Empty file added boilerplate/less/admin.less
Empty file.
Empty file added boilerplate/less/app.less
Empty file.
Empty file added boilerplate/locale/en.yml
Empty file.
70 changes: 70 additions & 0 deletions boilerplate/src/Listeners/AddClientAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* This file is part of <%= packageName %>.
*
* Copyright (c) 2018 <% authorName %>.
*
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace <%= namespace %>\Listener;

use DirectoryIterator;
use Flarum\Event\ConfigureLocales;
use Flarum\Event\ConfigureWebApp;
use Illuminate\Contracts\Events\Dispatcher;

class AddClientAssets
{
/**
* Subscribes to the Flarum events.
*
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureWebApp::class, [$this, 'configureWebApp']);
<% if (useLocale) { %>$events->listen(ConfigureLocales::class, [$this, 'addLocales']);<% } %>
}

/**
* Modifies the client view for forum/admin.
*
* @param ConfigureWebApp $event
*/
public function configureWebApp(ConfigureWebApp $event)
{
<% if (admin) { %>if ($event->isAdmin()) {
$event->addAssets([
<% if (useJs) { %>__DIR__.'/../../js/admin/dist/extension.js',<% } %>
<% if (useCss) { %>__DIR__.'/../../less/admin.less',<% } %>
]);
$event->addBootstrapper('<%= packageName %>/main');
}<% } %>

<% if (forum) { %>if ($event->isForum()) {
$event->addAssets([
<% if (useJs) { %>__DIR__.'/../../js/forum/dist/extension.js',<% } %>
<% if (useCss) { %>__DIR__.'/../../less/app.less',<% } %>
]);
$event->addBootstrapper('<%= packageName %>/main');
}<% } %>
}
<% if (useLocale) { %>
/**
* Provides i18n files.
*
* @param ConfigureLocales $event
*/
public function addLocales(ConfigureLocales $event)
{
foreach (new DirectoryIterator(__DIR__.'/../../locale') as $file) {
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
$event->locales->addTranslations($file->getBasename('.'.$file->getExtension()), $file->getPathname());
}
}
}<% } %>
}
Loading

0 comments on commit d85dd6b

Please sign in to comment.