Skip to content

Commit 2b81619

Browse files
committed
fix bugs
1 parent bc0533e commit 2b81619

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

lib/create-classes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export default async function (document, projectName, projectVersion) {
99
console.log(new Error('WHAT').stack)
1010
process.exit(1)
1111
}
12-
let document = {
12+
const doc = {
1313
data: klass,
1414
}
1515

1616
console.log(`Creating ${klass.id} in ${projectName}-${projectVersion}`)
17-
await saveDoc(document, projectName, projectVersion)
17+
await saveDoc(doc, projectName, projectVersion)
1818
}
1919

2020
return document

lib/save-document.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import fs from 'fs-extra'
22
import path from 'path'
33
import mkdirp from 'mkdirp'
44
import { pluralize } from 'inflected'
5+
import chalk from 'chalk'
56

67
// updateOrCreate
7-
export default function saveDoc(document, projectName, version = '') {
8+
export default async function saveDoc(document, projectName, version = '') {
89
let documentPath = path.join(
910
'tmp',
1011
'json-docs',
@@ -17,7 +18,8 @@ export default function saveDoc(document, projectName, version = '') {
1718
let json = JSON.stringify(document, null, 2)
1819

1920
return new Promise((resolve, reject) => {
20-
if (document.data.id.length > 50) {
21+
if ((version.startsWith('1.') || version.startsWith('0.')) && document.data.id.length > 50) {
22+
console.log(chalk.red(`\n\n⚠️ Skipping writing document with id ${chalk.yellow(document.data.id)} because it's too long\n\n`))
2123
// wtf ember 1.0 docs??
2224
return resolve()
2325
}

main.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ async function transformProject(project, projectName) {
5555
let existingDoc = `tmp/json-docs/${projectName}/projects/${projectName}.json`
5656
if (fs.existsSync(existingDoc)) {
5757
existingDoc = fs.readJsonSync(existingDoc)
58-
docToSave.data.relationships['project-versions'].data = docToSave.data.relationships[
59-
'project-versions'
60-
].data.concat(existingDoc.data.relationships['project-versions'].data)
58+
const newData = docToSave.data.relationships['project-versions'].data
59+
const oldData = existingDoc.data.relationships['project-versions'].data
60+
const updatedData = mergeById(newData, oldData)
61+
docToSave.data.relationships['project-versions'].data = updatedData
6162
}
6263

6364
remainingDocs.forEach(({ data }) => {
@@ -107,12 +108,14 @@ export async function apiDocsProcessor(
107108
let projRevFileContent = fs.readJsonSync(
108109
`tmp/json-docs/${project}/projects/${project}.json`
109110
)
111+
const availableVersions = []
110112
projRevFileContent.meta = {
111-
availableVersions: [],
113+
availableVersions,
112114
}
113115
projRevFileContent.data.relationships['project-versions'].data.forEach(({ id }) =>
114-
projRevFileContent.meta.availableVersions.push(id.replace(`${project}-`, ''))
116+
availableVersions.push(id.replace(`${project}-`, ''))
115117
)
118+
console.log({ project, availableVersions })
116119
fs.writeJsonSync(projRevFile, projRevFileContent)
117120
})
118121
)
@@ -122,3 +125,22 @@ export async function apiDocsProcessor(
122125
console.log('Done!')
123126
})
124127
}
128+
129+
function mergeById(arr1, arr2) {
130+
const seen = new Set()
131+
const result = []
132+
let maxLen = arr1.length > arr2.length ? arr1.length : arr2.length
133+
for (let i = 0; i < maxLen; i++) {
134+
if (i < arr1.length && !seen.has(arr1[i].id)) {
135+
result.push(arr1[i])
136+
seen.add(arr1[i].id)
137+
138+
}
139+
if (i < arr2.length && !seen.has(arr2[i].id)) {
140+
result.push(arr2[i])
141+
seen.add(arr2[i].id)
142+
}
143+
}
144+
145+
return result
146+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"ember-rfc176-data": "^0.3.12",
3838
"esm": "^3.2.25",
3939
"execa": "^2.0.4",
40+
"chalk": "^4.1.2",
4041
"fs-extra": "^8.1.0",
4142
"glob": "^7.1.4",
4243
"hard-rejection": "^2.1.0",

yarn.lock

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1:
9191
dependencies:
9292
color-convert "^1.9.0"
9393

94+
ansi-styles@^4.1.0:
95+
version "4.3.0"
96+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937"
97+
integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
98+
dependencies:
99+
color-convert "^2.0.1"
100+
94101
archive-type@^4.0.0:
95102
version "4.0.0"
96103
resolved "https://registry.yarnpkg.com/archive-type/-/archive-type-4.0.0.tgz#f92e72233056dfc6969472749c267bdb046b1d70"
@@ -292,6 +299,14 @@ chalk@^2.4.2:
292299
escape-string-regexp "^1.0.5"
293300
supports-color "^5.3.0"
294301

302+
chalk@^4.2.0:
303+
version "4.1.2"
304+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
305+
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
306+
dependencies:
307+
ansi-styles "^4.1.0"
308+
supports-color "^7.1.0"
309+
295310
chardet@^0.7.0:
296311
version "0.7.0"
297312
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
@@ -362,11 +377,23 @@ color-convert@^1.9.0:
362377
dependencies:
363378
color-name "1.1.3"
364379

380+
color-convert@^2.0.1:
381+
version "2.0.1"
382+
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
383+
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
384+
dependencies:
385+
color-name "~1.1.4"
386+
365387
366388
version "1.1.3"
367389
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
368390
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
369391

392+
color-name@~1.1.4:
393+
version "1.1.4"
394+
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
395+
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
396+
370397
371398
version "1.0.3"
372399
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
@@ -1203,6 +1230,11 @@ has-flag@^3.0.0:
12031230
version "3.0.0"
12041231
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
12051232

1233+
has-flag@^4.0.0:
1234+
version "4.0.0"
1235+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
1236+
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
1237+
12061238
has-symbol-support-x@^1.4.1:
12071239
version "1.4.2"
12081240
resolved "https://registry.yarnpkg.com/has-symbol-support-x/-/has-symbol-support-x-1.4.2.tgz#1409f98bc00247da45da67cee0a36f282ff26455"
@@ -2794,6 +2826,13 @@ supports-color@^5.3.0:
27942826
dependencies:
27952827
has-flag "^3.0.0"
27962828

2829+
supports-color@^7.1.0:
2830+
version "7.2.0"
2831+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-7.2.0.tgz#1b7dcdcb32b8138801b3e478ba6a51caa89648da"
2832+
integrity sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==
2833+
dependencies:
2834+
has-flag "^4.0.0"
2835+
27972836
table@^5.2.3:
27982837
version "5.4.1"
27992838
resolved "https://registry.yarnpkg.com/table/-/table-5.4.1.tgz#0691ae2ebe8259858efb63e550b6d5f9300171e8"

0 commit comments

Comments
 (0)