-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathfind_script_in_meta.js
executable file
·51 lines (40 loc) · 1.16 KB
/
find_script_in_meta.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env nodejs
// USAGE: ./find_script_in_meta.js [--name="My script"]
'use strict';
var args = {};
const fs = require('fs');
const upath = require('upath');
const config = 'config.json';
const glob = require( 'glob' );
if (fs.existsSync(config)) {
args = JSON.parse(fs.readFileSync(config));
}
[ 'username', 'password' ].forEach(function(k) { args[k] = args[k] || process.env['TD_' + k.toUpperCase()]; });
process.argv.forEach(function(val/*, index, array*/) {
var s = val.replace(/^[-]{1,2}/, '').split('=');
args[s[0]] = s[1] || true;
});
const error = function(m) {
console.error(m);
};
if (!args.path) {
return error('path argument missing');
}
const working_dir = upath.join('./', args.path);
if (!fs.existsSync(working_dir)) {
return error('working directory missing');
}
glob.sync(`${upath.join('./', working_dir)}/**/*.meta.json`).forEach(function(file) {
var c = fs.readFileSync(file);
var json;
try {
json = JSON.parse(c);
} catch (e) {}
if (json) {
if (args.name && json.name !== args.name) {
return;
} else {
console.log(`${file} => ${json.name}`);
}
}
});