You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

npmvc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npmvc - npm Package Compare versions

Comparing version

to
1.0.6-rc3

47

index.js

@@ -54,3 +54,3 @@ var fs = require("fs");

var _path = (tempPath || scope.basePath) + "/" + path + ".js";
var _path = ___path.normalize((tempPath || scope.basePath) + "/" + path + ".js");

@@ -201,4 +201,49 @@ var exists = fs.existsSync(_path);

/**
* contains the basic configurations for npm (puremvc) modules
* @type {Object}
*/
scope.modules = {};
/**
* returns the basic configuration for a npm (puremvc) module
* @param {String} module The name of the module
* @return {Object} A module configuration object
*/
scope.module = function(module) {
if(!scope.modules[module]) {
console.error("can not find module: "+ module);
process.exit(1);
} else {
return scope.modules[module];
}
};
/**
* Registers a new module
* @param {String} dir Directory of the root of the module (best to pass __dirname in index.js)
* @return {boolean} returns true if succesfull registered, otherwise false
*/
scope.registerModule = function(dir) {
var _config = require(dir+'/package.json');
if(!_config.name || !_config.puremvc || !_config.puremvc.sourcedir) {
console.error("registerModule config error: Please provide configuration in package.json");
console.error(_config);
return false;
}
_config.puremvc.name = _config.name;
_config.puremvc.version = _config.version;
_config.puremvc.sourcedir = _config.puremvc.sourceDir = ___path.normalize(dir+"/"+_config.puremvc.sourcedir);
scope.modules[_config.name] = _config.puremvc;
//loading local classes
for(var file in _config.puremvc.include) {
//console.log(_config.puremvc.include[file]);
scope.include(_config.puremvc.include[file], _config.puremvc.sourcedir);
}
return true;
}
return scope;
})(module.exports);

2

package.json
{
"name": "npmvc",
"version": "1.0.6-rc2",
"version": "1.0.6-rc3",
"description": "PureMVC for node.js",

@@ -5,0 +5,0 @@ "engines": {

@@ -1,2 +0,2 @@

[![Build Status](https://travis-ci.org/rstr74/npmvc.svg?branch=master)](https://travis-ci.org/rstr74/npmvc)
[![Build Status](https://travis-ci.org/rstr74/npmvc.svg?branch=develop)](https://travis-ci.org/rstr74/npmvc)
[![npm version badge](https://img.shields.io/npm/v/npmvc.svg)](https://www.npmjs.org/package/npmvc)

@@ -18,2 +18,6 @@ [![downloads badge](http://img.shields.io/npm/dm/npmvc.svg)](https://www.npmjs.org/package/npmvc)

### Current versions
* 1.0.6-rc3
* 1.0.5 (stable and tagged latest)
### install

@@ -145,3 +149,59 @@

# Creating npm modules
This is one way to create puremvc modules that harmonize with npm (node package manager).
in package.json add a puremvc object, and provide a namespace, sourcedir (relative from module root dir), and an array with initial includes.
The main property has to point to 'index.js'.
```
{
"name": "somemodule",
"version": "1.0.0",
"description": "Just a module",
"main": "index",
"puremvc":{
"namespace":"com.domain.somemodule",
"sourcedir":"./src/",
"include":[
"mediator/SomeMediator",
"model/SomeProxy"
]
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
```
for index.js use this code:
```js
module.exports = function(include,puremvc) {
puremvc.registerModule(__dirname);
}
```
Now in any point in your npmvc application you can import a module by using the include method:
```js
module.exports = function(include,puremvc) {
include("somemodule");
puremvc.define(
// CLASS INFO
{
name: 'com.domain.command.RunCommand',
parent: puremvc.SimpleCommand
},
// INSTANCE MEMBERS
{
execute: function() {
console.log(puremvc.module("somemodule"));
var mediator = new com.domain.somemodule.mediator.SomeMediator();
this.facade.registerMediator(mediator);
}
});
}
```
# Extra options:

@@ -148,0 +208,0 @@

@@ -78,3 +78,19 @@ var assert = require("assert");

// test registerModule
puremvc.include("npmvctestmodule");
puremvc.module("npmvctestmodule").should.be.an.instanceOf(Object).and.have.property('name');
debug("ok....npmvctestmodule config has a name propery");
puremvc.module("npmvctestmodule").name.should.equal("npmvctestmodule");
debug("ok....npmvctestmodule config has a name; npmvctestmodule");
puremvc.module("npmvctestmodule").should.be.an.instanceOf(Object).and.have.property('sourceDir');
debug("ok....npmvctestmodule config has a sourceDir property");
puremvc.module("npmvctestmodule").should.be.an.instanceOf(Object).and.have.property('sourcedir');
debug("ok....npmvctestmodule config has a sourcedir property");
puremvc.module("npmvctestmodule").should.be.an.instanceOf(Object).and.have.property('include');
debug("ok....npmvctestmodule config has a include property");
var someMediator = new com.domain.npmvctestmodule.mediator.SomeMediator();
someMediator.init().should.equal("com.domain.npmvctestmodule.mediator.SomeMediator");
debug("ok....npmvctestmodule SomeMediator.NAME equals com.domain.npmvctestmodule.mediator.SomeMediator");
debug("done..completed successfull");
process.exit(0);