Create Flarum Extension by FriendsOfFlarum

npm version node npm downloads OpenCollective Patreon

Create a Flarum extension from a boilerplate in minutes!

asciicast

Quick Overview

Using npx (npx comes with npm 5.2+ and higher):

npx @friendsofflarum/create-flarum-extension [dir]

Normally:

npm install -g @friendsofflarum/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 to interactively manager your node versions.

To create a new app, run a single command:

npx @friendsofflarum/create-flarum-extension my-extension

(npx comes with npm 5.2+ and higher, see quick overview for older npm versions)

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

Links

A utility by FriendsOfFlarum.

Nice work!

Is the license MIT by default, or something else? Would that be something for people to adjust by script, or would they always have to change manually if they don't want to use MIT?

    jordanjay29 If you watch the asciinema linked, the user gets to choose the License from a list of SPDX Licenses.
    The content of the license is then automatically included as LICENSE.md (author and/or year aren’t filled in automatically, though), and the composer.json license field is set to the license’s name.

    Ralkage I was just going to suggest that, you showed me that with the Cookie Consent extension ?

    I’ve been wanting to try my hand at some web programming. Admittedly, I’ve just done traditional and embedded programming. So this would be a bit different ball game. But I like getting my hands dirty and this should make it quite a bit easier learning the ropes.

    Nice !

    In the asciinema, "reflar" gets automatically capitalized in the extension name after you validate. Is that a feature of this program ?

      clarkwinkelmann Yep! The following values get formatted after you enter them:

      • Package names automatically become lowercase
      • Namespaces are appropriately capitalized, author\extensionname -> Author\Extensionname (not capizaliting each word because (a) want to keep it kinda light and (b) you never know when someone wants it capitalized or not)
      • Extension names are appropriately capitalized (if the word is more than 3 characters, to avoid capitalizing by, for, and others)

      Note: Incorrectly capitalized words/letters will not be made lowercase.

      v1.2.0 (2018-04-23)

      If using npm, remember to update with npm i -g @reflar/create-flarum-extension.

      Features

      • boilerplate: option to move less & locale to resources folder (84115bf) Ralkage

      Other

      • boilerplate: add installation w/ baazar & updating instructions

        datitisev Awesome tool!

        2 things:

        1. In composer.json, the namespace in the psr-4 autoload section isn't formatted correctly. So if I enter NorioDS\Bottle as the namespace during generation it should show up in the autoload section as "NorioDS\\Bottle\\".
        2. In bootstrap.php it refers to Listeners\AddClientAssets instead of (singular) Listener\AddClientAssets

        Great work! You've saved me a lot of time. Hopefully I can start contributing awesome extensions thanks to you ?

          Oh nevermind about #2. I see that the directory structure matches.

          NorioDS

          Hi, I'm trying this tool and going to reply just like you did, my extension is not load because of Listeners

          In src/Listeners/AddClientAssets.php should be
          namespace abc\abc-ext\Listeners; //with an 's' here

          10 days later

          v1.2.2 (2018-05-05)

          If using npm, remember to update with npm i -g @reflar/create-flarum-extension.

          Bug Fixes

          • boilerplate: assets listener doesn't register when necessary (f4e7446), closes #4
          • boilerplate: assets not registering if forum or admin are skipped (c66e351), closes #3

          Thanks to @Ralkage for posting these errors on Github.

          5 days later

          @datitisev I'm about to start another extension and can't remember what I'm supposed to put in each question. So a feature request would be examples.

          Like for "Package" I can't remember if it's the "English" name of the package or something like vendor/package-name. Having an example in light grey or something would be helpful to someone like me, still getting used to the generator.

            NorioDS Hm, I'll look into making it a little more clear. Right now there are some validation rules that tell you to use vendor/package-name, but I see that it's not enough.

            2 months later