@reactful/create 0.0.64 → 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 +20 -25
  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,11 +36,10 @@ 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
- await copyScaffold(`${base}/common`, destination)
42
- await copyScaffold(`${base}/templates/${answers.template}`, destination)
43
-
40
+ await downloadRepo(`common`, destination)
41
+ await downloadRepo(`templates/${answers.template}`, destination)
42
+
44
43
  renamingJSON(destination, answers.project)
45
44
 
46
45
  exec(`bun install`)
@@ -48,7 +47,7 @@ inquirer.prompt(questions).then(async function (answers) {
48
47
 
49
48
  function renamingJSON(directory, projectName) {
50
49
  const url = `${directory}/package.json`
51
- const txt = fs.readFileSync(url, { encoding:'utf-8' })
50
+ const txt = fs.readFileSync(url, { encoding: 'utf-8' })
52
51
  const obj = JSON.parse(txt)
53
52
 
54
53
  obj.name = projectName
@@ -58,25 +57,21 @@ function renamingJSON(directory, projectName) {
58
57
  console.log('')
59
58
  }
60
59
 
61
- 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}`
62
65
  const resposta = await fetch(url)
63
66
  const conteudo = await resposta.json()
64
-
67
+
65
68
  for (const item of conteudo) {
66
- if (item.type === 'file') {
67
- const arquivoUrl = item.download_url
68
- const arquivoNome = path.join(destino, item.name)
69
- const arquivoResposta = await fetch(arquivoUrl)
70
- const arquivoTexto = await arquivoResposta.text()
71
- fs.writeFileSync(arquivoNome, arquivoTexto)
72
- console.log(`Arquivo baixado: ${arquivoNome}`)
73
- }
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)
74
76
  }
75
- }
76
-
77
- async function copyScaffold(destination) {
78
- const url = 'https://github.com/jsenaribeiro/reactful/installation/'
79
-
80
- try { await downloadRepo(url, destination) }
81
- catch (error) { console.error(error) }
82
- }
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactful/create",
3
- "version": "0.0.64",
3
+ "version": "0.0.65",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "description": "reactful scafold tool",