@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.
Files changed (2) hide show
  1. package/index.js +22 -26
  2. 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 = [ 'empty', 'minimal', 'sampling' ]
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
- copyScaffold(`${base}/common`, destination)
42
- copyScaffold(`${base}/templates/${answers.template}`, destination)
43
- renamingJSON(destination, answers.project)
40
+ await downloadRepo(`common`, destination)
41
+ await downloadRepo(`templates/${answers.template}`, destination)
44
42
 
45
- console.log('')
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 function downloadRepo(url, destino) {
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
- if (item.type === 'file') {
66
- const arquivoUrl = item.download_url
67
- const arquivoNome = path.join(destino, item.name)
68
- const arquivoResposta = await fetch(arquivoUrl)
69
- const arquivoTexto = await arquivoResposta.text()
70
- fs.writeFileSync(arquivoNome, arquivoTexto)
71
- console.log(`Arquivo baixado: ${arquivoNome}`)
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactful/create",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "description": "reactful scafold tool",