Giter Site home page Giter Site logo

consign's People

Contributors

alexmick avatar ferreiro avatar jarradseers avatar paulomigalmeida avatar rodolfosilva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

consign's Issues

New collaborators needed

@jarradseers As no answer is provided in this project and it does not work properly nor the express-load is currently working correctly I suggest you to invite new collaborators to the project able to give the necessary support, I also suggest that you start by inviting guys that opened Pull Requests for your project that you agree on coding standards and implementation quality.

getRelativeTo gets confused when there are multiple occurences of the same separator in the string

Hi @jarradseers,

I have noticed a funny behavior when loading scripts into an express application that has a folder which is exactly the same as the separator argument used at the _getRelativeTo methods.

To make it easier to understand I ran a few examples where this error becomes more evident:

Scenario where it runs just fine:
Application full path: /var/current/app/controllers/homeController.js
Working directory: /var/current/

consign({cwd: 'app',  verbose: true})    
    .include('controllers')
    .then('routes')
    .into(app);

# _getRelativeTo output: ./controllers/homeController.js

Scenario where it gets mixed up:
Application full path: /var/app/current/app/controllers/homeController.js
Working directory: /var/app/current/

consign({cwd: 'app',  verbose: true})    
    .include('controllers')
    .then('routes')
    .into(app);

# _getRelativeTo output: ./current

I have taken a look into this and realized that the reason for this funny behavior is because in the _getRelativeTo definition you split the full path into 2 part and get the second occurrence.

Consign.prototype._getRelativeTo = function(location) {
  return '.' + location.split(this._options.cwd, 2)[1];
};

An easy way to solve this issue while considering back-compatibility at the same time would be to use pop() method right after split() to get the last segment of the location. Like this:

Consign.prototype._getRelativeTo = function(location) {
  return '.' + location.split(this._options.cwd).pop();
};

I'm gonna submit a PR to fix it, please accept it if you consider this would be a good addition to consign.

Best regards,

Paulo Almeida

MVC Modules

Hy, tath´s ok?
Firstly, sorry my english, kkkk.

My name is Jocelim Junior, i’m brazilian PHP developer and starting NodeJS world.
Currently i’m working in a project that needs to use yours "Cosign" library.
My necessity is group modules into unique folder that contains others folders used MVC pattern.

Example:
Modules > User > controllers
Modules > User > models
Modules > Produts > controllers
Modules > Produts > models

The function include(), import all files from only folder.

include('controllers')
controllers > *

I edited code to import all files from multiple folders, inside modules.

include('controllers')
Modules > Users > controllers
Modules > Products > controllers

include('models')
Modules > Users > models
Modules > Products > models

Alterations lib/cosign.js:
this._options = {
...
modules: null,
modulesIgnored: [],
modulesRequired: []
};

Consign.prototype.include = function (entity) {
this._lastOperation = 'include';

if (
	(
	  this._options.modules &&
	  this._options.modulesIgnored.length == 0 &&
	  this._options.modulesRequired.length == 0
	) ||
	(
	  this._options.modules &&
	  this._options.modulesIgnored.length > 0 &&
	  this._options.modulesIgnored.includes(entity) == false
	) ||
	(
	  this._options.modules &&
	  this._options.modulesRequired.length > 0 &&
	  this._options.modulesRequired.includes(entity) == true
	)
  ) {

	var modulesPath = path.resolve(this._options.cwd, this._options.modules);
	var dir = fs.readdirSync(modulesPath);

	for (var e in dir) {

	  let f = path.resolve(modulesPath, dir[e]);

	  if (fs.statSync(f).isDirectory()) {
		this._setLocations(f, entity, true);
	  }

	}

	return this;

} else {
	return this._setLocations(this._options.cwd, entity, true);
}

}

Consign.prototype._createNamespace = function (parent, parts, mod) {
var part = parts.shift();

if(this._options.modules && this._getKeyName(part) == this._options.modules){
parts.shift();
part = parts.shift();
}

if (!parent[part]) {
parent[this._getKeyName(part)] = parts.length ? {} : mod;
}

if (parts.length) {
parent = this._createNamespace(parent[part], parts, mod);
}

return parent;
};

Is this a good alteration to project?
I whant help you.
Thank's

Question API prefix like /api/v1/

Hi, let's suppose I want to prefix my routes with /api/v1 and I have this config file:

import express from 'express';
import consign from 'consign';

const app = express();

consign({ verbose: false })
  .include('libs/config.js')
  .then('db.js')
  .then('auth.js')
  .then('libs/middlewares.js')
  .then('routes')
  .then('libs/boot.js')
  .into(app);

module.exports = app;

and my routes definition does not start using a prefix, like:

