Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fragmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosommi committed Oct 20, 2015
2 parents ac8db92 + c34a11e commit 78a3888
Show file tree
Hide file tree
Showing 23 changed files with 373 additions and 117 deletions.
28 changes: 2 additions & 26 deletions es5/lib/app.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,14 @@ module.exports = yeoman.generators.Base.extend({
_this.fs.copyTpl(_this.templatePath("es6/features/steps/" + templatePath), _this.destinationPath("es6/features/steps/" + context.name + "/" + newName), context);
}, this);

//copy common steps
["_common.steps.js", "_accessToken.steps.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/steps/" + templatePath), _this.destinationPath("es6/features/steps/" + newName), context);
}, this);

//copy common functions
["_jsonWebToken.js", "_language.js", "_request.js", "_values.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/steps/common/" + templatePath), _this.destinationPath("es6/features/steps/common/" + newName), context);
}, this);

//copy support files
["_hooks.js", "_world.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/support/" + templatePath), _this.destinationPath("es6/features/support/" + newName), context);
}, this);

//copy controllers
["_modelController.js", "_applicationController.js"].forEach(function (templatePath) {
["_modelController.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/controllers/" + templatePath), _this.destinationPath("es6/app/controllers/" + newName), context);
}, this);

//copy managers
["_accountManager.js", "_modelManager.js"].forEach(function (templatePath) {
["_modelManager.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/managers/" + templatePath), _this.destinationPath("es6/app/managers/" + newName), context);
}, this);
Expand All @@ -118,12 +100,6 @@ module.exports = yeoman.generators.Base.extend({
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/routers/" + templatePath), _this.destinationPath("es6/app/routers/" + newName), context);
}, this);

//copy misc
["_errors.js", "_server.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/" + templatePath), _this.destinationPath("es6/app/" + newName), context);
}, this);
},

install: function yoInstall() {
Expand Down
116 changes: 116 additions & 0 deletions es5/lib/common.index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
"use strict";

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var _jargon = require("jargon");

var _jargon2 = _interopRequireDefault(_jargon);

var yeoman = require("yeoman-generator");
var chalk = require("chalk");
var yosay = require("yosay");

module.exports = yeoman.generators.Base.extend({
initializing: function yoInitializing() {
this.pkg = require("../../package.json");
},

prompting: function yoPrompt() {
var done = this.async();

// Have Yeoman greet the user.
this.log(yosay("Welcome to the stylish " + chalk.red("FamScudl") + " generator! our base path is " + this.destinationRoot()));

var prompts = [{
type: "input",
name: "name",
message: "What is the model name? (use camel case please)",
"default": "myModel"
}, {
type: "input",
name: "attributeString",
message: "Provide the model attributes sepparated by a comma? (like name,link,email,contactPhone)",
"default": "name"
}];

this.prompt(prompts, (function (props) {
this.props = props;
done();
}).bind(this));
},

writing: function yoWriting() {
var _this = this;

var context = {
name: this.props.name,
Name: (0, _jargon2["default"])(this.props.name).pascal.toString(),
names: (0, _jargon2["default"])(this.props.name).plural.toString(),
_name: (0, _jargon2["default"])(this.props.name).snake.toString(),
attributes: this.props.attributes,
attributeString: this.props.attributeString
};

context.attributes = context.attributeString.split(",");

//filling a strings that are going to be used in the templates to mock a test entity
context.attributesWithValues = "";
context.fieldsWithValues = "";
context.validateString = "";
context.attributes.forEach(function (attributeName, index) {
if (index > 0) {
var breakLine = ",\n";
context.attributesWithValues += breakLine;
context.fieldsWithValues += breakLine;
context.validateString += breakLine;
}
var snakeAttributeName = (0, _jargon2["default"])(attributeName).snake.toString();
context.attributesWithValues += "\"" + attributeName + "\": \"test " + attributeName + "\"";
context.fieldsWithValues += "\"" + snakeAttributeName + "\": " + context.name + "." + attributeName;
context.validateString += "this.ensure(\"" + attributeName + "\", isNotEmpty);";
});
context.attributesJson = JSON.stringify(context.attributesWithValues);

//copy common steps
["_common.steps.js", "_accessToken.steps.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/steps/" + templatePath), _this.destinationPath("es6/features/steps/" + newName), context);
}, this);

//copy common functions
["_jsonWebToken.js", "_language.js", "_request.js", "_values.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/steps/common/" + templatePath), _this.destinationPath("es6/features/steps/common/" + newName), context);
}, this);

