-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathfind-everything-that-uses.js
executable file
·88 lines (80 loc) · 2.7 KB
/
find-everything-that-uses.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
/*jshint asi:true */
/**
* @author Thomas Aylott <[email protected]>
* @copyright 2011 Sencha, Inc.
* @url https://gist.github.com/977391f357d547670b20
*/
// Find everything that uses something
// e.g. search-for-everything-that-uses Ext.Sheet
var fs = require('fs')
var ROOT = fs.realpathSync(process.env.EXT_SDK_ROOT)
var CLASS = process.argv[2]// || 'Ext.util.Observable'
var manifest = process.argv[3], PROJECT
if (!ROOT) {
console.error('You must define the environment variable EXT_SDK_ROOT as the root path of your Ext SDK')
process.exit(1)
}
if (!CLASS) {
console.error('Usage: \n\t' + process.argv[1].split('/').reverse()[0] + ' Ext.util.Observable\n')
process.exit(1)
}
var results = {
is: function(classManifest){
// console.log('# '+ classManifest.className +' id '+ CLASS)
console.log(ROOT + '/' + PROJECT + '/' + classManifest.source)
},
extend: function(classManifest){
// console.log('# '+ classManifest.className +' extends '+ CLASS)
console.log(ROOT + '/' + PROJECT + '/' + classManifest.source)
},
requires: function(classManifest){
// console.log('# '+ classManifest.className +' requires '+ CLASS)
console.log(ROOT + '/' + PROJECT + '/' + classManifest.source)
},
mixins: function(classManifest){
// console.log('# '+ classManifest.className +' mixes-in '+ CLASS)
console.log(ROOT + '/' + PROJECT + '/' + classManifest.source)
}
}
try{
PROJECT = manifest.match('platform|extjs|touch')[0]
manifest = JSON.parse(fs.readFileSync(manifest))
}catch(e){try{
manifest = JSON.parse(fs.readFileSync(ROOT + '/touch/build/touch-manifest.json'))
PROJECT = 'touch'
}catch(e){try{
manifest = JSON.parse(fs.readFileSync(ROOT + '/extjs/build/extjs-manifest.json'))
PROJECT = 'extjs'
}catch(e){try{
manifest = JSON.parse(fs.readFileSync(ROOT + '/extjs/build/Ext4-manifest.json'))
PROJECT = 'extjs'
}catch(e){
}}}}
if (!manifest) {
console.error('You need to build your manifest.json file')
process.exit(1)
}
console.error(PROJECT)
manifest.forEach(function(classManifest){
if (classManifest.className == CLASS) {
results.is(classManifest)
}
if (classManifest.extend == CLASS) {
results.extend(classManifest)
}
if (values(classManifest.mixins).indexOf(CLASS) != -1) {
results.mixins(classManifest)
}
if (classManifest.requires && classManifest.requires.indexOf(CLASS) != -1) {
results.requires(classManifest)
}
})
function values(object){
var values_ = []
for (var property in object) {
if (object.hasOwnProperty(property))
values_.push(object[property])
}
return values_
}