UNPKG

dotfiles-generator

Version:

Utility to auto-generate dotfiles like .gitignore, .editorconfig etc. in your project.

67 lines (50 loc) 1.65 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRootPath = getRootPath; exports.getSourcePath = getSourcePath; exports.getDestinationPath = getDestinationPath; exports.isPathExist = isPathExist; exports.isDirectoryExist = isDirectoryExist; exports.logger = logger; var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _fsExtra = require('fs-extra'); var _fsExtra2 = _interopRequireDefault(_fsExtra); var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function getRootPath() { return _path2.default.join(_path2.default.dirname(require.main.filename), '..'); } function getSourcePath() { return _path2.default.join(getRootPath(), 'dotfiles'); } /** * if not, check if env is passed and the value is l i.e. local, set the path for local installation * if not, which means a global installation, set the path to current directory * @param {*} env */ function getDestinationPath(mode) { return mode && mode === 'l' ? _path2.default.join(getRootPath(), '..', '..', '..') : process.cwd(); } function isPathExist(p) { return _fsExtra2.default.existsSync(p); } function isDirectoryExist(p) { return isPathExist(p) && _fsExtra2.default.statSync(p).isDirectory() ? true : false; } function logger(msg, t) { switch (t) { case 'ERROR': console.error(_chalk2.default.red(msg)); return false; case 'INFO': console.error(_chalk2.default.gray(msg)); break; default: console.log(msg); break; } }