contador-de-metas 1.0.0 → 1.2.0

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 (3) hide show
  1. package/README.md +3 -0
  2. package/contador.js +47 -10
  3. package/package.json +29 -21
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Contador de Metas 📋
2
+
3
+ ## Como Usar?
package/contador.js CHANGED
@@ -1,21 +1,25 @@
1
- // import dependecies
2
- const fs = require("fs");
3
- const readline = require("readline");
1
+ #!/usr/bin/env node
2
+ // const fs = require("fs");
3
+ // const readline = require("readline");
4
+ import fs from "fs"
5
+ import readline from "readline"
4
6
 
5
- const rl = readline.createInterface({
7
+ const userInput = readline.createInterface({
6
8
  input: process.stdin,
7
9
  output: process.stdout,
8
10
  });
9
11
 
10
- // Cria uma função que retorna uma Promise para perguntar algo ao usuário
11
12
  const askQuestion = (question) => {
12
13
  return new Promise((resolve) => {
13
- rl.question(question, (answer) => {
14
+ userInput.question(question, (answer) => {
14
15
  resolve(answer);
15
16
  });
16
17
  });
17
18
  };
18
19
 
20
+ //Variáveis de configuração
21
+ const endOfToDo = "Nível atual: "
22
+
19
23
  // read the text and split it on new lines
20
24
  // const lines = fs.readFileSync("todo-18012025" + ".txt").toString().split("\r\n");
21
25
  const lines = fs.readFileSync(".todo-16112025" + ".txt").toString().split("\n");
@@ -46,6 +50,7 @@ const regexNovaMeta = /^[ \t]*-.*/;
46
50
  // linhas que começam com traços mas pode ter tabulações ou espaços antes.
47
51
 
48
52
  (async () => {
53
+
49
54
  for(let i = 0; i<lines.length; i+=1){
50
55
  if(lines[i].match(regexNovaMeta)){
51
56
  oldchanges.push(lines[i])
@@ -54,6 +59,7 @@ const regexNovaMeta = /^[ \t]*-.*/;
54
59
  }
55
60
  }
56
61
  console.log(contadorNovaMeta, "novas metas ontem.")
62
+
57
63
  const resposta1 = await askQuestion("Deseja continuar?")
58
64
 
59
65
  let updatedLines
@@ -80,6 +86,7 @@ const regexNovaMeta = /^[ \t]*-.*/;
80
86
  }
81
87
  }
82
88
  console.log(contadorConclusao, "concluídos ontem.")
89
+
83
90
  const resposta2 = await askQuestion("Deseja continuar?")
84
91
 
85
92
  if(resposta2 == 1 && resposta2 == 1){
@@ -95,15 +102,45 @@ const regexNovaMeta = /^[ \t]*-.*/;
95
102
  return line;
96
103
  });
97
104
  // console.log(updatedLines)
105
+
106
+ addNovoNivel(updatedLines, contadorConclusao, contadorNovaMeta);
98
107
 
99
- let txt = updatedLines.join("\n")
100
- // console.log(txt)
101
- fs.writeFileSync('Novo Documento' + '.txt', txt)
108
+ let filedata = updatedLines.join("\n")
109
+ // console.log(filedata, "o texto acima")
110
+ // console.log(updatedLines, "updatedlines")
111
+ fs.writeFileSync('Novo Documento' + '.txt', filedata)
102
112
  }
103
113
 
104
- rl.close()
114
+ userInput.close()
105
115
  console.log(oldchanges)
106
116
  console.log("-" + contadorConclusao + "-" + contadorNovaMeta + "-")
107
117
  })();
108
118
 
119
+ function addNovoNivel(lines, numConclusao, numNovaMeta){
120
+ for (let i = lines.length - 1; i >= 0; i--) {
121
+ const line = lines[i];
122
+
123
+ if (line.includes(endOfToDo)) {
124
+ const arrayStringsDoFim = line.match(/\d+/g); //inteiros
125
+ const arrayNumerosDoFim = arrayStringsDoFim.map(Number);
126
+
127
+ // console.log("antes:", lines[i])
128
+ lines[i] = endOfToDo + (arrayNumerosDoFim[0] + numConclusao) + "-" + (arrayNumerosDoFim[1] + numNovaMeta)
129
+ // console.log("depois:", lines[i])
130
+
131
+ console.log(JSON.stringify(lines[i-1]))
132
+ // lines[i-1].replace(/\\r/g, ("-" + numConclusao + "-" + numNovaMeta + "-" + '\n'))
133
+ lines[i-1] = lines[i-1].replace('\r', '') + (" -" + numConclusao + "-" + numNovaMeta + "-")
134
+ console.log(JSON.stringify(lines[i-1]))
135
+
136
+ addProximoDia(lines, i)
137
+
138
+ i = -1
139
+ }
140
+ }
141
+ }
142
+
143
+ function addProximoDia(lines, index){
144
+ lines.splice(index, 0, '')
145
+ }
109
146
 
package/package.json CHANGED
@@ -1,21 +1,29 @@
1
- {
2
- "name": "contador-de-metas",
3
- "version": "1.0.0",
4
- "description": "",
5
- "main": "contador.js",
6
- "type": "module",
7
- "files": ["contador.js"],
8
- "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/caio-venancio/contador-de-metas.git"
14
- },
15
- "author": "Caio Venâncio",
16
- "license": "ISC",
17
- "bugs": {
18
- "url": "https://github.com/caio-venancio/contador-de-metas/issues"
19
- },
20
- "homepage": "https://github.com/caio-venancio/contador-de-metas#readme"
21
- }
1
+ {
2
+ "name": "contador-de-metas",
3
+ "version": "1.2.0",
4
+ "description": "",
5
+ "main": "contador.js",
6
+ "type": "module",
7
+ "files": [
8
+ "contador.js"
9
+ ],
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/caio-venancio/contador-de-metas.git"
16
+ },
17
+ "author": "Caio Venâncio",
18
+ "license": "ISC",
19
+ "bugs": {
20
+ "url": "https://github.com/caio-venancio/contador-de-metas/issues"
21
+ },
22
+ "homepage": "https://github.com/caio-venancio/contador-de-metas#readme",
23
+ "dependencies": {
24
+ "contador-de-metas": "^1.0.0"
25
+ },
26
+ "bin": {
27
+ "contador": "./contador.js"
28
+ }
29
+ }