Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50663 views
1
/*
2
* common.js: Common utility functions for flatiron.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var fs = require('fs'),
10
broadway = require('broadway');
11
12
//
13
// Hoist `broadway.common` to `flatiron.common`.
14
//
15
var common = module.exports = broadway.common.mixin({}, broadway.common);
16
17
//
18
// ### function templateUsage (app, commands)
19
// Updates the references to `<app>` to `app.name` in usage for the
20
// specified `commands`.
21
//
22
common.templateUsage = function (app, commands) {
23
if (!app.name) {
24
return commands;
25
}
26
27
function templateUsage(usage) {
28
return usage.map(function (line) {
29
return line.replace(/\<app\>/ig, app.name);
30
});
31
}
32
33
Object.keys(commands).forEach(function (command) {
34
if (command === 'usage') {
35
commands.usage = templateUsage(commands.usage);
36
}
37
else if (commands[command].usage) {
38
commands[command].usage = templateUsage(commands[command].usage);
39
}
40
});
41
};
42
43
//
44
// ### function tryReaddirSync (dir)
45
// #### @dir {string} Directory to attempt to list
46
//
47
// Attempts to call `fs.readdirSync` but ignores errors.
48
//
49
common.tryReaddirSync = function (dir) {
50
try { return fs.readdirSync(dir) }
51
catch (err) { return [] }
52
};
53