Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Tasks management
Browse files Browse the repository at this point in the history
  • Loading branch information
jblandry committed Mar 27, 2017
1 parent d6f48f4 commit dfa8649
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cli.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
".gitignore",
".npmignore",
".sublimelinterrc",
".travis.yml"
".travis.yml",
"license"
]
}
]
Expand Down
47 changes: 46 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const echo = console.log; // eslint-disable-line no-console

const os = require('os');
const path = require('path');
const glob = require('glob');
const readPkgUp = require('read-pkg-up');
const chalk = require('chalk');
const pad = require('pad');
Expand All @@ -27,7 +28,11 @@ const STATIC = global.___AbsolunetCli___ ? global.___AbsolunetCli___ : global.__
commands: {},
taskWidth: {},
fullUsage: {},
baseWidth: 0
baseWidth: 0,
tasks: {
path: '',
list: []
}
};


Expand Down Expand Up @@ -152,6 +157,46 @@ module.exports = class Cli {



//-- List tasks files
static initTasksList(tasksPath) {
STATIC.tasks.path = tasksPath;

const tasks = [];

glob.sync(`${STATIC.tasks.path}/!(default).js`).forEach((task) => {
tasks.push(task.split(STATIC.tasks.path).slice(-1).pop().substring(1).slice(0, -3));
});

STATIC.tasks.list = tasks;
}


//-- Route to good task
static tasksRouter(meowCli) {
const [task] = meowCli.input;

if (task) {
if (STATIC.tasks.list.includes(task)) {
require(`${STATIC.tasks.path}/${task}`)(meowCli); // eslint-disable-line global-require
} else {
meowCli.showHelp();
}
} else {
require(`${STATIC.tasks.path}/default`)(meowCli); // eslint-disable-line global-require
}
}


//-- Tasks
static get tasks() {
return STATIC.tasks.list;
}






//-- Is root
static isRoot() {
const user = os.userInfo();
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "@absolunet/cli",
"version": "0.0.2",
"description": "CLI utilities",
Expand All @@ -10,7 +10,7 @@
"repository": { "url": "git://github.com/absolunet/node-cli.git", "type":"git" },
"bugs": { "url": "https://github.com/absolunet/node-cli/issues" },

"engines": { "node": ">= 7.7.3" },
"engines": { "node": ">= 7.7.4" },
"scripts": {
"test": "mocha"
},
Expand All @@ -21,6 +21,7 @@

"dependencies": {
"chalk": "^1.1.3",
"glob": "^7.1.1",
"pad": "^1.1.0",
"read-pkg-up": "^2.0.0"
}
Expand Down

0 comments on commit dfa8649

Please sign in to comment.