@reactful/create 0.0.64 → 0.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +25 -28
  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,23 @@ function renamingJSON(directory, projectName) {
58
57
  console.log('')
59
58
  }
60
59
 
61
- async function downloadRepo(url, destino) {
62
- const resposta = await fetch(url)
63
- const conteudo = await resposta.json()
64
-
65
- 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
- }
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}`
65
+ const content = await fetch(url).then(x => x.json())
66
+
67
+ console.log('- url', url)
68
+ console.log('- res', JSON.stringify(res))
69
+
70
+ for (const item of content) {
71
+ if (item.type != 'file') continue
72
+
73
+ const filename = path.join(destination, item.name)
74
+ const response = await fetch(item.download_url)
75
+ const filetext = await response.text()
76
+
77
+ fs.writeFileSync(filename, filetext)
74
78
  }
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
- }
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactful/create",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "description": "reactful scafold tool",