@reactful/create 0.0.86 → 0.0.88
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +35 -24
- package/package.json +1 -1
package/index.js
CHANGED
@@ -62,38 +62,49 @@ const downloadRepo = async (subfolder, destination) =>
|
|
62
62
|
async function downloadGitHub(user, repository, subdir, destination) {
|
63
63
|
const prefix = `https://api.github.com/repos/${user}/${repository}`
|
64
64
|
const address = `${prefix}/contents/installation/${subdir}`
|
65
|
+
const response = await fetch(address)
|
66
|
+
const contents = await response.json()
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
68
|
+
if (!Array.isArray(contents) || !response.ok) {
|
69
|
+
console.log('moment: DIRECTORY...')
|
70
|
+
logging(response, contents)
|
71
|
+
throw 'failed to download scafold from github...'
|
72
|
+
}
|
73
|
+
|
74
|
+
for (const item of contents) {
|
75
|
+
if (item.type === 'dir' && item.name) {
|
76
|
+
const from = `${subdir}/${item.name}`
|
77
|
+
const goto = `${destination}/${item.name}`
|
78
|
+
await downloadRepo(from, goto); continue
|
77
79
|
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
const goto = `${destination}/${item.name}`
|
83
|
-
await downloadRepo(from, goto); continue
|
84
|
-
}
|
85
|
-
|
86
|
-
if (item.type != 'file') continue
|
87
|
-
|
80
|
+
|
81
|
+
if (item.type != 'file') continue
|
82
|
+
|
83
|
+
try {
|
88
84
|
const filename = path.join(destination, item.name)
|
89
85
|
const response = await fetch(item.download_url)
|
90
86
|
const filetext = await response.text()
|
91
|
-
|
87
|
+
|
92
88
|
fs.writeFileSync(filename, filetext)
|
93
|
-
}
|
89
|
+
}
|
90
|
+
catch(ex) {
|
91
|
+
console.log('MOMMENT: file...')
|
92
|
+
logging(response, contents)
|
93
|
+
throw ex
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
try {
|
94
98
|
}
|
95
99
|
catch(ex) {
|
96
|
-
console.log('
|
100
|
+
console.log('fetching: ', address)
|
97
101
|
throw ex
|
98
102
|
}
|
103
|
+
}
|
104
|
+
|
105
|
+
function logging(response, contents) {
|
106
|
+
console.log('url: ', response.url)
|
107
|
+
console.log('code: ', response.status)
|
108
|
+
console.log('array: ', Array.isArray(contents))
|
109
|
+
console.log('textual: ', JSON.stringify(contents))
|
99
110
|
}
|