-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incremental indexing support for api
- Loading branch information
1 parent
bf1d041
commit 72f69bc
Showing
11 changed files
with
416 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ node_modules | |
build | ||
drivers-output | ||
dist | ||
yarn-error.log | ||
tmp | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"singleQuote": true, | ||
"semi": false | ||
"semi": false, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Promise, all as waitForAllPromises } from 'bluebird' | ||
import S3 from 's3' | ||
import ora from 'ora' | ||
import humanSize from 'human-size' | ||
import http from 'http' | ||
import https from 'https' | ||
|
||
// To increase s3's download & upload dir perf | ||
http.globalAgent.maxSockets = https.globalAgent.maxSockets = 30 | ||
|
||
const { AWS_ACCESS_KEY, AWS_SECRET_KEY } = process.env | ||
|
||
const client = S3.createClient({ | ||
s3Options: { accessKeyId: AWS_ACCESS_KEY, secretAccessKey: AWS_SECRET_KEY } | ||
}) | ||
|
||
const jsonDocsDirDownloadOptions = { | ||
localDir: 'tmp/json-docs', | ||
s3Params: { Bucket: 'api-docs.emberjs.com', Prefix: 'json-docs' } | ||
} | ||
|
||
let revDocsDirDownloadOptions = { | ||
localDir: 'tmp/rev-index', | ||
s3Params: { Bucket: 'api-docs.emberjs.com', Prefix: 'rev-index' } | ||
} | ||
|
||
const syncDir = options => { | ||
return new Promise((resolve, reject) => { | ||
let sync = client.downloadDir(options) | ||
let progressIndicator = ora( | ||
`downloading ${options.s3Params.Prefix} docs` | ||
).start() | ||
|
||
sync.on('progress', () => { | ||
const { progressAmount, progressTotal } = sync | ||
progressIndicator.text = `Downloading json docs (${humanSize( | ||
progressAmount | ||
)} of ${humanSize(progressTotal)})` | ||
}) | ||
|
||
sync.on('end', () => { | ||
progressIndicator.succeed(`downloaded ${options.s3Params.Prefix} docs`) | ||
resolve() | ||
}) | ||
|
||
sync.on('error', err => { | ||
progressIndicator.fail() | ||
reject(err) | ||
}) | ||
}) | ||
} | ||
|
||
export default function downloadExistingDocsToLocal() { | ||
return waitForAllPromises([ | ||
syncDir(jsonDocsDirDownloadOptions), | ||
syncDir(revDocsDirDownloadOptions) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
import Bluebird from 'bluebird' | ||
import fs from 'file-system' | ||
import { resolve } from 'bluebird' | ||
import { | ||
emptyDirSync, | ||
existsSync, | ||
outputJsonSync, | ||
readJsonSync, | ||
rmdirSync, | ||
} from 'fs-extra' | ||
|
||
export function init(fileName) {} | ||
const outputFolder = './drivers-output' | ||
|
||
export function write(fileName, content) { | ||
return fs.writeFileSync( | ||
`./drivers-output/json/${fileName}.json`, | ||
JSON.stringify(content), | ||
'utf8' | ||
) | ||
function init() {} | ||
|
||
function write(indexName, content, projectName, version) { | ||
let fileName = `${outputFolder}/json/${projectName}/` | ||
fileName += version ? `${version}/${indexName}.json` : `${indexName}.json` | ||
|
||
return outputJsonSync(fileName, content, { spaces: 2 }) | ||
} | ||
|
||
function clear() { | ||
if (!existsSync(outputFolder)) { | ||
return resolve() | ||
} | ||
emptyDirSync(outputFolder) | ||
return resolve(rmdirSync(outputFolder)) | ||
} | ||
|
||
export function clear() { | ||
return Bluebird.resolve() | ||
function getPreviouslyIndexedVersions(projectName) { | ||
let fileName = `${outputFolder}/json/${projectName}/versions.json` | ||
|
||
if (!existsSync(fileName)) { | ||
return [] | ||
} | ||
|
||
let [{ versions }] = readJsonSync(fileName) | ||
return versions | ||
} | ||
|
||
export default { init, write, clear } | ||
export default { init, write, clear, getPreviouslyIndexedVersions } |
Oops, something went wrong.