tyr-cli
Version:
A command line interface for hammer-io.
58 lines (49 loc) • 5.07 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.generateSequelizeFiles = undefined;
/**
* Creates the sequelize file from the template and writes it to the user's project
* @param path the path to the db directory in the project
*/let createSequelizeFile = (() => {var _ref = _asyncToGenerator(
function* (path) {
const sequelizeTemplate = file.loadTemplate('./../../templates/sequelize/sequelize.js');
yield file.writeFile(`${path}/sequelize.js`, sequelizeTemplate);
});return function createSequelizeFile(_x) {return _ref.apply(this, arguments);};})();
/**
* Updates the package.json file for the project with the sequelize dependency
* @param path the path to the new project directory
* @returns {Promise<void>}
*/let updatePackageJsonWithSequelizeDependencies = (() => {var _ref2 = _asyncToGenerator(
function* (path) {
packageJsonUtil.addDependencyToPackageJsonFile(path, 'sequelize', '^4.33.2');
packageJsonUtil.addDependencyToPackageJsonFile(path, 'mysql2', '^1.5.2');
});return function updatePackageJsonWithSequelizeDependencies(_x2) {return _ref2.apply(this, arguments);};})();
/**
* Updates the index.js file to add the sequelize require statement
* @param path the path to the new project src folder
*/let updateIndexJs = (() => {var _ref3 = _asyncToGenerator(
function* (path) {
const indexJSFileName = `${path}/index.js`;
let contents = file.readFile(indexJSFileName);
const firstLine = 'const sequelize = require(\'./db/sequelize\');\n';
contents = firstLine + contents;
file.deleteFile(indexJSFileName);
file.writeFile(indexJSFileName, contents);
});return function updateIndexJs(_x3) {return _ref3.apply(this, arguments);};})();
/**
* Generates the files necessary for sequelize and updates the package.json with the proper
* dependencies
* @param configs
* @param projectPath
* @returns {Promise<void>}
*/let generateSequelizeFiles = exports.generateSequelizeFiles = (() => {var _ref4 = _asyncToGenerator(
function* (configs, projectPath) {
const path = `${projectPath}/`;
const dbFolderPath = `${path}/src/db`;
file.createDirectory(dbFolderPath);
// create sequelize file
yield createSequelizeFile(dbFolderPath);
// update package.json
yield updatePackageJsonWithSequelizeDependencies(path);
// update the index.js file
yield updateIndexJs(`${path}/src/`);
return configs;
});return function generateSequelizeFiles(_x4, _x5) {return _ref4.apply(this, arguments);};})();var _file = require('../utils/file');var file = _interopRequireWildcard(_file);var _packageJsonUtil = require('../utils/package-json-util');var packageJsonUtil = _interopRequireWildcard(_packageJsonUtil);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 _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 import/prefer-default-export,prefer-destructuring */