From 5ed7bef852256847a4856b97720844c8e0eebf33 Mon Sep 17 00:00:00 2001 From: jh3y Date: Tue, 23 Feb 2016 20:20:38 +0000 Subject: [PATCH 01/11] Foundation of rework to es6 implementation --- .babelrc | 1 + .eslintrc | 29 +++++ .jshintrc | 3 + Makefile | 4 - bin/kody | 2 +- .../fish/config.fish | 0 dummy_env/kody.json | 4 + gulpfile.js | 26 ---- lib/TASK_BOILERPLATE.js | 17 +++ lib/core.js | 42 ++++++ lib/kody.js | 121 ++++++++++++++---- lib/main.js | 51 +++----- lib/task_runner.js | 92 +------------ lib/tasks/a.js | 18 +++ lib/tasks/apm_install.js | 1 - lib/tasks/b.js | 13 ++ lib/tasks/brew_install.js | 44 ------- lib/tasks/dotfiles.js | 72 +++++++++++ lib/tasks/fish.js | 38 ------ lib/tasks/git_config.js | 58 --------- lib/tasks/gitconfig.js | 45 +++++++ lib/tasks/install_atom_packages.js | 31 ----- lib/tasks/install_dot_files.js | 67 ---------- lib/tasks/install_npm_modules.js | 37 ------ lib/tasks/npm_install.js | 37 ------ lib/tasks/osx.js | 43 ------- lib/tasks/remove_default_apple_apps.js | 36 ------ lib/tasks/set_osx_defaults.js | 43 ------- lib/tasks/set_up_brew_cask.js | 40 ------ lib/tasks/set_up_fish_shell.js | 38 ------ lib/tasks/set_up_git_config.js | 58 --------- lib/tasks/set_up_homebrew.js | 44 ------- lib/utils.js | 69 +++++----- package.json | 36 ++++-- .../coffee/lib/kody.coffee | 0 .../coffee/lib/main.coffee | 0 .../coffee/lib/task_runner.coffee | 0 .../lib/tasks/install_atom_packages.coffee | 0 .../coffee/lib/tasks/install_dot_files.coffee | 0 .../lib/tasks/install_npm_modules.coffee | 0 .../tasks/remove_default_apple_apps.coffee | 0 .../coffee/lib/tasks/set_osx_defaults.coffee | 0 .../coffee/lib/tasks/set_up_brew_cask.coffee | 0 .../coffee/lib/tasks/set_up_fish_shell.coffee | 0 .../coffee/lib/tasks/set_up_git_config.coffee | 0 .../coffee/lib/tasks/set_up_homebrew.coffee | 0 .../coffee/lib/tasks/task.coffee.boilerplate | 0 src.deprecated/coffee/lib/utils.coffee | 18 +++ .../coffee/test/test.coffee | 0 src/coffee/lib/utils.coffee | 30 ----- src/lib/TASK_BOILERPLATE.js | 15 +++ src/lib/core.js | 22 ++++ src/lib/kody.js | 82 ++++++++++++ src/lib/main.js | 27 ++++ src/lib/task_runner.js | 0 src/lib/tasks/a.js | 16 +++ src/lib/tasks/b.js | 11 ++ src/lib/tasks/dotfiles.js | 49 +++++++ src/lib/tasks/gitconfig.js | 44 +++++++ src/lib/utils.js | 48 +++++++ src/test/test.js | 0 test/test.js | 16 +-- wipe-dependencies.js | 18 +++ 63 files changed, 775 insertions(+), 881 deletions(-) create mode 100644 .babelrc create mode 100644 .eslintrc create mode 100644 .jshintrc delete mode 100644 Makefile rename dummy_env/{ config.link => config.link}/fish/config.fish (100%) delete mode 100644 gulpfile.js create mode 100644 lib/TASK_BOILERPLATE.js create mode 100644 lib/core.js create mode 100644 lib/tasks/a.js delete mode 100644 lib/tasks/apm_install.js create mode 100644 lib/tasks/b.js delete mode 100644 lib/tasks/brew_install.js create mode 100644 lib/tasks/dotfiles.js delete mode 100644 lib/tasks/fish.js delete mode 100644 lib/tasks/git_config.js create mode 100644 lib/tasks/gitconfig.js delete mode 100644 lib/tasks/install_atom_packages.js delete mode 100644 lib/tasks/install_dot_files.js delete mode 100644 lib/tasks/install_npm_modules.js delete mode 100644 lib/tasks/npm_install.js delete mode 100644 lib/tasks/osx.js delete mode 100644 lib/tasks/remove_default_apple_apps.js delete mode 100644 lib/tasks/set_osx_defaults.js delete mode 100644 lib/tasks/set_up_brew_cask.js delete mode 100644 lib/tasks/set_up_fish_shell.js delete mode 100644 lib/tasks/set_up_git_config.js delete mode 100644 lib/tasks/set_up_homebrew.js rename {src => src.deprecated}/coffee/lib/kody.coffee (100%) rename {src => src.deprecated}/coffee/lib/main.coffee (100%) rename {src => src.deprecated}/coffee/lib/task_runner.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/install_atom_packages.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/install_dot_files.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/install_npm_modules.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/remove_default_apple_apps.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/set_osx_defaults.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/set_up_brew_cask.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/set_up_fish_shell.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/set_up_git_config.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/set_up_homebrew.coffee (100%) rename {src => src.deprecated}/coffee/lib/tasks/task.coffee.boilerplate (100%) create mode 100644 src.deprecated/coffee/lib/utils.coffee rename {src => src.deprecated}/coffee/test/test.coffee (100%) delete mode 100644 src/coffee/lib/utils.coffee create mode 100644 src/lib/TASK_BOILERPLATE.js create mode 100644 src/lib/core.js create mode 100644 src/lib/kody.js create mode 100644 src/lib/main.js create mode 100644 src/lib/task_runner.js create mode 100644 src/lib/tasks/a.js create mode 100644 src/lib/tasks/b.js create mode 100644 src/lib/tasks/dotfiles.js create mode 100644 src/lib/tasks/gitconfig.js create mode 100644 src/lib/utils.js create mode 100644 src/test/test.js create mode 100644 wipe-dependencies.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..e4aa8fe --- /dev/null +++ b/.babelrc @@ -0,0 +1 @@ +{"presets": ["es2015"] } diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..849b0ff --- /dev/null +++ b/.eslintrc @@ -0,0 +1,29 @@ +{ + "parser": "babel-eslint", + "env": { + "node": true + }, + "rules": { + "semi": [1, "always"], + "quotes": [1, "single"], + "curly": [1, "multi-line"], + "eqeqeq": [1, "smart"], + "camelcase":[1, {"properties": "always"}], + "no-alert": 1, + "no-console": 2, + "no-debugger": 1, + "no-eq-null": 1, + "no-empty": 1, + "no-duplicate-case": 1, + "no-dupe-keys": 1, + "no-dupe-args": 1, + "comma-dangle": [1, "never"], + "no-unreachable": 1, + "no-else-return": 1, + "no-eval": 2, + "no-unused-vars": 1, + "no-use-before-define": 1, + "new-cap": 1, + "strict": [1, "never"] + } +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..a5aaaed --- /dev/null +++ b/.jshintrc @@ -0,0 +1,3 @@ +{ + "esnext": true +} diff --git a/Makefile b/Makefile deleted file mode 100644 index 8d13511..0000000 --- a/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -test: - @./node_modules/.bin/mocha -u tdd --reporter spec - -.PHONY: test \ No newline at end of file diff --git a/bin/kody b/bin/kody index 46864e4..16b726b 100755 --- a/bin/kody +++ b/bin/kody @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('../lib/main.js'); \ No newline at end of file +require('../lib/main.js'); diff --git a/dummy_env/ config.link/fish/config.fish b/dummy_env/config.link/fish/config.fish similarity index 100% rename from dummy_env/ config.link/fish/config.fish rename to dummy_env/config.link/fish/config.fish diff --git a/dummy_env/kody.json b/dummy_env/kody.json index 86812c4..bc40fa3 100644 --- a/dummy_env/kody.json +++ b/dummy_env/kody.json @@ -8,6 +8,10 @@ "install_npm_modules": false, "set_fish_shell_as_default": false, "remove_default_apple_apps": true, + "git_credentials": { + "name": "jh3y", + "email": "jh3y@users.noreply.github.com" + }, "brew_installs": [ "git", "mongodb", diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 2190ee5..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,26 +0,0 @@ -var gulp = require('gulp'), - plumber = require('gulp-plumber'), - coffee = require('gulp-coffee'), - sources = { - coffee: "src/coffee/**/*.coffee" - }, - destinations = { - build: "" - }; - -gulp.task('coffee::build', function(event) { - return gulp.src(sources.coffee) - .pipe(plumber()) - .pipe(coffee({ - bare:true - })) - .pipe(gulp.dest(destinations.build)); -}); - -gulp.task('coffee::watch', function(event) { - gulp.watch(sources.coffee, ["coffee::build"]); -}); - -gulp.task('dev', ['coffee::watch']); - -gulp.task('default', ["dev"]); diff --git a/lib/TASK_BOILERPLATE.js b/lib/TASK_BOILERPLATE.js new file mode 100644 index 0000000..bbed939 --- /dev/null +++ b/lib/TASK_BOILERPLATE.js @@ -0,0 +1,17 @@ +'use strict'; + +/** + * Task - description + * @license MIT + * @author author +*/ + +var options = { + name: 'TASK-0001', + description: 'sets up something', + exec: function exec(resolve, reject) { + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/core.js b/lib/core.js new file mode 100644 index 0000000..ced01c8 --- /dev/null +++ b/lib/core.js @@ -0,0 +1,42 @@ +'use strict'; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var utils = require('./utils'), + defaults = { + name: 'Generic task', + exec: function exec(e) { + return utils.log('running', 'info'); + } +}; + +var KodyTask = function () { + function KodyTask() { + var opts = arguments.length <= 0 || arguments[0] === undefined ? defaults : arguments[0]; + + _classCallCheck(this, KodyTask); + + this.name = opts.name; + this.exec = opts.exec; + } + + _createClass(KodyTask, [{ + key: 'run', + value: function run() { + var _this = this; + + return new Promise(function (resolve, reject) { + utils.log('Running ' + _this.name, 'info'); + if (_this.exec && typeof _this.exec === 'function') { + _this.exec(resolve, reject); + } + }); + } + }]); + + return KodyTask; +}(); + +exports.KodyTask = KodyTask; \ No newline at end of file diff --git a/lib/kody.js b/lib/kody.js index faefa68..11e2ac2 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -1,34 +1,101 @@ +'use strict'; -/* -kody - http://jh3y.github.io/kody +/** + * kody - .files manager for node +*/ -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, init, pkg, shell, task_runner, utils, welcome; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../package.json"); +var polyfill = require('babel-polyfill'), + colors = require('colors'), + shell = require('shelljs'), + inquirer = require('inquirer'), + pkg = require('../package.json'), + utils = require('./utils'), + fs = require('fs'), + task_runner = require('./task_runner'), + core = require('./core'), + PROPS = { + /** + * Define a task order. + * This is useful for when you wish one task to run before + * another. + * + * For example; there is no use installing apm modules before + * Atom IDE is installed as the apm CLI won't be available. + */ + TASK_ORDER: ['gitconfig.js', '*'], + TASKS_QUERY: { + type: 'checkbox', + name: 'tasks', + message: 'Choose the set up tasks you wish to run', + choices: [] + } +}, + welcome = function welcome() { + utils.log('==================================', 'info'); + utils.log('kody - .files & config runner', 'info'); + utils.log('==================================', 'info'); +}, + processTasks = function processTasks(tasks) { + tasks = tasks.tasks[Symbol.iterator](); + var processTask = function processTask(task) { + var newTask = new core.KodyTask(task.value); + newTask.run().then(function () { + utils.log('Task ' + newTask.name + ' has finished', 'info'); + var nextTask = tasks.next(); + if (nextTask.value) { + processTask(nextTask); + } else { + utils.log('ALL TASKS FINISHED', 'silly'); + } + }).then(function () { + throw new Error('Something went wrong'); + }); + }; + processTask(tasks.next()); +}, + sortFiles = function sortFiles(a, b) { + if (PROPS.TASK_ORDER.indexOf(b) !== -1 && PROPS.TASK_ORDER.indexOf(a) !== -1 && PROPS.TASK_ORDER.indexOf(a) < PROPS.TASK_ORDER.indexOf(b)) { + return -1; + } + if (PROPS.TASK_ORDER.indexOf(a) !== -1 || PROPS.TASK_ORDER.indexOf(b) !== -1) { + return 1; + } +}, + init = function init() { + welcome(); + var files = fs.readdirSync(__dirname + '/tasks'); + files = files.sort(sortFiles); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; -utils = require("./utils"); + try { + for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var file = _step.value; -task_runner = require("./task_runner"); + var taskOpts = require('./tasks/' + file).options; + var newChoice = { + name: taskOpts.name + ' - ' + taskOpts.description, + value: taskOpts + }; + PROPS.TASKS_QUERY.choices.push(newChoice); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } -exports.welcome = welcome = function() { - utils.log("===========================================", "info"); - utils.log("kody -- your .files and config runner", "info"); - return utils.log("===========================================", "info"); + inquirer.prompt(PROPS.TASKS_QUERY, processTasks); }; -exports.init = init = function() { - welcome(); - return task_runner.init(); -}; +exports.init = init; \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index 8ca6589..04f6afe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -1,40 +1,27 @@ - -/* -kody - http://jh3y.github.io/kody - -Entry point for kody. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, err, kody, pkg, program; - -program = require("commander"); - -colors = require("colors"); - -pkg = require("../package.json"); - -kody = require("./kody"); +'use strict'; + +/** + * kody - a .files manager + * + * @author jh3y 2016 + * @license MIT +*/ + +var program = require('commander'), + colors = require('colors'), + winston = require('winston'), + pkg = require('../package.json'), + utils = require('./utils'), + kody = require('./kody'); program.version(pkg.version); -program.on("--help", function() { - console.log(" Examples:"); - console.log(""); - console.log(" $ " + pkg.name); -}); +utils.setupLogger(); program.parse(process.argv); try { kody.init(); -} catch (_error) { - err = _error; - console.log("[", "kody".white, "]", err.toString().red); -} +} catch (err) { + utils.log(err.toString(), 'error'); +} \ No newline at end of file diff --git a/lib/task_runner.js b/lib/task_runner.js index 59ab3c5..9a390c3 100644 --- a/lib/task_runner.js +++ b/lib/task_runner.js @@ -1,91 +1 @@ - -/* -kody - http://jh3y.github.io/kody - -Task runner - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var KODY_CONFIG, apm, apple, brew, brewCask, colors, dotfiles, fish, gitConfig, grab_config, init, npm, osx, pkg, run, shell, taskMap, utils; - -colors = require("colors"); - -pkg = require("../package.json"); - -shell = require("shelljs"); - -utils = require("./utils"); - -brewCask = require("./tasks/set_up_brew_cask"); - -dotfiles = require("./tasks/install_dot_files"); - -gitConfig = require("./tasks/set_up_git_config"); - -osx = require("./tasks/set_osx_defaults"); - -apple = require('./tasks/remove_default_apple_apps'); - -brew = require("./tasks/set_up_homebrew"); - -npm = require("./tasks/install_npm_modules"); - -fish = require("./tasks/set_up_fish_shell"); - -apm = require("./tasks/install_atom_packages"); - -KODY_CONFIG = undefined; - -taskMap = { - install_dot_files: dotfiles.install, - install_homebrew_and_packages: brew.install, - install_brew_cask_and_casks: brewCask.setUp, - install_npm_modules: npm.install, - install_apm_packages: apm.install, - set_fish_shell_as_default: fish.setDefault, - set_osx_defaults: osx.setDefault, - remove_default_apple_apps: apple.remove -}; - -grab_config = function() { - var path; - path = process.cwd() + '/kody.json'; - return KODY_CONFIG = require(path); -}; - -exports.init = init = function() { - grab_config(); - if (KODY_CONFIG !== undefined) { - if (KODY_CONFIG.set_up_git_config) { - utils.log("Setting up Git credentials", "prompt"); - return gitConfig.setUp(); - } else { - utils.log("Git credentials already set up", "info"); - return run(); - } - } -}; - -exports.run = run = function() { - var key, map, tasks, value; - tasks = []; - for (map in taskMap) { - if (KODY_CONFIG[map] === true) { - tasks.push({ - func: taskMap[map], - args: KODY_CONFIG - }); - } - } - for (key in tasks) { - value = tasks[key]; - value.func(KODY_CONFIG); - } - return utils.log("kody has completed your set tasks!", "silly"); -}; +"use strict"; \ No newline at end of file diff --git a/lib/tasks/a.js b/lib/tasks/a.js new file mode 100644 index 0000000..6442d03 --- /dev/null +++ b/lib/tasks/a.js @@ -0,0 +1,18 @@ +'use strict'; + +/** + * Task - description + * @license MIT + * @author author +*/ +var utils = require('../utils'), + options = { + name: 'Set up A', + description: 'sets up A for use on system', + exec: function exec(resolve, reject) { + utils.log('setting up a .... buzz grrr ... bing'); + setTimeout(resolve, 5000); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/apm_install.js b/lib/tasks/apm_install.js deleted file mode 100644 index 8b13789..0000000 --- a/lib/tasks/apm_install.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/tasks/b.js b/lib/tasks/b.js new file mode 100644 index 0000000..67840f6 --- /dev/null +++ b/lib/tasks/b.js @@ -0,0 +1,13 @@ +'use strict'; + +var utils = require('../utils'), + options = { + name: 'Set up B', + description: 'sets up b for system wide use', + exec: function exec(resolve, reject) { + utils.log('setting up b .... beezz brrr ... bazing'); + setTimeout(resolve, 3000); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/brew_install.js b/lib/tasks/brew_install.js deleted file mode 100644 index 5fa1249..0000000 --- a/lib/tasks/brew_install.js +++ /dev/null @@ -1,44 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Homebrew installation and installation of brew packages. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, install, pkg, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.install = install = function(KODY_CONFIG) { - var pckgToInstall; - if (shell.exec("which brew", { - silent: true - }).output.trim() === "") { - utils.log("Attempting to intall Brew", "prompt"); - shell.exec('ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"'); - utils.log("Brew installed", "success"); - } else { - utils.log("Brew already installed", "warn"); - } - utils.log("Now running 'brew doctor'", "prompt"); - shell.exec("brew doctor"); - utils.log("NOTE: Take notice of anything Brew doctor has said, it may account for any issues you have with install", "warn"); - if (KODY_CONFIG.brew_installs.length > 0) { - pckgToInstall = KODY_CONFIG.brew_installs.join(" "); - shell.exec("brew install " + pckgToInstall); - } - return utils.log("Brew packages installed", "success"); -}; diff --git a/lib/tasks/dotfiles.js b/lib/tasks/dotfiles.js new file mode 100644 index 0000000..9a34d26 --- /dev/null +++ b/lib/tasks/dotfiles.js @@ -0,0 +1,72 @@ +'use strict'; + +/** + * DotFiles - set up symlinks for dotfiles suffixed with .link + * @license MIT + * @author jh3y +*/ + +var shell = require('shelljs'), + winston = require('winston'), + utils = require('../utils'), + PROPS = { + HOME_CMD: 'echo $HOME', + EMPTY_MSG: 'no .files for linking.', + FILE_REGEXP: /\.link$/, + FILE_SUFFIX: '.link' +}, + options = { + name: 'DotFiles', + description: 'sets up symlinks for global dotfiles', + exec: function exec(resolve, reject) { + // grab the home directory for the user. + var $HOME = shell.exec(PROPS.HOME_CMD, { + silent: true + }).output.trim(), + + // grab instances, these are files/dirs suffixed with ".link" + dotFiles = shell.find('.').filter(function (file) { + return file.match(PROPS.FILE_REGEXP); + }); + + if (dotFiles.length > 0) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = dotFiles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var dotFile = _step.value; + + var source = process.cwd() + '/' + dotFile; + var basename = dotFile; + if (basename.indexOf('/') !== -1) { + basename = basename.substr(basename.lastIndexOf('/') + 1); + } + basename = basename.replace(PROPS.FILE_SUFFIX, ''); + var destination = $HOME + '/.' + basename; + winston.success('linked ' + basename + ' to ' + destination); + // shell.ln('-sf', source, destination); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } else { + utils.log(PROPS.EMPTY_MSG, 'info'); + } + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/fish.js b/lib/tasks/fish.js deleted file mode 100644 index cec5a46..0000000 --- a/lib/tasks/fish.js +++ /dev/null @@ -1,38 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Sets Fish as default shell. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, set_default, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.set_default = set_default = function() { - var found; - found = shell.exec("find fish/set_default.*", { - silent: true - }).output; - if (found.indexOf("fish/set_default.*") === -1) { - utils.log("Setting Fish as default shell", "prompt"); - found = found.trim(); - shell.exec("sh ./" + found); - return utils.log("Fish set as default shell", "success"); - } else { - return utils.log("No shell script file found for setting fish as default", "error"); - } -}; diff --git a/lib/tasks/git_config.js b/lib/tasks/git_config.js deleted file mode 100644 index 0e360e8..0000000 --- a/lib/tasks/git_config.js +++ /dev/null @@ -1,58 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Git config set up. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, prompt, set_up, shell, task_runner, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -prompt = require("prompt"); - -prompt.message = "[ " + pkg.name.cyan + " ]"; - -prompt.delimiter = " "; - -prompt.start(); - -task_runner = require("../task_runner"); - -exports.set_up = set_up = function() { - var git_credential, uname; - uname = shell.exec('uname -s', { - silent: true - }); - if (uname.output.indexOf('Darwin') !== -1) { - git_credential = 'osxkeychain'; - } - return prompt.get([ - { - name: "name", - description: "enter your github author name:" - }, { - name: "email", - description: "enter your github email:" - } - ], function(err, result) { - shell.exec("sed -e 's/AUTHORNAME/" + result.name + "/g' -e 's/AUTHOREMAIL/" + result.email + "/g' -e 's/GIT_CREDENTIAL_HELPER/" + git_credential + "/g' git/gitconfig.starter", { - silent: true - }).output.to('git/gitconfig.symlink'); - utils.log("git config set up and ready", "success"); - return task_runner.run(); - }); -}; diff --git a/lib/tasks/gitconfig.js b/lib/tasks/gitconfig.js new file mode 100644 index 0000000..4166259 --- /dev/null +++ b/lib/tasks/gitconfig.js @@ -0,0 +1,45 @@ +'use strict'; + +/** + * GitConfig - Sets up global Git configuration pre symlink + * + * user git/gitconfig.starter as a starting point to create a system + * wide gitconfig. + * + * NOTE: This task could be made obsolete if you commit the author name + * and email as a gitconfig.link file. + * + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + utils = require('../utils'), + userConfig = require(process.cwd() + '/kody.json'); + +var options = { + name: 'GitConfig', + description: 'sets up global git configuration for symlinking', + /** + * Needs to check out what the config should be and send it over. + */ + exec: function exec(resolve, reject) { + var gitCredential = undefined, + gitName = undefined, + gitEmail = undefined; + var uname = shell.exec('uname -s', { silent: true }); + if (uname.output.indexOf('Darwin') !== -1) { + gitCredential = 'osxkeychain'; + } + gitName = userConfig.git_credentials.name; + gitEmail = userConfig.git_credentials.email; + + var configString = 'sed -e \'s/AUTHORNAME/' + gitName + '/g\' -e \'s/AUTHOREMAIL/' + gitEmail + '/g\' -e \'s/GIT_CREDENTIAL_HELPER/' + gitCredential + '/g\' git/gitconfig.starter'; + + shell.exec(configString, { silent: true }).stdout.to('git/gitconfig.link'); + + utils.log('GitConfig set up, ' + gitName + ', ' + gitEmail, 'info'); + setTimeout(resolve, 3000); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/install_atom_packages.js b/lib/tasks/install_atom_packages.js deleted file mode 100644 index 387349e..0000000 --- a/lib/tasks/install_atom_packages.js +++ /dev/null @@ -1,31 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Apm install - installs all your atom IDE apm packages - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, install, pkg, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.install = install = function(KODY_CONFIG) { - if (shell.which("apm").trim() !== "" && Object.keys(KODY_CONFIG.apm_packages).length > 0) { - utils.log("Installing apm packages", "prompt"); - shell.exec("apm install " + KODY_CONFIG.apm_packages.join(' ')); - return utils.log("Apm modules installed globally", "success"); - } -}; diff --git a/lib/tasks/install_dot_files.js b/lib/tasks/install_dot_files.js deleted file mode 100644 index 6be0e23..0000000 --- a/lib/tasks/install_dot_files.js +++ /dev/null @@ -1,67 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -.Files installation task - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, install, pkg, shell, utils; - -colors = require("colors"); - -pkg = require("../../package.json"); - -shell = require("shelljs"); - -utils = require("../utils"); - -exports.install = install = function() { - var HOME_DIR, basename, destination, dotfiles, elementsfiltered, key, source, value, _results; - HOME_DIR = shell.exec("echo $HOME", { - silent: true - }).output.trim(); - dotfiles = shell.exec("find */*.link *.link", { - silent: true - }).output; - if (dotfiles.indexOf("*/*.link *.link") === -1) { - dotfiles = dotfiles.split('\n'); - dotfiles.pop(); - elementsfiltered = undefined; - dotfiles.filter(function(a) { - if (a.split(".link").length === 2 && a.split('.link')[1].trim() === "") { - this.push(a); - } - return true; - }, elementsfiltered = []); - dotfiles = elementsfiltered; - if (dotfiles.length > 0) { - utils.log("Linking .files to your home directory", "prompt"); - _results = []; - for (key in dotfiles) { - value = dotfiles[key]; - source = process.cwd() + '/' + value; - basename = shell.exec("basename " + value, { - silent: true - }).output.trim(); - if (basename.indexOf('.link') !== -1) { - basename = "/." + basename.replace(".link", ""); - destination = HOME_DIR + basename; - shell.ln('-sf', source, destination); - _results.push(utils.log('linked ' + source + ' to ' + destination + '!', "info")); - } else { - _results.push(void 0); - } - } - return _results; - } else { - return utils.log("No .files found", "error"); - } - } -}; diff --git a/lib/tasks/install_npm_modules.js b/lib/tasks/install_npm_modules.js deleted file mode 100644 index f646a8c..0000000 --- a/lib/tasks/install_npm_modules.js +++ /dev/null @@ -1,37 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Npm install - installs all your global npm modules - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, install, pkg, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.install = install = function(KODY_CONFIG) { - var installStr, module; - if (shell.which("npm").trim() !== "" && Object.keys(KODY_CONFIG.global_npm_modules).length > 0) { - utils.log("Installing npm modules", "prompt"); - utils.log("kody will ask for sudo credentials here just because you are installing node modules globally on your machine", "warn"); - installStr = "sudo npm install -g"; - for (module in KODY_CONFIG.global_npm_modules) { - installStr += " " + module + "@" + KODY_CONFIG.global_npm_modules[module]; - } - shell.exec(installStr); - return utils.log("Npm modules installed globally", "success"); - } -}; diff --git a/lib/tasks/npm_install.js b/lib/tasks/npm_install.js deleted file mode 100644 index f646a8c..0000000 --- a/lib/tasks/npm_install.js +++ /dev/null @@ -1,37 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Npm install - installs all your global npm modules - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, install, pkg, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.install = install = function(KODY_CONFIG) { - var installStr, module; - if (shell.which("npm").trim() !== "" && Object.keys(KODY_CONFIG.global_npm_modules).length > 0) { - utils.log("Installing npm modules", "prompt"); - utils.log("kody will ask for sudo credentials here just because you are installing node modules globally on your machine", "warn"); - installStr = "sudo npm install -g"; - for (module in KODY_CONFIG.global_npm_modules) { - installStr += " " + module + "@" + KODY_CONFIG.global_npm_modules[module]; - } - shell.exec(installStr); - return utils.log("Npm modules installed globally", "success"); - } -}; diff --git a/lib/tasks/osx.js b/lib/tasks/osx.js deleted file mode 100644 index 3b30aff..0000000 --- a/lib/tasks/osx.js +++ /dev/null @@ -1,43 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -OSX Defaults writer. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, set_default, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.set_default = set_default = function() { - var found, uname; - uname = shell.exec('uname -s', { - silent: true - }); - if (uname.output.indexOf('Darwin') !== -1) { - found = shell.exec("find osx/set_default.*", { - silent: true - }).output; - if (found.indexOf("osx/set_default.*") === -1) { - utils.log("Setting Apple OSX Defaults", "prompt"); - found = found.trim(); - shell.exec("sh ./" + found); - return utils.log("Apple OSX defaults set", "success"); - } else { - return utils.log("No shell script file found for setting OSX Defaults", "error"); - } - } -}; diff --git a/lib/tasks/remove_default_apple_apps.js b/lib/tasks/remove_default_apple_apps.js deleted file mode 100644 index 3d08880..0000000 --- a/lib/tasks/remove_default_apple_apps.js +++ /dev/null @@ -1,36 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Remove default apple applications task - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, remove, shell, utils; - -colors = require('colors'); - -shell = require('shelljs'); - -pkg = require('../../package.json'); - -utils = require('../utils'); - -exports.remove = remove = function(KODY_CONFIG) { - if (KODY_CONFIG.apple_apps_to_remove && KODY_CONFIG.apple_apps_to_remove.length > 0) { - [].forEach.call(KODY_CONFIG.apple_apps_to_remove, function(appToRemove) { - var regex; - regex = new RegExp(" ", 'g'); - appToRemove = appToRemove.replace(regex, '\\ '); - shell.exec('sudo rm -rf /Applications/' + appToRemove); - return utils.log(appToRemove + ' removed', 'info'); - }); - return utils.log('Default Apple applications removed', 'success'); - } -}; diff --git a/lib/tasks/set_osx_defaults.js b/lib/tasks/set_osx_defaults.js deleted file mode 100644 index a734784..0000000 --- a/lib/tasks/set_osx_defaults.js +++ /dev/null @@ -1,43 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -OSX Defaults writer. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, setDefault, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.setDefault = setDefault = function() { - var found, uname; - uname = shell.exec('uname -s', { - silent: true - }); - if (uname.output.indexOf('Darwin') !== -1) { - found = shell.exec("find osx/set_default.*", { - silent: true - }).output; - if (found.indexOf("osx/set_default.*") === -1) { - utils.log("Setting Apple OSX Defaults", "prompt"); - found = found.trim(); - shell.exec("sh ./" + found); - return utils.log("Apple OSX defaults set", "success"); - } else { - return utils.log("No shell script file found for setting OSX Defaults", "error"); - } - } -}; diff --git a/lib/tasks/set_up_brew_cask.js b/lib/tasks/set_up_brew_cask.js deleted file mode 100644 index 4eed5ab..0000000 --- a/lib/tasks/set_up_brew_cask.js +++ /dev/null @@ -1,40 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Set up Homebrew cask - brew-cask. And also install casks. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, setUp, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.setUp = setUp = function(KODY_CONFIG) { - var key, value, _ref; - if (shell.which("brew") !== null && KODY_CONFIG.brew_casks.length > 0) { - shell.exec("brew prune"); - utils.log('Setting up Brew cask', "prompt"); - shell.exec("brew tap caskroom/cask"); - shell.exec("brew install brew-cask"); - _ref = KODY_CONFIG.brew_casks; - for (key in _ref) { - value = _ref[key]; - utils.log('installing ' + value); - shell.exec("brew cask install " + value); - } - return utils.log("Brew casks installed", "success"); - } -}; diff --git a/lib/tasks/set_up_fish_shell.js b/lib/tasks/set_up_fish_shell.js deleted file mode 100644 index 7cdd14d..0000000 --- a/lib/tasks/set_up_fish_shell.js +++ /dev/null @@ -1,38 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Sets Fish as default shell. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, setDefault, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.setDefault = setDefault = function() { - var found; - found = shell.exec("find fish/set_default.*", { - silent: true - }).output; - if (found.indexOf("fish/set_default.*") === -1) { - utils.log("Setting Fish as default shell", "prompt"); - found = found.trim(); - shell.exec("sh ./" + found); - return utils.log("Fish set as default shell", "success"); - } else { - return utils.log("No shell script file found for setting fish as default", "error"); - } -}; diff --git a/lib/tasks/set_up_git_config.js b/lib/tasks/set_up_git_config.js deleted file mode 100644 index ff7998c..0000000 --- a/lib/tasks/set_up_git_config.js +++ /dev/null @@ -1,58 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Git config set up. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, pkg, prompt, setUp, shell, task_runner, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -prompt = require("prompt"); - -prompt.message = "[ " + pkg.name.cyan + " ]"; - -prompt.delimiter = " "; - -prompt.start(); - -task_runner = require("../task_runner"); - -exports.setUp = setUp = function() { - var git_credential, uname; - uname = shell.exec('uname -s', { - silent: true - }); - if (uname.output.indexOf('Darwin') !== -1) { - git_credential = 'osxkeychain'; - } - return prompt.get([ - { - name: "name", - description: "enter your github author name:" - }, { - name: "email", - description: "enter your github email:" - } - ], function(err, result) { - shell.exec("sed -e 's/AUTHORNAME/" + result.name + "/g' -e 's/AUTHOREMAIL/" + result.email + "/g' -e 's/GIT_CREDENTIAL_HELPER/" + git_credential + "/g' git/gitconfig.starter", { - silent: true - }).output.to('git/gitconfig.link'); - utils.log("git config set up and ready", "success"); - return task_runner.run(); - }); -}; diff --git a/lib/tasks/set_up_homebrew.js b/lib/tasks/set_up_homebrew.js deleted file mode 100644 index dac11a1..0000000 --- a/lib/tasks/set_up_homebrew.js +++ /dev/null @@ -1,44 +0,0 @@ - -/* -kody - http://jh3y.github.io/kody - -Homebrew installation and installation of brew packages. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, install, pkg, shell, utils; - -colors = require("colors"); - -shell = require("shelljs"); - -pkg = require("../../package.json"); - -utils = require("../utils"); - -exports.install = install = function(KODY_CONFIG) { - var pckgToInstall; - if (shell.exec("which brew", { - silent: true - }).output.trim() === "") { - utils.log("Attempting to intall Brew", "prompt"); - shell.exec('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'); - utils.log("Brew installed", "success"); - } else { - utils.log("Brew already installed", "warn"); - } - utils.log("Now running 'brew doctor'", "prompt"); - shell.exec("brew doctor"); - utils.log("NOTE: Take notice of anything Brew doctor has said, it may account for any issues you have with install", "warn"); - if (KODY_CONFIG.brew_installs.length > 0) { - pckgToInstall = KODY_CONFIG.brew_installs.join(" "); - shell.exec("brew install " + pckgToInstall); - } - return utils.log("Brew packages installed", "success"); -}; diff --git a/lib/utils.js b/lib/utils.js index c803386..b4baca1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,29 +1,32 @@ - -/* -kody - http://jh3y.github.io/kody - -Utils for kody. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -var colors, log, pkg, prompt, shell; - -colors = require("colors"); - -pkg = require("../package.json"); - -shell = require("shelljs"); - -prompt = require("prompt"); +'use strict'; + +var colors = require('colors'), + winston = require('winston'), + pkg = require('../package.json'), + log = function log(msg) { + // winston.info('ererger'); + + var type = arguments.length <= 1 || arguments[1] === undefined ? 'default' : arguments[1]; +}, + loggerConfig = { + levels: { + info: 0, + warn: 1, + error: 2, + success: 0, + silly: 4 + }, + colors: { + info: 'blue', + warn: 'green', + error: 'yellow', + success: 'red', + silly: 'rainbow' + } +}; colors.setTheme({ - "default": 'grey', + default: 'grey', prompt: 'yellow', info: 'cyan', help: 'magenta', @@ -33,9 +36,17 @@ colors.setTheme({ silly: 'rainbow' }); -exports.log = log = function(msg, type) { - if (type == null) { - type = "default"; - } - return console.log('[', pkg.name.cyan, ']', msg[type]); +exports.setupLogger = function () { + winston.remove(winston.transports.Console); + winston.add(winston.transports.Console, { + levels: loggerConfig.levels, + formatter: function formatter(options) { + return '[' + pkg.name.cyan + '] ' + options.message; + } + }); + // winston.setLevels(loggerConfig.levels); + winston.level = 4; + winston.addColors(loggerConfig.colors); }; + +exports.log = log; \ No newline at end of file diff --git a/package.json b/package.json index c1cc3c3..ff28c44 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "homepage": "https://github.com/jh3y/kody", "author": { - "name": "jh3y", + "name": "jh3y ", "url": "http://jh3y.github.io" }, "repository": { @@ -20,8 +20,19 @@ "type": "MIT" } ], + "config": { + "SCRIPTS_DEST": "./", + "SCRIPTS_SRC": "src" + }, "scripts": { - "test": "make test" + "clean": "rm -rf lib test", + "test": "mocha -u tdd --reporter spec", + "build:scripts": "babel src/ -d $npm_package_config_SCRIPTS_DEST", + "lint:scripts": "eslint $npm_package_config_SCRIPTS_SRC", + "watch:scripts": "babel src/ --watch -d $npm_package_config_SCRIPTS_DEST", + "predev": "npm run build:scripts", + "dev": "npm run watch:scripts", + "update:packages": "node wipe-dependencies.js && rm -rf node_modules && npm update --save-dev && npm update --save" }, "preferGlobal": true, "bin": { @@ -31,17 +42,20 @@ "node": ">= 0.8.0" }, "dependencies": { - "commander": "^2.2.0", - "colors": "^0.6.2", - "shelljs": "^0.3.0", - "prompt": "^0.2.12", - "async": "^0.8.0" + "async": "^1.5.2", + "colors": "^1.1.2", + "commander": "^2.9.0", + "inquirer": "^0.12.0", + "shelljs": "^0.6.0", + "winston": "^2.1.1" }, "keywords": [], "devDependencies": { - "mocha": "^1.18.2", - "gulp": "^3.6.1", - "gulp-coffee": "^1.4.2", - "gulp-plumber": "^0.6.1" + "babel-cli": "^6.5.1", + "babel-eslint": "^5.0.0", + "babel-polyfill": "^6.5.0", + "babel-preset-es2015": "^6.5.0", + "eslint": "^2.2.0", + "mocha": "^2.4.5" } } diff --git a/src/coffee/lib/kody.coffee b/src.deprecated/coffee/lib/kody.coffee similarity index 100% rename from src/coffee/lib/kody.coffee rename to src.deprecated/coffee/lib/kody.coffee diff --git a/src/coffee/lib/main.coffee b/src.deprecated/coffee/lib/main.coffee similarity index 100% rename from src/coffee/lib/main.coffee rename to src.deprecated/coffee/lib/main.coffee diff --git a/src/coffee/lib/task_runner.coffee b/src.deprecated/coffee/lib/task_runner.coffee similarity index 100% rename from src/coffee/lib/task_runner.coffee rename to src.deprecated/coffee/lib/task_runner.coffee diff --git a/src/coffee/lib/tasks/install_atom_packages.coffee b/src.deprecated/coffee/lib/tasks/install_atom_packages.coffee similarity index 100% rename from src/coffee/lib/tasks/install_atom_packages.coffee rename to src.deprecated/coffee/lib/tasks/install_atom_packages.coffee diff --git a/src/coffee/lib/tasks/install_dot_files.coffee b/src.deprecated/coffee/lib/tasks/install_dot_files.coffee similarity index 100% rename from src/coffee/lib/tasks/install_dot_files.coffee rename to src.deprecated/coffee/lib/tasks/install_dot_files.coffee diff --git a/src/coffee/lib/tasks/install_npm_modules.coffee b/src.deprecated/coffee/lib/tasks/install_npm_modules.coffee similarity index 100% rename from src/coffee/lib/tasks/install_npm_modules.coffee rename to src.deprecated/coffee/lib/tasks/install_npm_modules.coffee diff --git a/src/coffee/lib/tasks/remove_default_apple_apps.coffee b/src.deprecated/coffee/lib/tasks/remove_default_apple_apps.coffee similarity index 100% rename from src/coffee/lib/tasks/remove_default_apple_apps.coffee rename to src.deprecated/coffee/lib/tasks/remove_default_apple_apps.coffee diff --git a/src/coffee/lib/tasks/set_osx_defaults.coffee b/src.deprecated/coffee/lib/tasks/set_osx_defaults.coffee similarity index 100% rename from src/coffee/lib/tasks/set_osx_defaults.coffee rename to src.deprecated/coffee/lib/tasks/set_osx_defaults.coffee diff --git a/src/coffee/lib/tasks/set_up_brew_cask.coffee b/src.deprecated/coffee/lib/tasks/set_up_brew_cask.coffee similarity index 100% rename from src/coffee/lib/tasks/set_up_brew_cask.coffee rename to src.deprecated/coffee/lib/tasks/set_up_brew_cask.coffee diff --git a/src/coffee/lib/tasks/set_up_fish_shell.coffee b/src.deprecated/coffee/lib/tasks/set_up_fish_shell.coffee similarity index 100% rename from src/coffee/lib/tasks/set_up_fish_shell.coffee rename to src.deprecated/coffee/lib/tasks/set_up_fish_shell.coffee diff --git a/src/coffee/lib/tasks/set_up_git_config.coffee b/src.deprecated/coffee/lib/tasks/set_up_git_config.coffee similarity index 100% rename from src/coffee/lib/tasks/set_up_git_config.coffee rename to src.deprecated/coffee/lib/tasks/set_up_git_config.coffee diff --git a/src/coffee/lib/tasks/set_up_homebrew.coffee b/src.deprecated/coffee/lib/tasks/set_up_homebrew.coffee similarity index 100% rename from src/coffee/lib/tasks/set_up_homebrew.coffee rename to src.deprecated/coffee/lib/tasks/set_up_homebrew.coffee diff --git a/src/coffee/lib/tasks/task.coffee.boilerplate b/src.deprecated/coffee/lib/tasks/task.coffee.boilerplate similarity index 100% rename from src/coffee/lib/tasks/task.coffee.boilerplate rename to src.deprecated/coffee/lib/tasks/task.coffee.boilerplate diff --git a/src.deprecated/coffee/lib/utils.coffee b/src.deprecated/coffee/lib/utils.coffee new file mode 100644 index 0000000..5975234 --- /dev/null +++ b/src.deprecated/coffee/lib/utils.coffee @@ -0,0 +1,18 @@ +const colors = require('colors'), + pkg = require('../package.json'), + log = function(msg, type = 'default') { + console.log('[', pkg.name.cyan, ']', msg[type]); + }; + +colors.setTheme({ + default: 'grey', + prompt : 'yellow', + info : 'cyan', + help : 'magenta', + warn : 'yellow', + error : 'red', + success: 'green', + silly : 'rainbow', +}); + +exports.log = log; diff --git a/src/coffee/test/test.coffee b/src.deprecated/coffee/test/test.coffee similarity index 100% rename from src/coffee/test/test.coffee rename to src.deprecated/coffee/test/test.coffee diff --git a/src/coffee/lib/utils.coffee b/src/coffee/lib/utils.coffee deleted file mode 100644 index 5c37806..0000000 --- a/src/coffee/lib/utils.coffee +++ /dev/null @@ -1,30 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Utils for kody. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -pkg = require "../package.json" -shell = require "shelljs" -prompt = require "prompt" -colors.setTheme - default: 'grey' - prompt: 'yellow' - info: 'cyan' - help: 'magenta' - warn: 'yellow' - error: 'red' - success: 'green' - silly: 'rainbow' - -exports.log = log = (msg, type = "default")-> - console.log '[', pkg.name.cyan, ']', msg[type] diff --git a/src/lib/TASK_BOILERPLATE.js b/src/lib/TASK_BOILERPLATE.js new file mode 100644 index 0000000..e41b734 --- /dev/null +++ b/src/lib/TASK_BOILERPLATE.js @@ -0,0 +1,15 @@ +/** + * Task - description + * @license MIT + * @author author +*/ + +const options = { + name: 'TASK-0001', + description: 'sets up something', + exec: function(resolve, reject) { + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/core.js b/src/lib/core.js new file mode 100644 index 0000000..bcdc24a --- /dev/null +++ b/src/lib/core.js @@ -0,0 +1,22 @@ +const utils = require('./utils'), + defaults = { + name: 'Generic task', + exec: e => utils.log('running', 'info') + }; + +class KodyTask { + constructor(opts = defaults) { + this.name = opts.name; + this.exec = opts.exec; + } + run() { + return new Promise((resolve, reject) => { + utils.log(`Running ${this.name}`, 'info'); + if (this.exec && typeof this.exec === 'function') { + this.exec(resolve, reject); + } + }); + } +} + +exports.KodyTask = KodyTask; diff --git a/src/lib/kody.js b/src/lib/kody.js new file mode 100644 index 0000000..c047d23 --- /dev/null +++ b/src/lib/kody.js @@ -0,0 +1,82 @@ +/** + * kody - .files manager for node +*/ + +const polyfill = require('babel-polyfill'), + colors = require('colors'), + shell = require('shelljs'), + inquirer = require('inquirer'), + pkg = require('../package.json'), + utils = require('./utils'), + fs = require('fs'), + task_runner = require('./task_runner'), + core = require('./core'), + PROPS = { + /** + * Define a task order. + * This is useful for when you wish one task to run before + * another. + * + * For example; there is no use installing apm modules before + * Atom IDE is installed as the apm CLI won't be available. + */ + TASK_ORDER : [ + 'gitconfig.js', + '*' + ], + TASKS_QUERY: { + type: 'checkbox', + name: 'tasks', + message: 'Choose the set up tasks you wish to run', + choices: [] + } + }, + welcome = function() { + utils.log('==================================', 'info'); + utils.log('kody - .files & config runner', 'info'); + utils.log('==================================', 'info'); + }, + processTasks = function(tasks) { + tasks = tasks.tasks[Symbol.iterator](); + let processTask = function(task) { + let newTask = new core.KodyTask(task.value); + newTask.run() + .then(() => { + utils.log(`Task ${newTask.name} has finished`, 'info'); + let nextTask = tasks.next(); + if (nextTask.value) { + processTask(nextTask); + } else { + utils.log('ALL TASKS FINISHED', 'silly'); + } + }) + .then(() => { + throw new Error('Something went wrong'); + }); + }; + processTask(tasks.next()); + }, + sortFiles = function(a, b) { + if(PROPS.TASK_ORDER.indexOf(b) !== -1 && PROPS.TASK_ORDER.indexOf(a) !== -1 && PROPS.TASK_ORDER.indexOf(a) < PROPS.TASK_ORDER.indexOf(b)) { + return -1; + } + if(PROPS.TASK_ORDER.indexOf(a) !== -1 || PROPS.TASK_ORDER.indexOf(b) !== -1) { + return 1; + } + }, + init = function() { + welcome(); + let files = fs.readdirSync(__dirname + '/tasks'); + files = files.sort(sortFiles); + for (let file of files) { + let taskOpts = require(`./tasks/${file}`).options; + let newChoice = { + name: `${taskOpts.name} - ${taskOpts.description}`, + value: taskOpts + }; + PROPS.TASKS_QUERY.choices.push(newChoice); + } + inquirer.prompt(PROPS.TASKS_QUERY, processTasks); + }; + +exports.init = init; diff --git a/src/lib/main.js b/src/lib/main.js new file mode 100644 index 0000000..971e039 --- /dev/null +++ b/src/lib/main.js @@ -0,0 +1,27 @@ +/** + * kody - a .files manager + * + * @author jh3y 2016 + * @license MIT +*/ + + +const program = require('commander'), + colors = require('colors'), + winston = require('winston'), + pkg = require('../package.json'), + utils = require('./utils'), + kody = require('./kody'); + +program + .version(pkg.version); + +utils.setupLogger(); + +program.parse(process.argv); + +try { + kody.init(); +} catch(err) { + utils.log(err.toString(), 'error'); +} diff --git a/src/lib/task_runner.js b/src/lib/task_runner.js new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/tasks/a.js b/src/lib/tasks/a.js new file mode 100644 index 0000000..3953539 --- /dev/null +++ b/src/lib/tasks/a.js @@ -0,0 +1,16 @@ +/** + * Task - description + * @license MIT + * @author author +*/ +const utils = require('../utils'), + options = { + name: 'Set up A', + description: 'sets up A for use on system', + exec: function(resolve, reject) { + utils.log('setting up a .... buzz grrr ... bing'); + setTimeout(resolve, 5000); + } + }; + +exports.options = options; diff --git a/src/lib/tasks/b.js b/src/lib/tasks/b.js new file mode 100644 index 0000000..af5e988 --- /dev/null +++ b/src/lib/tasks/b.js @@ -0,0 +1,11 @@ +const utils = require('../utils'), + options = { + name: 'Set up B', + description: 'sets up b for system wide use', + exec: function(resolve, reject) { + utils.log('setting up b .... beezz brrr ... bazing'); + setTimeout(resolve, 3000); + } + }; + +exports.options = options; diff --git a/src/lib/tasks/dotfiles.js b/src/lib/tasks/dotfiles.js new file mode 100644 index 0000000..39f2a63 --- /dev/null +++ b/src/lib/tasks/dotfiles.js @@ -0,0 +1,49 @@ +/** + * DotFiles - set up symlinks for dotfiles suffixed with .link + * @license MIT + * @author jh3y +*/ + +const shell = require('shelljs'), + winston = require('winston'), + utils = require('../utils'), + PROPS = { + HOME_CMD : 'echo $HOME', + EMPTY_MSG : 'no .files for linking.', + FILE_REGEXP: /\.link$/, + FILE_SUFFIX: '.link' + }, + options = { + name: 'DotFiles', + description: 'sets up symlinks for global dotfiles', + exec: function(resolve, reject) { + // grab the home directory for the user. + let $HOME = shell.exec(PROPS.HOME_CMD, { + silent: true + }).output.trim(), + // grab instances, these are files/dirs suffixed with ".link" + dotFiles = shell.find('.') + .filter(function(file) { + return file.match(PROPS.FILE_REGEXP); + }); + + if (dotFiles.length > 0) { + for(let dotFile of dotFiles) { + let source = `${process.cwd()}/${dotFile}`; + let basename = dotFile; + if (basename.indexOf('/') !== -1) { + basename = basename.substr(basename.lastIndexOf('/') + 1); + } + basename = basename.replace(PROPS.FILE_SUFFIX, ''); + let destination = `${$HOME}/.${basename}`; + winston.success(`linked ${basename} to ${destination}`); + // shell.ln('-sf', source, destination); + } + } else { + utils.log(PROPS.EMPTY_MSG, 'info'); + } + resolve(); + } + }; + +exports.options = options; diff --git a/src/lib/tasks/gitconfig.js b/src/lib/tasks/gitconfig.js new file mode 100644 index 0000000..c49cd1e --- /dev/null +++ b/src/lib/tasks/gitconfig.js @@ -0,0 +1,44 @@ +/** + * GitConfig - Sets up global Git configuration pre symlink + * + * user git/gitconfig.starter as a starting point to create a system + * wide gitconfig. + * + * NOTE: This task could be made obsolete if you commit the author name + * and email as a gitconfig.link file. + * + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + utils = require('../utils'), + userConfig = require(process.cwd() + '/kody.json'); + +const options = { + name: 'GitConfig', + description: 'sets up global git configuration for symlinking', + /** + * Needs to check out what the config should be and send it over. + */ + exec: function(resolve, reject) { + let gitCredential, + gitName, + gitEmail; + const uname = shell.exec('uname -s', {silent: true}); + if (uname.output.indexOf('Darwin') !== -1) { + gitCredential = 'osxkeychain'; + } + gitName = userConfig.git_credentials.name; + gitEmail = userConfig.git_credentials.email; + + let configString = `sed -e 's/AUTHORNAME/${gitName}/g' -e 's/AUTHOREMAIL/${gitEmail}/g' -e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g' git/gitconfig.starter`; + + shell.exec(configString, {silent: true}) + .stdout.to('git/gitconfig.link'); + + utils.log(`GitConfig set up, ${gitName}, ${gitEmail}`, 'info'); + setTimeout(resolve, 3000); + } +}; + +exports.options = options; diff --git a/src/lib/utils.js b/src/lib/utils.js new file mode 100644 index 0000000..a075346 --- /dev/null +++ b/src/lib/utils.js @@ -0,0 +1,48 @@ +const colors = require('colors'), + winston = require('winston'), + pkg = require('../package.json'), + log = function(msg, type = 'default') { + // winston.info('ererger'); + }, + loggerConfig = { + levels: { + info: 0, + warn: 1, + error: 2, + success: 0, + silly: 4 + }, + colors: { + info: 'blue', + warn: 'green', + error: 'yellow', + success: 'red', + silly: 'rainbow' + } + }; + +colors.setTheme({ + default: 'grey', + prompt : 'yellow', + info : 'cyan', + help : 'magenta', + warn : 'yellow', + error : 'red', + success: 'green', + silly : 'rainbow', +}); + +exports.setupLogger = function() { + winston.remove(winston.transports.Console); + winston.add(winston.transports.Console, { + levels: loggerConfig.levels, + formatter: function (options) { + return `[${pkg.name.cyan}] ${options.message}`; + } + }); + // winston.setLevels(loggerConfig.levels); + winston.level = 4; + winston.addColors(loggerConfig.colors); +} + +exports.log = log; diff --git a/src/test/test.js b/src/test/test.js new file mode 100644 index 0000000..e69de29 diff --git a/test/test.js b/test/test.js index 34c396a..9a390c3 100644 --- a/test/test.js +++ b/test/test.js @@ -1,15 +1 @@ -var assert, kody; - -assert = require("assert"); - -kody = require("../lib/kody"); - -suite("kody", function() { - return suite("run", function() { - return test("kody should throw an error if there's no config file", function() { - return assert.throws((function() { - return kody.init(); - }), Error); - }); - }); -}); +"use strict"; \ No newline at end of file diff --git a/wipe-dependencies.js b/wipe-dependencies.js new file mode 100644 index 0000000..88ed053 --- /dev/null +++ b/wipe-dependencies.js @@ -0,0 +1,18 @@ +var fs = require('fs'), + wipeDependencies = function() { + var file = fs.readFileSync('package.json'), + content = JSON.parse(file); + for (var devDep in content.devDependencies) { + content.devDependencies[devDep] = '*'; + } + for (var dep in content.dependencies) { + content.dependencies[dep] = '*'; + } + fs.writeFileSync('package.json', JSON.stringify(content)); + }; + +if (require.main === module) { + wipeDependencies(); +} else { + module.exports = wipeDependencies; +} From 7cc05782d9bb798b8dcde88c05431f2f3f704a75 Mon Sep 17 00:00:00 2001 From: jh3y Date: Tue, 23 Feb 2016 21:35:30 +0000 Subject: [PATCH 02/11] Implement winston logging for app wide ridding need for utils --- lib/core.js | 6 ++--- lib/kody.js | 12 ++++----- lib/main.js | 34 ++++++++++++++++++++++--- lib/tasks/a.js | 4 +-- lib/tasks/b.js | 4 +-- lib/tasks/dotfiles.js | 3 +-- lib/tasks/gitconfig.js | 9 +++---- lib/utils.js | 52 -------------------------------------- src/lib/core.js | 8 +++--- src/lib/kody.js | 12 ++++----- src/lib/main.js | 34 ++++++++++++++++++++++--- src/lib/tasks/a.js | 6 ++--- src/lib/tasks/b.js | 6 ++--- src/lib/tasks/dotfiles.js | 3 +-- src/lib/tasks/gitconfig.js | 51 ++++++++++++++++++------------------- src/lib/utils.js | 48 ----------------------------------- 16 files changed, 120 insertions(+), 172 deletions(-) delete mode 100644 lib/utils.js delete mode 100644 src/lib/utils.js diff --git a/lib/core.js b/lib/core.js index ced01c8..4dddb05 100644 --- a/lib/core.js +++ b/lib/core.js @@ -4,11 +4,11 @@ var _createClass = function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var utils = require('./utils'), +var winston = require('winston'), defaults = { name: 'Generic task', exec: function exec(e) { - return utils.log('running', 'info'); + return winston.info('running'); } }; @@ -28,7 +28,7 @@ var KodyTask = function () { var _this = this; return new Promise(function (resolve, reject) { - utils.log('Running ' + _this.name, 'info'); + winston.info('Running ' + _this.name); if (_this.exec && typeof _this.exec === 'function') { _this.exec(resolve, reject); } diff --git a/lib/kody.js b/lib/kody.js index 11e2ac2..c0d69fa 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -9,7 +9,7 @@ var polyfill = require('babel-polyfill'), shell = require('shelljs'), inquirer = require('inquirer'), pkg = require('../package.json'), - utils = require('./utils'), + winston = require('winston'), fs = require('fs'), task_runner = require('./task_runner'), core = require('./core'), @@ -31,21 +31,21 @@ var polyfill = require('babel-polyfill'), } }, welcome = function welcome() { - utils.log('==================================', 'info'); - utils.log('kody - .files & config runner', 'info'); - utils.log('==================================', 'info'); + winston.info('=================================='); + winston.info('kody - .files & config runner'); + winston.info('=================================='); }, processTasks = function processTasks(tasks) { tasks = tasks.tasks[Symbol.iterator](); var processTask = function processTask(task) { var newTask = new core.KodyTask(task.value); newTask.run().then(function () { - utils.log('Task ' + newTask.name + ' has finished', 'info'); + winston.info('Task ' + newTask.name + ' has finished'); var nextTask = tasks.next(); if (nextTask.value) { processTask(nextTask); } else { - utils.log('ALL TASKS FINISHED', 'silly'); + winston.silly('ALL TASKS FINISHED'); } }).then(function () { throw new Error('Something went wrong'); diff --git a/lib/main.js b/lib/main.js index 04f6afe..66c92ac 100644 --- a/lib/main.js +++ b/lib/main.js @@ -11,17 +11,43 @@ var program = require('commander'), colors = require('colors'), winston = require('winston'), pkg = require('../package.json'), - utils = require('./utils'), - kody = require('./kody'); + kody = require('./kody'), + PROPS = { + LOGGER_CONFIG: { + LEVELS: { + info: 1, + warn: 2, + error: 3, + success: 4, + silly: 5 + }, + COLORS: { + info: 'blue', + warn: 'yellow', + error: 'red', + success: 'green', + silly: 'rainbow' + } + } +}; program.version(pkg.version); -utils.setupLogger(); +winston.remove(winston.transports.Console); +winston.add(winston.transports.Console, { + level: 'silly', + colorize: true, + formatter: function formatter(options) { + var color = PROPS.LOGGER_CONFIG.COLORS[options.level]; + return '[' + pkg.name.cyan + '] ' + options.message[color]; + } +}); +winston.setLevels(PROPS.LOGGER_CONFIG.LEVELS); program.parse(process.argv); try { kody.init(); } catch (err) { - utils.log(err.toString(), 'error'); + winston.error(err.toString()); } \ No newline at end of file diff --git a/lib/tasks/a.js b/lib/tasks/a.js index 6442d03..f1e1ca1 100644 --- a/lib/tasks/a.js +++ b/lib/tasks/a.js @@ -5,12 +5,12 @@ * @license MIT * @author author */ -var utils = require('../utils'), +var winston = require('winston'), options = { name: 'Set up A', description: 'sets up A for use on system', exec: function exec(resolve, reject) { - utils.log('setting up a .... buzz grrr ... bing'); + winston.warn('setting up a .... buzz grrr ... bing'); setTimeout(resolve, 5000); } }; diff --git a/lib/tasks/b.js b/lib/tasks/b.js index 67840f6..5b48ee2 100644 --- a/lib/tasks/b.js +++ b/lib/tasks/b.js @@ -1,11 +1,11 @@ 'use strict'; -var utils = require('../utils'), +var winston = require('winston'), options = { name: 'Set up B', description: 'sets up b for system wide use', exec: function exec(resolve, reject) { - utils.log('setting up b .... beezz brrr ... bazing'); + winston.warn('setting up b .... beezz brrr ... bazing'); setTimeout(resolve, 3000); } }; diff --git a/lib/tasks/dotfiles.js b/lib/tasks/dotfiles.js index 9a34d26..d81c372 100644 --- a/lib/tasks/dotfiles.js +++ b/lib/tasks/dotfiles.js @@ -8,7 +8,6 @@ var shell = require('shelljs'), winston = require('winston'), - utils = require('../utils'), PROPS = { HOME_CMD: 'echo $HOME', EMPTY_MSG: 'no .files for linking.', @@ -63,7 +62,7 @@ var shell = require('shelljs'), } } } else { - utils.log(PROPS.EMPTY_MSG, 'info'); + winston.info(PROPS.EMPTY_MSG); } resolve(); } diff --git a/lib/tasks/gitconfig.js b/lib/tasks/gitconfig.js index 4166259..d6762fc 100644 --- a/lib/tasks/gitconfig.js +++ b/lib/tasks/gitconfig.js @@ -13,10 +13,9 @@ * @author jh3y */ var shell = require('shelljs'), - utils = require('../utils'), - userConfig = require(process.cwd() + '/kody.json'); - -var options = { + winston = require('winston'), + userConfig = require(process.cwd() + '/kody.json'), + options = { name: 'GitConfig', description: 'sets up global git configuration for symlinking', /** @@ -37,7 +36,7 @@ var options = { shell.exec(configString, { silent: true }).stdout.to('git/gitconfig.link'); - utils.log('GitConfig set up, ' + gitName + ', ' + gitEmail, 'info'); + winston.warn('GitConfig set up, ' + gitName + ', ' + gitEmail); setTimeout(resolve, 3000); } }; diff --git a/lib/utils.js b/lib/utils.js deleted file mode 100644 index b4baca1..0000000 --- a/lib/utils.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -var colors = require('colors'), - winston = require('winston'), - pkg = require('../package.json'), - log = function log(msg) { - // winston.info('ererger'); - - var type = arguments.length <= 1 || arguments[1] === undefined ? 'default' : arguments[1]; -}, - loggerConfig = { - levels: { - info: 0, - warn: 1, - error: 2, - success: 0, - silly: 4 - }, - colors: { - info: 'blue', - warn: 'green', - error: 'yellow', - success: 'red', - silly: 'rainbow' - } -}; - -colors.setTheme({ - default: 'grey', - prompt: 'yellow', - info: 'cyan', - help: 'magenta', - warn: 'yellow', - error: 'red', - success: 'green', - silly: 'rainbow' -}); - -exports.setupLogger = function () { - winston.remove(winston.transports.Console); - winston.add(winston.transports.Console, { - levels: loggerConfig.levels, - formatter: function formatter(options) { - return '[' + pkg.name.cyan + '] ' + options.message; - } - }); - // winston.setLevels(loggerConfig.levels); - winston.level = 4; - winston.addColors(loggerConfig.colors); -}; - -exports.log = log; \ No newline at end of file diff --git a/src/lib/core.js b/src/lib/core.js index bcdc24a..1df2d02 100644 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -1,7 +1,7 @@ -const utils = require('./utils'), - defaults = { +const winston = require('winston'), + defaults = { name: 'Generic task', - exec: e => utils.log('running', 'info') + exec: e => winston.info('running') }; class KodyTask { @@ -11,7 +11,7 @@ class KodyTask { } run() { return new Promise((resolve, reject) => { - utils.log(`Running ${this.name}`, 'info'); + winston.info(`Running ${this.name}`); if (this.exec && typeof this.exec === 'function') { this.exec(resolve, reject); } diff --git a/src/lib/kody.js b/src/lib/kody.js index c047d23..129f8df 100644 --- a/src/lib/kody.js +++ b/src/lib/kody.js @@ -7,7 +7,7 @@ const polyfill = require('babel-polyfill'), shell = require('shelljs'), inquirer = require('inquirer'), pkg = require('../package.json'), - utils = require('./utils'), + winston = require('winston'), fs = require('fs'), task_runner = require('./task_runner'), core = require('./core'), @@ -32,9 +32,9 @@ const polyfill = require('babel-polyfill'), } }, welcome = function() { - utils.log('==================================', 'info'); - utils.log('kody - .files & config runner', 'info'); - utils.log('==================================', 'info'); + winston.info('=================================='); + winston.info('kody - .files & config runner'); + winston.info('=================================='); }, processTasks = function(tasks) { tasks = tasks.tasks[Symbol.iterator](); @@ -42,12 +42,12 @@ const polyfill = require('babel-polyfill'), let newTask = new core.KodyTask(task.value); newTask.run() .then(() => { - utils.log(`Task ${newTask.name} has finished`, 'info'); + winston.info(`Task ${newTask.name} has finished`); let nextTask = tasks.next(); if (nextTask.value) { processTask(nextTask); } else { - utils.log('ALL TASKS FINISHED', 'silly'); + winston.silly('ALL TASKS FINISHED'); } }) .then(() => { diff --git a/src/lib/main.js b/src/lib/main.js index 971e039..9b41482 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -10,18 +10,44 @@ const program = require('commander'), colors = require('colors'), winston = require('winston'), pkg = require('../package.json'), - utils = require('./utils'), - kody = require('./kody'); + kody = require('./kody'), + PROPS = { + LOGGER_CONFIG: { + LEVELS: { + info : 1, + warn : 2, + error : 3, + success: 4, + silly : 5 + }, + COLORS: { + info : 'blue', + warn : 'yellow', + error : 'red', + success: 'green', + silly : 'rainbow' + } + } + }; program .version(pkg.version); -utils.setupLogger(); +winston.remove(winston.transports.Console); +winston.add(winston.transports.Console, { + level : 'silly', + colorize : true, + formatter: function (options) { + let color = PROPS.LOGGER_CONFIG.COLORS[options.level]; + return `[${pkg.name.cyan}] ${options.message[color]}`; + } +}); +winston.setLevels(PROPS.LOGGER_CONFIG.LEVELS); program.parse(process.argv); try { kody.init(); } catch(err) { - utils.log(err.toString(), 'error'); + winston.error(err.toString()); } diff --git a/src/lib/tasks/a.js b/src/lib/tasks/a.js index 3953539..63ee9fd 100644 --- a/src/lib/tasks/a.js +++ b/src/lib/tasks/a.js @@ -3,12 +3,12 @@ * @license MIT * @author author */ -const utils = require('../utils'), - options = { +const winston = require('winston'), + options = { name: 'Set up A', description: 'sets up A for use on system', exec: function(resolve, reject) { - utils.log('setting up a .... buzz grrr ... bing'); + winston.warn('setting up a .... buzz grrr ... bing'); setTimeout(resolve, 5000); } }; diff --git a/src/lib/tasks/b.js b/src/lib/tasks/b.js index af5e988..de278fd 100644 --- a/src/lib/tasks/b.js +++ b/src/lib/tasks/b.js @@ -1,9 +1,9 @@ -const utils = require('../utils'), - options = { +const winston = require('winston'), + options = { name: 'Set up B', description: 'sets up b for system wide use', exec: function(resolve, reject) { - utils.log('setting up b .... beezz brrr ... bazing'); + winston.warn('setting up b .... beezz brrr ... bazing'); setTimeout(resolve, 3000); } }; diff --git a/src/lib/tasks/dotfiles.js b/src/lib/tasks/dotfiles.js index 39f2a63..9aa9eb1 100644 --- a/src/lib/tasks/dotfiles.js +++ b/src/lib/tasks/dotfiles.js @@ -6,7 +6,6 @@ const shell = require('shelljs'), winston = require('winston'), - utils = require('../utils'), PROPS = { HOME_CMD : 'echo $HOME', EMPTY_MSG : 'no .files for linking.', @@ -40,7 +39,7 @@ const shell = require('shelljs'), // shell.ln('-sf', source, destination); } } else { - utils.log(PROPS.EMPTY_MSG, 'info'); + winston.info(PROPS.EMPTY_MSG); } resolve(); } diff --git a/src/lib/tasks/gitconfig.js b/src/lib/tasks/gitconfig.js index c49cd1e..38ea875 100644 --- a/src/lib/tasks/gitconfig.js +++ b/src/lib/tasks/gitconfig.js @@ -11,34 +11,33 @@ * @author jh3y */ const shell = require('shelljs'), - utils = require('../utils'), - userConfig = require(process.cwd() + '/kody.json'); + winston = require('winston'), + userConfig = require(process.cwd() + '/kody.json'), + options = { + name: 'GitConfig', + description: 'sets up global git configuration for symlinking', + /** + * Needs to check out what the config should be and send it over. + */ + exec: function(resolve, reject) { + let gitCredential, + gitName, + gitEmail; + const uname = shell.exec('uname -s', {silent: true}); + if (uname.output.indexOf('Darwin') !== -1) { + gitCredential = 'osxkeychain'; + } + gitName = userConfig.git_credentials.name; + gitEmail = userConfig.git_credentials.email; -const options = { - name: 'GitConfig', - description: 'sets up global git configuration for symlinking', - /** - * Needs to check out what the config should be and send it over. - */ - exec: function(resolve, reject) { - let gitCredential, - gitName, - gitEmail; - const uname = shell.exec('uname -s', {silent: true}); - if (uname.output.indexOf('Darwin') !== -1) { - gitCredential = 'osxkeychain'; - } - gitName = userConfig.git_credentials.name; - gitEmail = userConfig.git_credentials.email; - - let configString = `sed -e 's/AUTHORNAME/${gitName}/g' -e 's/AUTHOREMAIL/${gitEmail}/g' -e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g' git/gitconfig.starter`; + let configString = `sed -e 's/AUTHORNAME/${gitName}/g' -e 's/AUTHOREMAIL/${gitEmail}/g' -e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g' git/gitconfig.starter`; - shell.exec(configString, {silent: true}) - .stdout.to('git/gitconfig.link'); + shell.exec(configString, {silent: true}) + .stdout.to('git/gitconfig.link'); - utils.log(`GitConfig set up, ${gitName}, ${gitEmail}`, 'info'); - setTimeout(resolve, 3000); - } -}; + winston.warn(`GitConfig set up, ${gitName}, ${gitEmail}`); + setTimeout(resolve, 3000); + } + }; exports.options = options; diff --git a/src/lib/utils.js b/src/lib/utils.js deleted file mode 100644 index a075346..0000000 --- a/src/lib/utils.js +++ /dev/null @@ -1,48 +0,0 @@ -const colors = require('colors'), - winston = require('winston'), - pkg = require('../package.json'), - log = function(msg, type = 'default') { - // winston.info('ererger'); - }, - loggerConfig = { - levels: { - info: 0, - warn: 1, - error: 2, - success: 0, - silly: 4 - }, - colors: { - info: 'blue', - warn: 'green', - error: 'yellow', - success: 'red', - silly: 'rainbow' - } - }; - -colors.setTheme({ - default: 'grey', - prompt : 'yellow', - info : 'cyan', - help : 'magenta', - warn : 'yellow', - error : 'red', - success: 'green', - silly : 'rainbow', -}); - -exports.setupLogger = function() { - winston.remove(winston.transports.Console); - winston.add(winston.transports.Console, { - levels: loggerConfig.levels, - formatter: function (options) { - return `[${pkg.name.cyan}] ${options.message}`; - } - }); - // winston.setLevels(loggerConfig.levels); - winston.level = 4; - winston.addColors(loggerConfig.colors); -} - -exports.log = log; From b4e57e093e5c74ee949b17d18a078e9e05f088ed Mon Sep 17 00:00:00 2001 From: jh3y Date: Tue, 23 Feb 2016 23:08:26 +0000 Subject: [PATCH 03/11] Add more linting rules and work on reducing linting --- .eslintrc | 101 +++++++++++++++++++++++++------- lib/core.js | 10 ++-- lib/kody.js | 117 +++++++++++++++++++++---------------- src/lib/core.js | 13 ++--- src/lib/kody.js | 128 +++++++++++++++++++++++------------------ src/lib/task_runner.js | 0 6 files changed, 229 insertions(+), 140 deletions(-) delete mode 100644 src/lib/task_runner.js diff --git a/.eslintrc b/.eslintrc index 849b0ff..83dcc04 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,29 +1,86 @@ { "parser": "babel-eslint", "env": { - "node": true + "node": true, + "es6": true }, "rules": { - "semi": [1, "always"], - "quotes": [1, "single"], - "curly": [1, "multi-line"], - "eqeqeq": [1, "smart"], - "camelcase":[1, {"properties": "always"}], - "no-alert": 1, - "no-console": 2, - "no-debugger": 1, - "no-eq-null": 1, - "no-empty": 1, - "no-duplicate-case": 1, - "no-dupe-keys": 1, - "no-dupe-args": 1, - "comma-dangle": [1, "never"], - "no-unreachable": 1, - "no-else-return": 1, - "no-eval": 2, - "no-unused-vars": 1, - "no-use-before-define": 1, - "new-cap": 1, - "strict": [1, "never"] + # Possible errors + comma-dangle: 2, + no-console: 2, + no-cond-assign: 2, + no-control-regex: 2, + no-debugger: 2, + no-dupe-args: 2, + no-dupe-keys: 2, + no-duplicate-case: 2, + no-empty: 2, + no-empty-character-class: 2, + no-ex-assign: 2, + no-extra-boolean-cast: 2, + no-extra-semi: 2, + no-func-assign: 2, + no-invalid-regexp: 2, + no-irregular-whitespace: 2, + no-negated-in-lhs: 2, + no-obj-calls: 2, + no-proto: 2, + no-unexpected-multiline: 2, + no-unreachable: 2, + use-isnan: 2, + valid-typeof: 2, + valid-jsdoc: 2, + # Best practices + curly: [2, "multi"], + eqeqeq: 2, + no-fallthrough: 2, + no-param-reassign: 2, + no-octal: 2, + no-redeclare: 2, + # strict mode + strict: [2, "global"], + # variables + no-delete-var: 2, + no-undef: 2, + no-unused-vars: 2, + # node + no-mixed-requires: 2, + no-new-require: 2, + # stylistic + brace-style: 2, + camelcase: 2, + comma-style: 2, + comma-spacing: 2, + eol-last: 2, + indent: [2, 2, {SwitchCase: 1}], + keyword-spacing: 2, + max-len: [2, 80, 2], + max-depth: [2, 4], + new-cap: 2, + new-parens: 2, + no-mixed-spaces-and-tabs: 2, + no-multiple-empty-lines: [2, {max: 2}], + no-trailing-spaces: 2, + quotes: [2, "single"], + semi: 2, + sort-vars: 2, + space-before-blocks: [2, "always"], + space-before-function-paren: [2, "never"], + space-in-parens: [2, "never"], + space-infix-ops: 2, + space-unary-ops: 2, + # es6 + arrow-parens: [2, "always"], + arrow-spacing: [2, {"before": true, "after": true}], + constructor-super: 2, + no-class-assign: 2, + no-confusing-arrow: 2, + no-const-assign: 2, + no-dupe-class-members: 2, + no-this-before-super: 2, + no-var: 2, + prefer-const: 2, + prefer-rest-params: 2, + template-curly-spacing: 2 } } diff --git a/lib/core.js b/lib/core.js index 4dddb05..719d5c4 100644 --- a/lib/core.js +++ b/lib/core.js @@ -4,10 +4,10 @@ var _createClass = function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var winston = require('winston'), - defaults = { +var winston = require('winston'); +var defaults = { name: 'Generic task', - exec: function exec(e) { + exec: function exec() { return winston.info('running'); } }; @@ -29,9 +29,7 @@ var KodyTask = function () { return new Promise(function (resolve, reject) { winston.info('Running ' + _this.name); - if (_this.exec && typeof _this.exec === 'function') { - _this.exec(resolve, reject); - } + if (_this.exec && typeof _this.exec === 'function') _this.exec(resolve, reject); }); } }]); diff --git a/lib/kody.js b/lib/kody.js index c0d69fa..08cd84c 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -3,25 +3,21 @@ /** * kody - .files manager for node */ - -var polyfill = require('babel-polyfill'), - colors = require('colors'), - shell = require('shelljs'), - inquirer = require('inquirer'), - pkg = require('../package.json'), - winston = require('winston'), +require('babel-polyfill'); +var core = require('./core'), fs = require('fs'), - task_runner = require('./task_runner'), - core = require('./core'), - PROPS = { - /** - * Define a task order. - * This is useful for when you wish one task to run before - * another. - * - * For example; there is no use installing apm modules before - * Atom IDE is installed as the apm CLI won't be available. - */ + inquirer = require('inquirer'), + winston = require('winston'); + +/** +* Define a task order. +* This is useful for when you wish one task to run before +* another. +* +* For example; there is no use installing apm modules before +* Atom IDE is installed as the apm CLI won't be available. +*/ +var PROPS = { TASK_ORDER: ['gitconfig.js', '*'], TASKS_QUERY: { type: 'checkbox', @@ -30,38 +26,13 @@ var polyfill = require('babel-polyfill'), choices: [] } }, - welcome = function welcome() { - winston.info('=================================='); - winston.info('kody - .files & config runner'); - winston.info('=================================='); -}, - processTasks = function processTasks(tasks) { - tasks = tasks.tasks[Symbol.iterator](); - var processTask = function processTask(task) { - var newTask = new core.KodyTask(task.value); - newTask.run().then(function () { - winston.info('Task ' + newTask.name + ' has finished'); - var nextTask = tasks.next(); - if (nextTask.value) { - processTask(nextTask); - } else { - winston.silly('ALL TASKS FINISHED'); - } - }).then(function () { - throw new Error('Something went wrong'); - }); - }; - processTask(tasks.next()); -}, - sortFiles = function sortFiles(a, b) { - if (PROPS.TASK_ORDER.indexOf(b) !== -1 && PROPS.TASK_ORDER.indexOf(a) !== -1 && PROPS.TASK_ORDER.indexOf(a) < PROPS.TASK_ORDER.indexOf(b)) { - return -1; - } - if (PROPS.TASK_ORDER.indexOf(a) !== -1 || PROPS.TASK_ORDER.indexOf(b) !== -1) { - return 1; - } -}, - init = function init() { + +/** + * initializes Kody + * + * @returns {undefined} +*/ +init = function init() { welcome(); var files = fs.readdirSync(__dirname + '/tasks'); files = files.sort(sortFiles); @@ -96,6 +67,52 @@ var polyfill = require('babel-polyfill'), } inquirer.prompt(PROPS.TASKS_QUERY, processTasks); +}, + +/** + * loops through task objects and runs them + * + * @param {KodyTask[]} tasks - Array of KodyTask objects to be processed + * @returns {undefined} +*/ +processTasks = function processTasks(tasks) { + var processTask = function processTask(task) { + var newTask = new core.KodyTask(task.value); + newTask.run().then(function () { + winston.info('Task ' + newTask.name + ' has finished'); + var nextTask = tasksToProcess.next(); + if (nextTask.value) processTask(nextTask);else winston.silly('ALL TASKS FINISHED'); + }).then(function () { + throw new Error('Something went wrong'); + }); + }, + tasksToProcess = tasks.tasks[Symbol.iterator](); + processTask(tasksToProcess.next()); +}, + +/** + * used to sort ordering of task files based on desire. + * + * @param {string} a - string representing task filename + * @param {string} b - string representing task filename + * @returns {bool} - used by Array.sort +*/ +sortFiles = function sortFiles(a, b) { + var aIndex = PROPS.TASK_ORDER.indexOf(a), + bIndex = PROPS.TASK_ORDER.indexOf(b); + if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) return -1; + if (aIndex !== -1 || bIndex !== -1) return 1; +}, + +/** + * welcome msg for user + * + * @returns {undefined} +*/ +welcome = function welcome() { + winston.info('=================================='); + winston.info('kody - .files & config runner'); + winston.info('=================================='); }; exports.init = init; \ No newline at end of file diff --git a/src/lib/core.js b/src/lib/core.js index 1df2d02..4399011 100644 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -1,8 +1,8 @@ -const winston = require('winston'), - defaults = { - name: 'Generic task', - exec: e => winston.info('running') - }; +const winston = require('winston'); +const defaults = { + name: 'Generic task', + exec: () => winston.info('running') +}; class KodyTask { constructor(opts = defaults) { @@ -12,9 +12,8 @@ class KodyTask { run() { return new Promise((resolve, reject) => { winston.info(`Running ${this.name}`); - if (this.exec && typeof this.exec === 'function') { + if (this.exec && typeof this.exec === 'function') this.exec(resolve, reject); - } }); } } diff --git a/src/lib/kody.js b/src/lib/kody.js index 129f8df..c89a7ab 100644 --- a/src/lib/kody.js +++ b/src/lib/kody.js @@ -1,25 +1,21 @@ /** * kody - .files manager for node */ +require('babel-polyfill'); +const core = require('./core'), + fs = require('fs'), + inquirer = require('inquirer'), + winston = require('winston'); -const polyfill = require('babel-polyfill'), - colors = require('colors'), - shell = require('shelljs'), - inquirer = require('inquirer'), - pkg = require('../package.json'), - winston = require('winston'), - fs = require('fs'), - task_runner = require('./task_runner'), - core = require('./core'), - PROPS = { - /** - * Define a task order. - * This is useful for when you wish one task to run before - * another. - * - * For example; there is no use installing apm modules before - * Atom IDE is installed as the apm CLI won't be available. - */ +/** +* Define a task order. +* This is useful for when you wish one task to run before +* another. +* +* For example; there is no use installing apm modules before +* Atom IDE is installed as the apm CLI won't be available. +*/ +const PROPS = { TASK_ORDER : [ 'gitconfig.js', '*' @@ -31,52 +27,74 @@ const polyfill = require('babel-polyfill'), choices: [] } }, - welcome = function() { - winston.info('=================================='); - winston.info('kody - .files & config runner'); - winston.info('=================================='); - }, - processTasks = function(tasks) { - tasks = tasks.tasks[Symbol.iterator](); - let processTask = function(task) { - let newTask = new core.KodyTask(task.value); - newTask.run() - .then(() => { - winston.info(`Task ${newTask.name} has finished`); - let nextTask = tasks.next(); - if (nextTask.value) { - processTask(nextTask); - } else { - winston.silly('ALL TASKS FINISHED'); - } - }) - .then(() => { - throw new Error('Something went wrong'); - }); - }; - processTask(tasks.next()); - }, - sortFiles = function(a, b) { - if(PROPS.TASK_ORDER.indexOf(b) !== -1 && PROPS.TASK_ORDER.indexOf(a) !== -1 && PROPS.TASK_ORDER.indexOf(a) < PROPS.TASK_ORDER.indexOf(b)) { - return -1; - } - if(PROPS.TASK_ORDER.indexOf(a) !== -1 || PROPS.TASK_ORDER.indexOf(b) !== -1) { - return 1; - } - }, - init = function() { + /** + * initializes Kody + * + * @returns {undefined} + */ + init = function() { welcome(); let files = fs.readdirSync(__dirname + '/tasks'); files = files.sort(sortFiles); - for (let file of files) { - let taskOpts = require(`./tasks/${file}`).options; - let newChoice = { + for (const file of files) { + const taskOpts = require(`./tasks/${file}`).options; + const newChoice = { name: `${taskOpts.name} - ${taskOpts.description}`, value: taskOpts }; PROPS.TASKS_QUERY.choices.push(newChoice); } inquirer.prompt(PROPS.TASKS_QUERY, processTasks); + }, + /** + * loops through task objects and runs them + * + * @param {KodyTask[]} tasks - Array of KodyTask objects to be processed + * @returns {undefined} + */ + processTasks = function(tasks) { + const processTask = function(task) { + const newTask = new core.KodyTask(task.value); + newTask.run() + .then(() => { + winston.info(`Task ${newTask.name} has finished`); + const nextTask = tasksToProcess.next(); + if (nextTask.value) + processTask(nextTask); + else + winston.silly('ALL TASKS FINISHED'); + }) + .then(() => { + throw new Error('Something went wrong'); + }); + }, + tasksToProcess = tasks.tasks[Symbol.iterator](); + processTask(tasksToProcess.next()); + }, + /** + * used to sort ordering of task files based on desire. + * + * @param {string} a - string representing task filename + * @param {string} b - string representing task filename + * @returns {bool} - used by Array.sort + */ + sortFiles = function(a, b) { + const aIndex = PROPS.TASK_ORDER.indexOf(a), + bIndex = PROPS.TASK_ORDER.indexOf(b); + if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) + return -1; + if (aIndex !== -1 || bIndex !== -1) + return 1; + }, + /** + * welcome msg for user + * + * @returns {undefined} + */ + welcome = function() { + winston.info('=================================='); + winston.info('kody - .files & config runner'); + winston.info('=================================='); }; exports.init = init; diff --git a/src/lib/task_runner.js b/src/lib/task_runner.js deleted file mode 100644 index e69de29..0000000 From 970c205623ce00960485d11f75b9fdf6a222eae0 Mon Sep 17 00:00:00 2001 From: jh3y Date: Tue, 23 Feb 2016 23:40:14 +0000 Subject: [PATCH 04/11] Remove problematic sort-vars rule and reduce linting --- .eslintrc | 1 - lib/TASK_BOILERPLATE.js | 3 ++- lib/main.js | 12 ++++----- lib/tasks/a.js | 6 ++--- lib/tasks/b.js | 6 ++--- lib/tasks/dotfiles.js | 16 +++++------- lib/tasks/gitconfig.js | 32 +++++++++++------------ src/lib/TASK_BOILERPLATE.js | 2 +- src/lib/main.js | 51 ++++++++++++++++++------------------- src/lib/tasks/a.js | 18 ++++++------- src/lib/tasks/b.js | 18 ++++++------- src/lib/tasks/dotfiles.js | 28 ++++++++++---------- src/lib/tasks/gitconfig.js | 36 +++++++++++++------------- 13 files changed, 111 insertions(+), 118 deletions(-) diff --git a/.eslintrc b/.eslintrc index 83dcc04..70718ca 100644 --- a/.eslintrc +++ b/.eslintrc @@ -63,7 +63,6 @@ no-trailing-spaces: 2, quotes: [2, "single"], semi: 2, - sort-vars: 2, space-before-blocks: [2, "always"], space-before-function-paren: [2, "never"], space-in-parens: [2, "never"], diff --git a/lib/TASK_BOILERPLATE.js b/lib/TASK_BOILERPLATE.js index bbed939..4f3ef99 100644 --- a/lib/TASK_BOILERPLATE.js +++ b/lib/TASK_BOILERPLATE.js @@ -9,7 +9,8 @@ var options = { name: 'TASK-0001', description: 'sets up something', - exec: function exec(resolve, reject) { + exec: function exec(resolve) { + // NOTE: to reject, include reject parameter resolve(); } }; diff --git a/lib/main.js b/lib/main.js index 66c92ac..8e376a1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -6,13 +6,13 @@ * @author jh3y 2016 * @license MIT */ - -var program = require('commander'), - colors = require('colors'), - winston = require('winston'), +require('colors'); +var kody = require('./kody'), pkg = require('../package.json'), - kody = require('./kody'), - PROPS = { + program = require('commander'), + winston = require('winston'); + +var PROPS = { LOGGER_CONFIG: { LEVELS: { info: 1, diff --git a/lib/tasks/a.js b/lib/tasks/a.js index f1e1ca1..ada6bb7 100644 --- a/lib/tasks/a.js +++ b/lib/tasks/a.js @@ -5,11 +5,11 @@ * @license MIT * @author author */ -var winston = require('winston'), - options = { +var winston = require('winston'); +var options = { name: 'Set up A', description: 'sets up A for use on system', - exec: function exec(resolve, reject) { + exec: function exec(resolve) { winston.warn('setting up a .... buzz grrr ... bing'); setTimeout(resolve, 5000); } diff --git a/lib/tasks/b.js b/lib/tasks/b.js index 5b48ee2..24b4c61 100644 --- a/lib/tasks/b.js +++ b/lib/tasks/b.js @@ -1,10 +1,10 @@ 'use strict'; -var winston = require('winston'), - options = { +var winston = require('winston'); +var options = { name: 'Set up B', description: 'sets up b for system wide use', - exec: function exec(resolve, reject) { + exec: function exec(resolve) { winston.warn('setting up b .... beezz brrr ... bazing'); setTimeout(resolve, 3000); } diff --git a/lib/tasks/dotfiles.js b/lib/tasks/dotfiles.js index d81c372..b2732d4 100644 --- a/lib/tasks/dotfiles.js +++ b/lib/tasks/dotfiles.js @@ -7,8 +7,9 @@ */ var shell = require('shelljs'), - winston = require('winston'), - PROPS = { + winston = require('winston'); + +var PROPS = { HOME_CMD: 'echo $HOME', EMPTY_MSG: 'no .files for linking.', FILE_REGEXP: /\.link$/, @@ -17,7 +18,7 @@ var shell = require('shelljs'), options = { name: 'DotFiles', description: 'sets up symlinks for global dotfiles', - exec: function exec(resolve, reject) { + exec: function exec(resolve) { // grab the home directory for the user. var $HOME = shell.exec(PROPS.HOME_CMD, { silent: true @@ -39,11 +40,10 @@ var shell = require('shelljs'), var source = process.cwd() + '/' + dotFile; var basename = dotFile; - if (basename.indexOf('/') !== -1) { - basename = basename.substr(basename.lastIndexOf('/') + 1); - } + if (basename.indexOf('/') !== -1) basename = basename.substr(basename.lastIndexOf('/') + 1); basename = basename.replace(PROPS.FILE_SUFFIX, ''); var destination = $HOME + '/.' + basename; + winston.info('' + source); winston.success('linked ' + basename + ' to ' + destination); // shell.ln('-sf', source, destination); } @@ -61,9 +61,7 @@ var shell = require('shelljs'), } } } - } else { - winston.info(PROPS.EMPTY_MSG); - } + } else winston.info(PROPS.EMPTY_MSG); resolve(); } }; diff --git a/lib/tasks/gitconfig.js b/lib/tasks/gitconfig.js index d6762fc..ecc47c7 100644 --- a/lib/tasks/gitconfig.js +++ b/lib/tasks/gitconfig.js @@ -13,28 +13,26 @@ * @author jh3y */ var shell = require('shelljs'), - winston = require('winston'), userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var PROPS = { + STARTER: 'git/gitconfig.starter', + OUTPUT: 'git/gitconfig.link' +}, options = { name: 'GitConfig', description: 'sets up global git configuration for symlinking', - /** - * Needs to check out what the config should be and send it over. - */ - exec: function exec(resolve, reject) { - var gitCredential = undefined, - gitName = undefined, - gitEmail = undefined; - var uname = shell.exec('uname -s', { silent: true }); - if (uname.output.indexOf('Darwin') !== -1) { - gitCredential = 'osxkeychain'; - } - gitName = userConfig.git_credentials.name; - gitEmail = userConfig.git_credentials.email; - - var configString = 'sed -e \'s/AUTHORNAME/' + gitName + '/g\' -e \'s/AUTHOREMAIL/' + gitEmail + '/g\' -e \'s/GIT_CREDENTIAL_HELPER/' + gitCredential + '/g\' git/gitconfig.starter'; + exec: function exec(resolve) { + var gitCredential = 'osxkeychain', + gitEmail = userConfig.git_credentials.email, + gitName = userConfig.git_credentials.name, + nameCmd = '-e \'s/AUTHORNAME/' + gitName + '/g\'', + emailCmd = '-e \'s/AUTHOREMAIL/' + gitEmail + '/g\'', + credentialCmd = '-e \'s/GIT_CREDENTIAL_HELPER/' + gitCredential + '/g\'', + cG = 'sed ' + nameCmd + ' ' + emailCmd + ' ' + credentialCmd + ' ' + PROPS.STARTER; - shell.exec(configString, { silent: true }).stdout.to('git/gitconfig.link'); + shell.exec(cG, { silent: true }).stdout.to(PROPS.OUTPUT); winston.warn('GitConfig set up, ' + gitName + ', ' + gitEmail); setTimeout(resolve, 3000); diff --git a/src/lib/TASK_BOILERPLATE.js b/src/lib/TASK_BOILERPLATE.js index e41b734..c085d4a 100644 --- a/src/lib/TASK_BOILERPLATE.js +++ b/src/lib/TASK_BOILERPLATE.js @@ -7,7 +7,7 @@ const options = { name: 'TASK-0001', description: 'sets up something', - exec: function(resolve, reject) { + exec: function(resolve) { // NOTE: to reject, include reject parameter resolve(); } }; diff --git a/src/lib/main.js b/src/lib/main.js index 9b41482..3743124 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -4,31 +4,30 @@ * @author jh3y 2016 * @license MIT */ +require('colors'); +const kody = require('./kody'), + pkg = require('../package.json'), + program = require('commander'), + winston = require('winston'); - -const program = require('commander'), - colors = require('colors'), - winston = require('winston'), - pkg = require('../package.json'), - kody = require('./kody'), - PROPS = { - LOGGER_CONFIG: { - LEVELS: { - info : 1, - warn : 2, - error : 3, - success: 4, - silly : 5 - }, - COLORS: { - info : 'blue', - warn : 'yellow', - error : 'red', - success: 'green', - silly : 'rainbow' - } +const PROPS = { + LOGGER_CONFIG: { + LEVELS: { + info : 1, + warn : 2, + error : 3, + success: 4, + silly : 5 + }, + COLORS: { + info : 'blue', + warn : 'yellow', + error : 'red', + success: 'green', + silly : 'rainbow' } - }; + } +}; program .version(pkg.version); @@ -37,8 +36,8 @@ winston.remove(winston.transports.Console); winston.add(winston.transports.Console, { level : 'silly', colorize : true, - formatter: function (options) { - let color = PROPS.LOGGER_CONFIG.COLORS[options.level]; + formatter: function(options) { + const color = PROPS.LOGGER_CONFIG.COLORS[options.level]; return `[${pkg.name.cyan}] ${options.message[color]}`; } }); @@ -48,6 +47,6 @@ program.parse(process.argv); try { kody.init(); -} catch(err) { +} catch (err) { winston.error(err.toString()); } diff --git a/src/lib/tasks/a.js b/src/lib/tasks/a.js index 63ee9fd..10abaac 100644 --- a/src/lib/tasks/a.js +++ b/src/lib/tasks/a.js @@ -3,14 +3,14 @@ * @license MIT * @author author */ -const winston = require('winston'), - options = { - name: 'Set up A', - description: 'sets up A for use on system', - exec: function(resolve, reject) { - winston.warn('setting up a .... buzz grrr ... bing'); - setTimeout(resolve, 5000); - } - }; +const winston = require('winston'); +const options = { + name : 'Set up A', + description: 'sets up A for use on system', + exec : function(resolve) { + winston.warn('setting up a .... buzz grrr ... bing'); + setTimeout(resolve, 5000); + } +}; exports.options = options; diff --git a/src/lib/tasks/b.js b/src/lib/tasks/b.js index de278fd..63b04ac 100644 --- a/src/lib/tasks/b.js +++ b/src/lib/tasks/b.js @@ -1,11 +1,11 @@ -const winston = require('winston'), - options = { - name: 'Set up B', - description: 'sets up b for system wide use', - exec: function(resolve, reject) { - winston.warn('setting up b .... beezz brrr ... bazing'); - setTimeout(resolve, 3000); - } - }; +const winston = require('winston'); +const options = { + name : 'Set up B', + description: 'sets up b for system wide use', + exec : function(resolve) { + winston.warn('setting up b .... beezz brrr ... bazing'); + setTimeout(resolve, 3000); + } +}; exports.options = options; diff --git a/src/lib/tasks/dotfiles.js b/src/lib/tasks/dotfiles.js index 9aa9eb1..1296fe4 100644 --- a/src/lib/tasks/dotfiles.js +++ b/src/lib/tasks/dotfiles.js @@ -5,8 +5,9 @@ */ const shell = require('shelljs'), - winston = require('winston'), - PROPS = { + winston = require('winston'); + +const PROPS = { HOME_CMD : 'echo $HOME', EMPTY_MSG : 'no .files for linking.', FILE_REGEXP: /\.link$/, @@ -15,32 +16,31 @@ const shell = require('shelljs'), options = { name: 'DotFiles', description: 'sets up symlinks for global dotfiles', - exec: function(resolve, reject) { + exec: function(resolve) { // grab the home directory for the user. - let $HOME = shell.exec(PROPS.HOME_CMD, { - silent: true - }).output.trim(), + const $HOME = shell.exec(PROPS.HOME_CMD, { + silent: true + }).output.trim(), // grab instances, these are files/dirs suffixed with ".link" dotFiles = shell.find('.') .filter(function(file) { return file.match(PROPS.FILE_REGEXP); }); - if (dotFiles.length > 0) { - for(let dotFile of dotFiles) { - let source = `${process.cwd()}/${dotFile}`; + if (dotFiles.length > 0) + for (const dotFile of dotFiles) { + const source = `${process.cwd()}/${dotFile}`; let basename = dotFile; - if (basename.indexOf('/') !== -1) { + if (basename.indexOf('/') !== -1) basename = basename.substr(basename.lastIndexOf('/') + 1); - } basename = basename.replace(PROPS.FILE_SUFFIX, ''); - let destination = `${$HOME}/.${basename}`; + const destination = `${$HOME}/.${basename}`; + winston.info(`${source}`); winston.success(`linked ${basename} to ${destination}`); // shell.ln('-sf', source, destination); } - } else { + else winston.info(PROPS.EMPTY_MSG); - } resolve(); } }; diff --git a/src/lib/tasks/gitconfig.js b/src/lib/tasks/gitconfig.js index 38ea875..d1d2f49 100644 --- a/src/lib/tasks/gitconfig.js +++ b/src/lib/tasks/gitconfig.js @@ -11,29 +11,27 @@ * @author jh3y */ const shell = require('shelljs'), - winston = require('winston'), userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +const PROPS = { + STARTER: 'git/gitconfig.starter', + OUTPUT : 'git/gitconfig.link' + }, options = { - name: 'GitConfig', + name : 'GitConfig', description: 'sets up global git configuration for symlinking', - /** - * Needs to check out what the config should be and send it over. - */ - exec: function(resolve, reject) { - let gitCredential, - gitName, - gitEmail; - const uname = shell.exec('uname -s', {silent: true}); - if (uname.output.indexOf('Darwin') !== -1) { - gitCredential = 'osxkeychain'; - } - gitName = userConfig.git_credentials.name; - gitEmail = userConfig.git_credentials.email; - - let configString = `sed -e 's/AUTHORNAME/${gitName}/g' -e 's/AUTHOREMAIL/${gitEmail}/g' -e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g' git/gitconfig.starter`; + exec : function(resolve) { + const gitCredential = 'osxkeychain', + gitEmail = userConfig.git_credentials.email, + gitName = userConfig.git_credentials.name, + nameCmd = `-e 's/AUTHORNAME/${gitName}/g'`, + emailCmd = `-e 's/AUTHOREMAIL/${gitEmail}/g'`, + credentialCmd = `-e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g'`, + cG = `sed ${nameCmd} ${emailCmd} ${credentialCmd} ${PROPS.STARTER}`; - shell.exec(configString, {silent: true}) - .stdout.to('git/gitconfig.link'); + shell.exec(cG, {silent: true}) + .stdout.to(PROPS.OUTPUT); winston.warn(`GitConfig set up, ${gitName}, ${gitEmail}`); setTimeout(resolve, 3000); From e7e80cf2ddbf1eeced29e1c5b4dac3e17c563207 Mon Sep 17 00:00:00 2001 From: jh3y Date: Sun, 28 Feb 2016 21:02:49 +0000 Subject: [PATCH 05/11] Rework of kody to es6 --- createTask.sh | 20 ++++++ dummy_env/kody.json | 53 +++++++-------- lib/TASK_BOILERPLATE.js | 18 ------ lib/kody.js | 3 +- lib/task_runner.js | 1 - lib/tasks/a.js | 18 ------ lib/tasks/apm.js | 29 +++++++++ lib/tasks/b.js | 13 ---- lib/tasks/brewCask.js | 53 +++++++++++++++ lib/tasks/dotfiles.js | 8 +-- lib/tasks/fishDefault.js | 25 ++++++++ lib/tasks/gitconfig.js | 7 +- lib/tasks/homebrew.js | 36 +++++++++++ lib/tasks/npm.js | 55 ++++++++++++++++ lib/tasks/osxDefaults.js | 25 ++++++++ lib/tasks/removeOsxApps.js | 52 +++++++++++++++ package.json | 5 +- src.deprecated/coffee/lib/kody.coffee | 25 -------- src.deprecated/coffee/lib/main.coffee | 34 ---------- src.deprecated/coffee/lib/task_runner.coffee | 64 ------------------- .../lib/tasks/install_atom_packages.coffee | 25 -------- .../coffee/lib/tasks/install_dot_files.coffee | 43 ------------- .../lib/tasks/install_npm_modules.coffee | 27 -------- .../tasks/remove_default_apple_apps.coffee | 27 -------- .../coffee/lib/tasks/set_osx_defaults.coffee | 30 --------- .../coffee/lib/tasks/set_up_brew_cask.coffee | 28 -------- .../coffee/lib/tasks/set_up_fish_shell.coffee | 28 -------- .../coffee/lib/tasks/set_up_git_config.coffee | 39 ----------- .../coffee/lib/tasks/set_up_homebrew.coffee | 32 ---------- .../coffee/lib/tasks/task.coffee.boilerplate | 21 ------ src.deprecated/coffee/lib/utils.coffee | 18 ------ src.deprecated/coffee/test/test.coffee | 9 --- src/lib/TASK_BOILERPLATE.js | 15 ----- src/lib/kody.js | 3 + src/lib/task.boilerplate | 18 ++++++ src/lib/tasks/a.js | 16 ----- src/lib/tasks/apm.js | 31 +++++++++ src/lib/tasks/b.js | 11 ---- src/lib/tasks/brewCask.js | 30 +++++++++ src/lib/tasks/dotfiles.js | 5 +- src/lib/tasks/fishDefault.js | 24 +++++++ src/lib/tasks/gitconfig.js | 7 +- src/lib/tasks/homebrew.js | 36 +++++++++++ src/lib/tasks/npm.js | 33 ++++++++++ src/lib/tasks/osxDefaults.js | 24 +++++++ src/lib/tasks/removeOsxApps.js | 29 +++++++++ src/test/test.js | 12 ++++ test/test.js | 15 ++++- 48 files changed, 586 insertions(+), 594 deletions(-) create mode 100644 createTask.sh delete mode 100644 lib/TASK_BOILERPLATE.js delete mode 100644 lib/task_runner.js delete mode 100644 lib/tasks/a.js create mode 100644 lib/tasks/apm.js delete mode 100644 lib/tasks/b.js create mode 100644 lib/tasks/brewCask.js create mode 100644 lib/tasks/fishDefault.js create mode 100644 lib/tasks/homebrew.js create mode 100644 lib/tasks/npm.js create mode 100644 lib/tasks/osxDefaults.js create mode 100644 lib/tasks/removeOsxApps.js delete mode 100644 src.deprecated/coffee/lib/kody.coffee delete mode 100644 src.deprecated/coffee/lib/main.coffee delete mode 100644 src.deprecated/coffee/lib/task_runner.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/install_atom_packages.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/install_dot_files.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/install_npm_modules.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/remove_default_apple_apps.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/set_osx_defaults.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/set_up_brew_cask.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/set_up_fish_shell.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/set_up_git_config.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/set_up_homebrew.coffee delete mode 100644 src.deprecated/coffee/lib/tasks/task.coffee.boilerplate delete mode 100644 src.deprecated/coffee/lib/utils.coffee delete mode 100644 src.deprecated/coffee/test/test.coffee delete mode 100644 src/lib/TASK_BOILERPLATE.js create mode 100644 src/lib/task.boilerplate delete mode 100644 src/lib/tasks/a.js create mode 100644 src/lib/tasks/apm.js delete mode 100644 src/lib/tasks/b.js create mode 100644 src/lib/tasks/brewCask.js create mode 100644 src/lib/tasks/fishDefault.js create mode 100644 src/lib/tasks/homebrew.js create mode 100644 src/lib/tasks/npm.js create mode 100644 src/lib/tasks/osxDefaults.js create mode 100644 src/lib/tasks/removeOsxApps.js diff --git a/createTask.sh b/createTask.sh new file mode 100644 index 0000000..e682e4e --- /dev/null +++ b/createTask.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +while getopts :a:d:t:f: name +do + case $name in + a)author=$OPTARG + ;; + d)description=$OPTARG + ;; + t)title=$OPTARG + ;; + f)file=$OPTARG + ;; + *)echo "Invalid arg";; + esac +done + +sed -e "s/@AUTHOR/$author/g" -e "s/@TITLE/$title/g" -e "s/@DESCRIPTION/$description/g" src/lib/task.boilerplate > src/lib/tasks/$file.js + +echo New task created at src/lib/tasks/$file.js diff --git a/dummy_env/kody.json b/dummy_env/kody.json index bc40fa3..9041abd 100644 --- a/dummy_env/kody.json +++ b/dummy_env/kody.json @@ -1,46 +1,39 @@ { - "set_up_git_config": false, - "set_osx_defaults": false, - "install_dot_files": false, - "install_brew_cask_and_casks": false, - "install_homebrew_and_packages": false, - "install_apm_packages": false, - "install_npm_modules": false, - "set_fish_shell_as_default": false, - "remove_default_apple_apps": true, - "git_credentials": { - "name": "jh3y", - "email": "jh3y@users.noreply.github.com" + "gitCredentials": { + "name": "SomeUser", + "email": "SomeUser@SomeEmail.com" }, - "brew_installs": [ + "brewInstalls": [ "git", "mongodb", "ruby-build", "rbenv", "fish" ], - "brew_casks": [ + "brewCasks": [ "google-chrome", "heroku-toolbelt", "spotify" ], - "apm_packages": [ - "css-color-highlighting", - "atom-linter" + "apmPackages": [ + "css-color-underline", + "linter-jshint" ], - "global_npm_modules": { - "sike": "latest", - "less": "latest", - "jade": "latest", - "gulp": "latest", - "grunt-cli": "latest", - "express-generator": "latest", - "docpad": "latest", - "component": "latest", - "coffee-script": "latest", - "bower": "latest" - }, - "apple_apps_to_remove": [ + "globalNpmModules": [ + "sike", + "less", + "jade", + "gulp", + "grunt-cli", + "express-generator", + "docpad", + "component", + "coffee-script", + "bower" + ], + "fishDefaultScriptPath": "fish/set_default.sh", + "osxDefaultScriptPath": "osx/set_default.sh", + "osxAppsToRemove": [ "Chess.app", "Game Center.app" ] diff --git a/lib/TASK_BOILERPLATE.js b/lib/TASK_BOILERPLATE.js deleted file mode 100644 index 4f3ef99..0000000 --- a/lib/TASK_BOILERPLATE.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -/** - * Task - description - * @license MIT - * @author author -*/ - -var options = { - name: 'TASK-0001', - description: 'sets up something', - exec: function exec(resolve) { - // NOTE: to reject, include reject parameter - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/kody.js b/lib/kody.js index 08cd84c..f45b904 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -18,7 +18,7 @@ var core = require('./core'), * Atom IDE is installed as the apm CLI won't be available. */ var PROPS = { - TASK_ORDER: ['gitconfig.js', '*'], + TASK_ORDER: ['gitconfig.js', 'homebrew.js', 'brewCask.js', '*'], TASKS_QUERY: { type: 'checkbox', name: 'tasks', @@ -36,6 +36,7 @@ init = function init() { welcome(); var files = fs.readdirSync(__dirname + '/tasks'); files = files.sort(sortFiles); + winston.info(files); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; diff --git a/lib/task_runner.js b/lib/task_runner.js deleted file mode 100644 index 9a390c3..0000000 --- a/lib/task_runner.js +++ /dev/null @@ -1 +0,0 @@ -"use strict"; \ No newline at end of file diff --git a/lib/tasks/a.js b/lib/tasks/a.js deleted file mode 100644 index ada6bb7..0000000 --- a/lib/tasks/a.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -/** - * Task - description - * @license MIT - * @author author -*/ -var winston = require('winston'); -var options = { - name: 'Set up A', - description: 'sets up A for use on system', - exec: function exec(resolve) { - winston.warn('setting up a .... buzz grrr ... bing'); - setTimeout(resolve, 5000); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/apm.js b/lib/tasks/apm.js new file mode 100644 index 0000000..987017e --- /dev/null +++ b/lib/tasks/apm.js @@ -0,0 +1,29 @@ +'use strict'; + +/** + * apm installs - installs Atom IDE packages + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var options = { + name: 'apm', + description: 'installs apm packages for Atom IDE', + exec: function exec(resolve) { + var apmWhich = shell.exec('which apm', { silent: true }); + if (apmWhich.output.trim() !== '') { + if (userConfig.apmPackages.length > 0) { + winston.warn('NOTE: package installation may fail if a\n package is already installed. If problems persist remove the\n atom packages install directory and do a fresh install'); + var packages = userConfig.apmPackages.join(' '); + shell.exec('apm install ' + packages); + winston.success('apm packages installed'); + } else winston.info('no packages to install'); + } else winston.error('Atom IDE not installed'); + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/b.js b/lib/tasks/b.js deleted file mode 100644 index 24b4c61..0000000 --- a/lib/tasks/b.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -var winston = require('winston'); -var options = { - name: 'Set up B', - description: 'sets up b for system wide use', - exec: function exec(resolve) { - winston.warn('setting up b .... beezz brrr ... bazing'); - setTimeout(resolve, 3000); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/brewCask.js b/lib/tasks/brewCask.js new file mode 100644 index 0000000..fadfbcc --- /dev/null +++ b/lib/tasks/brewCask.js @@ -0,0 +1,53 @@ +'use strict'; + +/** + * set up brew cask - install brew cask and install casks + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var options = { + name: 'set up brew cask', + description: 'install brew cask and install casks', + exec: function exec(resolve) { + var brewInstalled = shell.which('brew') !== null, + casks = userConfig.brewCasks; + if (brewInstalled && casks.length > 0) { + shell.exec('brew prune'); + shell.exec('brew tap caskroom/cask'); + shell.exec('brew install brew-cask'); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = casks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var cask = _step.value; + + shell.exec('brew cask install ' + cask); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + winston.success('casks installed'); + } else winston.warn('brew-cask not installed. Either brew not installed\n or no casks defined in kody.json'); + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/dotfiles.js b/lib/tasks/dotfiles.js index b2732d4..95f3412 100644 --- a/lib/tasks/dotfiles.js +++ b/lib/tasks/dotfiles.js @@ -19,13 +19,10 @@ var PROPS = { name: 'DotFiles', description: 'sets up symlinks for global dotfiles', exec: function exec(resolve) { - // grab the home directory for the user. var $HOME = shell.exec(PROPS.HOME_CMD, { silent: true }).output.trim(), - - // grab instances, these are files/dirs suffixed with ".link" - dotFiles = shell.find('.').filter(function (file) { + dotFiles = shell.find('.').filter(function (file) { return file.match(PROPS.FILE_REGEXP); }); @@ -43,9 +40,8 @@ var PROPS = { if (basename.indexOf('/') !== -1) basename = basename.substr(basename.lastIndexOf('/') + 1); basename = basename.replace(PROPS.FILE_SUFFIX, ''); var destination = $HOME + '/.' + basename; - winston.info('' + source); + shell.ln('-sf', source, destination); winston.success('linked ' + basename + ' to ' + destination); - // shell.ln('-sf', source, destination); } } catch (err) { _didIteratorError = true; diff --git a/lib/tasks/fishDefault.js b/lib/tasks/fishDefault.js new file mode 100644 index 0000000..d1f9c1e --- /dev/null +++ b/lib/tasks/fishDefault.js @@ -0,0 +1,25 @@ +'use strict'; + +/** + * set fish shell - set fish shell as default shell + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var options = { + name: 'set fish shell', + description: 'set fish shell as default shell', + exec: function exec(resolve) { + var scriptPath = userConfig.fishDefaultScriptPath; + if (scriptPath) { + shell.exec('sh ./' + scriptPath); + winston.success('fish shell set as default'); + } else winston.error('fish shell script not found'); + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/gitconfig.js b/lib/tasks/gitconfig.js index ecc47c7..0adc95d 100644 --- a/lib/tasks/gitconfig.js +++ b/lib/tasks/gitconfig.js @@ -25,17 +25,16 @@ var PROPS = { description: 'sets up global git configuration for symlinking', exec: function exec(resolve) { var gitCredential = 'osxkeychain', - gitEmail = userConfig.git_credentials.email, - gitName = userConfig.git_credentials.name, + gitEmail = userConfig.gitCredentials.email, + gitName = userConfig.gitCredentials.name, nameCmd = '-e \'s/AUTHORNAME/' + gitName + '/g\'', emailCmd = '-e \'s/AUTHOREMAIL/' + gitEmail + '/g\'', credentialCmd = '-e \'s/GIT_CREDENTIAL_HELPER/' + gitCredential + '/g\'', cG = 'sed ' + nameCmd + ' ' + emailCmd + ' ' + credentialCmd + ' ' + PROPS.STARTER; shell.exec(cG, { silent: true }).stdout.to(PROPS.OUTPUT); - winston.warn('GitConfig set up, ' + gitName + ', ' + gitEmail); - setTimeout(resolve, 3000); + resolve(); } }; diff --git a/lib/tasks/homebrew.js b/lib/tasks/homebrew.js new file mode 100644 index 0000000..6d7542a --- /dev/null +++ b/lib/tasks/homebrew.js @@ -0,0 +1,36 @@ +'use strict'; + +/** + * homebrew - install and set up homebrew + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var PROPS = { + URL: 'https://raw.githubusercontent.com/Homebrew/install/master/install' +}, + options = { + name: 'homebrew', + description: 'install and set up homebrew', + exec: function exec(resolve) { + var brewInstalled = shell.which('brew') !== null, + packages = userConfig.brewInstalls; + if (!brewInstalled) { + winston.info('installing Homebrew'); + shell.exec('ruby -e "$(curl -fsSL ' + PROPS.URL + ')"'); + winston.success('Homebrew installed'); + } else winston.warn('Homebrew already installed'); + shell.exec('brew doctor'); + winston.warn('NOTE: any info from brew doctor may\n account for any issues with package installs'); + if (packages.length > 0) { + shell.exec('brew install ' + packages.join(' ')); + winston.success('brew packages installed'); + } + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/npm.js b/lib/tasks/npm.js new file mode 100644 index 0000000..a10c0fa --- /dev/null +++ b/lib/tasks/npm.js @@ -0,0 +1,55 @@ +'use strict'; + +/** + * npm installs - installs desired global modules + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var PROPS = { + ERROR_MSG: 'npm is not installed', + WARN: 'NOTE: incorrect npm permissions may cause an error.', + FIX_URL: 'https://docs.npmjs.com/getting-started/fixing-npm-permissions' +}, + options = { + name: 'npm installs', + description: 'installs desired global modules', + exec: function exec(resolve) { + var npmWhich = shell.exec('which npm', { silent: true }); + if (npmWhich.output.trim() !== '') { + var modules = userConfig.globalNpmModules; + winston.warn(PROPS.WARN + ' See: ' + PROPS.FIX_URL); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = modules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var module = _step.value; + + winston.info('attempting to install ' + module); + shell.exec('npm install -g ' + module); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } else winston.error(PROPS.ERROR_MSG); + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/osxDefaults.js b/lib/tasks/osxDefaults.js new file mode 100644 index 0000000..7016b16 --- /dev/null +++ b/lib/tasks/osxDefaults.js @@ -0,0 +1,25 @@ +'use strict'; + +/** + * OSX defaults - set system wide OSX defaults + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var options = { + name: 'OSX defaults', + description: 'sets system wide OSX defaults', + exec: function exec(resolve) { + var scriptPath = userConfig.osxDefaultScriptPath; + if (scriptPath) { + shell.exec('sh ./' + scriptPath); + winston.success('OSX defaults set'); + } else winston.error('OSX defaults script not found'); + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/lib/tasks/removeOsxApps.js b/lib/tasks/removeOsxApps.js new file mode 100644 index 0000000..b2e0b5f --- /dev/null +++ b/lib/tasks/removeOsxApps.js @@ -0,0 +1,52 @@ +'use strict'; + +/** + * Remove OSX apps - removes unwanted default OSX apps + * @license MIT + * @author jh3y +*/ +var shell = require('shelljs'), + userConfig = require(process.cwd() + '/kody.json'), + winston = require('winston'); + +var options = { + name: 'Remove OSX apps', + description: 'removes unwanted default OSX apps', + exec: function exec(resolve) { + var space = new RegExp(' ', 'g'); + var apps = userConfig.appleAppsToRemove; + if (apps && apps.length > 0) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = apps[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var app = _step.value; + + var sanitizedApp = app.replace(space, '\\ '); + shell.exec('sudo rm -rf /Applications/' + sanitizedApp); + winston.info(sanitizedApp + ' removed from system'); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + winston.success('default OSX applications removed'); + } else winston.info('no apps to remove'); + resolve(); + } +}; + +exports.options = options; \ No newline at end of file diff --git a/package.json b/package.json index ff28c44..4ddc45c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "kody", "description": "dotfiles in node", - "version": "0.1.1", + "version": "1.0.0", "main": "index.js", "homepage": "https://github.com/jh3y/kody", "author": { @@ -32,7 +32,8 @@ "watch:scripts": "babel src/ --watch -d $npm_package_config_SCRIPTS_DEST", "predev": "npm run build:scripts", "dev": "npm run watch:scripts", - "update:packages": "node wipe-dependencies.js && rm -rf node_modules && npm update --save-dev && npm update --save" + "update:packages": "node wipe-dependencies.js && rm -rf node_modules && npm update --save-dev && npm update --save", + "create:task": "sh createTask.sh" }, "preferGlobal": true, "bin": { diff --git a/src.deprecated/coffee/lib/kody.coffee b/src.deprecated/coffee/lib/kody.coffee deleted file mode 100644 index 3ff884b..0000000 --- a/src.deprecated/coffee/lib/kody.coffee +++ /dev/null @@ -1,25 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -shell = require "shelljs" -pkg = require "../package.json" -utils = require "./utils" -task_runner = require "./task_runner" - -exports.welcome = welcome = ()-> - utils.log "===========================================", "info" - utils.log "kody -- your .files and config runner", "info" - utils.log "===========================================", "info" -exports.init = init = () -> - welcome() - task_runner.init() diff --git a/src.deprecated/coffee/lib/main.coffee b/src.deprecated/coffee/lib/main.coffee deleted file mode 100644 index 571abd4..0000000 --- a/src.deprecated/coffee/lib/main.coffee +++ /dev/null @@ -1,34 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Entry point for kody. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -program = require "commander" -colors = require "colors" -pkg = require "../package.json" -kody = require "./kody" - -program - .version(pkg.version) - -program.on "--help", -> - console.log " Examples:" - console.log "" - console.log " $ " + pkg.name - return - -program.parse process.argv - -try - kody.init() -catch err - console.log "[", "kody".white, "]", err.toString().red diff --git a/src.deprecated/coffee/lib/task_runner.coffee b/src.deprecated/coffee/lib/task_runner.coffee deleted file mode 100644 index 8061940..0000000 --- a/src.deprecated/coffee/lib/task_runner.coffee +++ /dev/null @@ -1,64 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Task runner - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -pkg = require "../package.json" -shell = require "shelljs" -utils = require "./utils" -brewCask = require "./tasks/set_up_brew_cask" -dotfiles = require "./tasks/install_dot_files" -gitConfig = require "./tasks/set_up_git_config" -osx = require "./tasks/set_osx_defaults" -apple = require './tasks/remove_default_apple_apps' -brew = require "./tasks/set_up_homebrew" -npm = require "./tasks/install_npm_modules" -fish = require "./tasks/set_up_fish_shell" -apm = require "./tasks/install_atom_packages" - -KODY_CONFIG = `undefined` - -taskMap = - install_dot_files: dotfiles.install - install_homebrew_and_packages: brew.install - install_brew_cask_and_casks: brewCask.setUp - install_npm_modules: npm.install - install_apm_packages: apm.install - set_fish_shell_as_default: fish.setDefault - set_osx_defaults: osx.setDefault - remove_default_apple_apps: apple.remove - -grab_config = ()-> - path = process.cwd() + '/kody.json' - KODY_CONFIG = require(path) - -exports.init = init = ()-> - grab_config() - if KODY_CONFIG isnt `undefined` - if KODY_CONFIG.set_up_git_config - utils.log "Setting up Git credentials", "prompt" - gitConfig.setUp() - else - utils.log "Git credentials already set up", "info" - run() - -exports.run = run = ()-> - tasks = [] - for map of taskMap - if KODY_CONFIG[map] is true - tasks.push - func: taskMap[map] - args: KODY_CONFIG - for key, value of tasks - value.func KODY_CONFIG - utils.log "kody has completed your set tasks!", "silly" diff --git a/src.deprecated/coffee/lib/tasks/install_atom_packages.coffee b/src.deprecated/coffee/lib/tasks/install_atom_packages.coffee deleted file mode 100644 index de9e086..0000000 --- a/src.deprecated/coffee/lib/tasks/install_atom_packages.coffee +++ /dev/null @@ -1,25 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Apm install - installs all your atom IDE apm packages - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.install = install = (KODY_CONFIG)-> - if shell.which("apm").trim() isnt "" and Object.keys(KODY_CONFIG.apm_packages).length > 0 - utils.log "Installing apm packages", "prompt" - # for index, pckg of KODY_CONFIG.apm_packages - # shell.exec "apm install " + pckg - shell.exec "apm install " + KODY_CONFIG.apm_packages.join ' ' - utils.log "Apm modules installed globally", "success" diff --git a/src.deprecated/coffee/lib/tasks/install_dot_files.coffee b/src.deprecated/coffee/lib/tasks/install_dot_files.coffee deleted file mode 100644 index 2bf85e4..0000000 --- a/src.deprecated/coffee/lib/tasks/install_dot_files.coffee +++ /dev/null @@ -1,43 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -.Files installation task - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### -colors = require "colors" -pkg = require "../../package.json" -shell = require "shelljs" -utils = require "../utils" - -exports.install = install = () -> - HOME_DIR = shell.exec("echo $HOME", {silent: true}).output.trim() - dotfiles = shell.exec("find */*.link *.link", {silent: true}).output - if dotfiles.indexOf("*/*.link *.link") is -1 - dotfiles = dotfiles.split '\n' - dotfiles.pop() - elementsfiltered = `undefined` - dotfiles.filter((a) -> - if a.split(".link").length is 2 and a.split('.link')[1].trim() is "" - @push a - true - , elementsfiltered = []) - dotfiles = elementsfiltered - if dotfiles.length > 0 - utils.log "Linking .files to your home directory", "prompt" - for key, value of dotfiles - source = process.cwd() + '/' + value - basename = shell.exec("basename " + value, {silent: true}).output.trim() - if basename.indexOf('.link') isnt -1 - basename = "/." + basename.replace ".link", "" - destination = HOME_DIR + basename - shell.ln '-sf', source, destination - utils.log 'linked ' + source + ' to ' + destination + '!', "info" - else - utils.log "No .files found", "error" diff --git a/src.deprecated/coffee/lib/tasks/install_npm_modules.coffee b/src.deprecated/coffee/lib/tasks/install_npm_modules.coffee deleted file mode 100644 index 0b89056..0000000 --- a/src.deprecated/coffee/lib/tasks/install_npm_modules.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Npm install - installs all your global npm modules - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.install = install = (KODY_CONFIG)-> - if shell.which("npm").trim() isnt "" and Object.keys(KODY_CONFIG.global_npm_modules).length > 0 - utils.log "Installing npm modules", "prompt" - utils.log "kody will ask for sudo credentials here just because you are installing node modules globally on your machine", "warn" - installStr = "sudo npm install -g" - for module of KODY_CONFIG.global_npm_modules - installStr += " " + module + "@" + KODY_CONFIG.global_npm_modules[module] - shell.exec installStr - utils.log "Npm modules installed globally", "success" diff --git a/src.deprecated/coffee/lib/tasks/remove_default_apple_apps.coffee b/src.deprecated/coffee/lib/tasks/remove_default_apple_apps.coffee deleted file mode 100644 index ebc144c..0000000 --- a/src.deprecated/coffee/lib/tasks/remove_default_apple_apps.coffee +++ /dev/null @@ -1,27 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Remove default apple applications task - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require 'colors' -shell = require 'shelljs' -pkg = require '../../package.json' -utils = require '../utils' - -exports.remove = remove = (KODY_CONFIG) -> - if KODY_CONFIG.apple_apps_to_remove and KODY_CONFIG.apple_apps_to_remove.length > 0 - [].forEach.call KODY_CONFIG.apple_apps_to_remove, (appToRemove) -> - regex = new RegExp " ", 'g' - appToRemove = appToRemove.replace regex, '\\ ' - shell.exec 'sudo rm -rf /Applications/' + appToRemove - utils.log appToRemove + ' removed', 'info' - utils.log 'Default Apple applications removed', 'success' diff --git a/src.deprecated/coffee/lib/tasks/set_osx_defaults.coffee b/src.deprecated/coffee/lib/tasks/set_osx_defaults.coffee deleted file mode 100644 index 78bfdb7..0000000 --- a/src.deprecated/coffee/lib/tasks/set_osx_defaults.coffee +++ /dev/null @@ -1,30 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -OSX Defaults writer. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.setDefault = setDefault = ()-> - uname = shell.exec('uname -s', {silent:true}) - if uname.output.indexOf('Darwin') isnt -1 - found = shell.exec("find osx/set_default.*", {silent: true}).output - if found.indexOf("osx/set_default.*") is -1 - utils.log "Setting Apple OSX Defaults", "prompt" - found = found.trim() - shell.exec "sh ./" + found - utils.log "Apple OSX defaults set", "success" - else - utils.log "No shell script file found for setting OSX Defaults", "error" diff --git a/src.deprecated/coffee/lib/tasks/set_up_brew_cask.coffee b/src.deprecated/coffee/lib/tasks/set_up_brew_cask.coffee deleted file mode 100644 index cf25fda..0000000 --- a/src.deprecated/coffee/lib/tasks/set_up_brew_cask.coffee +++ /dev/null @@ -1,28 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Set up Homebrew cask - brew-cask. And also install casks. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.setUp = setUp = (KODY_CONFIG)-> - if shell.which("brew") isnt null and KODY_CONFIG.brew_casks.length > 0 - shell.exec("brew prune") - utils.log 'Setting up Brew cask', "prompt" - shell.exec("brew tap caskroom/cask") - shell.exec("brew install brew-cask") - for key, value of KODY_CONFIG.brew_casks - utils.log 'installing ' + value - shell.exec("brew cask install " + value) - utils.log "Brew casks installed", "success" diff --git a/src.deprecated/coffee/lib/tasks/set_up_fish_shell.coffee b/src.deprecated/coffee/lib/tasks/set_up_fish_shell.coffee deleted file mode 100644 index a974b81..0000000 --- a/src.deprecated/coffee/lib/tasks/set_up_fish_shell.coffee +++ /dev/null @@ -1,28 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Sets Fish as default shell. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.setDefault = setDefault = ()-> - found = shell.exec("find fish/set_default.*", {silent: true}).output - if found.indexOf("fish/set_default.*") is -1 - utils.log "Setting Fish as default shell", "prompt" - found = found.trim() - shell.exec "sh ./" + found - utils.log "Fish set as default shell", "success" - else - utils.log "No shell script file found for setting fish as default", "error" diff --git a/src.deprecated/coffee/lib/tasks/set_up_git_config.coffee b/src.deprecated/coffee/lib/tasks/set_up_git_config.coffee deleted file mode 100644 index a09cd54..0000000 --- a/src.deprecated/coffee/lib/tasks/set_up_git_config.coffee +++ /dev/null @@ -1,39 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Git config set up. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" -prompt = require "prompt" -prompt.message = "[ " + pkg.name.cyan + " ]" -prompt.delimiter = " " -prompt.start() - -task_runner = require "../task_runner" - -exports.setUp = setUp = () -> - uname = shell.exec('uname -s', {silent:true}) - if uname.output.indexOf('Darwin') isnt -1 - git_credential = 'osxkeychain' - prompt.get [ - name: "name" - description: "enter your github author name:" - , - name: "email" - description: "enter your github email:" - ], (err, result)-> - shell.exec("sed -e 's/AUTHORNAME/" + result.name + "/g' -e 's/AUTHOREMAIL/" + result.email + "/g' -e 's/GIT_CREDENTIAL_HELPER/" + git_credential + "/g' git/gitconfig.starter", {silent: true}).output.to 'git/gitconfig.link' - utils.log "git config set up and ready", "success" - task_runner.run() diff --git a/src.deprecated/coffee/lib/tasks/set_up_homebrew.coffee b/src.deprecated/coffee/lib/tasks/set_up_homebrew.coffee deleted file mode 100644 index a72d964..0000000 --- a/src.deprecated/coffee/lib/tasks/set_up_homebrew.coffee +++ /dev/null @@ -1,32 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -Homebrew installation and installation of brew packages. - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.install = install = (KODY_CONFIG)-> - if shell.exec("which brew", {silent: true}).output.trim() is "" - utils.log "Attempting to intall Brew", "prompt" - shell.exec('ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"') - utils.log "Brew installed", "success" - else - utils.log "Brew already installed", "warn" - utils.log "Now running 'brew doctor'", "prompt" - shell.exec "brew doctor" - utils.log "NOTE: Take notice of anything Brew doctor has said, it may account for any issues you have with install", "warn" - if KODY_CONFIG.brew_installs.length > 0 - pckgToInstall = KODY_CONFIG.brew_installs.join " " - shell.exec "brew install " + pckgToInstall - utils.log "Brew packages installed", "success" diff --git a/src.deprecated/coffee/lib/tasks/task.coffee.boilerplate b/src.deprecated/coffee/lib/tasks/task.coffee.boilerplate deleted file mode 100644 index 60f6265..0000000 --- a/src.deprecated/coffee/lib/tasks/task.coffee.boilerplate +++ /dev/null @@ -1,21 +0,0 @@ -### -kody - http://jh3y.github.io/kody - -BOILERPLATE TASK FILE - -Licensed under the MIT license - -Jhey Tompkins (c) 2014. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -### - -colors = require "colors" -shell = require "shelljs" -pkg = require "../../package.json" -utils = require "../utils" - -exports.boiler = boiler = (KODY_CONFIG)-> - # DO SOME AWESOME HACKING IN HERE. diff --git a/src.deprecated/coffee/lib/utils.coffee b/src.deprecated/coffee/lib/utils.coffee deleted file mode 100644 index 5975234..0000000 --- a/src.deprecated/coffee/lib/utils.coffee +++ /dev/null @@ -1,18 +0,0 @@ -const colors = require('colors'), - pkg = require('../package.json'), - log = function(msg, type = 'default') { - console.log('[', pkg.name.cyan, ']', msg[type]); - }; - -colors.setTheme({ - default: 'grey', - prompt : 'yellow', - info : 'cyan', - help : 'magenta', - warn : 'yellow', - error : 'red', - success: 'green', - silly : 'rainbow', -}); - -exports.log = log; diff --git a/src.deprecated/coffee/test/test.coffee b/src.deprecated/coffee/test/test.coffee deleted file mode 100644 index 2643e26..0000000 --- a/src.deprecated/coffee/test/test.coffee +++ /dev/null @@ -1,9 +0,0 @@ -assert = require("assert") -kody = require("../lib/kody") - -suite "kody", -> - suite "run", -> - test "kody should throw an error if there's no config file", -> - assert.throws (-> - kody.init() - ), Error diff --git a/src/lib/TASK_BOILERPLATE.js b/src/lib/TASK_BOILERPLATE.js deleted file mode 100644 index c085d4a..0000000 --- a/src/lib/TASK_BOILERPLATE.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Task - description - * @license MIT - * @author author -*/ - -const options = { - name: 'TASK-0001', - description: 'sets up something', - exec: function(resolve) { // NOTE: to reject, include reject parameter - resolve(); - } -}; - -exports.options = options; diff --git a/src/lib/kody.js b/src/lib/kody.js index c89a7ab..e7d3953 100644 --- a/src/lib/kody.js +++ b/src/lib/kody.js @@ -18,6 +18,8 @@ const core = require('./core'), const PROPS = { TASK_ORDER : [ 'gitconfig.js', + 'homebrew.js', + 'brewCask.js', '*' ], TASKS_QUERY: { @@ -36,6 +38,7 @@ const PROPS = { welcome(); let files = fs.readdirSync(__dirname + '/tasks'); files = files.sort(sortFiles); + winston.info(files); for (const file of files) { const taskOpts = require(`./tasks/${file}`).options; const newChoice = { diff --git a/src/lib/task.boilerplate b/src/lib/task.boilerplate new file mode 100644 index 0000000..d357135 --- /dev/null +++ b/src/lib/task.boilerplate @@ -0,0 +1,18 @@ +/** + * @TITLE - @DESCRIPTION + * @license MIT + * @author @AUTHOR +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const options = { + name: '@TITLE', + description: '@DESCRIPTION', + exec: function(resolve) { // NOTE: to reject, include reject parameter + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/a.js b/src/lib/tasks/a.js deleted file mode 100644 index 10abaac..0000000 --- a/src/lib/tasks/a.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Task - description - * @license MIT - * @author author -*/ -const winston = require('winston'); -const options = { - name : 'Set up A', - description: 'sets up A for use on system', - exec : function(resolve) { - winston.warn('setting up a .... buzz grrr ... bing'); - setTimeout(resolve, 5000); - } -}; - -exports.options = options; diff --git a/src/lib/tasks/apm.js b/src/lib/tasks/apm.js new file mode 100644 index 0000000..b9a2623 --- /dev/null +++ b/src/lib/tasks/apm.js @@ -0,0 +1,31 @@ +/** + * apm installs - installs Atom IDE packages + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const options = { + name: 'apm', + description: 'installs apm packages for Atom IDE', + exec: function(resolve) { + const apmWhich = shell.exec('which apm', {silent: true}); + if (apmWhich.output.trim() !== '') + if (userConfig.apmPackages.length > 0) { + winston.warn(`NOTE: package installation may fail if a + package is already installed. If problems persist remove the + atom packages install directory and do a fresh install`); + const packages = userConfig.apmPackages.join(' '); + shell.exec(`apm install ${packages}`); + winston.success('apm packages installed'); + } else + winston.info('no packages to install'); + else + winston.error('Atom IDE not installed'); + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/b.js b/src/lib/tasks/b.js deleted file mode 100644 index 63b04ac..0000000 --- a/src/lib/tasks/b.js +++ /dev/null @@ -1,11 +0,0 @@ -const winston = require('winston'); -const options = { - name : 'Set up B', - description: 'sets up b for system wide use', - exec : function(resolve) { - winston.warn('setting up b .... beezz brrr ... bazing'); - setTimeout(resolve, 3000); - } -}; - -exports.options = options; diff --git a/src/lib/tasks/brewCask.js b/src/lib/tasks/brewCask.js new file mode 100644 index 0000000..e697370 --- /dev/null +++ b/src/lib/tasks/brewCask.js @@ -0,0 +1,30 @@ +/** + * set up brew cask - install brew cask and install casks + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const options = { + name: 'set up brew cask', + description: 'install brew cask and install casks', + exec: function(resolve) { + const brewInstalled = shell.which('brew') !== null, + casks = userConfig.brewCasks; + if (brewInstalled && casks.length > 0) { + shell.exec('brew prune'); + shell.exec('brew tap caskroom/cask'); + shell.exec('brew install brew-cask'); + for (const cask of casks) + shell.exec(`brew cask install ${cask}`); + winston.success('casks installed'); + } else + winston.warn(`brew-cask not installed. Either brew not installed + or no casks defined in kody.json`); + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/dotfiles.js b/src/lib/tasks/dotfiles.js index 1296fe4..7ad7ee3 100644 --- a/src/lib/tasks/dotfiles.js +++ b/src/lib/tasks/dotfiles.js @@ -17,11 +17,9 @@ const PROPS = { name: 'DotFiles', description: 'sets up symlinks for global dotfiles', exec: function(resolve) { - // grab the home directory for the user. const $HOME = shell.exec(PROPS.HOME_CMD, { silent: true }).output.trim(), - // grab instances, these are files/dirs suffixed with ".link" dotFiles = shell.find('.') .filter(function(file) { return file.match(PROPS.FILE_REGEXP); @@ -35,9 +33,8 @@ const PROPS = { basename = basename.substr(basename.lastIndexOf('/') + 1); basename = basename.replace(PROPS.FILE_SUFFIX, ''); const destination = `${$HOME}/.${basename}`; - winston.info(`${source}`); + shell.ln('-sf', source, destination); winston.success(`linked ${basename} to ${destination}`); - // shell.ln('-sf', source, destination); } else winston.info(PROPS.EMPTY_MSG); diff --git a/src/lib/tasks/fishDefault.js b/src/lib/tasks/fishDefault.js new file mode 100644 index 0000000..7507ef4 --- /dev/null +++ b/src/lib/tasks/fishDefault.js @@ -0,0 +1,24 @@ +/** + * set fish shell - set fish shell as default shell + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const options = { + name: 'set fish shell', + description: 'set fish shell as default shell', + exec: function(resolve) { + const scriptPath = userConfig.fishDefaultScriptPath; + if (scriptPath) { + shell.exec(`sh ./${scriptPath}`); + winston.success('fish shell set as default'); + } else + winston.error('fish shell script not found'); + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/gitconfig.js b/src/lib/tasks/gitconfig.js index d1d2f49..68b66ef 100644 --- a/src/lib/tasks/gitconfig.js +++ b/src/lib/tasks/gitconfig.js @@ -23,8 +23,8 @@ const PROPS = { description: 'sets up global git configuration for symlinking', exec : function(resolve) { const gitCredential = 'osxkeychain', - gitEmail = userConfig.git_credentials.email, - gitName = userConfig.git_credentials.name, + gitEmail = userConfig.gitCredentials.email, + gitName = userConfig.gitCredentials.name, nameCmd = `-e 's/AUTHORNAME/${gitName}/g'`, emailCmd = `-e 's/AUTHOREMAIL/${gitEmail}/g'`, credentialCmd = `-e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g'`, @@ -32,9 +32,8 @@ const PROPS = { shell.exec(cG, {silent: true}) .stdout.to(PROPS.OUTPUT); - winston.warn(`GitConfig set up, ${gitName}, ${gitEmail}`); - setTimeout(resolve, 3000); + resolve(); } }; diff --git a/src/lib/tasks/homebrew.js b/src/lib/tasks/homebrew.js new file mode 100644 index 0000000..dba8bf3 --- /dev/null +++ b/src/lib/tasks/homebrew.js @@ -0,0 +1,36 @@ +/** + * homebrew - install and set up homebrew + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const PROPS = { + URL: 'https://raw.githubusercontent.com/Homebrew/install/master/install' + }, + options = { + name: 'homebrew', + description: 'install and set up homebrew', + exec: function(resolve) { + const brewInstalled = shell.which('brew') !== null, + packages = userConfig.brewInstalls; + if (!brewInstalled) { + winston.info('installing Homebrew'); + shell.exec(`ruby -e "$(curl -fsSL ${PROPS.URL})"`); + winston.success('Homebrew installed'); + } else + winston.warn('Homebrew already installed'); + shell.exec('brew doctor'); + winston.warn(`NOTE: any info from brew doctor may + account for any issues with package installs`); + if (packages.length > 0) { + shell.exec(`brew install ${packages.join(' ')}`); + winston.success('brew packages installed'); + } + resolve(); + } + }; + +exports.options = options; diff --git a/src/lib/tasks/npm.js b/src/lib/tasks/npm.js new file mode 100644 index 0000000..c61a76f --- /dev/null +++ b/src/lib/tasks/npm.js @@ -0,0 +1,33 @@ +/** + * npm installs - installs desired global modules + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const PROPS = { + ERROR_MSG: 'npm is not installed', + WARN: 'NOTE: incorrect npm permissions may cause an error.', + FIX_URL: 'https://docs.npmjs.com/getting-started/fixing-npm-permissions' + }, + options = { + name: 'npm installs', + description: 'installs desired global modules', + exec: function(resolve) { + const npmWhich = shell.exec('which npm', {silent: true}); + if (npmWhich.output.trim() !== '') { + const modules = userConfig.globalNpmModules; + winston.warn(`${PROPS.WARN} See: ${PROPS.FIX_URL}`); + for (const module of modules) { + winston.info(`attempting to install ${module}`); + shell.exec(`npm install -g ${module}`); + } + } else + winston.error(PROPS.ERROR_MSG); + resolve(); + } + }; + +exports.options = options; diff --git a/src/lib/tasks/osxDefaults.js b/src/lib/tasks/osxDefaults.js new file mode 100644 index 0000000..9d2a090 --- /dev/null +++ b/src/lib/tasks/osxDefaults.js @@ -0,0 +1,24 @@ +/** + * OSX defaults - set system wide OSX defaults + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const options = { + name: 'OSX defaults', + description: 'sets system wide OSX defaults', + exec: function(resolve) { + const scriptPath = userConfig.osxDefaultScriptPath; + if (scriptPath) { + shell.exec(`sh ./${scriptPath}`); + winston.success('OSX defaults set'); + } else + winston.error('OSX defaults script not found'); + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/removeOsxApps.js b/src/lib/tasks/removeOsxApps.js new file mode 100644 index 0000000..599817b --- /dev/null +++ b/src/lib/tasks/removeOsxApps.js @@ -0,0 +1,29 @@ +/** + * Remove OSX apps - removes unwanted default OSX apps + * @license MIT + * @author jh3y +*/ +const shell = require('shelljs'), + userConfig = require(`${process.cwd()}/kody.json`), + winston = require('winston'); + +const options = { + name: 'Remove OSX apps', + description: 'removes unwanted default OSX apps', + exec: function(resolve) { + const space = new RegExp(' ', 'g'); + const apps = userConfig.osxAppsToRemove; + if (apps && apps.length > 0) { + for (const app of apps) { + const sanitizedApp = app.replace(space, '\\ '); + shell.exec(`sudo rm -rf /Applications/${sanitizedApp}`); + winston.info(`${sanitizedApp} removed from system`); + } + winston.success('default OSX applications removed'); + } else + winston.info('no apps to remove'); + resolve(); + } +}; + +exports.options = options; diff --git a/src/test/test.js b/src/test/test.js index e69de29..3925cf6 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -0,0 +1,12 @@ +const assert = require('assert'), + kody = require('../lib/kody'); + +suite('kody', ()=> { + suite('run', ()=> { + test('should throw error if no config file present', ()=> { + assert.throws(() => { + kody.init(); + }, Error); + }) + }) +}) diff --git a/test/test.js b/test/test.js index 9a390c3..b701630 100644 --- a/test/test.js +++ b/test/test.js @@ -1 +1,14 @@ -"use strict"; \ No newline at end of file +'use strict'; + +var assert = require('assert'), + kody = require('../lib/kody'); + +suite('kody', function () { + suite('run', function () { + test('should throw error if no config file present', function () { + assert.throws(function () { + kody.init(); + }, Error); + }); + }); +}); \ No newline at end of file From fa61374e2e7c47cd3a41fb4409b51776169fac4d Mon Sep 17 00:00:00 2001 From: jh3y Date: Sun, 28 Feb 2016 21:14:15 +0000 Subject: [PATCH 06/11] Remove clutter from dummy config and alter git config logging --- dummy_env/kody.json | 12 ------------ lib/tasks/gitconfig.js | 2 +- lib/tasks/removeOsxApps.js | 2 +- src/lib/tasks/gitconfig.js | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/dummy_env/kody.json b/dummy_env/kody.json index 9041abd..551bb90 100644 --- a/dummy_env/kody.json +++ b/dummy_env/kody.json @@ -5,14 +5,10 @@ }, "brewInstalls": [ "git", - "mongodb", - "ruby-build", - "rbenv", "fish" ], "brewCasks": [ "google-chrome", - "heroku-toolbelt", "spotify" ], "apmPackages": [ @@ -20,14 +16,6 @@ "linter-jshint" ], "globalNpmModules": [ - "sike", - "less", - "jade", - "gulp", - "grunt-cli", - "express-generator", - "docpad", - "component", "coffee-script", "bower" ], diff --git a/lib/tasks/gitconfig.js b/lib/tasks/gitconfig.js index 0adc95d..1432c0c 100644 --- a/lib/tasks/gitconfig.js +++ b/lib/tasks/gitconfig.js @@ -33,7 +33,7 @@ var PROPS = { cG = 'sed ' + nameCmd + ' ' + emailCmd + ' ' + credentialCmd + ' ' + PROPS.STARTER; shell.exec(cG, { silent: true }).stdout.to(PROPS.OUTPUT); - winston.warn('GitConfig set up, ' + gitName + ', ' + gitEmail); + winston.info('git config set for "' + gitName + '" with email "' + gitEmail + '"'); resolve(); } }; diff --git a/lib/tasks/removeOsxApps.js b/lib/tasks/removeOsxApps.js index b2e0b5f..b608feb 100644 --- a/lib/tasks/removeOsxApps.js +++ b/lib/tasks/removeOsxApps.js @@ -14,7 +14,7 @@ var options = { description: 'removes unwanted default OSX apps', exec: function exec(resolve) { var space = new RegExp(' ', 'g'); - var apps = userConfig.appleAppsToRemove; + var apps = userConfig.osxAppsToRemove; if (apps && apps.length > 0) { var _iteratorNormalCompletion = true; var _didIteratorError = false; diff --git a/src/lib/tasks/gitconfig.js b/src/lib/tasks/gitconfig.js index 68b66ef..d4fe3b9 100644 --- a/src/lib/tasks/gitconfig.js +++ b/src/lib/tasks/gitconfig.js @@ -32,7 +32,7 @@ const PROPS = { shell.exec(cG, {silent: true}) .stdout.to(PROPS.OUTPUT); - winston.warn(`GitConfig set up, ${gitName}, ${gitEmail}`); + winston.info(`git config set for "${gitName}" with email "${gitEmail}"`); resolve(); } }; From bfda6bf56706687ce98b9c7bd1182dc35e09c0d0 Mon Sep 17 00:00:00 2001 From: jh3y Date: Mon, 7 Mar 2016 19:51:40 +0000 Subject: [PATCH 07/11] Refactor tasks out into user defined instead --- README.md | 226 ++++++++++-------- dummy_env/{kody.json => .kodyrc} | 5 + .../lib/tasks => dummy_env/kody.tasks}/apm.js | 18 +- .../kody.tasks}/brewCask.js | 12 +- dummy_env/kody.tasks/fishDefault.js | 20 ++ .../kody.tasks}/gitconfig.js | 12 +- .../kody.tasks}/homebrew.js | 18 +- .../lib/tasks => dummy_env/kody.tasks}/npm.js | 14 +- dummy_env/kody.tasks/osxDefaults.js | 20 ++ .../kody.tasks}/removeOsxApps.js | 14 +- lib/core.js | 9 +- lib/kody.js | 116 +++++++-- lib/main.js | 4 +- lib/tasks/apm.js | 29 --- lib/tasks/brewCask.js | 53 ---- lib/tasks/fishDefault.js | 25 -- lib/tasks/gitconfig.js | 41 ---- lib/tasks/homebrew.js | 36 --- lib/tasks/npm.js | 55 ----- lib/tasks/osxDefaults.js | 25 -- lib/tasks/removeOsxApps.js | 52 ---- src/lib/core.js | 9 +- src/lib/kody.js | 56 +++-- src/lib/main.js | 6 +- src/lib/task.boilerplate | 6 +- src/lib/tasks/fishDefault.js | 24 -- src/lib/tasks/osxDefaults.js | 24 -- 27 files changed, 353 insertions(+), 576 deletions(-) rename dummy_env/{kody.json => .kodyrc} (88%) rename {src/lib/tasks => dummy_env/kody.tasks}/apm.js (53%) rename {src/lib/tasks => dummy_env/kody.tasks}/brewCask.js (66%) create mode 100644 dummy_env/kody.tasks/fishDefault.js rename {src/lib/tasks => dummy_env/kody.tasks}/gitconfig.js (73%) rename {src/lib/tasks => dummy_env/kody.tasks}/homebrew.js (59%) rename {src/lib/tasks => dummy_env/kody.tasks}/npm.js (64%) create mode 100644 dummy_env/kody.tasks/osxDefaults.js rename {src/lib/tasks => dummy_env/kody.tasks}/removeOsxApps.js (57%) delete mode 100644 lib/tasks/apm.js delete mode 100644 lib/tasks/brewCask.js delete mode 100644 lib/tasks/fishDefault.js delete mode 100644 lib/tasks/gitconfig.js delete mode 100644 lib/tasks/homebrew.js delete mode 100644 lib/tasks/npm.js delete mode 100644 lib/tasks/osxDefaults.js delete mode 100644 lib/tasks/removeOsxApps.js delete mode 100644 src/lib/tasks/fishDefault.js delete mode 100644 src/lib/tasks/osxDefaults.js diff --git a/README.md b/README.md index de6ee08..3092b5a 100644 --- a/README.md +++ b/README.md @@ -1,124 +1,150 @@ -̨[![Build Status](https://travis-ci.org/jh3y/kody.svg)](http://travis-ci.org/jh3y/kody) +[![Build Status](https://travis-ci.org/jh3y/kody.svg)](http://travis-ci.org/jh3y/kody) ![alt tag](https://raw.github.com/jh3y/pics/master/kody/kody.png) kody === -_A `.files` and environment configuration manager for OSX created with node_ +_A `.files` and environment configuration manager for OSX created with node_ -_inspired by Zach Holmans popular [dotfiles](https://github.com/holman/dotfiles), stripped down for what I need and written in node.js_ +_inspired by Zach Holmans popular [dotfiles](https://github.com/holman/dotfiles), stripped down and written in node.js_ `kody` is a command line tool that helps you maintain your .files/configurations/installations etc. -* One command will take care of things. +* One command to take care of all the thingz! * No restrictions on where you run from or store you symlink files. * Easy to extend and tweak. -* Set what tasks you want to run and packages you want to install from one config file. -* just needs `node` and your configuration. +* Interactive CLI that prompts which tasks you want to run. +* Just needs `node` and your configuration files. -##Current implemented tasks +`kody` is essentially a task runner. It comes with one task that will symlink your .files to your `$HOME` directory. Anything else is defined by your own configuration. + +## Installation +You'll need to install `node/npm` first as this is a dependency of `kody`. + +1. Install `kody` +```shell +npm install -g kody +``` +2. Set up your `kody_env`(can be named anything, mine is [here](https://github.com/jh3y/kody_env)!) directory and necessary files (Refer to [usage](#Usage)) +3. Run `kody` from within your directory (if you're unsure about anything, backup your original symlinking files to be safe.) +```shell +kody +``` +4. Enjoy not having to manually do everything to set up your machine :smile:! + + +## Usage +In order to use `kody` you'll need to set up a `kody` configuration directory containing a `.kodyrc` file. + +Start out with the `dummy_env` directory as a starting point and extend from there if you get stuck. It's what I created my own `kody_env` from and does work. + +### Symlinking +`kody` comes with a default task for symlinking files to your `$HOME` directory. The only requirement is that you suffix any files/directories with `.link` in order for those files/directories to be symlinked. + +For example; a `kody` configuration directory containing a directory named `atom.link` would be symlinked to `.atom`. +```js +WHEREVER/atom.link -> $HOME/.atom +``` + +### .kodyrc file +The `.kodyrc` file is used to define variables that will be used by tasks that you define in your configuration. It will also define the order of any defined tasks. +#### An example +```json +{ + "order": [ + "a.js", + "b.js", + "*" + ], + "brewInstalls": [ + "git", + "fish" + ], + "globalNpmModules": [ + "coffee-script", + "bower" + ] +} +``` +The `order` key is the only key that is defined by `kody` and required if you need some tasks to run before others. In this example; `a` will run before `b`. A real example would be maybe say making sure `homebrew` would be installed before `brew cask` could be ran. + +Any other keys in the `.kodyrc` file are purely user defined and made available in any tasks you write/use. For example; you could use an array with key `globalNpmModules` to define a set of global npm modules to install on your machine. + +### Creating tasks +Defining tasks for `kody` to run is what automates your machine setup. +`kody` will automatically pick up any `.js` files within directories that contain `.tasks` in their name. For example; `kody.tasks/`. + +A symlinking task is included with `kody`. The rest is your imagination. + +The task boilerplate is as follows; + +```js +const options = { + name: 'Task A', + description: 'A task that does something', + exec: function(resolve, reject, shell, log, config) { + // Do some stuff then resolve it. + resolve(); + } +}; + +exports.options = options; +``` +Tasks are defined by exporting an options object from `.js` files. You define `name`, `description` and `exec`. + +* `name {string}` - defines a task name to be used by `kody`. +* `description {string}` - defines a description for a task. +* `exec {function}` - defines a function that will be run by `kody`. The parameters are important. You can name them whatever you want. The `resolve/reject` function must be invoked in order for the task to finish as `kody` relies on `Promises` to run through tasks. `shell` gives you access to the `shelljs` API. `log` gives you access to `kody`'s instance of `winston` logger. Lastly, `config` gives you access to the `.kodyrc` config object. + +#### An example task +For an example task, let's install `Homebrew`, the package manager for `OSX`. + +```js +const PROPS = { + URL: 'https://raw.githubusercontent.com/Homebrew/install/master/install' + }, + options = { + name: 'homebrew', + description: 'install and set up homebrew', + exec: function(resolve, reject, shell, log, config) { + const brewInstalled = shell.which('brew') !== null, + packages = config.brewInstalls; + if (!brewInstalled) { + log.info('installing Homebrew'); + shell.exec(`ruby -e "$(curl -fsSL ${PROPS.URL})"`); + log.success('Homebrew installed'); + } else + log.warn('Homebrew already installed'); + shell.exec('brew doctor'); + log.warn(`NOTE: any info from brew doctor may + account for any issues with package installs`); + if (packages.length > 0) { + shell.exec(`brew install ${packages.join(' ')}`); + log.success('brew packages installed'); + } + resolve(); + } + }; + +exports.options = options; +``` +#### Tasks that have already been written * set up git -* symlink config files to home directory * write OSX defaults * Install and set up Homebrew * Install brew cask and install other programs supported by brew cask such as Spotify, Chrome, etc. -* Set fish shell as default shell(only worth running if you've installed fish) +* Set up fish shell * Install Atom IDE packages -* Remove unwanted default system applications __* NEW!__ - -##Disclaimer -I've only used `kody` on OSX(Up to Yosemite, haven't braved Capitan yet) and therefore I can't say for sure how it will run on non-unix based systems etc. `kody` will essentially make symbollic links to the $HOME directory on your PATH and then runs commands from the command line that would normally be executed with bash such as `npm install`. - -##Installation -As a prerequisite it's assumed you have `npm` installed as this is the one dependency for using `kody`. - -1. Install `kody` - - - npm install -g kody - - -2. Set up your `kody_env`(can be named anything, mine is [here](https://github.com/jh3y/kody_env)!) directory and necessary files (Refer to [conventions](#conventions)) -3. Tweak your `kody.json` file. -4. Run `kody` from within your directory (if you're unsure about anything, backup your original symlinking files to be safe.) - - - kody - - -5. Hack away, sit back and enjoy something else taking care of env setup! +* Remove unwanted default system applications -##Conventions -###Naming conventions for symlinking -For the symlinking task in `kody` there is only one thing to remember, suffix(?) `.link` to the end of either the directory you wish to symlink or the file you wish to symlink from within the directory you're working in. See the `dummy_env` folder for an example setup. -###Start from the boilerplate -Start out with the `dummy_env` directory as a starting point and extend from there if you get stuck. It's what I use to develop against so will work and is an easy place to start from. -##kody.json -In order for `kody` to run, you need a `kody.json` file in place within the directory where your config lies. In here you can modify different options to tweak what tasks you want to run, what packages you wish to install etc. - -Refer to the `kody.json` file within the `dummy_env` folder if you get stuck. - -The options so far, are as follows; - -###`set_up_git_config` : true/false -Set whether the git credential task runner should be run. -###`set_osx_defaults` : true/false -Set whether to run the Apple OSX Defaults option writer. -###`install_dot_files` : true/false -Set whether to run symlinking task, -###`install_brew_cask_and_casks` : true/false -Set whether the brew cask set up task will be run along with the installation of brew casks defined in `brew_casks`. -###`install_homebrew_and_packages` : true/false -Set whether Homebrew installation task is run. -###`install_npm_modules` : true/false -Set whether global npm modules are installed that are defined within `global_npm_modules` -###`remove_default_apple_apps` : true/false -Set whether `kody` should remove defined default applications that are unwanted. -###`install_apm_packages` : true/false -Set whether Atom IDE packages are installed that are defined within `apm_packages`. -###`set_fish_shell_as_default` : true/false -Set whether the shell script for setting fish as the default shell should be run. -###`brew_installs` : true/false -Defines the brew installs to run. -###`brew_casks` : string array -Defines the brew casks to be installed. -###`apple_apps_to_remove`: string array -Defines the default apple installed applications to be removed. -###`apm_packages`: string array -Defines the atom IDE packages to be installed. -###`global_npm_modules` : object -Defines the npm modules to be installed globally along with their version. - -##Known issues -* If you are happily using a directory with `kody` but then delete it, this will ruin your symlinks in home and you will need to set up again. It's ideal if you can back up your original config files. You can always just manually copy them into the home directory if need be or delete them and run `kody`. - - I will be writing a backup option for the symlinking tasks of `kody`. - -* Not so much an issue but an improvement, but it would be nice to call the individual tasks out. For example, - - - kody install_apm_packages - - -##Extending -If you're looking to extend by adding more tasks, you can get a head start with the boilerplate coffeescript file in `src/coffee/lib/tasks`. -`kody` has been written in coffeescript and uses `gulp` for coffee compilation and watching. If you want to extend and develop `kody` you'll need to get `gulp` installed too. - -The structure of the repo should be relatively easy to become familiar with and I've included a boilerplate task file within the tasks directory. The main concern when developing is creating your own task file and then integrating it into `task_runner.coffee` and setting new configuration keys to test it out within `kody.json`. - - -##Contributing -Feel free to get involved and give me some pointers on what could be improved. - -Refer to __extending__ above and fork the repo. - -I look forward to any potential pull requests! +##Disclaimer +I've only used `kody` on OSX(Up to Yosemite, haven't braved Capitan yet) and therefore I can't say for sure how it will run on non-unix based systems etc. `kody` will essentially make symbollic links to the $HOME directory on your PATH and then runs commands from the command line that would normally be executed with bash such as `npm install`. -##Support +=== -Any problems or questions, feel free to post an issue or tweet me, @_jh3y! +Any problems or questions, feel free to post an issue or tweet me, [@_jh3y](https://twitter.com/@_jh3y)! -@jh3y 2014 +@jh3y 2016 diff --git a/dummy_env/kody.json b/dummy_env/.kodyrc similarity index 88% rename from dummy_env/kody.json rename to dummy_env/.kodyrc index 551bb90..e84705e 100644 --- a/dummy_env/kody.json +++ b/dummy_env/.kodyrc @@ -1,4 +1,9 @@ { + "order": [ + "homebrew.js", + "brewCask.js", + "*" + ], "gitCredentials": { "name": "SomeUser", "email": "SomeUser@SomeEmail.com" diff --git a/src/lib/tasks/apm.js b/dummy_env/kody.tasks/apm.js similarity index 53% rename from src/lib/tasks/apm.js rename to dummy_env/kody.tasks/apm.js index b9a2623..3d4a142 100644 --- a/src/lib/tasks/apm.js +++ b/dummy_env/kody.tasks/apm.js @@ -3,27 +3,23 @@ * @license MIT * @author jh3y */ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - const options = { name: 'apm', description: 'installs apm packages for Atom IDE', - exec: function(resolve) { + exec: function(resolve, reject, shell, log, config) { const apmWhich = shell.exec('which apm', {silent: true}); if (apmWhich.output.trim() !== '') - if (userConfig.apmPackages.length > 0) { - winston.warn(`NOTE: package installation may fail if a + if (config.apmPackages.length > 0) { + log.warn(`NOTE: package installation may fail if a package is already installed. If problems persist remove the atom packages install directory and do a fresh install`); - const packages = userConfig.apmPackages.join(' '); + const packages = config.apmPackages.join(' '); shell.exec(`apm install ${packages}`); - winston.success('apm packages installed'); + log.success('apm packages installed'); } else - winston.info('no packages to install'); + log.info('no packages to install'); else - winston.error('Atom IDE not installed'); + log.error('Atom IDE not installed'); resolve(); } }; diff --git a/src/lib/tasks/brewCask.js b/dummy_env/kody.tasks/brewCask.js similarity index 66% rename from src/lib/tasks/brewCask.js rename to dummy_env/kody.tasks/brewCask.js index e697370..555b3d5 100644 --- a/src/lib/tasks/brewCask.js +++ b/dummy_env/kody.tasks/brewCask.js @@ -3,25 +3,21 @@ * @license MIT * @author jh3y */ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - const options = { name: 'set up brew cask', description: 'install brew cask and install casks', - exec: function(resolve) { + exec: function(resolve, reject, shell, log, config) { const brewInstalled = shell.which('brew') !== null, - casks = userConfig.brewCasks; + casks = config.brewCasks; if (brewInstalled && casks.length > 0) { shell.exec('brew prune'); shell.exec('brew tap caskroom/cask'); shell.exec('brew install brew-cask'); for (const cask of casks) shell.exec(`brew cask install ${cask}`); - winston.success('casks installed'); + log.success('casks installed'); } else - winston.warn(`brew-cask not installed. Either brew not installed + log.warn(`brew-cask not installed. Either brew not installed or no casks defined in kody.json`); resolve(); } diff --git a/dummy_env/kody.tasks/fishDefault.js b/dummy_env/kody.tasks/fishDefault.js new file mode 100644 index 0000000..4058908 --- /dev/null +++ b/dummy_env/kody.tasks/fishDefault.js @@ -0,0 +1,20 @@ +/** + * set fish shell - set fish shell as default shell + * @license MIT + * @author jh3y +*/ +const options = { + name: 'set fish shell', + description: 'set fish shell as default shell', + exec: function(resolve, reject, shell, log, config) { + const scriptPath = config.fishDefaultScriptPath; + if (scriptPath) { + shell.exec(`sh ./${scriptPath}`); + log.success('fish shell set as default'); + } else + log.error('fish shell script not found'); + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/gitconfig.js b/dummy_env/kody.tasks/gitconfig.js similarity index 73% rename from src/lib/tasks/gitconfig.js rename to dummy_env/kody.tasks/gitconfig.js index d4fe3b9..7331306 100644 --- a/src/lib/tasks/gitconfig.js +++ b/dummy_env/kody.tasks/gitconfig.js @@ -10,10 +10,6 @@ * @license MIT * @author jh3y */ -const shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - const PROPS = { STARTER: 'git/gitconfig.starter', OUTPUT : 'git/gitconfig.link' @@ -21,10 +17,10 @@ const PROPS = { options = { name : 'GitConfig', description: 'sets up global git configuration for symlinking', - exec : function(resolve) { + exec : function(resolve, reject, shell, log, config) { const gitCredential = 'osxkeychain', - gitEmail = userConfig.gitCredentials.email, - gitName = userConfig.gitCredentials.name, + gitEmail = config.gitCredentials.email, + gitName = config.gitCredentials.name, nameCmd = `-e 's/AUTHORNAME/${gitName}/g'`, emailCmd = `-e 's/AUTHOREMAIL/${gitEmail}/g'`, credentialCmd = `-e 's/GIT_CREDENTIAL_HELPER/${gitCredential}/g'`, @@ -32,7 +28,7 @@ const PROPS = { shell.exec(cG, {silent: true}) .stdout.to(PROPS.OUTPUT); - winston.info(`git config set for "${gitName}" with email "${gitEmail}"`); + log.info(`git config set for "${gitName}" with email "${gitEmail}"`); resolve(); } }; diff --git a/src/lib/tasks/homebrew.js b/dummy_env/kody.tasks/homebrew.js similarity index 59% rename from src/lib/tasks/homebrew.js rename to dummy_env/kody.tasks/homebrew.js index dba8bf3..e525f1f 100644 --- a/src/lib/tasks/homebrew.js +++ b/dummy_env/kody.tasks/homebrew.js @@ -3,31 +3,27 @@ * @license MIT * @author jh3y */ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - const PROPS = { URL: 'https://raw.githubusercontent.com/Homebrew/install/master/install' }, options = { name: 'homebrew', description: 'install and set up homebrew', - exec: function(resolve) { + exec: function(resolve, reject, shell, log, config) { const brewInstalled = shell.which('brew') !== null, - packages = userConfig.brewInstalls; + packages = config.brewInstalls; if (!brewInstalled) { - winston.info('installing Homebrew'); + log.info('installing Homebrew'); shell.exec(`ruby -e "$(curl -fsSL ${PROPS.URL})"`); - winston.success('Homebrew installed'); + log.success('Homebrew installed'); } else - winston.warn('Homebrew already installed'); + log.warn('Homebrew already installed'); shell.exec('brew doctor'); - winston.warn(`NOTE: any info from brew doctor may + log.warn(`NOTE: any info from brew doctor may account for any issues with package installs`); if (packages.length > 0) { shell.exec(`brew install ${packages.join(' ')}`); - winston.success('brew packages installed'); + log.success('brew packages installed'); } resolve(); } diff --git a/src/lib/tasks/npm.js b/dummy_env/kody.tasks/npm.js similarity index 64% rename from src/lib/tasks/npm.js rename to dummy_env/kody.tasks/npm.js index c61a76f..c0df6be 100644 --- a/src/lib/tasks/npm.js +++ b/dummy_env/kody.tasks/npm.js @@ -3,10 +3,6 @@ * @license MIT * @author jh3y */ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - const PROPS = { ERROR_MSG: 'npm is not installed', WARN: 'NOTE: incorrect npm permissions may cause an error.', @@ -15,17 +11,17 @@ const PROPS = { options = { name: 'npm installs', description: 'installs desired global modules', - exec: function(resolve) { + exec: function(resolve, reject, shell, log, config) { const npmWhich = shell.exec('which npm', {silent: true}); if (npmWhich.output.trim() !== '') { - const modules = userConfig.globalNpmModules; - winston.warn(`${PROPS.WARN} See: ${PROPS.FIX_URL}`); + const modules = config.globalNpmModules; + log.warn(`${PROPS.WARN} See: ${PROPS.FIX_URL}`); for (const module of modules) { - winston.info(`attempting to install ${module}`); + log.info(`attempting to install ${module}`); shell.exec(`npm install -g ${module}`); } } else - winston.error(PROPS.ERROR_MSG); + log.error(PROPS.ERROR_MSG); resolve(); } }; diff --git a/dummy_env/kody.tasks/osxDefaults.js b/dummy_env/kody.tasks/osxDefaults.js new file mode 100644 index 0000000..eb0d6c4 --- /dev/null +++ b/dummy_env/kody.tasks/osxDefaults.js @@ -0,0 +1,20 @@ +/** + * OSX defaults - set system wide OSX defaults + * @license MIT + * @author jh3y +*/ +const options = { + name: 'OSX defaults', + description: 'sets system wide OSX defaults', + exec: function(resolve, reject, shell, log, config) { + const scriptPath = config.osxDefaultScriptPath; + if (scriptPath) { + shell.exec(`sh ./${scriptPath}`); + log.success('OSX defaults set'); + } else + log.error('OSX defaults script not found'); + resolve(); + } +}; + +exports.options = options; diff --git a/src/lib/tasks/removeOsxApps.js b/dummy_env/kody.tasks/removeOsxApps.js similarity index 57% rename from src/lib/tasks/removeOsxApps.js rename to dummy_env/kody.tasks/removeOsxApps.js index 599817b..d3df11e 100644 --- a/src/lib/tasks/removeOsxApps.js +++ b/dummy_env/kody.tasks/removeOsxApps.js @@ -3,25 +3,21 @@ * @license MIT * @author jh3y */ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - const options = { name: 'Remove OSX apps', description: 'removes unwanted default OSX apps', - exec: function(resolve) { + exec: function(resolve, reject, shell, log, config) { const space = new RegExp(' ', 'g'); - const apps = userConfig.osxAppsToRemove; + const apps = config.osxAppsToRemove; if (apps && apps.length > 0) { for (const app of apps) { const sanitizedApp = app.replace(space, '\\ '); shell.exec(`sudo rm -rf /Applications/${sanitizedApp}`); - winston.info(`${sanitizedApp} removed from system`); + log.info(`${sanitizedApp} removed from system`); } - winston.success('default OSX applications removed'); + log.success('default OSX applications removed'); } else - winston.info('no apps to remove'); + log.info('no apps to remove'); resolve(); } }; diff --git a/lib/core.js b/lib/core.js index 719d5c4..99f2131 100644 --- a/lib/core.js +++ b/lib/core.js @@ -4,7 +4,12 @@ var _createClass = function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var winston = require('winston'); +var fs = require('fs'), + winston = require('winston'), + shell = require('shelljs'); + +var rc = JSON.parse(fs.readFileSync(process.cwd() + '/.kodyrc', 'utf-8')); + var defaults = { name: 'Generic task', exec: function exec() { @@ -29,7 +34,7 @@ var KodyTask = function () { return new Promise(function (resolve, reject) { winston.info('Running ' + _this.name); - if (_this.exec && typeof _this.exec === 'function') _this.exec(resolve, reject); + if (_this.exec && typeof _this.exec === 'function') _this.exec(resolve, reject, shell, winston, rc); }); } }]); diff --git a/lib/kody.js b/lib/kody.js index f45b904..54d1031 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -4,11 +4,13 @@ * kody - .files manager for node */ require('babel-polyfill'); -var core = require('./core'), - fs = require('fs'), + +var fs = require('fs'), inquirer = require('inquirer'), winston = require('winston'); +var rc = undefined; + /** * Define a task order. * This is useful for when you wish one task to run before @@ -18,7 +20,6 @@ var core = require('./core'), * Atom IDE is installed as the apm CLI won't be available. */ var PROPS = { - TASK_ORDER: ['gitconfig.js', 'homebrew.js', 'brewCask.js', '*'], TASKS_QUERY: { type: 'checkbox', name: 'tasks', @@ -28,29 +29,23 @@ var PROPS = { }, /** - * initializes Kody + * returns tasks in a given directory * - * @returns {undefined} + * @param {string} directory - directory to return tasks from. + * @returns {array} - file contents of tasks. */ -init = function init() { - welcome(); - var files = fs.readdirSync(__dirname + '/tasks'); - files = files.sort(sortFiles); - winston.info(files); +getTasks = function getTasks(directory) { + var tasks = fs.readdirSync(directory); + var addresses = []; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { - for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var file = _step.value; + for (var _iterator = tasks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var task = _step.value; - var taskOpts = require('./tasks/' + file).options; - var newChoice = { - name: taskOpts.name + ' - ' + taskOpts.description, - value: taskOpts - }; - PROPS.TASKS_QUERY.choices.push(newChoice); + addresses.push(directory + '/' + task); } } catch (err) { _didIteratorError = true; @@ -67,6 +62,80 @@ init = function init() { } } + return addresses; +}, + +/** +* initializes Kody +* +* @returns {undefined} +*/ +init = function init() { + welcome(); + try { + rc = JSON.parse(fs.readFileSync(process.cwd() + '/.kodyrc', 'utf-8')); + } catch (err) { + throw Error('Missing .kodyrc file.'); + } + var files = getTasks(__dirname + '/tasks'); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = fs.readdirSync(process.cwd())[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var dir = _step2.value; + + var isDir = fs.statSync(dir).isDirectory(); + var areTasks = dir.indexOf('.tasks') !== -1; + if (isDir && areTasks) files = files.concat(getTasks(process.cwd() + '/' + dir)); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + files = files.sort(sortFiles); + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = files[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var file = _step3.value; + + var taskOpts = require('' + file).options; + var newChoice = { + name: taskOpts.name + ' - ' + taskOpts.description, + value: taskOpts + }; + PROPS.TASKS_QUERY.choices.push(newChoice); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + inquirer.prompt(PROPS.TASKS_QUERY, processTasks); }, @@ -77,6 +146,7 @@ init = function init() { * @returns {undefined} */ processTasks = function processTasks(tasks) { + var core = require('./core'); var processTask = function processTask(task) { var newTask = new core.KodyTask(task.value); newTask.run().then(function () { @@ -99,8 +169,8 @@ processTasks = function processTasks(tasks) { * @returns {bool} - used by Array.sort */ sortFiles = function sortFiles(a, b) { - var aIndex = PROPS.TASK_ORDER.indexOf(a), - bIndex = PROPS.TASK_ORDER.indexOf(b); + var aIndex = rc.order.indexOf(a), + bIndex = rc.order.indexOf(b); if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) return -1; if (aIndex !== -1 || bIndex !== -1) return 1; }, @@ -111,9 +181,9 @@ sortFiles = function sortFiles(a, b) { * @returns {undefined} */ welcome = function welcome() { - winston.info('=================================='); - winston.info('kody - .files & config runner'); - winston.info('=================================='); + winston.info('==================================='); + winston.info(' kody - .files & config runner '); + winston.info('==================================='); }; exports.init = init; \ No newline at end of file diff --git a/lib/main.js b/lib/main.js index 8e376a1..14f5580 100644 --- a/lib/main.js +++ b/lib/main.js @@ -31,8 +31,6 @@ var PROPS = { } }; -program.version(pkg.version); - winston.remove(winston.transports.Console); winston.add(winston.transports.Console, { level: 'silly', @@ -44,7 +42,7 @@ winston.add(winston.transports.Console, { }); winston.setLevels(PROPS.LOGGER_CONFIG.LEVELS); -program.parse(process.argv); +program.version(pkg.version).parse(process.argv); try { kody.init(); diff --git a/lib/tasks/apm.js b/lib/tasks/apm.js deleted file mode 100644 index 987017e..0000000 --- a/lib/tasks/apm.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -/** - * apm installs - installs Atom IDE packages - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var options = { - name: 'apm', - description: 'installs apm packages for Atom IDE', - exec: function exec(resolve) { - var apmWhich = shell.exec('which apm', { silent: true }); - if (apmWhich.output.trim() !== '') { - if (userConfig.apmPackages.length > 0) { - winston.warn('NOTE: package installation may fail if a\n package is already installed. If problems persist remove the\n atom packages install directory and do a fresh install'); - var packages = userConfig.apmPackages.join(' '); - shell.exec('apm install ' + packages); - winston.success('apm packages installed'); - } else winston.info('no packages to install'); - } else winston.error('Atom IDE not installed'); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/brewCask.js b/lib/tasks/brewCask.js deleted file mode 100644 index fadfbcc..0000000 --- a/lib/tasks/brewCask.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -/** - * set up brew cask - install brew cask and install casks - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var options = { - name: 'set up brew cask', - description: 'install brew cask and install casks', - exec: function exec(resolve) { - var brewInstalled = shell.which('brew') !== null, - casks = userConfig.brewCasks; - if (brewInstalled && casks.length > 0) { - shell.exec('brew prune'); - shell.exec('brew tap caskroom/cask'); - shell.exec('brew install brew-cask'); - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = casks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var cask = _step.value; - - shell.exec('brew cask install ' + cask); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - winston.success('casks installed'); - } else winston.warn('brew-cask not installed. Either brew not installed\n or no casks defined in kody.json'); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/fishDefault.js b/lib/tasks/fishDefault.js deleted file mode 100644 index d1f9c1e..0000000 --- a/lib/tasks/fishDefault.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -/** - * set fish shell - set fish shell as default shell - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var options = { - name: 'set fish shell', - description: 'set fish shell as default shell', - exec: function exec(resolve) { - var scriptPath = userConfig.fishDefaultScriptPath; - if (scriptPath) { - shell.exec('sh ./' + scriptPath); - winston.success('fish shell set as default'); - } else winston.error('fish shell script not found'); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/gitconfig.js b/lib/tasks/gitconfig.js deleted file mode 100644 index 1432c0c..0000000 --- a/lib/tasks/gitconfig.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict'; - -/** - * GitConfig - Sets up global Git configuration pre symlink - * - * user git/gitconfig.starter as a starting point to create a system - * wide gitconfig. - * - * NOTE: This task could be made obsolete if you commit the author name - * and email as a gitconfig.link file. - * - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var PROPS = { - STARTER: 'git/gitconfig.starter', - OUTPUT: 'git/gitconfig.link' -}, - options = { - name: 'GitConfig', - description: 'sets up global git configuration for symlinking', - exec: function exec(resolve) { - var gitCredential = 'osxkeychain', - gitEmail = userConfig.gitCredentials.email, - gitName = userConfig.gitCredentials.name, - nameCmd = '-e \'s/AUTHORNAME/' + gitName + '/g\'', - emailCmd = '-e \'s/AUTHOREMAIL/' + gitEmail + '/g\'', - credentialCmd = '-e \'s/GIT_CREDENTIAL_HELPER/' + gitCredential + '/g\'', - cG = 'sed ' + nameCmd + ' ' + emailCmd + ' ' + credentialCmd + ' ' + PROPS.STARTER; - - shell.exec(cG, { silent: true }).stdout.to(PROPS.OUTPUT); - winston.info('git config set for "' + gitName + '" with email "' + gitEmail + '"'); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/homebrew.js b/lib/tasks/homebrew.js deleted file mode 100644 index 6d7542a..0000000 --- a/lib/tasks/homebrew.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -/** - * homebrew - install and set up homebrew - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var PROPS = { - URL: 'https://raw.githubusercontent.com/Homebrew/install/master/install' -}, - options = { - name: 'homebrew', - description: 'install and set up homebrew', - exec: function exec(resolve) { - var brewInstalled = shell.which('brew') !== null, - packages = userConfig.brewInstalls; - if (!brewInstalled) { - winston.info('installing Homebrew'); - shell.exec('ruby -e "$(curl -fsSL ' + PROPS.URL + ')"'); - winston.success('Homebrew installed'); - } else winston.warn('Homebrew already installed'); - shell.exec('brew doctor'); - winston.warn('NOTE: any info from brew doctor may\n account for any issues with package installs'); - if (packages.length > 0) { - shell.exec('brew install ' + packages.join(' ')); - winston.success('brew packages installed'); - } - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/npm.js b/lib/tasks/npm.js deleted file mode 100644 index a10c0fa..0000000 --- a/lib/tasks/npm.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -/** - * npm installs - installs desired global modules - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var PROPS = { - ERROR_MSG: 'npm is not installed', - WARN: 'NOTE: incorrect npm permissions may cause an error.', - FIX_URL: 'https://docs.npmjs.com/getting-started/fixing-npm-permissions' -}, - options = { - name: 'npm installs', - description: 'installs desired global modules', - exec: function exec(resolve) { - var npmWhich = shell.exec('which npm', { silent: true }); - if (npmWhich.output.trim() !== '') { - var modules = userConfig.globalNpmModules; - winston.warn(PROPS.WARN + ' See: ' + PROPS.FIX_URL); - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = modules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var module = _step.value; - - winston.info('attempting to install ' + module); - shell.exec('npm install -g ' + module); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } else winston.error(PROPS.ERROR_MSG); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/osxDefaults.js b/lib/tasks/osxDefaults.js deleted file mode 100644 index 7016b16..0000000 --- a/lib/tasks/osxDefaults.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -/** - * OSX defaults - set system wide OSX defaults - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var options = { - name: 'OSX defaults', - description: 'sets system wide OSX defaults', - exec: function exec(resolve) { - var scriptPath = userConfig.osxDefaultScriptPath; - if (scriptPath) { - shell.exec('sh ./' + scriptPath); - winston.success('OSX defaults set'); - } else winston.error('OSX defaults script not found'); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/lib/tasks/removeOsxApps.js b/lib/tasks/removeOsxApps.js deleted file mode 100644 index b608feb..0000000 --- a/lib/tasks/removeOsxApps.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -/** - * Remove OSX apps - removes unwanted default OSX apps - * @license MIT - * @author jh3y -*/ -var shell = require('shelljs'), - userConfig = require(process.cwd() + '/kody.json'), - winston = require('winston'); - -var options = { - name: 'Remove OSX apps', - description: 'removes unwanted default OSX apps', - exec: function exec(resolve) { - var space = new RegExp(' ', 'g'); - var apps = userConfig.osxAppsToRemove; - if (apps && apps.length > 0) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = apps[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var app = _step.value; - - var sanitizedApp = app.replace(space, '\\ '); - shell.exec('sudo rm -rf /Applications/' + sanitizedApp); - winston.info(sanitizedApp + ' removed from system'); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - - winston.success('default OSX applications removed'); - } else winston.info('no apps to remove'); - resolve(); - } -}; - -exports.options = options; \ No newline at end of file diff --git a/src/lib/core.js b/src/lib/core.js index 4399011..cec2e5e 100644 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -1,4 +1,9 @@ -const winston = require('winston'); +const fs = require('fs'), + winston = require('winston'), + shell = require('shelljs'); + +const rc = JSON.parse(fs.readFileSync(`${process.cwd()}/.kodyrc`, 'utf-8')); + const defaults = { name: 'Generic task', exec: () => winston.info('running') @@ -13,7 +18,7 @@ class KodyTask { return new Promise((resolve, reject) => { winston.info(`Running ${this.name}`); if (this.exec && typeof this.exec === 'function') - this.exec(resolve, reject); + this.exec(resolve, reject, shell, winston, rc); }); } } diff --git a/src/lib/kody.js b/src/lib/kody.js index e7d3953..721921c 100644 --- a/src/lib/kody.js +++ b/src/lib/kody.js @@ -2,11 +2,13 @@ * kody - .files manager for node */ require('babel-polyfill'); -const core = require('./core'), - fs = require('fs'), + +const fs = require('fs'), inquirer = require('inquirer'), winston = require('winston'); +let rc; + /** * Define a task order. * This is useful for when you wish one task to run before @@ -16,12 +18,6 @@ const core = require('./core'), * Atom IDE is installed as the apm CLI won't be available. */ const PROPS = { - TASK_ORDER : [ - 'gitconfig.js', - 'homebrew.js', - 'brewCask.js', - '*' - ], TASKS_QUERY: { type: 'checkbox', name: 'tasks', @@ -30,17 +26,40 @@ const PROPS = { } }, /** - * initializes Kody + * returns tasks in a given directory * - * @returns {undefined} + * @param {string} directory - directory to return tasks from. + * @returns {array} - file contents of tasks. + */ + getTasks = function(directory) { + const tasks = fs.readdirSync(directory); + const addresses = []; + for (const task of tasks) + addresses.push(`${directory}/${task}`); + return addresses; + }, + /** + * initializes Kody + * + * @returns {undefined} */ init = function() { welcome(); - let files = fs.readdirSync(__dirname + '/tasks'); + try { + rc = JSON.parse(fs.readFileSync(`${process.cwd()}/.kodyrc`, 'utf-8')); + } catch (err) { + throw Error('Missing .kodyrc file.'); + } + let files = getTasks(`${__dirname}/tasks`); + for (const dir of fs.readdirSync(process.cwd())) { + const isDir = fs.statSync(dir).isDirectory(); + const areTasks = dir.indexOf('.tasks') !== -1; + if (isDir && areTasks) + files = files.concat(getTasks(`${process.cwd()}/${dir}`)); + } files = files.sort(sortFiles); - winston.info(files); for (const file of files) { - const taskOpts = require(`./tasks/${file}`).options; + const taskOpts = require(`${file}`).options; const newChoice = { name: `${taskOpts.name} - ${taskOpts.description}`, value: taskOpts @@ -56,6 +75,7 @@ const PROPS = { * @returns {undefined} */ processTasks = function(tasks) { + const core = require('./core'); const processTask = function(task) { const newTask = new core.KodyTask(task.value); newTask.run() @@ -82,8 +102,8 @@ const PROPS = { * @returns {bool} - used by Array.sort */ sortFiles = function(a, b) { - const aIndex = PROPS.TASK_ORDER.indexOf(a), - bIndex = PROPS.TASK_ORDER.indexOf(b); + const aIndex = rc.order.indexOf(a), + bIndex = rc.order.indexOf(b); if (bIndex !== -1 && aIndex !== -1 && aIndex < bIndex) return -1; if (aIndex !== -1 || bIndex !== -1) @@ -95,9 +115,9 @@ const PROPS = { * @returns {undefined} */ welcome = function() { - winston.info('=================================='); - winston.info('kody - .files & config runner'); - winston.info('=================================='); + winston.info('==================================='); + winston.info(' kody - .files & config runner '); + winston.info('==================================='); }; exports.init = init; diff --git a/src/lib/main.js b/src/lib/main.js index 3743124..0839ea4 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -29,8 +29,6 @@ const PROPS = { } }; -program - .version(pkg.version); winston.remove(winston.transports.Console); winston.add(winston.transports.Console, { @@ -43,7 +41,9 @@ winston.add(winston.transports.Console, { }); winston.setLevels(PROPS.LOGGER_CONFIG.LEVELS); -program.parse(process.argv); +program + .version(pkg.version) + .parse(process.argv); try { kody.init(); diff --git a/src/lib/task.boilerplate b/src/lib/task.boilerplate index d357135..7a1b0cf 100644 --- a/src/lib/task.boilerplate +++ b/src/lib/task.boilerplate @@ -3,14 +3,10 @@ * @license MIT * @author @AUTHOR */ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - const options = { name: '@TITLE', description: '@DESCRIPTION', - exec: function(resolve) { // NOTE: to reject, include reject parameter + exec: function(resolve, reject, shell, log, config) { resolve(); } }; diff --git a/src/lib/tasks/fishDefault.js b/src/lib/tasks/fishDefault.js deleted file mode 100644 index 7507ef4..0000000 --- a/src/lib/tasks/fishDefault.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * set fish shell - set fish shell as default shell - * @license MIT - * @author jh3y -*/ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - -const options = { - name: 'set fish shell', - description: 'set fish shell as default shell', - exec: function(resolve) { - const scriptPath = userConfig.fishDefaultScriptPath; - if (scriptPath) { - shell.exec(`sh ./${scriptPath}`); - winston.success('fish shell set as default'); - } else - winston.error('fish shell script not found'); - resolve(); - } -}; - -exports.options = options; diff --git a/src/lib/tasks/osxDefaults.js b/src/lib/tasks/osxDefaults.js deleted file mode 100644 index 9d2a090..0000000 --- a/src/lib/tasks/osxDefaults.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * OSX defaults - set system wide OSX defaults - * @license MIT - * @author jh3y -*/ -const shell = require('shelljs'), - userConfig = require(`${process.cwd()}/kody.json`), - winston = require('winston'); - -const options = { - name: 'OSX defaults', - description: 'sets system wide OSX defaults', - exec: function(resolve) { - const scriptPath = userConfig.osxDefaultScriptPath; - if (scriptPath) { - shell.exec(`sh ./${scriptPath}`); - winston.success('OSX defaults set'); - } else - winston.error('OSX defaults script not found'); - resolve(); - } -}; - -exports.options = options; From e884930c8d36a96a48c3204cb8b23dcc0647b997 Mon Sep 17 00:00:00 2001 From: jh3y Date: Mon, 7 Mar 2016 20:04:12 +0000 Subject: [PATCH 08/11] Add task ordering check based on rc --- lib/kody.js | 2 +- src/lib/kody.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/kody.js b/lib/kody.js index 54d1031..5f24b9f 100644 --- a/lib/kody.js +++ b/lib/kody.js @@ -105,7 +105,7 @@ init = function init() { } } - files = files.sort(sortFiles); + if (rc && rc.order && rc.order.length > 0) files = files.sort(sortFiles); var _iteratorNormalCompletion3 = true; var _didIteratorError3 = false; var _iteratorError3 = undefined; diff --git a/src/lib/kody.js b/src/lib/kody.js index 721921c..4ca5ab0 100644 --- a/src/lib/kody.js +++ b/src/lib/kody.js @@ -57,7 +57,8 @@ const PROPS = { if (isDir && areTasks) files = files.concat(getTasks(`${process.cwd()}/${dir}`)); } - files = files.sort(sortFiles); + if (rc && rc.order && rc.order.length > 0) + files = files.sort(sortFiles); for (const file of files) { const taskOpts = require(`${file}`).options; const newChoice = { From 281cdd984674a9f58974563ccdd6d8c9045395bd Mon Sep 17 00:00:00 2001 From: jh3y Date: Mon, 7 Mar 2016 20:08:43 +0000 Subject: [PATCH 09/11] Update README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3092b5a..a7ab4eb 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,10 @@ exports.options = options; -##Disclaimer +## Under the hood +`kody` is written using `es6` with `babel` and is developed using `npm run scripts`. + +## Disclaimer I've only used `kody` on OSX(Up to Yosemite, haven't braved Capitan yet) and therefore I can't say for sure how it will run on non-unix based systems etc. `kody` will essentially make symbollic links to the $HOME directory on your PATH and then runs commands from the command line that would normally be executed with bash such as `npm install`. === From 958cdc5dde7feeba94eeba43256a1af1519f1924 Mon Sep 17 00:00:00 2001 From: jh3y Date: Tue, 8 Mar 2016 21:06:36 +0000 Subject: [PATCH 10/11] Update README --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a7ab4eb..769de41 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,21 @@ [![Build Status](https://travis-ci.org/jh3y/kody.svg)](http://travis-ci.org/jh3y/kody) +![img](https://img.shields.io/badge/version-1.0.0-000000.svg) +![img](https://img.shields.io/badge/language-JS-9a12b3.svg) +![img](https://img.shields.io/badge/license-MIT-22a7f0.svg) ![alt tag](https://raw.github.com/jh3y/pics/master/kody/kody.png) kody === -_A `.files` and environment configuration manager for OSX created with node_ +_An interactive `.files` and environment configuration CLI tool for OSX, created with node_ _inspired by Zach Holmans popular [dotfiles](https://github.com/holman/dotfiles), stripped down and written in node.js_ -`kody` is a command line tool that helps you maintain your .files/configurations/installations etc. - -* One command to take care of all the thingz! +* One command * No restrictions on where you run from or store you symlink files. * Easy to extend and tweak. * Interactive CLI that prompts which tasks you want to run. -* Just needs `node` and your configuration files. - +* Just needs `node` and your configuration. `kody` is essentially a task runner. It comes with one task that will symlink your .files to your `$HOME` directory. Anything else is defined by your own configuration. From 8fc387ec4d2e1458d5bcab5a7de61db1520a122a Mon Sep 17 00:00:00 2001 From: jh3y Date: Tue, 8 Mar 2016 21:10:55 +0000 Subject: [PATCH 11/11] Add issue/PR templates to repo --- ISSUE_TEMPLATE.md | 11 +++++++++++ PULL_REQUEST_TEMPLATE.md | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 ISSUE_TEMPLATE.md create mode 100644 PULL_REQUEST_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..4a1bb3a --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,11 @@ +Issue summary +=== + +Expected behavior +=== + +Actual behavior +=== + +Steps to reproduce +=== diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..9517b3a --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,10 @@ +Fixes # || Adds new feature X +=== + +Changes include; + +* a +* b +* c + +@jh3y