Skip to content

fix: ensure ember-data works properly #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions generate-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@ import minimist from 'minimist'
import path from 'path'
import 'hard-rejection/register'

import { apiDocsProcessor } from './main'

const argv = minimist(process.argv.slice(2))

const { project, version } = argv
const { project, version, install, build } = argv

const exit = function exit() {
console.log(...arguments)
process.exit(1)
}

const runCmd = async (cmd, path) => {
console.log(chalk.underline(`Running '${chalk.green(cmd)}'`))
const executedCmd = await execa(cmd, { cwd: path, shell: true })
console.log(chalk.underline(`Running '${chalk.green(cmd)}' in '${path}'`))
try {
const executedCmd = await execa(`cd ${path} && ${cmd}`, { shell: true })

if (executedCmd.failed) {
console.error(executedCmd.stderr)
if (executedCmd.failed) {
console.error(executedCmd.stdout)
console.error(executedCmd.stderr)
process.exit(1)

}
console.log(executedCmd.stdout + '\n')
} catch (error) {
console.log(error)
process.exit(1)
}

console.log(executedCmd.stdout + '\n')
}
;(async () => {
if (!project || !version) {
Expand Down Expand Up @@ -55,11 +63,15 @@ const runCmd = async (cmd, path) => {

let buildDocs = async projDirPath => {
checkIfProjectDirExists(projDirPath)
await runCmd('yarn', projDirPath)

console.log('\n\n')
if (install) {
await runCmd(project === 'ember' ? 'yarn' : 'pnpm install', projDirPath)
console.log('\n\n')
}

await runCmd(project === 'ember' ? 'yarn docs' : 'yarn workspace ember-data docs', projDirPath)
if (build) {
await runCmd(project === 'ember' ? 'yarn docs' : 'pnpm build:docs', projDirPath)
}

const projYuiDocFile = `tmp/s3-docs/v${version}/${project}-docs.json`
removeSync(projYuiDocFile)
Expand All @@ -81,13 +93,5 @@ const runCmd = async (cmd, path) => {

await buildDocs(dirMap[project])

await execa('yarn', [
'start',
'--project',
project,
'--version',
version,
'--ignorePreviouslyIndexedDoc',
'--no-sync'
]).stdout.pipe(process.stdout)
await apiDocsProcessor([project], [version], true, false, true)
})()
3 changes: 1 addition & 2 deletions lib/add-inherited-items.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import RSVP from 'rsvp'

export default function addInheritedItems(docSets) {
docSets.forEach(versionData => {
Expand Down Expand Up @@ -29,7 +28,7 @@ export default function addInheritedItems(docSets) {
})
})

return RSVP.resolve(docSets)
return Promise.resolve(docSets)
}

function getParents(klass, classes) {
Expand Down
3 changes: 1 addition & 2 deletions lib/add-since-tags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import RSVP from 'rsvp'

export default function addSinceTags(docSets) {
let versionIndex = Object.create(null)
Expand Down Expand Up @@ -44,7 +43,7 @@ export default function addSinceTags(docSets) {

classes.forEach(klass => (klass.since = versionIndex['class'][klass.name][0]))

return RSVP.resolve(docSets)
return Promise.resolve(docSets)
}

function sortVersionIndex(versionIndex) {
Expand Down
13 changes: 7 additions & 6 deletions lib/create-classes.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import RSVP from 'rsvp'
import saveDoc from './save-document'

export default (document, projectName, projectVersion) => {
export default async function (document, projectName, projectVersion) {
let things = document.data

return RSVP.map(things, klass => {
for (const klass of things) {
if (!klass.id) {
console.log(klass)
console.log(new Error('WHAT').stack)
process.exit(1)
}
let document = {
const doc = {
data: klass,
}

console.log(`Creating ${klass.id} in ${projectName}-${projectVersion}`)
return saveDoc(document, projectName, projectVersion)
}).then(() => document)
await saveDoc(doc, projectName, projectVersion)
}

return document
}
12 changes: 7 additions & 5 deletions lib/create-project-versions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import tojsonapi from 'yuidoc-to-jsonapi/lib/converter'
import RSVP from 'rsvp'
import saveDoc from './save-document'
import updateIDs from './update-with-versions-and-project'

export default function createProjectVersions(versions, projectName) {
return RSVP.map(versions, version => {
export default async function createProjectVersions(versions, projectName) {
const results = []
for (const version of versions) {
let jsonapidoc = updateIDs(tojsonapi(version.data), version.version)

let projectData = {
Expand Down Expand Up @@ -50,6 +50,8 @@ export default function createProjectVersions(versions, projectName) {
included: [projectData],
}

return saveDoc(versionDocument, projectName, version.version)
})
const result = await saveDoc(versionDocument, projectName, version.version)
results.push(result)
}
return results
}
6 changes: 2 additions & 4 deletions lib/fetch-yui-docs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import compareVersions from 'compare-versions'
import download from 'download'
import fs from 'fs-extra'
import { isEmpty, trim } from 'lodash'
import mkdirp from 'mkdirp'
import pkgVersions from 'pkg-versions'
import { all, resolve } from 'rsvp'

let filterValidVersions = (specificDocsVersion, ignorePreviouslyIndexedDoc) => version => {
let isCompatibleVersion =
Expand All @@ -20,7 +18,7 @@ let filterValidVersions = (specificDocsVersion, ignorePreviouslyIndexedDoc) => v

async function fetchYuiDocsFromNpm(projects, projectName, filterValidVersionsForRequestedDocs) {
if (!projects.includes(projectName)) {
return resolve()
return Promise.resolve()
}

let projectPkgMap = {
Expand All @@ -38,7 +36,7 @@ async function fetchYuiDocsFromNpm(projects, projectName, filterValidVersionsFor
getProjectFileUrl = v => `https://unpkg.com/ember-data@${v}/dist/docs/data.json`
}

return await all(
return await Promise.all(
versionsToProcess.map(async v => {
let url = getProjectFileUrl(v)
let targetDir = `tmp/s3-docs/v${v}`
Expand Down
38 changes: 25 additions & 13 deletions lib/markup.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import marked from 'marked'
import { marked } from 'marked'
import hljs from 'highlight.js'
import cheerio from 'cheerio'

marked.setOptions({
highlight: code => hljs.highlightAuto(code).value,
})

export default doc => {
doc.data.forEach(({ id, attributes }) => {
console.log(`Generating markup for ${id}`)
export default function (doc) {
console.log('transforming markup for document')
for (const data of doc.data) {
const { id, attributes } = data
console.log(`\tGenerating markup for ${id}`)

let description = attributes.description
try {
const description = attributes.description

if (description) {
attributes.description = highlight(description)
}
if (description) {
attributes.description = highlight(description)
}

replaceDescriptionFor(attributes.methods)
replaceDescriptionFor(attributes.properties)
replaceDescriptionFor(attributes.events)
})
// console.log('\tcompleted highlighting')

replaceDescriptionFor(attributes.methods)
replaceDescriptionFor(attributes.properties)
replaceDescriptionFor(attributes.events)
// console.log(`\tMarkup Generated for ${id}\n`)
} catch (e) {
console.log(`Error generating markup for ${id}`)
console.log(e)
process.exit(1)
}
}

console.log('completed markup transformation for document')
return doc
}

Expand All @@ -41,7 +53,7 @@ function highlight(description) {
return String.fromCharCode(dec)
})
}
let markedup = removeHLJSPrefix(marked(description))
let markedup = removeHLJSPrefix(marked.parse(description))
let $ = cheerio.load(markedup)

let codeBlocks = $('pre code')
Expand Down
5 changes: 2 additions & 3 deletions lib/modules-transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import RSVP from 'rsvp'

function addSubModulesParentAttribute(moduleObj) {
moduleObj.parent = moduleObj.is_submodule ? moduleObj.module : null
Expand Down Expand Up @@ -78,8 +77,8 @@ export default function transformModules(docSets) {
})
})
} catch (e) {
return RSVP.reject(e)
return Promise.reject(e)
}

return RSVP.resolve(docSets)
return Promise.resolve(docSets)
}
1 change: 0 additions & 1 deletion lib/normalize-ember-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import { Promise } from 'rsvp'
import { byType } from './filter-jsonapi-doc'

const missingDoc = ({ id, version }) => {
Expand Down
12 changes: 5 additions & 7 deletions lib/normalize-ids.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'lodash'
import RSVP from 'rsvp'
import saveDoc from './save-document'
import tojsonapi from 'yuidoc-to-jsonapi/lib/converter'
import updateIDs from './update-with-versions-and-project'
Expand Down Expand Up @@ -38,7 +37,7 @@ function filter176(project, version, { attributes }) {
return project !== 'ember' || parseInt(version.split('.')[1]) < 16 || attributes.name !== 'ember'
}

function normalizeIDs(pVersions, projectName) {
async function normalizeIDs(pVersions, projectName) {
let jsonapidocs = pVersions.map(({ data, version }) => {
Object.keys(data.modules).forEach(k => {
let modWithVer = data.modules[k]
Expand Down Expand Up @@ -115,16 +114,15 @@ function normalizeIDs(pVersions, projectName) {
}
})

let versionDocs = RSVP.map(projectVersions, projectVersion => {
for (const projectVersion of projectVersions) {
let doc = { data: projectVersion }

let version = projectVersion.attributes.version

return saveDoc(doc, projectName, version)
})
await saveDoc(doc, projectName, version)
}

let doc = { data: jsonapidoc.data.concat(projectVersions) }
return versionDocs.then(() => doc)
return { data: jsonapidoc.data.concat(projectVersions) }
}

export default normalizeIDs
2 changes: 0 additions & 2 deletions lib/rev-docs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import revFile from 'rev-file'
import fs from 'fs-extra'
import ora from 'ora'
import { Promise } from 'rsvp'
import { basename as getFileName } from 'path'
import { isArray } from 'lodash/lang'
import { singularize } from 'inflected'
Expand Down Expand Up @@ -60,7 +59,6 @@ function revProjVersionFiles(project, ver) {

fs.writeJsonSync(projVerRevFile, projVerRevContent)
opProgress.succeed('Revving done!')
Promise.resolve()
}

export default revProjVersionFiles
9 changes: 5 additions & 4 deletions lib/save-document.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fs from 'fs-extra'
import RSVP from 'rsvp'
import path from 'path'
import mkdirp from 'mkdirp'
import { pluralize } from 'inflected'
import chalk from 'chalk'

// updateOrCreate
export default function saveDoc(document, projectName, version = '') {
export default async function saveDoc(document, projectName, version = '') {
let documentPath = path.join(
'tmp',
'json-docs',
Expand All @@ -17,8 +17,9 @@ export default function saveDoc(document, projectName, version = '') {

let json = JSON.stringify(document, null, 2)

return new RSVP.Promise((resolve, reject) => {
if (document.data.id.length > 50) {
return new Promise((resolve, reject) => {
if ((version.startsWith('1.') || version.startsWith('0.')) && document.data.id.length > 50) {
console.log(chalk.red(`\n\n⚠️ Skipping writing document with id ${chalk.yellow(document.data.id)} because it's too long\n\n`))
// wtf ember 1.0 docs??
return resolve()
}
Expand Down
27 changes: 10 additions & 17 deletions lib/transform-yui-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ import transformModules from './modules-transform'
import addInheritedItems from './add-inherited-items'
import normalizeIDs from './normalize-ids'

export default function transformYuiObject(docs, projName) {
return transformModules(docs)
.then(d => {
console.log('transformed', d)
let doc = addInheritedItems(d)
console.log('added inherited')
return doc
})
.then(d => {
let doc = normalizeIDs(d, projName)
console.log('normalized ids')
return doc
})
.catch(e => {
console.error(e)
throw e
})
export default async function transformYuiObject(docs, projName) {
let d = await transformModules(docs)
console.log('\ttransformed yui object')
d = await addInheritedItems(d)
console.log('\tadded inherited')

d = await normalizeIDs(d, projName)
console.log('\tnormalized ids')

return d
}
Loading