-
Notifications
You must be signed in to change notification settings - Fork 727
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
trying to get generate-doc-examples.js working #2284
Open
anniegale9538
wants to merge
13
commits into
main
Choose a base branch
from
annieh/adding_doc_examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c5c0491
trying to get generate-doc-examples working
anniegale9538 e2106d3
using ts-standard
anniegale9538 a92c10f
removing standard and swapping back to using node instead of npx tsx
anniegale9538 4943771
formatting changes
anniegale9538 e6eb400
removing unnecessary eslint add
anniegale9538 15b27f8
trying to get generate-doc-examples working
anniegale9538 73d14c8
using ts-standard
anniegale9538 70fe962
removing standard and swapping back to using node instead of npx tsx
anniegale9538 e097c25
formatting changes
anniegale9538 a3fdac6
removing unnecessary eslint add
anniegale9538 cf352ed
Merge branch 'annieh/adding_doc_examples' of github.com:elastic/elast…
anniegale9538 f57ff8c
resolving Conversion of type error
anniegale9538 a50ba52
Merge branch 'main' into annieh/adding_doc_examples
anniegale9538 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,5 @@ test/bundlers/parcel-test/.parcel-cache | |
|
||
lib | ||
junit-output | ||
|
||
parsed-alternative-report.json |
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,11 +21,9 @@ | |||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* To run this generator you must have the | ||||||||||||||||||||||
* `alternatives_report.spec.json` placed in the root of this project. | ||||||||||||||||||||||
* To get the `alternatives_report.spec.json` you must run the script | ||||||||||||||||||||||
* to parse the original `alternatives_report.json`, which is not yet public | ||||||||||||||||||||||
* and lives in github.com/elastic/clients-team/tree/master/scripts/docs-json-generator | ||||||||||||||||||||||
* | ||||||||||||||||||||||
* `parsed-alternative-report.json` (not public) placed in the root of this project. | ||||||||||||||||||||||
* It lives in https://github.com/elastic/clients-flight-recorder/blob/main/recordings/docs/parsed-alternative-report.json | ||||||||||||||||||||||
|
||||||||||||||||||||||
* This script will remove the content of the `docs/doc_examples` folder and generate | ||||||||||||||||||||||
* all the files present in the `enabledFiles` list below. | ||||||||||||||||||||||
* You can run it with the following command: | ||||||||||||||||||||||
|
@@ -38,7 +36,7 @@ | |||||||||||||||||||||
const { join } = require('path') | ||||||||||||||||||||||
const { writeFileSync } = require('fs') | ||||||||||||||||||||||
const rimraf = require('rimraf') | ||||||||||||||||||||||
const standard = require('standard') | ||||||||||||||||||||||
const tsStandard = require('ts-standard') | ||||||||||||||||||||||
const dedent = require('dedent') | ||||||||||||||||||||||
|
||||||||||||||||||||||
const docsExamplesDir = join('docs', 'doc_examples') | ||||||||||||||||||||||
|
@@ -109,14 +107,14 @@ const enabledFiles = [ | |||||||||||||||||||||
'search/suggesters.asciidoc' | ||||||||||||||||||||||
] | ||||||||||||||||||||||
|
||||||||||||||||||||||
function generate () { | ||||||||||||||||||||||
async function generate () { | ||||||||||||||||||||||
rimraf.sync(join(docsExamplesDir, '*')) | ||||||||||||||||||||||
const examples = require(join(__dirname, '..', 'alternatives_report.spec.json')) | ||||||||||||||||||||||
const examples = require(join(__dirname, '..', 'parsed-alternative-report.json')) | ||||||||||||||||||||||
for (const example of examples) { | ||||||||||||||||||||||
if (example.lang !== 'console') continue | ||||||||||||||||||||||
if (!enabledFiles.includes(example.source_location.file)) continue | ||||||||||||||||||||||
|
||||||||||||||||||||||
const asciidoc = generateAsciidoc(example.parsed_source) | ||||||||||||||||||||||
const asciidoc = await generateAsciidoc(example.parsed_source) | ||||||||||||||||||||||
writeFileSync( | ||||||||||||||||||||||
join(docsExamplesDir, `${example.digest}.asciidoc`), | ||||||||||||||||||||||
asciidoc, | ||||||||||||||||||||||
|
@@ -125,7 +123,7 @@ function generate () { | |||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function generateAsciidoc (source) { | ||||||||||||||||||||||
async function generateAsciidoc (source) { | ||||||||||||||||||||||
let asciidoc = '// This file is autogenerated, DO NOT EDIT\n' | ||||||||||||||||||||||
asciidoc += '// Use `node scripts/generate-docs-examples.js` to generate the docs examples\n\n' | ||||||||||||||||||||||
let code = 'async function run (client) {\n// START\n' | ||||||||||||||||||||||
|
@@ -142,7 +140,15 @@ console.log(response${getResponsePostfix(i)}) | |||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
code += '// END\n}' | ||||||||||||||||||||||
const { results } = standard.lintTextSync(code, { fix: true }) | ||||||||||||||||||||||
const { results } = await new Promise((resolve, reject) => { | ||||||||||||||||||||||
tsStandard.lintText(code, { fix: true }, (err, result) => { | ||||||||||||||||||||||
if (err) { | ||||||||||||||||||||||
reject(err) | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
resolve(result) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
Comment on lines
+143
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to wrap this explicitly in a Promise. Since you made
Suggested change
|
||||||||||||||||||||||
code = results[0].output | ||||||||||||||||||||||
code = code.slice(code.indexOf('// START\n') + 9, code.indexOf('\n\n// END')) | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd switch back to what was already there just to keep things consistent. Pinning to an exact version is not ideal unless absolutely necessary.