Skip to content

Commit

Permalink
Added list choices for ci cd
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron-K-T-Berry committed Mar 1, 2019
1 parent b82778f commit ae7fe2e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
# Todo
- Add support for other ci cd platforms like travis
- Add option to specify path of install
- Print out all options after yo message
- Print out all options after yo message
- Better testing of git configs in prompts
56 changes: 43 additions & 13 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const licenses = [
{ name: "No License (Copyrighted)", value: "UNLICENSED" }
];

const ciCdPlatforms = ["travisCi", "circleCi", "None"];

const getLicenseValue = name => {
for (const item of licenses) {
if (item.name === name) {
Expand All @@ -30,9 +32,14 @@ const getLicenseValue = name => {
}
};

var gitConfigs = gitConfig.sync();
let configs = {};
let roleRoot;

module.exports = class extends Generator {
initializing() {
configs.gitConfigs = gitConfig.sync();
}

prompting() {
this.log(yosay(`Welcome to the groundbreaking ${chalk.red("generator-ansible")} generator!`));

Expand Down Expand Up @@ -60,13 +67,13 @@ module.exports = class extends Generator {
type: "text",
name: "gitAuthorName",
message: "What is your name (Will be used in the meta file and package.json)?",
default: gitConfigs.user.name
default: configs.gitConfigs.user.name
},
{
type: "text",
name: "gitAuthorEmail",
message: "What is your email (Will be used in the meta file and package.json)?",
default: gitConfigs.user.email
default: configs.gitConfigs.user.email
},
{
type: "confirm",
Expand Down Expand Up @@ -96,9 +103,18 @@ module.exports = class extends Generator {
return response.includeMolecule;
},
type: "confirm",
name: "includeCircleCi",
message: "Would you like to include a basic circle ci config for molecule?",
name: "includeCiCd",
message: "Would you like to include a basic ci cd config for molecule?",
default: true
},
{
when: response => {
return response.includeCiCd;
},
type: "list",
name: "ciCdPlatform",
message: "What ci cd platform?",
choices: ciCdPlatforms
}
];

Expand Down Expand Up @@ -131,20 +147,33 @@ module.exports = class extends Generator {
});
}

configuring() {
// Setting veriables for the rest of the generator from prompts
roleRoot = `./${this.props.roleName}`;

// CICD
if (this.props.includeCiCd) {
switch (this.props.ciCdPlatform) {
case "None":
break;
case "travisCi":
this.fs.copy(this.templatePath("travis/.travis.yml"), path.join(roleRoot, ".travis.yml"));
break;
case "circleCi":
mkdirp.sync(path.join(roleRoot, ".circleci"));
this.fs.copy(this.templatePath("ci/.circleci"), path.join(roleRoot, ".circleci"));
break;
}
}
}

default() {
// Folder root
const roleRoot = `./${this.props.roleName}`;
this.props.roleRoot = roleRoot;
mkdirp.sync(roleRoot);
this.fs.copy(this.templatePath("root-files"), roleRoot);
this.fs.copy(this.templatePath("root-files/.**"), roleRoot);

// CIRCLECI
if (this.props.includeCircleCi) {
mkdirp.sync(path.join(roleRoot, ".circleci"));
this.fs.copy(this.templatePath(".circleci"), path.join(roleRoot, ".circleci"));
}

// DEFAULTS
mkdirp.sync(path.join(roleRoot, "defaults"));
this.fs.copy(this.templatePath("defaults"), path.join(roleRoot, "defaults"));
Expand All @@ -163,7 +192,6 @@ module.exports = class extends Generator {
}

writing() {
const roleRoot = `./${this.props.roleName}`;

// MOLECULE
if (this.props.includeMolecule) {
Expand Down Expand Up @@ -256,4 +284,6 @@ module.exports = class extends Generator {
// Fixing permissions
exec(`chmod +x ${path.join(this.destinationRoot(), this.props.roleRoot, "run-test.sh")}`);
}

end() {}
};
1 change: 1 addition & 0 deletions generators/app/templates/ci/travis/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO write this file

0 comments on commit ae7fe2e

Please sign in to comment.