示例#1
0
文件: app.js 项目: iDhruv22/matisse
 }, function(err, ids) {
   if (err) {} else {
     var user = new UserModel;
     user.load(ids[0], function(err, props) {
       if (err) {
         return err;
       }
       user.belongsTo(whiteBoard, 'ownedBoard', function(err, relExists) {
         if (relExists) {} else {
           if (whiteBoard.property('createdBy') == "") whiteBoard.property('createdBy', userName);
           user.link(whiteBoard, 'sharedBoard');
           whiteBoard.link(user, 'userShared');
           user.save(noop);
           whiteBoard.save(noop);
         }
       });
     });
   }
 });
示例#2
0
function signup(externalUser, req, cb) {
	userModel.load({
		criteria: { username: new RegExp(['^', req.name, '$'].join(''), 'i') }
	}, function (err, user) {
		if (err)
			cb(err, null, false);

		tokenModel.list({
			criteria: { user: user._id, token: req.token }
		}, function (err, token) {

			if (err)
				cb(err, null, false);

			telegramUserModel.createFor(externalUser, user, cb);

		});
	});
}
示例#3
0
    it('should load the component and fire their lifecircle callback by app.start, app.afterStart, app.stop', function(done) {
      var startCount = 0, afterStartCount = 0, stopCount = 0;

      var mockComponent = {
        start: function(cb) {
          console.log('start invoked');
          startCount++;
          cb();
        },

        afterStart: function(cb) {
          console.log('afterStart invoked');
          afterStartCount++;
          cb();
        },

        stop: function(force, cb) {
          console.log('stop invoked');
          stopCount++;
          cb();
        }
      };

      app.init({base: mockBase});
      app.load(mockComponent);
      app.start(function(err) {
        should.not.exist(err);
      });

      setTimeout(function() {
        // wait for after start
        app.stop(false);

        setTimeout(function() {
          // wait for stop
          startCount.should.equal(1);
          afterStartCount.should.equal(1);
          stopCount.should.equal(1);
          done();
        }, WAIT_TIME);
      }, WAIT_TIME);
    });
示例#4
0
文件: index.js 项目: Martin91/matisse
 loggedInUser.find({userID:userID}, function(err,ids) {
     if (err) {
         renderLogin(res);
     } else {
         loggedInUser.load(ids[0], function (err, props) {
             if (err) {
                 renderLogin(res);
             } else {
                 // get the boards linked with this user
                 loggedInUser.getAll('Board', 'ownedBoard', function (err, boardIds) {
                     if (err) {
                         renderDashboard(res);
                     } else {
                         server.emit('valid owned boards', req, res, loggedInUser, boardIds);
                     }
                 });
             }
         });
     }
 });
示例#5
0
  proto.preset = function(preset) {
    if (typeof preset === 'function') {
      preset(this);
    } else {
      try {
        var modulePath = path.join(this.options.presets, preset);
        var module = require(modulePath);

        if (typeof module.load === 'function') {
          module.load(this);
        } else {
          throw new Error('preset ' + modulePath + ' has no load() function');
        }
      } catch (err) {
        throw new Error('preset ' + modulePath + ' could not be loaded: ' + err.message);
      }
    }

    return this;
  };
示例#6
0
文件: index.js 项目: Martin91/matisse
        boardIds.forEach(function (id) {
            var board = new BoardModel();
            board.load(id, function (err, props) {
                if (err) {
                    renderDashboard(res);
                } else {
                    boards.push ({
                        id:this.id,
  					    url: props.url,
					    name: props.name,
   					    container: props.container,
	   				    canvasWidth: props.canvasWidth,
		   			    canvasHeight: props.canvasHeight
                    });
                    if (++i === boardCount) {
                        callback(boards);
                    }
                }
            });
        });
