-
Notifications
You must be signed in to change notification settings - Fork 69
/
get_cloudinary_js.ps1
122 lines (104 loc) · 2.19 KB
/
get_cloudinary_js.ps1
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
write-host
write-host "This script will download cloudinary-js files"
write-host "Usage: .\get_cloudinary_js.ps1 [directory] [content subdirectory] [scripts subdirectory]"
write-host "Example: .\get_cloudinary_js.ps1 c:\site content scripts"
$tmp = "$pwd\cloudinary_temp"
try
{
if (test-path $tmp)
{
remove-item $tmp -recurse
}
}
catch
{
write-error "Couldn't remove temporary directory $tmp!"
write-host
exit
}
$root = $pwd
if ($args.count -ge 1)
{
$root = $args[0]
}
if ($args.count -ge 2)
{ $content = "$root\" + $args[1] }
else
{ $content = "$root\Content" }
if ($args.count -ge 3)
{ $scripts = "$root\" + $args[2] }
else
{ $scripts = "$root\Scripts" }
write-host "Files will be downloaded to the following directory:"
write-host "Content: $content"
write-host "Scripts: $scripts"
write-host "Downloading and extracting, please wait..."
try
{
new-item -itemtype directory -path $tmp | out-null
}
catch
{
write-error "Couldn't create temporary directory $tmp!"
write-host
exit
}
try
{
$shell = new-object -com shell.application
$webclient = new-object System.Net.WebClient
$url = "https://github.com/cloudinary/cloudinary_js/archive/master.zip"
$zip = "$tmp\cloudinary_js.zip"
$webclient.DownloadFile($url, $zip)
}
catch
{
write-error "Couldn't download file $url to $zip!"
write-host
exit
}
try
{
$zipPackage = $shell.NameSpace($zip)
$tmpDir = $shell.NameSpace($tmp)
foreach($item in $zipPackage.items())
{
$tmpDir.copyhere($item)
}
}
catch
{
write-error "Couldn't extract file $zip to $tmpDir!"
write-host
exit
}
try
{
if (-not (test-path $content))
{ new-item -itemtype directory -path $content | out-null }
}
catch
{
write-error "Couldn't create directory $content!"
write-host
exit
}
try
{
if (-not (test-path $scripts))
{ new-item -itemtype directory -path $scripts | out-null }
}
catch
{
write-error "Couldn't create directory $scripts!"
write-host
exit
}
copy-item $tmp\cloudinary_js-master\js\* -destination $scripts -recurse
copy-item $tmp\cloudinary_js-master\html\* -destination $content -recurse
remove-item $tmp -recurse
write-host "Downloading is completed."
write-host
get-childitem $scripts
if ($scripts -ne $content)
{ get-childitem $content }