//copy support files
["_hooks.js", "_world.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/features/support/" + templatePath), _this.destinationPath("es6/features/support/" + newName), context);
}, this);

//copy controllers
["_applicationController.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/controllers/" + templatePath), _this.destinationPath("es6/app/controllers/" + newName), context);
}, this);

//copy managers
["_accountManager.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_model", "" + context.name).replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/managers/" + templatePath), _this.destinationPath("es6/app/managers/" + newName), context);
}, this);

//copy misc
["_errors.js", "_server.js"].forEach(function (templatePath) {
var newName = templatePath.replace("_", "");
_this.fs.copyTpl(_this.templatePath("es6/app/" + templatePath), _this.destinationPath("es6/app/" + newName), context);
}, this);
},

install: function yoInstall() {
this.installDependencies({
skipInstall: true
});
}
});
14 changes: 3 additions & 11 deletions es5/spec/app.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,25 @@ describe("troupe", function () {
});

it("creates cucumber js files", function () {
assert.file(["es6/features/steps/" + name + "/" + name + ".show.steps.js", "es6/features/steps/" + name + "/" + name + ".create.steps.js", "es6/features/steps/" + name + "/" + name + ".update.steps.js", "es6/features/steps/" + name + "/" + name + ".delete.steps.js", "es6/features/steps/" + name + "/" + name + ".list.steps.js", "es6/features/steps/common/jsonWebToken.js", "es6/features/steps/common/language.js", "es6/features/steps/common/request.js", "es6/features/steps/common/values.js", "es6/features/steps/accessToken.steps.js", "es6/features/support/hooks.js", "es6/features/support/world.js"]);
});

it("creates a common step file", function () {
assert.file(["es6/features/steps/common.steps.js"]);
assert.file(["es6/features/steps/" + name + "/" + name + ".show.steps.js", "es6/features/steps/" + name + "/" + name + ".create.steps.js", "es6/features/steps/" + name + "/" + name + ".update.steps.js", "es6/features/steps/" + name + "/" + name + ".delete.steps.js", "es6/features/steps/" + name + "/" + name + ".list.steps.js"]);
});

it("creates the model and his spec", function () {
assert.file(["es6/app/models/" + name + ".js", "es6/spec/" + name + ".spec.js"]);
});

it("creates the controllers", function () {
assert.file(["es6/app/controllers/" + name + "Controller.js", "es6/app/controllers/applicationController.js"]);
assert.file(["es6/app/controllers/" + name + "Controller.js"]);
});

it("creates the managers", function () {
assert.file(["es6/app/managers/" + name + "Manager.js", "es6/app/managers/accountManager.js"]);
assert.file(["es6/app/managers/" + name + "Manager.js"]);
});

it("creates the router", function () {
assert.file(["es6/app/routers/" + name + "Router.js", "es6/app/routers/" + name + "Routes.js"]);
});

it("creates misc files", function () {
assert.file(["es6/app/errors.js", "es6/app/server.js"]);
});