示例#7
0
async function onCreateNode({ node, boundActionCreators, loadNodeContent }) {
  const { createNode, createParentChildLink } = boundActionCreators
  if (node.internal.mediaType !== `text/yaml`) {
    return
  }

  const content = await loadNodeContent(node)
  const parsedContent = jsYaml.load(content)

  // TODO handle non-array data.
  if (_.isArray(parsedContent)) {
    const yamlArray = parsedContent.map((obj, i) => {
      const objStr = JSON.stringify(obj)
      const contentDigest = crypto
        .createHash(`md5`)
        .update(objStr)
        .digest(`hex`)

      return {
        ...obj,
        id: obj.id ? obj.id : `${node.id} [${i}] >>> YAML`,
        children: [],
        parent: node.id,
        internal: {
          contentDigest,
          // TODO make choosing the "type" a lot smarter. This assumes
          // the parent node is a file.
          // PascalCase
          type: _.upperFirst(_.camelCase(`${node.name} Yaml`)),
        },
      }
    })

    _.each(yamlArray, y => {
      createNode(y)
      createParentChildLink({ parent: node, child: y })
    })
  }

  return
}
            nodegrass.get("https://www.zhihu.com/collection/" + collid + "?page=" + pageindex, function(data, status, headers) {
                var $ = cheerio.load(data);
                var arrUrl = [];
                $(data).find('.zm-item-title a').each(function() {
                    arrUrl.push("https://www.zhihu.com" + $(this).attr('href'));
                });
                console.log(arrUrl.join('索引:' + pageindex + '\r\n') + '索引:' + pageindex + '\r\n');

                for (var urlindex = 0; urlindex < arrUrl.length; urlindex++) {
                    (function(urlindex) {
                        var url = arrUrl[urlindex];
                        var queobj = {
                            question_url: url,
                            dianzanshu: dianzanshu
                        };
                        if (isDownloadImg) {
                            zhihu.start(queobj); //进行图片下载 
                        }
                    })(urlindex);
                }
            });
示例#9
0
        Async.each(files, function (file, callback) {

            var path = Path.resolve(settings.globOptions.cwd, file);
            var module = require(path);
            var model = module;

            if (module.hasOwnProperty('load') && typeof(module.load) === 'function') {
                model = module.load(server);
            }

            if (model.schema instanceof Mongoose.Schema) {
                server.expose(model.modelName, model);
                server.log(['hapi-mongoose-models', 'plugin'], 'Model `' + model.modelName + '` loaded');
            }
            else {
                server.log(['hapi-mongoose-models', 'plugin'], 'File `' + file + '` not ' +
                           'contains a mongoose model, will be ignored')
            }

            return Hoek.nextTick(callback)();
        }, next);
示例#10
0
文件: app.js 项目: Martin91/matisse
            userIds.forEach(function (userid) {
                var user = new UserModel();
                user.load(userid, function (err, props) {
                    user.getAll('Board', 'sharedBoard', function(err, ids) {
                        console.log("shared");
                        console.log(ids);
                        if(!err) {
                            ids.forEach(function (id) {
                                var board = new BoardModel();
                                board.load(id, function (err, props) {
                                    console.log(id);
                                    console.log("---------");
                                    board.link(user, 'userShared');
                                    board.save(noop);
                                });
                            });
                        }
                        else {
                            console.log("***Error in unlinking sharedBoard from other users***"+err);
                        }
                    });

                    user.getAll('Board', 'ownedBoard', function(err, bids) {
                        console.log("owned");
                        console.log(bids);
                        if(!err) {
                            bids.forEach(function (bid) {
                                var sboard = new BoardModel();
                                sboard.load(bid, function (err, props) {
                                    sboard.link(user, 'userOwned');
                                    sboard.save(noop);
                                });
                            });
                        } else {
                            console.log("***Error in linking ownedBoard from other users***"+err);
                        }
                    });

                });
            });
示例#11
0
		it('should load module with cli args including "bar list"', function (done) {
			var c = new Context({ name: 'bar', path: path.join(__dirname, 'resources', 'commands', 'bar.js') }),
				logger = new MockLogger,
				cli = {
					argv: {
						$0: 'node titanium',
						$: 'titanium',
						$_: ['bar', 'list'],
						_: ['list'],
						$command: 'bar'
					}
				};

			c.load(logger, {}, cli, function (err, ctx) {
				assert(!err, 'expected "bar" to load without error');
				cli.argv.should.have.ownProperty('$command');
				cli.argv.$command.should.equal('bar');
				cli.argv.should.have.ownProperty('$subcommand');
				cli.argv.$subcommand.should.equal('list');
				done();
			});
		});
示例#12
0
			c.load(logger, {}, {}, function (err, ctx) {
				assert(!err, 'expected "foo" to load without error');

				var x = c.getFlagsOptions();
				x.flags.should.have.ownProperty('quiet');
				x.flags.should.have.ownProperty('colors');
				x.options.should.have.ownProperty('sdk');
				x.options.should.have.ownProperty('target');

				var c2 = new Context({ name: 'bar', path: path.join(__dirname, 'resources', 'commands', 'bar.js'), parent: c });
				c2.load(logger, {}, {}, function (err, ctx) {
					assert(!err, 'expected "bar" to load without error');

					var y = c2.getFlagsOptions();
					y.flags.should.have.ownProperty('quiet');
					y.flags.should.have.ownProperty('colors');
					y.options.should.have.ownProperty('sdk');
					y.options.should.have.ownProperty('target');

					done();
				});
			});
