Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_modules
More file actions
Latest commit
executable file
·58 lines (42 loc) · 1.38 KB
/
Copy pathfetch_modules
File metadata and controls
executable file
·58 lines (42 loc) · 1.38 KB
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
#!/usr/bin/env node
varfs=require('fs')
varhttp=require('http')
varpath=require('path')
varurl=require('url')
vares=require('esprima')
varestraverse=require('estraverse')
varmkdirp=require('mkdirp')
varbase=process.argv[2]
functionreadFile(base){
try{
varcode=fs.readFileSync(base).toString()
estraverse.traverse(es.parse(code),{
enter: function(node,parent){
if(node.type=='VariableDeclarator'&&node.init.callee.name=='require'){
varp=node.init.arguments[0].value
varmatch=p.indexOf(':')>-1
if(match){
varorigin=url.parse(p)
varfullpath=path.join(__dirname,'/node_modules',origin.hostname,origin.pathname)
vardirname=path.dirname(fullpath)
varfilename=path.basename(fullpath)
mkdirp.sync(dirname)
varwritestream=fs.createWriteStream(fullpath)
varreq=http.request(url.parse(p),function(res){
res.setEncoding('utf8')
res.pipe(writestream)
})
req.on('error',function(e){
console.log('problem getting module: '+e.message);
})
req.end()
}
else{
readFile(path.resolve(p)+'.js')
}
}
}
})
}catch($){return}
}
readFile(base)