describe("(about the content of every feature)", function () {
it("should have some this.database = on it", function () {
assert.fileContent([["es6/features/steps/" + name + "/" + name + ".show.steps.js", "this.database"]]);
Expand Down
38 changes: 38 additions & 0 deletions es5/spec/common.index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";

var path = require("path");
var assert = require("yeoman-generator").assert;
var helpers = require("yeoman-generator").test;
var os = require("os");

describe("troupe", function () {
var name = undefined;

before(function (done) {
name = "model";
helpers.run(path.join(__dirname, "../../generators/common")).inDir(path.join(os.tmpdir(), "./temp-test")).withOptions({ "skip-install": true }).withPrompts({
name: name,
attributes: "name"
}).on("end", done);
});

it("creates cucumber js files", function () {
assert.file(["es6/features/steps/common/jsonWebToken.js", "es6/features/steps/common/language.js", "es6/features/steps/common/request.js", "es6/features/steps/common/values.js", "es6/features/steps/accessToken.steps.js", "es6/features/support/hooks.js", "es6/features/support/world.js"]);
});

it("creates a common step file", function () {
assert.file(["es6/features/steps/common.steps.js"]);
});

it("creates the controllers", function () {
assert.file(["es6/app/controllers/applicationController.js"]);
});

it("creates the managers", function () {
assert.file(["es6/app/managers/accountManager.js"]);
});

it("creates misc files", function () {
assert.file(["es6/app/errors.js", "es6/app/server.js"]);
});
});
3 changes: 2 additions & 1 deletion es5/spec/features.index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe("troupe:features", function () {
before(function (done) {
name = "model";
helpers.run(path.join(__dirname, "../../generators/features")).inDir(path.join(os.tmpdir(), "./temp-test")).withOptions({ "skip-install": true }).withPrompts({
name: name
name: name,
attributes: "name"
}).on("end", done);
});

Expand Down
56 changes: 2 additions & 54 deletions es6/lib/app.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,47 +82,8 @@ module.exports = yeoman.generators.Base.extend({
);
}, this);

//copy common steps
["_common.steps.js",
"_accessToken.steps.js"]
.forEach((templatePath) => {
let newName = templatePath.replace("_", "");
this.fs.copyTpl(
this.templatePath(`es6/features/steps/${templatePath}`),
this.destinationPath(`es6/features/steps/${newName}`),
context
);
}, this);

//copy common functions
["_jsonWebToken.js",
"_language.js",
"_request.js",
"_values.js"]
.forEach((templatePath) => {
let newName = templatePath.replace("_", "");
this.fs.copyTpl(
this.templatePath(`es6/features/steps/common/${templatePath}`),
this.destinationPath(`es6/features/steps/common/${newName}`),
context
);
}, this);

//copy support files
["_hooks.js",
"_world.js"]
.forEach((templatePath) => {
let newName = templatePath.replace("_", "");
this.fs.copyTpl(
this.templatePath(`es6/features/support/${templatePath}`),
this.destinationPath(`es6/features/support/${newName}`),
context
);
}, this);

//copy controllers
["_modelController.js",
"_applicationController.js"]
["_modelController.js"]
.forEach((templatePath) => {
let newName = templatePath.replace("_model", `${context.name}`).replace("_", "");
this.fs.copyTpl(
Expand All @@ -133,8 +94,7 @@ module.exports = yeoman.generators.Base.extend({
}, this);

//copy managers
["_accountManager.js",
"_modelManager.js"]
["_modelManager.js"]
.forEach((templatePath) => {
let newName = templatePath.replace("_model", `${context.name}`).replace("_", "");
this.fs.copyTpl(
Expand Down Expand Up @@ -169,18 +129,6 @@ module.exports = yeoman.generators.Base.extend({
context
);
}, this);

//copy misc
["_errors.js",
"_server.js"]
.forEach((templatePath) => {
let newName = templatePath.replace("_", "");
this.fs.copyTpl(
this.templatePath(`es6/app/${templatePath}`),
this.destinationPath(`es6/app/${newName}`),
context
);
}, this);
},

install: function yoInstall() {
Expand Down
Loading

0 comments on commit 78a3888

Please sign in to comment.