Skip to content

RC1.0 Core Packages

Luc Claustres edited this page Dec 22, 2015 · 19 revisions

Towards the RC (Release candidate) we are planning to release the next packages...

  1. i18n - Internationalisation
  2. Circles - Abstract data structure and api to describe object heirarchy and is used for permissions and content permissions
  3. Permissions - Role based heirarchical permissions system
  4. Menu - Menu management

In the admin package we plan to expose all settings for the packages in the modules page in the admin and to revive the ability to disable and enable core packages. A more robust Error implementation in package form.

Global dependency injection scheme

Use Inject to push your service to the core to be aggregated. inject(service);

In /packages/custom/customPkg/mean.json use 'dependencies' to list other mean package dependencies: {'dependencies':{}} All mean.json dependencies are packages, not applications.

If a package is an intended application entry point, it should be declared in the root mean.json 'dependencies'.

Unify all packages and move packages/core to packages/linnovate. There needs to be some more definite separation ofmeanio from packages/core/** or packages/linnovate/**. meanio should be the application in its entirety. packages are just a method of configuration and injecting code.

Unified dependency management

There are two different ways to manage dependencies right now : Aggregation-core-module#specifying-files-to-be-aggregated. The global approach is fine for core dependencies required by all modules. The second one is fine for independent modules but has two drawbacks:

  1. As the dependencies are embedded into each module you might have the same dependency used twice (if used by two modules of your application), potentially leading to conflicts.
  2. The dependency list is not available outside the server code so you cannot for instance add a gulp task to create a minified file of all dependencies of your module such as it is possible in the global approach. This makes MEAN.io not really friendly for approaches decoupling client/server code such as cordova.

The first issue can be resolved by keeping installing everything in the global bower_components folder and let bower manage this for us (you can benefit from resolution on specific versions as well, etc.). So we should have the following .bowerrc in all modules:

{
  "directory": "../../../bower_components",
  "storage": {
          "packages": "../../../.bower-cache",
          "registry": "../../../.bower-registry"
  },
  "tmp": "../../../.bower-tmp"
}

For the last issue we should have a 'service' that seamlessly manages the dependency injection as usual but based on a assets.json file for each module, for instance this file for a module named mymodule should be like this:

{
  "mymodule": {
    "css": {
      "bower_components/build/mymodule/css/mymodule.min.css": [
        "bower_components/library/lib.css",
        ...
      ]
    },
    "js": {
      "bower_components/build/mymodule/js/mymodule.min.js": [
        "bower_components/lib/lib.js",
        ...
      ]
    },
    "angularDependencies": ["mean.mymodule", "lib", ...]
  }
}

Then the dependencies injection should look like this in the app.js of the module:

var Module = require('meanio').Module;
var moduleName = 'mymodule';
var AssetsManager = require(core('AssetsManager'));
var assets = new AssetsManager(require('./assets.json'), moduleName);
var MyModule = new Module(moduleName);

// MEAN packages registration
MyModule.register(function (app, auth, database, system) {

    // Perform assets aggregation based on local assets.json for global dependencies
    assets.aggregateAssets(MyModule);

    // We enable routing. By default the Package Object is passed to the routes
    MyModule.routes(app, auth, database);

    ...
}

The required service for dependencies injection is detailed here : AssetsManager.

Once you have all of this you can easily create a gulp task to generate all your minified dependencies:

function createLinkElement(css) {
    return '\t<link rel="stylesheet" href="' + css + '">\n';
}

function createScriptElement(js) {
    return '\t<script type="text/javascript" src="' + js + '"></script>\n';
}

function parseCustomPackages(callback) {
  var files = fs.readdirSync('packages/custom');

  for (var i = 0; i < files.length; i++) {
    callback(files[i]);
  }
};

parseCustomPackages(function(packageName){
        var pkg = require('../packages/custom/' + packageName + '/assets.json');

        if (_.values(pkg[packageName].css)[0].length > 0) {
            if (process.env.NODE_ENV === 'production') {
                css += createLinkElement(_.keys(pkg[packageName].css)[0]);
            } else {
                var cssCustomFiles = _.values(pkg[packageName].css)[0];
                for (var l = 0; l < cssCustomFiles.length; l += 1) {
                    // Take care to update path to public files if required
                    css += createLinkElement(updatePath(cssCustomFiles[l]));
                }
            }
        }

        if(_.values(pkg[packageName].js)[0].length > 0){
            if (process.env.NODE_ENV === 'production') {
                js += createScriptElement(_.keys(pkg[packageName].js)[0]);
            } else {
                var jsCustomFiles = _.values(pkg[packageName].js)[0];
                for (var m = 0; m < jsCustomFiles.length; m += 1) {
                    js += createScriptElement(updatePath(jsCustomFiles[m]));
                }
            }
        }

    // Do whatever you want with CSS/JS file tags
    ...
});

Using a plugin like gulp-inject it is then possible to inject the dependencies in an index.html file to build a phonegap-ready application.

Clone this wiki locally