import async from 'async';
import crypto from 'crypto';
import nodemailer from 'nodemailer';
import { EmailTemplate } from 'email-templates';
import path from 'path';

module.exports = app => {
  const cfg = app.libs.config;
  const Users = app.db.models.Users;

  app.route('/user')
    .all(app.auth.authenticate())
    /**```

How can I do it ?

custom name for a folder being consigned

Hi,

I have a folder query_modules, which i will consign to app like so.

\query_modules
   firstModule.js
   secondModule.js
consign().include('query_modules').into(app)

Now to access any of the modules inside query_modules I should ideally do

app.query_modules.firstModule

But this does not really bid well with JS naming convention which is camelCase

So, is there a way in consign to customize the name for the folder when consigning to make all modules in query_modules to be access like this?

app.queryModules.firstModule

Error in cwd

I've tried use the [email protected] and this error was returned when I tried start my application in another notebooks (This worked normally in my notebook):

`C:\Users\lukas.camargo\OneDrive\serveJa\node_modules\consign\lib\consign.js:145
if (!parent[part]) {
^

TypeError: Cannot read property 'OneDrive' of undefined
at Consign._createNamespace (C:\Users\lukas.camargo\OneDrive\serveJa\node_modules\consign\lib\consign.js:145:14)
at Consign._createNamespace (C:\Users\lukas.camargo\OneDrive\serveJa\node_modules\consign\lib\consign.js:150:19)
at Consign._createNamespace (C:\Users\lukas.camargo\OneDrive\serveJa\node_modules\consign\lib\consign.js:150:19)
at Consign.into (C:\Users\lukas.camargo\OneDrive\serveJa\node_modules\consign\lib\consign.js:244:19)
at module.exports (C:\Users\lukas.camargo\OneDrive\serveJa\server\config\config.js:52:10)
at Object. (C:\Users\lukas.camargo\OneDrive\serveJa\server.js:10:34)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3`

My code was:

consign({ cwd: 'server/config', verbose : false }) .include('models') .then('routes') .into(app);

To fix that I had to do downgrade to @0.1.5 and use this code:

consign({ cwd: process.cwd()+'\\server\\config', verbose : true }) .include('models') .then('routes') .into(app);

I believe there any error in new version.

why this error? please help.

Error:
consign-error

My configuration consign:

consign() .include('config/dbConnection.js') .then('app/routes') .then('app/models') .then('app/controllers') .into(app);

API Versioning

Now i have this:

consign({"cwd":process.cwd() + "\\app\\v1","verbose":false}).include("models").then("controllers").then("routes").into(app)

with

image

In the future how can i accomplish api versioning versioning (v1/ v2/ routes)?

api question

@jarradseers Great repo!

Question though, what if instead of wanting to structure an express app like this:

\root
    \models
    \views
    \routers
    \public

I wanted to do something more modular like this:

\root
    \public
    \apps
        \app_one
            \models
            \views
            \routers
            \public
        \app_two
            \models
            \views
            \routers
            \public

Can your api handle this? If so how? Thanks.

Question about recursive routes

Hi... I have been trying to use consign in one of my projects. I am wondering if consign can consider folders as route paths... What I mean is - if I have some routes in file routes/user.js ... the generated routes are:
app.get('/user/', get_all);
app.get('/user/:id', get_all);
app.post('/user/:id', update);
app.post('/user', create);
app.detete('/user/:id' : del);

and all I do is just move the routes/user.js to routes/api/user.js ... now I want the routes to be generated routes to be:

app.get('/api/user/', get_all);
app.get('/api/user/:id', get_all);
app.post('/api/user/:id', update);
app.post('/api/user', create);
app.detete('/api/user/:id' : del);

Note that I have not made changes to the user.js file. Because now its in a subfolder, the subfolder gets added to the route path. Can Consign do something like this?

Almost impossible to debug syntax errors

When a script is loaded, if it has a syntax error, its almost impossible to know what script had the error from consign's output. In Consign.prototype.into(), I suggest the following:

    var script = this._files[f]
      , parts = this._getRelativeTo(script).split(path.sep).slice(1)
      , args = []
    ;

    try {
      var mod = require( script );
    } catch(err) {
      throw( 'Failed to require: ' +  script + ', because: ' + err.message );
    }

How to not include tilda files

I am an old man and I use emacs as my editor, which drops "file.js~" when I edit "file.js". Consign is picking these up ... effectively including old versions of files I just edited.

I cannot figure out how to exclude *~

Async support

Does consign have async support ? I couldn't find it.

Package dead?

I saw in the npm site that this package doesn't has support and updates for at least 4 years.
Is this project really dead?
Is there an alternative package that could be used?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.