@reactful/create 0.0.63 → 0.0.65
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +22 -26
- package/package.json +1 -1
package/index.js
CHANGED
@@ -16,14 +16,14 @@ console.log(line)
|
|
16
16
|
console.log(`${decor}( ${GREEN}reactful${RESET}.js )${decor}`)
|
17
17
|
console.log(line)
|
18
18
|
|
19
|
-
const templates = [
|
19
|
+
const templates = ['empty', 'minimal', 'sampling']
|
20
20
|
|
21
21
|
const questions = [
|
22
22
|
{
|
23
23
|
type: 'list',
|
24
24
|
name: 'template',
|
25
25
|
message: 'Which template?',
|
26
|
-
choices: templates,
|
26
|
+
choices: templates,
|
27
27
|
prefix
|
28
28
|
},
|
29
29
|
{ type: 'input', name: 'project', message: 'Project name?', prefix },
|
@@ -36,46 +36,42 @@ inquirer.prompt(questions).then(async function (answers) {
|
|
36
36
|
exec(`cd ${answers.project}`)
|
37
37
|
|
38
38
|
const destination = path.join(process.cwd(), answers.project)
|
39
|
-
const base = 'https://github.com/jsenaribeiro/reactful/installation/'
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
renamingJSON(destination, answers.project)
|
40
|
+
await downloadRepo(`common`, destination)
|
41
|
+
await downloadRepo(`templates/${answers.template}`, destination)
|
44
42
|
|
45
|
-
|
43
|
+
renamingJSON(destination, answers.project)
|
46
44
|
|
47
45
|
exec(`bun install`)
|
48
46
|
})
|
49
47
|
|
50
48
|
function renamingJSON(directory, projectName) {
|
51
49
|
const url = `${directory}/package.json`
|
52
|
-
const txt = fs.readFileSync(url, { encoding:'utf-8' })
|
50
|
+
const txt = fs.readFileSync(url, { encoding: 'utf-8' })
|
53
51
|
const obj = JSON.parse(txt)
|
54
52
|
|
55
53
|
obj.name = projectName
|
56
54
|
|
57
55
|
fs.writeFileSync(url, JSON.stringify(obj, null, 3))
|
56
|
+
|
57
|
+
console.log('')
|
58
58
|
}
|
59
59
|
|
60
|
-
async
|
60
|
+
const downloadRepo = async (subfolder, destination) =>
|
61
|
+
downloadGitHub('jsenaribeiro', 'reactful', subfolder, destination)
|
62
|
+
|
63
|
+
async function downloadGitHub(user, repository, subfolder, destination) {
|
64
|
+
const url = `https://api.github.com/repos/${user}/${repository}/contents/${subfolder}`
|
61
65
|
const resposta = await fetch(url)
|
62
66
|
const conteudo = await resposta.json()
|
63
|
-
|
67
|
+
|
64
68
|
for (const item of conteudo) {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}
|
69
|
+
if (item.type != 'file') continue
|
70
|
+
|
71
|
+
const filename = path.join(destination, item.name)
|
72
|
+
const response = await fetch(item.download_url)
|
73
|
+
const filetext = await response.text()
|
74
|
+
|
75
|
+
fs.writeFileSync(filename, filetext)
|
73
76
|
}
|
74
|
-
|
75
|
-
|
76
|
-
async function copyScaffold(destination) {
|
77
|
-
const url = 'https://github.com/jsenaribeiro/reactful/installation/'
|
78
|
-
|
79
|
-
try { await downloadRepo(url, destination) }
|
80
|
-
catch (error) { console.error(error) }
|
81
|
-
}
|
77
|
+
}
|