tyr-cli
Version:
A command line interface for hammer-io.
263 lines (204 loc) • 19.2 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.generateProject = exports.commitToGithub = exports.setUpThirdPartyTools = exports.generateStaticFiles = exports.heroku = exports.generateSkadiFiles = exports.generateSequelizeFiles = exports.generateMochaFiles = exports.generateBasicNodeProject = undefined;
/**
* Facilitates enabling github for the user. Enables/Creates GitHub repository
* @configs the configuration object
* @returns {Promise<void>}
*/let github = (() => {var _ref = _asyncToGenerator(
function* (configs) {
const repositoryName = configs.projectConfigurations.projectName;
const repositoryDescription = configs.projectConfigurations.description;
const credentials = configs.credentials.github;
const isPrivate = configs.projectConfigurations.isPrivateProject;
yield githubService.createGitHubRepository(
repositoryName,
repositoryDescription,
credentials,
isPrivate);
return configs;
});return function github(_x) {return _ref.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for a basic nodejs project
* @param configs the configurations object
* @param filePath the new project's file path
* @returns {Promise<void>}
*/let generateBasicNodeProject = exports.generateBasicNodeProject = (() => {var _ref2 = _asyncToGenerator(
function* (configs, filePath) {
const projectPath = `${filePath}/${configs.projectConfigurations.projectName}`;
yield projectService.generateBasicNodeFiles(configs, projectPath);
return configs;
});return function generateBasicNodeProject(_x2, _x3) {return _ref2.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for GitHub/Git Support
* @param configs the configurations object
* @param projectPath the new project's file path
* @returns {Promise<void>}
*/let generateGithubFiles = (() => {var _ref3 = _asyncToGenerator(
function* (configs, projectPath) {
yield githubService.generateGithubFiles(projectPath);
return configs;
});return function generateGithubFiles(_x4, _x5) {return _ref3.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for TravisCI support
* @param configs the configurations object
* @param projectPath the new project's file path
* @returns {Promise<void>}
*/let generateTravisFiles = (() => {var _ref4 = _asyncToGenerator(
function* (configs, projectPath) {
yield travisService.generateTravisCIFile(configs, projectPath);
return configs;
});return function generateTravisFiles(_x6, _x7) {return _ref4.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for Docker support
* @param configs the configurations object
* @param projectPath the new project's file path
* @returns {Promise<void>}
*/let generateDockerFiles = (() => {var _ref5 = _asyncToGenerator(
function* (configs, projectPath) {
yield dockerService.generateDockerFiles(projectPath);
return configs;
});return function generateDockerFiles(_x8, _x9) {return _ref5.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for ExpressJS
* @param configs the configuration object
* @param projectPath the new project's file path
* @returns {Promise<void>}
*/let generateExpressFiles = (() => {var _ref6 = _asyncToGenerator(
function* (configs, projectPath) {
yield expressService.generateExpressFiles(projectPath);
return configs;
});return function generateExpressFiles(_x10, _x11) {return _ref6.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for mocha
* @param configs the configuration object
* @param projectPath the new project's file path
* @returns {Promise<*>}
*/let generateMochaFiles = exports.generateMochaFiles = (() => {var _ref7 = _asyncToGenerator(
function* (configs, projectPath) {
yield mochaService.generateMochaFiles(projectPath);
return configs;
});return function generateMochaFiles(_x12, _x13) {return _ref7.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for sequelize
* @param configs the configuration object
* @param projectPath the new project's file path
* @returns {Promise<*>}
*/let generateSequelizeFiles = exports.generateSequelizeFiles = (() => {var _ref8 = _asyncToGenerator(
function* (configs, projectPath) {
yield sequelizeService.generateSequelizeFiles(configs, projectPath);
return configs;
});return function generateSequelizeFiles(_x14, _x15) {return _ref8.apply(this, arguments);};})();
/**
* Facilitates generating the necessary files for skadi
* @param configs the configuration object
* @param projectPath the new proejct's file path
* @returns {Promise<void>}
*/let generateSkadiFiles = exports.generateSkadiFiles = (() => {var _ref9 = _asyncToGenerator(
function* (configs, projectPath) {
yield skadiService.generateSkadiFiles(configs, projectPath);
return configs;
});return function generateSkadiFiles(_x16, _x17) {return _ref9.apply(this, arguments);};})();
/**
* Facilitates enabling travis ci for the user.
* @configs the configuration object
* @returns {Promise<void>}
*/let travisci = (() => {var _ref10 = _asyncToGenerator(
function* (configs) {
yield travisService.enableTravis(configs);
return configs;
});return function travisci(_x18) {return _ref10.apply(this, arguments);};})();
/**
* Facilitates enabling heroku for the user. Creates Heroku App.
* @param configs the configuration object
* @returns {Boolean} returns true if the app was successfully created, returns false if there
* was an error because the app name is unavailable.
*/let heroku = exports.heroku = (() => {var _ref11 = _asyncToGenerator(
function* (configs) {
const updatedConfig = configs;
let appName = configs.projectConfigurations.projectName;
const apiKey = configs.credentials.heroku.apiKey;
appName = (0, _herokuUtil.makeHerokuAppNameCompliant)(appName);
if (appName !== configs.projectConfigurations.projectName) {
log.warn('The name you chose was not compatible with Heroku naming conventions. We\'ve made your app name all ' +
'lowercase letters and removed any special characters and replaced them with a \'-\'.');
}
let isCreated = yield herokuService.createApp(appName, apiKey);
while (!isCreated) {
log.warn('The name you chose was not available on Heroku. We\'ve appended a short id at the' +
' end of your application name in order to make in unique.');
appName = `${appName}-${_shortid2.default.generate().substring(0, 7)}`;
appName = (0, _herokuUtil.makeHerokuAppNameCompliant)(appName);
isCreated = yield herokuService.createApp(appName, apiKey);
}
updatedConfig.projectConfigurations.herokuAppName = appName;
log.info(`Successfully created Heroku App ${appName}`);
return updatedConfig;
});return function heroku(_x19) {return _ref11.apply(this, arguments);};})();
// The services construct. This object acts as a selector. Add a method to this construct if there
// is a new service to the application. From that method, you can add the functionality to start
// supporting a new third party service.
let generateStaticFiles = exports.generateStaticFiles = (() => {var _ref12 = _asyncToGenerator(
function* (configs, filePath) {
// generating static files
const projectPath = `${filePath}/${configs.projectConfigurations.projectName}`;
try {
for (const key of Object.keys(configs.toolingConfigurations)) {
const tool = configs.toolingConfigurations[key];
if (staticFileGenerators[tool.toLowerCase()]) {
yield staticFileGenerators[tool.toLowerCase()](configs, projectPath);
}
}
} catch (error) {
return Promise.reject(error);
}
// write configs to a file
yield projectService.generateTyrfile(configs, projectPath);
});return function generateStaticFiles(_x20, _x21) {return _ref12.apply(this, arguments);};})();let setUpThirdPartyTools = exports.setUpThirdPartyTools = (() => {var _ref13 = _asyncToGenerator(
function* (configs) {
// enabling third party tools
try {
for (const key of Object.keys(configs.toolingConfigurations)) {
const tool = configs.toolingConfigurations[key];
if (services[tool.toLowerCase()]) {
// eslint-disable-next-line no-param-reassign
configs = yield services[tool.toLowerCase()](configs);
}
}
} catch (error) {
return Promise.reject(error);
}
});return function setUpThirdPartyTools(_x22) {return _ref13.apply(this, arguments);};})();let commitToGithub = exports.commitToGithub = (() => {var _ref14 = _asyncToGenerator(
function* (configs, filePath) {
// init, add, commit, push to github
try {
if (configs.toolingConfigurations.sourceControl && configs.toolingConfigurations.sourceControl.toLowerCase() === 'github') {
yield githubService.initAddCommitAndPush(
configs.credentials.github,
configs.projectConfigurations.projectName,
filePath);
log.info('Successfully committed and pushed files to GitHub Repository');
}
} catch (error) {
return Promise.reject(error);
}
});return function commitToGithub(_x23, _x24) {return _ref14.apply(this, arguments);};})();
/**
* Generates a project
* @param configs the configurations object
* @returns {Promise<void>}
*/let generateProject = exports.generateProject = (() => {var _ref15 = _asyncToGenerator(
function* (configs) {
console.log();
log.info('>>> Generating Project!', configs);
const filePath = process.cwd();
try {
yield generateBasicNodeProject(configs, filePath);
yield setUpThirdPartyTools(configs);
yield generateStaticFiles(configs, filePath);
yield commitToGithub(configs, filePath);
} catch (error) {
log.error(error.message);
}
});return function generateProject(_x25) {return _ref15.apply(this, arguments);};})();var _shortid = require('shortid');var _shortid2 = _interopRequireDefault(_shortid);var _projectService = require('./services/project-service');var projectService = _interopRequireWildcard(_projectService);var _githubService = require('./services/github-service');var githubService = _interopRequireWildcard(_githubService);var _herokuService = require('./services/heroku-service');var herokuService = _interopRequireWildcard(_herokuService);var _travisService = require('./services/travis-service');var travisService = _interopRequireWildcard(_travisService);var _dockerService = require('./services/docker-service');var dockerService = _interopRequireWildcard(_dockerService);var _expressService = require('./services/express-service');var expressService = _interopRequireWildcard(_expressService);var _mochaService = require('./services/mocha-service');var mochaService = _interopRequireWildcard(_mochaService);var _sequelizeService = require('./services/sequelize-service');var sequelizeService = _interopRequireWildcard(_sequelizeService);var _skadiService = require('./services/skadi-service');var skadiService = _interopRequireWildcard(_skadiService);var _winston = require('./utils/winston');var _herokuUtil = require('./utils/heroku-util');function _interopRequireWildcard(obj) {if (obj && obj.__esModule) {return obj;} else {var newObj = {};if (obj != null) {for (var key in obj) {if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key];}}newObj.default = obj;return newObj;}}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};} /* eslint-disable no-param-reassign,no-await-in-loop,no-restricted-syntax,prefer-destructuring */const log = (0, _winston.getActiveLogger)();const services = { github, travisci, heroku }; // The file generator construct. This object acts as a selector. Add a key/value pair to this
// construct if the new service you are adding requires static files to be generated. The value
// should be a method that should call the file generator.
const staticFileGenerators = { github: generateGithubFiles, travisci: generateTravisFiles, docker: generateDockerFiles, expressjs: generateExpressFiles, mocha: generateMochaFiles, sequelize: generateSequelizeFiles, skadi: generateSkadiFiles };