I want to create a cli to create admin users I have the user model setup in api/models/User.js
and in cli on
var User, program;
program = require("commander");
User = require("../api/models/User");
program.version("0.0.1");
program.command("create_user").description("Create a user into database").action(function() {
return console.log(User);
});
program.parse(process.argv);
User log is:
User = {
attributes: {
username: "string",
password: "string",
}
};
and no waterline methods available to use.
You can use sails run <command>
.
Simply create <appPath>/commands/index.js
with this content:
module.exports = {
testcommand: function (done) {
// .. your code
console.log('this is my testcommand');
done();
}
}
now you can run sails run testcommand
If any one needs this:
sails = require("sails");
sails.lift({
log: {
level: 'silent'
}
}, function() {
User.create(obj);
process.stdin.destroy();
});
来源:https://stackoverflow.com/questions/16739291/sails-js-using-models-outside-web-server