示例#13
0
		it('should load module with cli args including "help" command', function (done) {
			var c = new Context({ name: 'foo', path: path.join(__dirname, 'resources', 'commands', 'foo.js') }),
				logger = new MockLogger,
				cli = {
					argv: {
						$0: 'node titanium',
						$: 'titanium',
						$_: ['help'],
						_: [],
						$command: 'help'
					},
					sdk: {
						path: 'foo/bar'
					}
				};

			c.load(logger, {}, cli, function (err, ctx) {
				assert(!err, 'expected "foo" to load without error');
				cli.argv.should.have.ownProperty('$command');
				cli.argv.$command.should.equal('help');
				done();
			});
		});
示例#14
0
		it('should load module with function-based config', function (done) {
			var c = new Context({ name: 'bar', path: path.join(__dirname, 'resources', 'commands', 'bar.js') }),
				logger = new MockLogger;

			c.load(logger, {}, {}, function (err, ctx) {
				assert(!err, 'expected "bar" to load without error');

				ctx.flags.should.have.ownProperty('quiet');
				ctx.flags.should.have.ownProperty('colors');

				ctx.options.should.have.ownProperty('sdk');
				ctx.options.should.have.ownProperty('target');

				ctx.aliases.should.have.ownProperty('q');
				ctx.aliases.q.should.include('quiet');
				ctx.aliases.should.have.ownProperty('s');
				ctx.aliases.s.should.include('sdk');

				ctx.subcommands.should.have.ownProperty('list');

				done();
			});
		});
示例#15
0
		return co(function*() {
			// If the name is undefined, load all the plugins.
			if (name === undefined) {
				// Load all plugins in the config.
				for (const plugin of this.config.PLUGINS) {
					yield this.load(plugin).catch(ERROR);
				}
			} else {
				// Make sure the plugin isn't already loaded.
				if (this.plugins.find(element => element.name === name)) {
					throw new Error(`Plugin "${ name }" is already loaded.`);
				}

				// Load the plugin.
				const Plugin = require('./plugins/' + name);
				const plugin = new Plugin(this);
				this.plugins.push({
					name: name,
					plugin: plugin
				});
				yield plugin.load();
				console.log(`Loaded plugin "${ name }".`);
			}
		}.bind(this));
示例#16
0
		it('should load module with cli arg --platform', function (done) {
			var c = new Context({ name: 'foo', path: path.join(__dirname, 'resources', 'commands', 'foo.js') }),
				logger = new MockLogger,
				cli = {
					argv: {
						$0: 'node titanium',
						$: 'titanium',
						$_: ['--platform', 'ios'],
						_: [],
						$command: 'bar'
					},
					sdk: {
						path: __dirname
					},
					scanHooks: function () {}
				};

			c.load(logger, {}, cli, function (err, ctx) {
				assert(!err, 'expected "foo" to load without error');
				cli.argv.should.have.ownProperty('platform');
				cli.argv.platform.should.equal('ios');
				done();
			});
		});
 }).then(function() {
     // Load configuration file
     return config.load();
 }).then(function() {
示例#18
0
 it('should load preferences fixture', () => {
   preferences.load().should.eql(prefs_fixture);
 });
示例#19
0
文件: upsert.js 项目: aflatter/Locker
var path = require('path');
var fs = require('fs');
var request = require('request');
var lconfig = require(path.join(__dirname, "../Common/node/lconfig.js"));
lconfig.load(path.join(__dirname, "../Config/config.json"));

try {
    var js = JSON.parse(fs.readFileSync('./package.json'));
} catch(e) {
    console.error("missing or invalid ./package.json?");
    process.exit(1);

}
var base = path.dirname(__dirname) + "/"; // parent of Ops and trailing slash
var full = path.join(process.cwd(),"package.json");
var local = full.replace(base, "");
console.log("upserting "+local);
request.post({url:lconfig.lockerBase+'/map/upsert?manifest='+local}, function(err, resp) {
    if(err){
        console.error(err);
        process.exit(1);
    }
    console.log("done!");
    process.exit(0);
});
示例#20
0
			models.room_model.find({}, function(error, rooms){
				data.rooms = rooms;
				viewUtils.load(res, 'admin/rooms', data);
			});
示例#21
0
			models.prob_model.find({}, function(error, probs){
				data.probs = probs;
				viewUtils.load(res, 'admin/probs', data);
			});
示例#22
0
  appenders: [
    {
      type: 'ConsoleAppender',
      name: 'console',
      layout: {
        type: 'pattern',
        pattern: '%d{yyy-MM-dd HH:mm:ss} [%p] %c - %m%n'
      }
    }
  ],
  loggers: [
    {
      level: 'all',
      appenders: [
        'console'
      ]
    }
  ]
};

// Initialize and start Woodman with the above config,
// and log a few messages to the console.
woodman.load(config, function (err) {
  if (err) throw err;

  var logger = woodman.getLogger('joshfire.woodman.examples.node.node-amd');
  logger.log('Welcome to Woodman');
  logger.info('This is an info message');
  logger.warn('This is a warning');
  logger.error('This is an error');
});
示例#23
0
  next();
});

