Skip to content

Commit 0b809af

Browse files
chore: update default branch (#107)
* chore: add logs on seed (#101) * fix: add logs and sync save * fix: documentation * Update moment to version 2.26.0 (#106) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> * Update eslint-plugin-jest to version 23.13.1 (#104) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> * Update mongoose to version 5.9.15 (#105) Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: Márcio Vinícius Sena <contato@marciosena.com.br> Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
1 parent 3a61f57 commit 0b809af

4 files changed

Lines changed: 57 additions & 31 deletions

File tree

DOCUMENTATION.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@
205205
"name":"Gênesis",
206206
"author":"Moisés",
207207
"group":"Pentateuco",
208-
"version":"nvi"
209-
},
210-
"chapter": {
211-
"number": 1,
212-
"verses": 31
208+
"version":"nvi",
209+
"chapter": {
210+
"number": 1,
211+
"verses": 31
212+
}
213213
},
214214
"chapter": 1,
215215
"number": 1,

__test__/seeders/verse.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,38 @@ mongoose.connection.on('error', err => {
1616
console.error(`%s ${err}`, chalk.red('x'))
1717
})
1818

19-
const loadVerses = async (version) => {
20-
const { data, lang, name } = version
19+
let total = 0
20+
const verses = []
21+
const lang = 'pt'
22+
23+
function numberWithCommas (x) {
24+
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
25+
}
26+
27+
const saveAll = () => {
28+
const verse = verses.shift()
29+
const doc = new Verse(verse)
30+
doc.save((err, saved) => {
31+
if (err) throw err
32+
const nextVerse = verses[0]
33+
if (nextVerse && verse.book.abbrev[lang] !== nextVerse.book.abbrev[lang]) {
34+
console.log(' %s All verses off %s were saved. \n - %s verses to go.', chalk.green('✓'), chalk.blue(`${verse.book.abbrev[lang]}`), chalk.yellow(numberWithCommas(verses.length)))
35+
}
36+
--total ? saveAll() : process.exit()
37+
})
38+
}
39+
40+
const loadVerses = async (params) => {
41+
const { data, name } = params
2142
const bookList = await Book.find()
2243
const booksMap = {}
44+
2345
await bookList.map(book => (booksMap[book.abbrev[lang]] = book._id))
2446

2547
try {
2648
for (const book of data) {
2749
await book.chapters.map(async (chapter, chapterIndex) => {
28-
await chapter.map(async (verse, verseIndex) => {
50+
return chapter.map(async (verse, verseIndex) => {
2951
const newVerse = {
3052
book: {
3153
id: booksMap[book.abbrev] && booksMap[book.abbrev]._id,
@@ -38,18 +60,22 @@ const loadVerses = async (version) => {
3860
text: verse,
3961
version: name
4062
}
41-
await Verse.create(newVerse)
63+
verses.push(newVerse)
4264
})
4365
})
4466
}
4567
} catch (err) {
46-
console.log('Error', err)
68+
console.log(` - %s error - ${err}`, chalk.red('x'))
69+
} finally {
70+
console.log(' - %s verses will be persisted.', chalk.yellow(numberWithCommas(verses.length)))
71+
total = verses.length
72+
saveAll()
4773
}
4874
}
4975

76+
console.log('%s All verses will be deleted and registered again. \n %s There are more than %s verses, this can take a few minutes.', chalk.green('✓'), chalk.blue('-'), chalk.yellow('30,000'))
77+
5078
Verse.deleteMany({}, async () => {
51-
const versions = [
52-
{ data: nvi, name: 'nvi', lang: 'pt' }
53-
]
54-
loadVerses(versions[1])
79+
console.log(' %s All verses have been erased.', chalk.green('✓'))
80+
loadVerses({ data: nvi, name: 'nvi' })
5581
})

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"lint": "eslint ./",
1515
"dev": "nodemon --exec babel-node app.js",
1616
"start": "NODE_ENV=production babel-node app.js",
17-
"test:db:book": "babel-node __test__/seeders/book.js",
18-
"test:db:verse": "babel-node __test__/seeders/verse.js",
17+
"seed:book": "babel-node __test__/seeders/book.js",
18+
"seed:verse": "babel-node __test__/seeders/verse.js",
1919
"test": "jest --testTimeout=25000",
2020
"test:coverage": "jest --coverage --testTimeout=25000",
2121
"test:watch": "jest --watch --coverage --testTimeout=25000"
@@ -42,8 +42,8 @@
4242
"jest": "^24.9.0",
4343
"jsonwebtoken": "^8.5.1",
4444
"md5": "^2.2.1",
45-
"moment": "^2.25.3",
46-
"mongoose": "^5.9.14",
45+
"moment": "^2.26.0",
46+
"mongoose": "^5.9.15",
4747
"pug": "^2.0.4",
4848
"redis": "^3.0.2",
4949
"supertest": "^4.0.2"
@@ -55,7 +55,7 @@
5555
"eslint-plugin-import": "^2.20.2",
5656
"eslint-plugin-import-helpers": "^1.0.2",
5757
"eslint-plugin-node": "^11.1.0",
58-
"eslint-plugin-jest": "^23.11.0",
58+
"eslint-plugin-jest": "^23.13.1",
5959
"eslint-plugin-promise": "^4.2.1",
6060
"eslint-plugin-standard": "^4.0.1",
6161
"husky": "^3.1.0",

yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,10 +2667,10 @@ eslint-plugin-import@^2.20.2:
26672667
read-pkg-up "^2.0.0"
26682668
resolve "^1.12.0"
26692669

2670-
eslint-plugin-jest@^23.11.0:
2671-
version "23.11.0"
2672-
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.11.0.tgz#6e01d83ea74c1eefd60811655bbc288bd8ab2e7d"
2673-
integrity sha512-qedvh6mcMgoLFHjITtG40yKOCu5Fa1GMYesDOclU30ZvtVkf+DaH0fnCn1ysOX/QMdk2SGhQvxvYLowcLaM0GA==
2670+
eslint-plugin-jest@^23.13.1:
2671+
version "23.13.1"
2672+
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.13.1.tgz#b2ce83f76064ad8ba1f1f26f322b86a86e44148e"
2673+
integrity sha512-TRLJH6M6EDvGocD98a7yVThrAOCK9WJfo9phuUb0MJptcrOYZeCKzC9aOzZCD93sxXCsiJVZywaTHdI/mAi0FQ==
26742674
dependencies:
26752675
"@typescript-eslint/experimental-utils" "^2.5.0"
26762676

@@ -4832,10 +4832,10 @@ mkdirp@^0.5.1:
48324832
dependencies:
48334833
minimist "0.0.8"
48344834

4835-
moment@^2.25.3:
4836-
version "2.25.3"
4837-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.25.3.tgz#252ff41319cf41e47761a1a88cab30edfe9808c0"
4838-
integrity sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg==
4835+
moment@^2.26.0:
4836+
version "2.26.0"
4837+
resolved "https://registry.yarnpkg.com/moment/-/moment-2.26.0.tgz#5e1f82c6bafca6e83e808b30c8705eed0dcbd39a"
4838+
integrity sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw==
48394839

48404840
mongodb@3.5.7:
48414841
version "3.5.7"
@@ -4865,10 +4865,10 @@ mongoose-seed@^0.6.0:
48654865
lodash "~4.17.11"
48664866
path "~0.12.7"
48674867

4868-
mongoose@^5.9.14:
4869-
version "5.9.14"
4870-
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.9.14.tgz#73dff38457c254f6a0eff2741642a62c5138b4c8"
4871-
integrity sha512-LScxCruQv0YpU/9DasKdThd+3r3PFQbCgesmfa6g0pTDOIiD1A9N9OQsGYrDf+dyUksfLCxJYYF9qpBHLvS1tg==
4868+
mongoose@^5.9.15:
4869+
version "5.9.15"
4870+
resolved "https://registry.yarnpkg.com/mongoose/-/mongoose-5.9.15.tgz#935e157d1429c0702b71c5ecf0e6801faa771091"
4871+
integrity sha512-dGIDqaQkAJoLl7lsRLy70mDg+VcL1IPOHr/0f23MLF45PtnM5exRdmienfyVjdrSVGgTus+1sMUKef6vSnrDZg==
48724872
dependencies:
48734873
bson "^1.1.4"
48744874
kareem "2.3.1"

0 commit comments

Comments
 (0)