如何在树线中获得项目机器

How to get the project machine in treeline

treeline 中,您有一个项目机器,其中包含您的自定义机器和创建用户等功能。

我想知道是否有可变或简单的方法来检索项目机器目录名称(例如“_project_1234_0.0.1”)部分。

我打算从服务创建用户(和其他模型)。

由于我的问题没有答案,我抽出时间整理了一下。

将以下内容放入

config/bootstrap.js

// Set Treeline machine
var fs = require('fs');
var _ = require('lodash');

// Get all machine directories and loop through them
var machines = fs.readdirSync('api/machines/');
_.forEach(machines, function(machine){

  // Find the machine starting with '_project_'
  if(_.startsWith(machine, '_project_')){
    // Set machine name in sails.config.treeline
    sails.config.treeline.machine = machine;
  }
});

treeline 机器名称将在整个项目中作为

访问

sails.config.treeline.machine