// set up sessions
app.use(session({
  secret: 'this is actually public'
}));

// give views/layouts direct access to session data
app.use(function(req, res, next){
  res.locals.session = req.session;
  next();
});

// make everything in db/*.json available in app.locals
db.load(app);

// routes (found in app/routes.js)

routes.bind(app);

// auto render any view that exists

app.get(/^\/([^.]+)$/, function (req, res) {

	var path = (req.params[0]);

	res.render(path, function(err, html) {
		if (err) {
			console.log(err);
			res.send(404);
示例#24
0
 assert.throws(function () {
   jsyaml.load(fs.readFileSync(error_filename, 'utf8'));
 }, _errors.YAMLError);
示例#25
0
文件: server.js 项目: olegdev/kungfu
// ============= Bootstrap models ==========

fs.readdirSync(join(BASE_PATH, 'server/models')).forEach(function (file) {
  if (~file.indexOf('.js')) require(join(BASE_PATH, 'server/models', file));
});

// ============ Bootstrap api =============
fs.readdirSync(join(BASE_PATH, 'server/api')).forEach(function (file) {
  if (~file.indexOf('.js')) require(join(BASE_PATH, 'server/api', file));
});

// ============ Load dictionary ===========
dictionary.load(function(err) {
	if (!err) {
		/****/ logger.info('Dictionary loaded with ' + dictionary.dictionary.words.length + ' words');
	} else {
		/****/ logger.error('Dictionary load error');
	}
});

// ============ Load bots ===========
bots.load(function(err) {
	if (!err) {
		/****/ logger.info('Bots loaded');
	} else {
		/****/ logger.error('Bots load error');
	}
});

// ============ Recalc rating ===========
rating.recalcRating(function(err) {
(function testRequire() {
  var foo = SandboxedModule.load('../fixture/foo').exports;
  assert.strictEqual(foo.foo, 'foo');
  assert.strictEqual(foo.bar, 'bar');
})();
    expect(function () {
      var normalizer = new Normalizer();
      normalizer.load({url_rules : []});

      expect(normalizer.normalize('/sample')).eql({name : '/sample'});
    }).not.throws();
示例#28
0
require('othermodule');
require('submodule');

// Explicit order
require('./views/Error');

var path = require('path');
var bones = require(path.join(__dirname, '../../'));

bones.load(__dirname);

if (!module.parent) {
    bones.start();
}
示例#29
0
'use strict';
/*
Примерный файл подключения AzbNode
*/
var cfg = {
	'path' : {
		'azbnode' : './azbnode',
		'app' : './azbnapps/telegram_azbnbot',
		'subapp' : 'default',
	}
};

var azbn = require(cfg.path.azbnode + '/azbnode');

azbn.load('azbnodeevents', new require(cfg.path.azbnode + '/azbnodeevents')(azbn));
azbn.event('loaded_azbnode', azbn);


//парсинг параметров командной строки
azbn.parseArgv();
azbn.event('parsed_argv', azbn);

cfg.path.subapp = azbn.getArgv('root')||cfg.path.subapp;

azbn.load('mysql', require(cfg.path.app + '/' + cfg.path.subapp + '/mysql'));

azbn.event('loaded_mdls', azbn);

/* --------- Код здесь --------- */

//azbn.echo(azbn.mdl('cfg').vk.appId);
示例#30
0
 it('should null when no preferences exist', () => {
   fs.removeSync(preferences.file());
   should.not.exist(preferences.load());
 });